package Ġcom . vik as . paging 3 . view . loader Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . lifecycle Scope Ċ import Ġandroidx . paging . Experimental Paging Api Ċ import Ġandroidx . recyclerview . widget . Grid LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . vik as . paging 3 . R Ċ import Ġcom . vik as . paging 3 . view . loader . adapter . Loader Dog go Image Adapter Ċ import Ġcom . vik as . paging 3 . view . loader . adapter . Loader State Adapter Ċ import Ġkotlinx . coroutines . flow . collect Latest Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . launch Ċ Ċ @ Experimental Paging Api Ċ class ĠLoader Fragment Ġ: ĠFragment ( R . layout . fragment _ loader ) Ġ{ ĊĊĠĠĠ Ġlateinit Ġvar Ġrv Dog go Loader : ĠRecyclerView ĊĠĠĠ Ġlateinit Ġvar Ġloader ViewModel : ĠLoader ViewModel ĊĠĠĠ Ġlateinit Ġvar Ġadapter : ĠLoader Dog go Image Adapter ĊĠĠĠ Ġlateinit Ġvar Ġloader State Adapter : ĠLoader State Adapter ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġinit Members () ĊĠĠĠĠĠĠĠ ĠsetUp Views ( view ) ĊĠĠĠĠĠĠĠ Ġfetch Dog go Images () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfetch Dog go Images () Ġ{ ĊĠĠĠĠĠĠĠ Ġlifecycle Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloader ViewModel . fetch Dog go Images (). distinct Until Changed (). collect Latest Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . submit Data ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit Members () Ġ{ ĊĠĠĠĠĠĠĠ Ġloader ViewModel Ġ= Ġdefault ViewModel Provider Factory . create ( Loader ViewModel :: class . java ) ĊĠĠĠĠĠĠĠ Ġadapter Ġ= ĠLoader Dog go Image Adapter () ĊĠĠĠĠĠĠĠ Ġloader State Adapter Ġ= ĠLoader State Adapter Ġ{ Ġadapter . retry () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠsetUp Views ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrv Dog go Loader Ġ= Ġview . findViewById ( R . id . rv Dog go Loader ) ĊĠĠĠĠĠĠĠ Ġrv Dog go Loader . layout Manager Ġ= ĠGrid LayoutManager ( context , Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġrv Dog go Loader . adapter Ġ= Ġadapter . with Load State Footer ( loader State Adapter ) ĊĠĠĠ Ġ} Ċ }