package Ġcom . ud acity . aster oid radar . main Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Context Ċ import Ġandroid . net . Connectivity Manager Ċ import Ġandroid . net . Network Info Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . ud acity . aster oid radar . database . A ster oid Rad ar Database Ċ import Ġcom . ud acity . aster oid radar . domain . A ster oid Ċ import Ġcom . ud acity . aster oid radar . domain . Picture OfDay Ċ import Ġcom . ud acity . aster oid radar . repository . App Repository Ċ import Ġkotlinx . coroutines . launch Ċ import Ġtim ber . log . Tim ber Ċ Ċ class ĠMain ViewModel ( application : ĠApplication ) Ġ: ĠAndroid ViewModel ( application ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġdatabase Ġ= ĠA ster oid Rad ar Database . getInstance ( application ) ĊĠĠĠ Ġprivate Ġval Ġapp Repository Ġ= ĠApp Repository ( database ) ĊĠĠĠ Ġprivate Ġval Ġ_ navigate To Detail A ster oid Ġ= ĠMutable LiveData < A ster oid ?> () ĊĊĠĠĠ Ġval Ġaster oid List : ĠLive Data < List < A ster oid >> ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġapp Repository . aster oid List ĊĊĠĠĠ Ġval Ġimage : ĠLive Data < Picture OfDay > ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġapp Repository . current Image ĊĊĠĠĠ Ġval Ġnavigate To Detail A ster oid ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ navigate To Detail A ster oid ĊĊĠĠĠ Ġfun Ġon Navigate To Detail A ster oid Click ( aster oid : ĠA ster oid ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ navigate To Detail A ster oid . value Ġ= Ġaster oid ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon Navigate To Detail A ster oid Click () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ navigate To Detail A ster oid . value Ġ= Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ ĠTim ber . i (" init ĠViewModel ") ĊĠĠĠĠĠĠĠ Ġval Ġcm Ġ= Ġapplication . getSystem Service ( Context . CONNECT IVITY _ SERVICE ) Ġas ĠConnect ivity Manager ĊĠĠĠĠĠĠĠ Ġval Ġactive Network : ĠNetwork Info ? Ġ= Ġcm . active Network Info ĊĠĠĠĠĠĠĠ Ġif Ġ( active Network ?. isConnected Ġ== Ġtrue ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġapp Repository . refresh Image () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġapp Repository . refresh A ster oids () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ