package Ġcom . l ind ung ises ama . ui . main . fragment . home Ċ Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġcom . l ind ung ises ama . R Ċ import Ġcom . l ind ung ises ama . config . AppConfig . DEFAULT _ TIMESTAMP _ FORMAT Ċ import Ġcom . l ind ung ises ama . model . response . Ret rofit Status Ċ import Ġcom . l ind ung ises ama . ui . guides . Guide Detail Activity Ċ import Ġcom . l ind ung ises ama . ui . guides . Guide Detail Activity . Companion . GUID E _ DETAIL _ DATA Ċ import Ġcom . l ind ung ises ama . ui . guides . Guide List Activity Ċ import Ġcom . l ind ung ises ama . ui . main . Main ViewModel Ċ import Ġcom . l ind ung ises ama . ui . main . fragment . home . adapter . Gu ides Adapter Ċ import Ġcom . l ind ung ises ama . ui . main . fragment . home . adapter . Gu ides ItemClickListener Ċ import Ġcom . l ind ung ises ama . ui . main . fragment . home . adapter . My th b usters Adapter Ċ import Ġcom . l ind ung ises ama . ui . main . fragment . home . adapter . My th b usters ItemClickListener Ċ import Ġcom . l ind ung ises ama . ui . my th b usters . My th b uster Detail Activity Ċ import Ġcom . l ind ung ises ama . ui . my th b usters . My th b uster Detail Activity . Companion . MY TH BU STER _ DETAIL _ DATA Ċ import Ġcom . l ind ung ises ama . ui . my th b usters . My th b uster List Activity Ċ import Ġcom . l ind ung ises ama . utils . ErrorHandler Ċ import Ġcom . the fin est artist . fin est webview . Fin est WebView Ċ import Ġkotlinx . android . synt hetic . main . layout _ covid _ current _ cases .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ current _ updates .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ guides .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ my th b usters .* Ċ import Ġorg . k oin . android . view model . ext . android . shared ViewModel Ċ import Ġjava . text . SimpleDateFormat Ċ import Ġjava . util .* Ċ Ċ class ĠHome Fragment Ġ: ĠFragment (), ĠGu ides ItemClickListener , ĠMy th b usters ItemClickListener Ġ{ ĊĊ ĉ private Ġval Ġmain ViewModel : ĠMain ViewModel Ġby Ġshared ViewModel () ĊĊ ĉ override Ġfun ĠonCreate View ( Ċĉ ĉ in flater : ĠLayoutInflater , Ċĉ ĉ container : ĠViewGroup ?, Ċĉ ĉ savedInstanceState : ĠBundle ? Ċ ĉ ): ĠView ? Ġ= Ġinflater . inflate ( R . layout . fragment _ home , Ġcontainer , Ġfalse ) ĊĊ ĉ override Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . on View Created ( view , ĠsavedInstanceState ) Ċĉ ĉ retain Instance Ġ= Ġtrue Ċĉ ĉ show Loading Current Cov id Case () Ċĉ ĉ show Gu ides Loading () Ċĉ ĉ show My th b usters Loading () Ċĉ ĉ context ?. let Ġ{ Ġcontext Ġ-> Ċĉĉ ĉ card _ current _ update _ 1 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 1 )) Ċĉĉ ĉ } Ċĉĉ ĉ card _ current _ update _ 2 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 2 )) Ċĉĉ ĉ } Ċĉĉ ĉ card _ current _ update _ 3 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 3 )) Ċĉĉ ĉ } Ċĉĉ ĉ card _ current _ update _ 4 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 4 )) Ċĉĉ ĉ } Ċĉĉ ĉ card _ current _ update _ 5 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 5 )) Ċĉĉ ĉ } Ċĉĉ ĉ card _ current _ update _ 6 . setOnClickListener Ġ{ Ċĉĉĉ ĉ Fin est WebView . Builder ( context ) Ċĉĉĉĉ ĉ . show ( resources . getString ( R . string . link _ current _ update _ 6 )) Ċĉĉ ĉ } Ċĉĉ ĉ button _ guides _ list . setOnClickListener Ġ{ Ċĉĉĉ ĉ startActivity ( Intent ( context , ĠGuide List Activity :: class . java )) Ċĉĉ ĉ } Ċĉĉ ĉ button _ my th b usters _ list . setOnClickListener Ġ{ Ċĉĉĉ ĉ startActivity ( Intent ( context , ĠMy th b uster List Activity :: class . java )) Ċĉĉ ĉ } Ċĉĉ ĉ val Ġguides Adapter Ġ= ĠGu ides Adapter ( context , Ġthis @ Home Fragment ) Ċĉĉ ĉ val Ġmy th b usters Adapter Ġ= ĠMy th b usters Adapter ( context , Ġthis @ Home Fragment ) Ċĉĉ ĉ guides _ recycler _ view . apply Ġ{ Ċĉĉĉ ĉ adapter Ġ= Ġguides Adapter Ċĉĉĉ ĉ layout Manager Ġ= ĠLinearLayoutManager ( context ) Ċĉĉĉ ĉ set Has Fixed Size ( true ) Ċĉĉ ĉ } Ċĉĉ ĉ my th b usters _ recycler _ view . apply Ġ{ Ċĉĉĉ ĉ adapter Ġ= Ġmy th b usters Adapter Ċĉĉĉ ĉ layout Manager Ġ= ĠLinearLayoutManager ( context ) Ċĉĉĉ ĉ set Has Fixed Size ( true ) Ċĉĉ ĉ } Ċĉĉ ĉ main ViewModel . current Case Response . observe ( view Lifecycle Owner , ĠObserver Ġ{ Ċĉĉĉ ĉ when Ġ( it . status ) Ġ{ Ċĉĉĉĉ ĉ Ret rofit Status . SUCCESS Ġ-> Ġit . data ?. let Ġ{ Ġdata Ġ-> Ċĉĉĉĉĉ ĉ txt _ covid _ current _ confirmed . text Ġ= Ċĉĉĉĉĉĉ ĉ if Ġ( data . cases Ġ!= Ġnull ) Ġdata . cases . toString () Ġelse Ġ"-" Ċĉĉĉĉĉ ĉ txt _ covid _ current _ recovery . text Ġ= Ċĉĉĉĉĉĉ ĉ if Ġ( data . active Ġ!= Ġnull ) Ġdata . active . toString () Ġelse Ġ"-" Ċĉĉĉĉĉ ĉ txt _ covid _ current _ re covered . text Ġ= Ċĉĉĉĉĉĉ ĉ if Ġ( data . re covered Ġ!= Ġnull ) Ġdata . re covered . toString () Ġelse Ġ"-" Ċĉĉĉĉĉ ĉ txt _ covid _ current _ death . text Ġ= Ċĉĉĉĉĉĉ ĉ if Ġ( data . deaths Ġ!= Ġnull ) Ġdata . deaths . toString () Ġelse Ġ"-" Ċĉĉĉĉĉ ĉ data . updated ?. let Ġ{ Ġtimestamp Ġ-> Ċĉĉĉĉĉĉ ĉ txt _ covid _ current _ timestamp . text Ġ= ĠgetString ( Ċĉĉĉĉĉĉĉ ĉ R . string . text _ current _ cases _ ref reshed _ time , Ċĉĉĉĉĉĉĉ ĉ convert TimeStamp To LocalDate ( timestamp ) Ċĉĉĉĉĉĉ ĉ ) Ċĉĉĉĉĉĉ ĉ txt _ covid _ current _ timestamp . visibility Ġ= ĠView . VISIBLE Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ else Ġ-> Ġ{ Ċĉĉĉĉĉ ĉ set Empty Current Cov id Case () Ċĉĉĉĉĉ ĉ activity ?. let Ġ{ Ġactivity Ġ-> Ċĉĉĉĉĉĉ ĉ ErrorHandler . show ( activity . support FragmentManager , Ġit . status ) Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉĉ ĉ hide Loading Current Cov id Case () Ċĉĉĉ ĉ if Ġ(! main ViewModel . guides Is Executed Ċĉĉĉĉ ĉ && Ġ! main ViewModel . guides Loaded Ċĉĉĉ ĉ ) Ġmain ViewModel . get Gu ides () Ċĉĉ ĉ }) Ċĉĉ ĉ main ViewModel . guides . observe ( view Lifecycle Owner , ĠObserver Ġ{ Ċĉĉĉ ĉ when Ġ( it . status ) Ġ{ Ċĉĉĉĉ ĉ Ret rofit Status . SUCCESS Ġ-> Ġit . data ?. let Ġ{ Ġdata Ġ-> Ċĉĉĉĉĉ ĉ guides Adapter . setData ( data ) Ċĉĉĉĉĉ ĉ hide Gu ides Loading () Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ else Ġ-> Ġactivity ?. let Ġ{ Ġactivity Ġ-> Ċĉĉĉĉĉ ĉ ErrorHandler . show ( activity . support FragmentManager , Ġit . status ) Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉĉ ĉ if Ġ(! main ViewModel . my th b usters Is Executed Ċĉĉĉĉ ĉ && Ġ! main ViewModel . my th b usters Loaded Ċĉĉĉ ĉ ) Ġmain ViewModel . get My th b usters () Ċĉĉ ĉ }) Ċĉĉ ĉ main ViewModel . my th b usters . observe ( view Lifecycle Owner , ĠObserver Ġ{ Ċĉĉĉ ĉ when Ġ( it . status ) Ġ{ Ċĉĉĉĉ ĉ Ret rofit Status . SUCCESS Ġ-> Ġit . data ?. let Ġ{ Ġdata Ġ-> Ċĉĉĉĉĉ ĉ my th b usters Adapter . setData ( data ) Ċĉĉĉĉĉ ĉ hide My th b usters Loading () Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ else Ġ-> Ġactivity ?. let Ġ{ Ġactivity Ġ-> Ċĉĉĉĉĉ ĉ ErrorHandler . show ( activity . support FragmentManager , Ġit . status ) Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ }) Ċĉĉ ĉ main ViewModel . prism ic Response . observe ( view Lifecycle Owner , ĠObserver Ġ{ Ċĉĉĉ ĉ if Ġ( it . status Ġ!= ĠRet rofit Status . SUCCESS ) Ġactivity ?. let Ġ{ Ġactivity Ġ-> Ċĉĉĉĉ ĉ ErrorHandler . show ( activity . support FragmentManager , Ġit . status ) Ċĉĉĉ ĉ } Ġelse Ġif Ġ(! main ViewModel . current Case Is Executed Ċĉĉĉĉ ĉ && Ġ! main ViewModel . current Case Loaded Ċĉĉĉ ĉ ) Ġmain ViewModel . getCurrent Case () Ċĉĉ ĉ }) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġshow Loading Current Cov id Case () Ġ{ Ċĉ ĉ txt _ covid _ current _ confirmed . visibility Ġ= ĠView . GONE Ċĉ ĉ loading _ covid _ current _ confirmed . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ txt _ covid _ current _ recovery . visibility Ġ= ĠView . GONE Ċĉ ĉ loading _ covid _ current _ recovery . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ txt _ covid _ current _ re covered . visibility Ġ= ĠView . GONE Ċĉ ĉ loading _ covid _ current _ re covered . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ txt _ covid _ current _ death . visibility Ġ= ĠView . GONE Ċĉ ĉ loading _ covid _ current _ death . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġset Empty Current Cov id Case () Ġ{ Ċĉ ĉ txt _ covid _ current _ confirmed . text Ġ= Ġ"-" Ċĉ ĉ txt _ covid _ current _ recovery . text Ġ= Ġ"-" Ċĉ ĉ txt _ covid _ current _ re covered . text Ġ= Ġ"-" Ċĉ ĉ txt _ covid _ current _ death . text Ġ= Ġ"-" Ċĉ ĉ txt _ covid _ current _ timestamp . visibility Ġ= ĠView . GONE Ċ ĉ } ĊĊ ĉ private Ġfun Ġhide Loading Current Cov id Case () Ġ{ Ċĉ ĉ loading _ covid _ current _ confirmed . visibility Ġ= ĠView . GONE Ċĉ ĉ txt _ covid _ current _ confirmed . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ loading _ covid _ current _ recovery . visibility Ġ= ĠView . GONE Ċĉ ĉ txt _ covid _ current _ recovery . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ loading _ covid _ current _ re covered . visibility Ġ= ĠView . GONE Ċĉ ĉ txt _ covid _ current _ re covered . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ loading _ covid _ current _ death . visibility Ġ= ĠView . GONE Ċĉ ĉ txt _ covid _ current _ death . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġshow Gu ides Loading () Ġ{ Ċĉ ĉ guides _ recycler _ view . visibility Ġ= ĠView . GONE Ċĉ ĉ guides _ loading . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġhide Gu ides Loading () Ġ{ Ċĉ ĉ guides _ loading . visibility Ġ= ĠView . GONE Ċĉ ĉ guides _ recycler _ view . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġshow My th b usters Loading () Ġ{ Ċĉ ĉ my th b usters _ recycler _ view . visibility Ġ= ĠView . GONE Ċĉ ĉ my th b usters _ loading . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġhide My th b usters Loading () Ġ{ Ċĉ ĉ my th b usters _ loading . visibility Ġ= ĠView . GONE Ċĉ ĉ my th b usters _ recycler _ view . visibility Ġ= ĠView . VISIBLE Ċ ĉ } ĊĊ ĉ private Ġfun Ġconvert TimeStamp To LocalDate ( timestamp : ĠLong ): ĠString Ġ= Ċĉ ĉ SimpleDateFormat ( DEFAULT _ TIMESTAMP _ FORMAT , ĠLocale . getDefault ()). format ( Date ( timestamp )) ĊĊ ĉ override Ġfun Ġon Gu ides Item Click ( result : Ġcom . l ind ung ises ama . model . raw . guides . Result ) Ġ{ Ċĉ ĉ startActivity ( Ċĉĉ ĉ Intent ( activity , ĠGuide Detail Activity :: class . java ) Ċĉĉĉ ĉ . putExtra ( GUID E _ DETAIL _ DATA , Ġresult ) Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon My th b usters Item Click ( result : Ġcom . l ind ung ises ama . model . raw . my th b usters . Result ) Ġ{ Ċĉ ĉ startActivity ( Ċĉĉ ĉ Intent ( activity , ĠMy th b uster Detail Activity :: class . java ) Ċĉĉĉ ĉ . putExtra ( MY TH BU STER _ DETAIL _ DATA , Ġresult ) Ċĉ ĉ ) Ċ ĉ } Ċ } Ċ