package Ġcom . android . nik hil . world now . news . list Ċ Ċ import Ġandroid . arch . lifecycle . LiveData Ċ import Ġandroid . arch . lifecycle . Mutable LiveData Ċ import Ġandroid . arch . lifecycle . Transform ations Ċ import Ġcom . android . nik hil . world now . base . Base ViewModel Ċ import Ġcom . android . nik hil . world now . model . Result Ċ import Ġcom . android . nik hil . world now . repository . News Repository Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠNews View Modal Ġ@ Inject Ġconstructor () Ġ: ĠBase ViewModel () Ġ{ ĊĊĠ Ġprivate Ġvar Ġerror Ġ= ĠMutable LiveData < Boolean >() ĊĠ Ġ@ Inject Ġlateinit Ġvar Ġnews Repository : ĠNews Repository ĊĠ Ġprivate Ġvar Ġnews LiveData Ġ= ĠMutable LiveData < List < Result >>() ĊĊĠ Ġfun Ġget News () Ġ{ ĊĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠ Ġnews Repository . get News () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget News Data (): LiveData < List < Result >> Ġ= Ġnews LiveData ĊĊĠ Ġfun Ġget Error LiveData () Ġ= Ġerror ĊĊĠ Ġfun Ġobserve Repository () Ġ{ ĊĠĠĠ Ġnews LiveData Ġ= ĠTransform ations . switch Map ( news Repository . news List LiveData ) Ġ{ Ġresults List Ġ-> ĊĠĠĠĠĠ Ġval Ġdata Ġ= ĠMutable LiveData < List < Result >>() ĊĠĠĠĠĠ Ġdata . value Ġ= Ġresults List ĊĠĠĠĠĠ Ġdata ĊĠĠĠ Ġ} Ġas ĠMutable LiveData < List < Result >> ĊĠ Ġ} Ċ }