package Ġit . il ker . repeat card . ui . home Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . View . IN VISIBLE Ċ import Ġandroid . view . View . VISIBLE Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġit . il ker . repeat card . R Ċ import Ġit . il ker . repeat card . db . flash card . Flash card Ċ import Ġit . il ker . repeat card . ui . flash card detail . Flash card Detail Activity Ċ import Ġit . il ker . repeat card . ui . util . exhaustive Ċ import Ġorg . k oin . android . ext . android . inject Ċ Ċ class ĠHome Screen Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġhome ViewModel : ĠHome ViewModel Ġby Ġinject () ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlatest Cards Adapter : ĠHome Adapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlatest Quiz Results Adapter : ĠHome Adapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlatest Cards Listener : ĠHome Listener ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlatest Cards : ĠRecyclerView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlatest Quiz Results : ĠRecyclerView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġno Flash card Text : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġno Quiz Result Text : ĠTextView ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . home _ fragment , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġobserve ViewModel () ĊĠĠĠĠĠĠĠ Ġhome ViewModel . send ( Flash card Event . Load ) ĊĠĠĠĠĠĠĠ Ġsetup Views ( view ) ĊĠĠĠĠĠĠĠ Ġsetup RecyclerView ( view ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup Views ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġno Flash card Text Ġ= Ġview . findViewById ( R . id . no _ cards ) ĊĠĠĠĠĠĠĠ Ġno Quiz Result Text Ġ= Ġview . findViewById ( R . id . no _ quiz ) ĊĠĠĠĠĠĠĠ Ġno Flash card Text . visibility Ġ= ĠVIS IBLE ĊĠĠĠĠĠĠĠ Ġno Quiz Result Text . visibility Ġ= ĠVIS IBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup RecyclerView ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlatest Cards Ġ= Ġview . findViewById ( R . id . latest _ cards ) ĊĠĠĠĠĠĠĠ Ġlatest Quiz Results Ġ= Ġview . findViewById ( R . id . latest _ quiz _ results ) ĊĠĠĠĠĠĠĠ Ġlatest Cards . layout Manager Ġ= ĠLinearLayoutManager ( this . context ) ĊĠĠĠĠĠĠĠ Ġlatest Quiz Results . layout Manager Ġ= ĠLinearLayoutManager ( this . context ) ĊĊĠĠĠĠĠĠĠ Ġlatest Cards Listener Ġ= Ġobject Ġ: ĠHome Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcard Clicked ( flash card : ĠFlash card ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠFlash card Detail Activity . open Flash card Detail Activity ( view . context , Ġflash card . id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġlatest Cards Adapter Ġ= ĠHome Adapter ( latest Cards Listener ) ĊĠĠĠĠĠĠĠ Ġlatest Quiz Results Adapter Ġ= ĠHome Adapter ( latest Cards Listener ) ĊĠĠĠĠĠĠĠ Ġlatest Cards . adapter Ġ= Ġlatest Cards Adapter ĊĠĠĠĠĠĠĠ Ġlatest Quiz Results . adapter Ġ= Ġlatest Quiz Results Adapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġobserve ViewModel () Ġ{ ĊĠĠĠĠĠĠĠ Ġhome ViewModel . state . observe ( view Lifecycle Owner , ĠObserver Ġ{ Ġstate Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ( state ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠFlash card State . Error Ġ-> Ġshow Error () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠFlash card State . Success Ġ-> Ġshow Results ( state . flash cards ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}. exhaustive ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġno Flash card Text . visibility Ġ= ĠVIS IBLE ĊĠĠĠĠĠĠĠ Ġlatest Cards Adapter . submit List ( listOf ()) ĊĠĠĠĠĠĠĠ Ġlatest Cards Adapter . notify DataSet Changed () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Results ( flash cards : ĠList < Flash card >) Ġ{ ĊĠĠĠĠĠĠĠ Ġno Flash card Text . visibility Ġ= ĠIN VISIBLE ĊĠĠĠĠĠĠĠ Ġlatest Cards Adapter . submit List ( flash cards ) ĊĠĠĠĠĠĠĠ Ġlatest Cards Adapter . notify DataSet Changed () ĊĠĠĠ Ġ} Ċ } Ċ