package Ġcom . vik as . paging 3 . view . remote Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ 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 . remote . adapter . Remote Dog go Image Adapter Ċ import Ġkotlinx . coroutines . flow . collect Latest Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . launch Ċ Ċ /** Ċ Ġ* ĠView Ġto Ġfetch Ġthe Ġresults Ġfrom Ġthe Ġremote Ġapi Ġand Ġdirectly Ġshows Ġin Ġthe Ġre cycler view Ċ Ġ* Ġwith Ġlazy Ġpagination Ġenabled Ċ Ġ*/ Ċ @ Experimental Paging Api Ċ class ĠRemote Fragment Ġ: ĠFragment ( R . layout . fragment _ remote ) Ġ{ ĊĊĠĠĠ Ġlateinit Ġvar Ġrv Dog go Remote : ĠRecyclerView ĊĠĠĠ Ġlateinit Ġvar Ġremote ViewModel : ĠRemote ViewModel ĊĠĠĠ Ġlateinit Ġvar Ġadapter : ĠRemote Dog go Image 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 Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġremote ViewModel . fetch Dog go Images (). distinct Until Changed (). collect Latest Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . submit Data ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// call Ġthis Ġfor Ġrx java Ġobservable Ġbased Ġpaging ĊĠĠĠ Ġ@ Suppress Lint (" Check Result ") ĊĠĠĠ Ġprivate Ġfun Ġfetch Dog go Images Observable () Ġ{ ĊĠĠĠĠĠĠĠ Ġremote ViewModel . fetch Dog go Images Observable (). subscribe Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlifecycle Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . submit Data ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// call Ġthis Ġfor Ġlive Ġdata Ġbased Ġpaging ĊĠĠĠ Ġprivate Ġfun Ġfetch Dog go Images LiveData () Ġ{ ĊĠĠĠĠĠĠĠ Ġremote ViewModel . fetch Dog go Images LiveData (). observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlifecycle Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . submit Data ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit Members () Ġ{ ĊĠĠĠĠĠĠĠ Ġremote ViewModel Ġ= Ġdefault ViewModel Provider Factory . create ( Remote ViewModel :: class . java ) ĊĠĠĠĠĠĠĠ Ġadapter Ġ= ĠRemote Dog go Image Adapter () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠsetUp Views ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrv Dog go Remote Ġ= Ġview . findViewById ( R . id . rv Dog go Remote ) ĊĠĠĠĠĠĠĠ Ġrv Dog go Remote . layout Manager Ġ= ĠGrid LayoutManager ( context , Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġrv Dog go Remote . adapter Ġ= Ġadapter ĊĠĠĠ Ġ} Ċ }