/* Ċ Copyright Ġ 2 0 2 1 ĠMat he us ĠM ene zes Ċ Ċ 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 Ġbr . com . math sem ilio . simple ap od browser . ui . screens . favorite apods list Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view .* Ċ import Ġandroidx . appcompat . widget . Search View Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġbr . com . math sem ilio . simple ap od browser . R Ċ import Ġbr . com . math sem ilio . simple ap od browser . common . util . on Query TextChanged Listener Ċ import Ġbr . com . math sem ilio . simple ap od browser . domain . model . Ap od Ċ import Ġbr . com . math sem ilio . simple ap od browser . domain . use case . favorite ap od . Fetch Ap ods Based On Search Query UseCase Ċ import Ġbr . com . math sem ilio . simple ap od browser . domain . use case . favorite ap od . Fetch Ap ods Based On Search Query UseCase . Fetch Ap od Based On Search QueryResult Ċ import Ġbr . com . math sem ilio . simple ap od browser . domain . use case . favorite ap od . Fetch Favorite Ap ods UseCase Ċ import Ġbr . com . math sem ilio . simple ap od browser . domain . use case . favorite ap od . Fetch Favorite Ap ods UseCase . Fetch Favorite Ap ods Result Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . common . Base Fragment Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . common . delegate . Container Layout Delegate Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . common . manager . Messages Manager Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . common . navigation . Scre ens Navigator Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . screens . favorite apods list . view . Favorite Ap ods Screen View Ċ import Ġbr . com . math sem ilio . simple ap od browser . ui . screens . favorite apods list . view . Favorite Ap ods Screen View Impl Ċ import Ġkotlinx . coroutines . Coroutine Scope Ċ import Ġkotlinx . coroutines . cancel Children Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠF avorite Ap ods Fragment Ġ: ĠBase Fragment (), ĠF avorite Ap ods Screen View . Listener Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġview : ĠF avorite Ap ods Screen View ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontainer Layout Delegate : ĠContainer Layout Delegate ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġscreens Navigator : ĠS cre ens Navigator ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmessages Manager : ĠMessages Manager ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcoroutine Scope : ĠCor outine Scope ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfetch Favorite Ap od UseCase : ĠFetch Favorite Ap ods UseCase ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfetch Ap ods Based On Search Query UseCase : ĠFetch Ap ods Based On Search Query UseCase ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġset Has Options Menu ( true ) ĊĊĠĠĠĠĠĠĠ Ġcontainer Layout Delegate Ġ= Ġcomposition Root . container Layout Delegate ĊĊĠĠĠĠĠĠĠ Ġscreens Navigator Ġ= ĠS cre ens Navigator ( find Nav Controller ()) ĊĠĠĠĠĠĠĠ Ġmessages Manager Ġ= Ġcomposition Root . messages Manager ĊĠĠĠĠĠĠĠ Ġcoroutine Scope Ġ= Ġcomposition Root . coroutine Scope Provider . UI Bound Scope ĊĊĠĠĠĠĠĠĠ Ġfetch Favorite Ap od UseCase Ġ= Ġcomposition Root . fetch Favorite Ap od UseCase ĊĠĠĠĠĠĠĠ Ġfetch Ap ods Based On Search Query UseCase Ġ= Ġcomposition Root . fetch Ap ods Based On Search Query UseCase ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠĠĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView Ġ{ ĊĠĠĠĠĠĠĠ Ġview Ġ= ĠF avorite Ap ods Screen View Impl ( in flater , Ġcontainer ) ĊĠĠĠĠĠĠĠ Ġreturn Ġview . root View ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Favorite Ap od Clicked ( favorite Ap od : ĠAp od ) Ġ{ ĊĠĠĠĠĠĠĠ Ġscreens Navigator . to Favorite Ap od Details Screen ( favorite Ap od ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfetch Favorite Ap ods () Ġ{ ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview . show Progress Indicator () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfetch Favorite Ap od UseCase . fetch Favorite Ap ods () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandle Fetch Favorite Ap ods Result ( result ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġhandle Fetch Favorite Ap ods Result ( result : ĠFetch Favorite Ap ods Result ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ( result ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠFetch Favorite Ap ods Result . Completed Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview . hide Progress Indicator () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresult . apods ?. let Ġ{ Ġview . bind ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFetch Favorite Ap ods Result . Failed Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview . hide Progress Indicator () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmessages Manager . show Unexpected Error Occurred Message () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate Options Menu ( menu : ĠMenu , Ġinflater : ĠMenu Inflater ) Ġ{ ĊĠĠĠĠĠĠĠ Ġinflater . inflate ( R . menu . toolbar _ ap od _ favorites , Ġmenu ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsearch View MenuItem Ġ= Ġmenu . find Item ( R . id . toolbar _ action _ search _ favorites ) ĊĠĠĠĠĠĠĠ Ġval Ġsearch View Ġ= Ġsearch View MenuItem . action View Ġas ĠSearch View ĊĊĠĠĠĠĠĠĠ Ġsearch View . on Query TextChanged Listener Ġ{ Ġsearch Query Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfetch Favorite Ap ods Based On Search Query ( search Query ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfetch Favorite Ap ods Based On Search Query ( search Query : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġfetch Ap ods Based On Search Query UseCase . fetch Ap ods Based On ( search Query ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandle Fetch Ap ods Based On Search QueryResult ( result ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġhandle Fetch Ap ods Based On Search QueryResult ( ĊĠĠĠĠĠĠĠ Ġresult : ĠFetch Ap od Based On Search QueryResult ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ( result ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠFetch Ap od Based On Search QueryResult . Completed Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview . hide Progress Indicator () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresult . matching Ap ods ?. let Ġ{ Ġview . bind ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFetch Ap od Based On Search QueryResult . Failed Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview . hide Progress Indicator () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Options ItemSelected ( item : ĠMenuItem ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwhen Ġ( item . itemId ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . toolbar _ action _ settings Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġscreens Navigator . to Settings Screen () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġsuper . on Options ItemSelected ( item ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonStart () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onStart () ĊĠĠĠĠĠĠĠ Ġview . addListener ( this ) ĊĠĠĠĠĠĠĠ Ġfetch Favorite Ap ods () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Stop () ĊĠĠĠĠĠĠĠ Ġview . remove Listener ( this ) ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . coroutine Context . cancel Children () ĊĠĠĠ Ġ} Ċ } Ċ