package Ġcom . ric ardo jr so usa . mov ook . presentation . main Ċ Ċ import Ġandroidx . h ilt . Ass isted Ċ import Ġandroidx . h ilt . lifecycle . ViewModel Inject Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Saved State Handle Ċ import Ġcom . ric ardo jr so usa . mov ook . core . data . Movie Ċ import Ġcom . ric ardo jr so usa . mov ook . framework . Movie Use Cases Ċ import Ġcom . ric ardo jr so usa . mov ook . presentation . Base ViewModel Ċ import Ġcom . ric ardo jr so usa . mov ook . utils . Single Live Event Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠMain ViewModel Ġ@ ViewModel Inject Ġconstructor (@ Ass isted Ġprivate Ġval Ġsaved State Handle : ĠSaved State Handle , Ġprivate Ġval Ġmovie Use Cases : ĠMovie Use Cases ) Ġ: ĠBase ViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġ_ movies InThe at res : ĠSingle Live Event < List < Movie >> Ġ= ĠSingle Live Event () ĊĠĠĠ Ġval Ġmovies InThe at res : ĠLive Data < List < Movie >> Ġ= Ġ_ movies InThe at res ĊĊĠĠĠ Ġprivate Ġvar Ġnow Playing Movies Current Page Ġ= Ġ 1 ĊĠĠĠ Ġprivate Ġvar Ġnow Playing Movies Total Pages Ġ= Ġ 0 ĊĠĠĠ Ġprivate Ġvar ĠisLoading Ġ= Ġfalse ĊĊĠĠĠ Ġprivate Ġval Ġ_ loaded Items : ĠMutable List < Movie > Ġ= Ġmutable ListOf () ĊĠĠĠ Ġval Ġloaded Items : ĠList < Movie > Ġ= Ġ_ loaded Items ĊĊĠĠĠ Ġprivate Ġval Ġ_ top R ated Movie Back drop : ĠMutable LiveData < String ?> Ġ= ĠMutable LiveData () ĊĠĠĠ Ġval Ġtop R ated Movie Back drop : ĠLive Data < String ?> Ġ= Ġ_ top R ated Movie Back drop ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġget Movies InThe at res ( now Playing Movies Current Page ) ĊĠĠĠĠĠĠĠ ĠgetRandom Back drop () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Movies InThe at res ( page : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġwrapper Ġ= Ġmovie Use Cases . get Movies InThe at res . invoke ( page ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġnow Playing Movies Total Pages Ġ= Ġwrapper . total Pages ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ movies InThe at res . post Value ( wrapper . results ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ loaded Items . addAll ( wrapper . results ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠisLoading Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġload Next Page Of Now Playing Movies () Ġ{ ĊĠĠĠĠĠĠĠ ĠisLoading Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġnow Playing Movies Current Page Ġ+= Ġ 1 ĊĠĠĠĠĠĠĠ Ġget Movies InThe at res ( now Playing Movies Current Page ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Last Page () Ġ= Ġnow Playing Movies Current Page Ġ== Ġnow Playing Movies Total Pages ĊĊĠĠĠ Ġfun ĠisLoading () Ġ= ĠisLoading ĊĊĠĠĠ Ġprivate Ġfun ĠgetRandom Back drop () Ġ{ ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġimage Ġ= Ġmovie Use Cases . get Top R ated Movies Back dro ps . invoke () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ top R ated Movie Back drop . post Value ( image ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ