/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠT ai lo red ĠMedia ĠGmbH . Ċ Ġ* ĠCreated Ġby ĠFl orian ĠSch uster . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ġ*/ Ċ Ċ package Ġcom . ta ilo red apps . count rie sex ample . favorites Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . core . view . isVisible Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . lifecycle Scope Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġat . fl or ians ch uster . control . bind Ċ import Ġcom . ta ilo red apps . android ap pt emplate . base . ui . view Binding Ċ import Ġcom . ta ilo red apps . count rie sex ample . R Ċ import Ġcom . ta ilo red apps . count rie sex ample . all . Country Adapter Ċ import Ġcom . ta ilo red apps . count rie sex ample . all . Country Adapter Interaction Type Ċ import Ġcom . ta ilo red apps . count rie sex ample . databinding . Fragment F avorites Binding Ċ import Ġcom . ta ilo red apps . count rie sex ample . l ifts AppBar With Ċ import Ġcom . ta ilo red apps . count rie sex ample . remove L ifts AppBar With Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . flow . filter Is Instance Ċ import Ġkotlinx . coroutines . flow . launch In Ċ import Ġkotlinx . coroutines . flow . map Ċ import Ġorg . k oin . android . ext . android . inject Ċ import Ġorg . k oin . android x . view model . ext . android . viewModel Ċ Ċ class ĠF avorites View Ġ: ĠFragment ( R . layout . fragment _ favorites ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġbinding Ġby Ġview Binding ( Fragment F avorites Binding :: bind ) ĊĠĠĠ Ġprivate Ġval Ġnav Controller Ġby Ġlazy (:: find Nav Controller ) ĊĠĠĠ Ġprivate Ġval Ġadapter Ġby Ġinject < Country Adapter >() ĊĠĠĠ Ġprivate Ġval ĠviewModel Ġby ĠviewModel < F avorites ViewModel >() ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġbinding . rv F avorites . adapter Ġ= Ġadapter ĊĊĠĠĠĠĠĠĠ Ġadapter . interaction . filter Is Instance < Country Adapter Interaction Type . Detail Click >() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠF avorites View Directions . action F avorites To Detail ( it . id ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. bind ( to Ġ= Ġnav Controller :: navigate ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. launch In ( view Lifecycle Owner . lifecycle Scope ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġaction ĊĠĠĠĠĠĠĠ Ġadapter . interaction . filter Is Instance < Country Adapter Interaction Type . Favorite Click >() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠF avorites ViewModel . Action . Remove Favorite ( it . country ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. bind ( to Ġ= ĠviewModel :: dispatch ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. launch In ( view Lifecycle Owner . lifecycle Scope ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstate ĊĠĠĠĠĠĠĠ ĠviewModel . state . map Ġ{ Ġit . countries Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. distinct Until Changed () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. bind ( to Ġ= Ġadapter :: submit List ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. launch In ( view Lifecycle Owner . lifecycle Scope ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . state . map Ġ{ Ġit . countries . isEmpty () Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. distinct Until Changed () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. bind ( to Ġ= Ġbinding . empty Layout . empty Layout :: isVisible :: set ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. launch In ( view Lifecycle Owner . lifecycle Scope ) ĊĠĠĠĠĠĠĠ Ġbinding . empty Layout ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonStart () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onStart () ĊĠĠĠĠĠĠĠ Ġl ifts AppBar With ( binding . rv F avorites ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Stop () ĊĠĠĠĠĠĠĠ Ġremove L ifts AppBar With ( binding . rv F avorites ) ĊĠĠĠ Ġ} Ċ }