package Ġcom . example . cock tail catalog . views Ċ Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . lifecycle . lifecycle Scope Ċ import Ġandroidx . navigation . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . example . cock tail catalog . view models . Dr ink ViewModel Ċ import Ġcom . example . cock tail catalog . R Ċ import Ġcom . example . cock tail catalog . adapters . Dr ink ListAdapter Ċ import Ġcom . example . cock tail catalog . view models . Ingredient ViewModel Ċ import Ġkotlinx . android . synt hetic . main . dr ink _ history _ fragment .* Ċ import Ġkotlinx . android . synt hetic . main . fragment _ search _ results .* Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠD rink History Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġnew Instance () Ġ= ĠD rink History Fragment () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠD rink ViewModel ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġdrink ListAdapter : ĠD rink ListAdapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġview Manager : ĠRecyclerView . LayoutManager ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠViewModel Provider ( this ). get ( Dr ink ViewModel :: class . java ) ĊĠĠĠĠĠĠĠ Ġview Manager Ġ= ĠLinearLayoutManager ( require Context ()) ĊĠĠĠĠĠĠĠ Ġdrink ListAdapter Ġ= ĠD rink ListAdapter ( viewModel . listOf Dr inks ) Ġ{ Ġit Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . get Dr inks ById ( it . id ) Ġ{ Ġd Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠD rink ViewModel . selected Dr ink Ġ= Ġd ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview ?. find Nav Controller () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . navigate ( R . id . action _ dr ink History Fragment _ to _ dr ink Details Fragment ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠviewModel . get Recent Dr inks () ĊĊĊĊ ĊĠĠĠĠĠĠĠ ĠviewModel . listOf Dr inks . observe ( view Lifecycle Owner , Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdrink ListAdapter . notify DataSet Changed () ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . dr ink _ history _ fragment , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġre cyclerView Recent Dr inks . apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter Ġ= Ġdrink ListAdapter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= Ġview Manager ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊ Ċ }