package Ġcom . cr az yle g end . setof useful kotlin extensions . nav Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Toast Ċ import Ġandroid . widget . Toast . LENGTH _ LONG Ċ import Ġandroidx . core . view . isVisible Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . view Models Ċ import Ġcom . cr az yle g end . common . if True Ċ import Ġcom . cr az yle g end . fragment . view Coroutine Scope Ċ import Ġcom . cr az yle g end . internet detector . Internet Detector Ċ import Ġcom . cr az yle g end . lifecycle . repe ating Job On Started Ċ import Ġcom . cr az yle g end . ret rofit . ret rofit Result .* Ċ import Ġcom . cr az yle g end . ret rofit . ret rofit Result . on ApiError Ċ import Ġcom . cr az yle g end . ret rofit . throw ables . is No Connection Exception Ċ import Ġcom . cr az yle g end . ret rofit . view state .* Ċ import Ġcom . cr az yle g end . setof useful kotlin extensions . R Ċ import Ġcom . cr az yle g end . setof useful kotlin extensions . Test AV M Ċ import Ġcom . cr az yle g end . setof useful kotlin extensions . adapter . Test Model Ċ import Ġcom . cr az yle g end . setof useful kotlin extensions . adapter . Test View Binding Adapter Ċ import Ġcom . cr az yle g end . setof useful kotlin extensions . databinding . Fragment Test Binding Ċ import Ġcom . cr az yle g end . view . setIs Not Refresh ing Ċ import Ġcom . cr az yle g end . view . setIs Refresh ing Ċ import Ġcom . cr az yle g end . view . setOnClickListener Cooldown Ċ import Ġcom . cr az yle g end . view binding . view Binding Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ import Ġkotlinx . coroutines . flow . collect Ċ import Ġkotlinx . coroutines . launch Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠH rist ij an , Ġdate Ġ 2 / 1 5 / 2 1 Ċ Ġ*/ Ċ class ĠMV IF ragment Ġ: ĠFragment ( R . layout . fragment _ test ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġbinding Ġby Ġview Binding ( Fragment Test Binding :: bind ) ĊĊĠĠĠ Ġprivate Ġval Ġadapter Ġby Ġlazy Ġ{ ĠTest View Binding Adapter () Ġ} ĊĠĠĠ Ġprivate Ġval Ġinternet Detector Ġby Ġlazy Ġ{ ĠInternet Detector ( require Context ()) Ġ} ĊĠĠĠ Ġprivate Ġval Ġtest AV M Ġby Ġview Models < Test AV M >() ĊĊĠĠĠ Ġprivate Ġvar Ġsn ackBar : ĠSn ackbar ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġtoast : ĠToast ? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġbinding . recycler . adapter Ġ= Ġadapter ĊĊĠĠĠĠĠĠĠ Ġrepe ating Job On Started Ġ{ Ġtest AV M . posts . collect Ġ{ Ġretrofit Result Ġ-> Ġupdate UIState ( ret rofit Result ) Ġ} Ġ} ĊĠĠĠĠĠĠĠ Ġrepe ating Job On Started Ġ{ Ġtest AV M . view Event . collect Ġ{ Ġview Event Ġ-> Ġhandle View Events ( view Event ) Ġ} Ġ} ĊĊĠĠĠĠĠĠĠ Ġbinding . swipe To Refresh . setOn Refresh Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . swipe To Refresh . setIs Refresh ing () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtest AV M . get Posts () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . static Posts . setOnClickListener Cooldown Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtest AV M . getRandom Posts () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġhandle View Events ( view Event : ĠView Event ) Ġ{ ĊĠĠĠĠĠĠĠ Ġview Event . isError . and ( test AV M . is Data Loaded ). if True (:: show Error Sn ack ) ĊĠĠĠĠĠĠĠ Ġview Event . is ApiError . if True Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtoast ?. cancel () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtoast Ġ= ĠToast . makeText ( require Context (), Ġhandle ApiError ( test AV M . saved State Handle , Ġview Event . as ApiError Body ), ĠLEN GTH _ LONG ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtoast ?. show () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġupdate UIState ( ret rofit Result : ĠRet rofit Result < List < Test Model >>) Ġ{ ĊĠĠĠĠĠĠĠ Ġretrofit Result . getAs Throwable ?. let Ġ{ Ġthrowable Ġ-> Ġthrowable . is No Connection Exception . if True Ġ{ Ġretry On Internet Available ( throwable ) Ġ} Ġ} ĊĊĠĠĠĠĠĠĠ Ġ! ret rofit Result . isLoading . if True Ġ{ Ġbinding . swipe To Refresh . setIs Not Refresh ing () Ġ} ĊĠĠĠĠĠĠĠ Ġbinding . error . isVisible Ġ= Ġtest AV M . is Data Not Loaded Ġand Ġ( ret rofit Result . isError Ġ|| Ġretrofit Result . is ApiError ) ĊĠĠĠĠĠĠĠ Ġbinding . center Big Loading . isVisible Ġ= Ġretrofit Result . isLoading Ġand Ġtest AV M . is Data Not Loaded ĊĠĠĠĠĠĠĠ Ġbinding . progress . isVisible Ġ= Ġretrofit Result . isLoading Ġand Ġtest AV M . is Data Loaded ĊĠĠĠĠĠĠĠ Ġadapter . submit List ( test AV M . payload ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Error Sn ack () Ġ{ ĊĠĠĠĠĠĠĠ Ġsn ackBar ?. dismiss () ĊĠĠĠĠĠĠĠ Ġsn ackBar Ġ= ĠSn ackbar . make ( require View (), Ġ" Error Ġhas Ġoccurred ", ĠSn ackbar . LENGTH _ LONG ) ĊĠĠĠĠĠĠĠ Ġsn ackBar ?. show () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠĠĠĠĠ Ġsn ackBar Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġtoast Ġ= Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġretry On Internet Available ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthrowable . is No Connection Exception . if True Ġ{ Ġview Coroutine Scope . launch Ġ{ Ġobserve Internet Connectivity () Ġ} Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġobserve Internet Connectivity () Ġ{ ĊĠĠĠĠĠĠĠ Ġinternet Detector . state . collect Ġ{ Ġhas Connection Ġ-> Ġhas Connection . if True Ġ{ Ġtest AV M . get Posts () Ġ} Ġ} ĊĠĠĠ Ġ} Ċ Ċ }