package Ġio . github . jo a og ou ve ia 8 9 . open weather Ċ Ċ import Ġandroid . location . Location Ċ import Ġandroidx . lifecycle .* Ċ import Ġio . github . jo a og ou ve ia 8 9 . open weather . k tx . observe Once Vm Ċ import Ġio . github . jo a og ou ve ia 8 9 . open weather . weather _ data . Weather Data Repository Ċ import Ġio . github . jo a og ou ve ia 8 9 . open weather . weather _ data . Weather Location Manager Ċ import Ġio . github . jo a og ou ve ia 8 9 . open weather . weather _ data . local . entities . Weather Ċ import Ġio . github . jo a og ou ve ia 8 9 . open weather . weather _ information . Weather Fetching State Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ import Ġkotlin . math .* Ċ Ċ class ĠMain ViewModel ĊĠĠĠ Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġweather Repository : ĠWeather Data Repository , ĊĠĠĠ Ġprivate Ġval Ġweather Location Manager : ĠWeather Location Manager ): ĠViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġweather List : ĠList < Weather > ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ weather List ĊĊĠĠĠ Ġval Ġweather Fetching State : ĠLive Data < Weather Fetching State > ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ weather Fetching State ĊĊĠĠĠ Ġval Ġcity Name : ĠString ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġweather Location Manager . city Name ĊĊĠĠĠ Ġprivate Ġvar Ġ_ weather Fetching State Ġ= ĠMutable LiveData < Weather Fetching State >() ĊĊĠĠĠ Ġprivate Ġvar Ġ_ weather List Ġ= ĠlistOf < Weather >() ĊĊĠĠĠ Ġprivate Ġval Ġcurrent Location Observer Ġ= ĠObserver < Location >{ Ġcurrent Location Ġ-> ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġweather Repository . get Weather List ( current Location ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ weather Fetching State . post Value ( Weather Fetching State . Loading ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}. observe Once Vm ( weather List Observer ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġweather List Observer Ġ= ĠObserver < List < Weather >> Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( it Ġ== Ġnull Ġ|| Ġit . isEmpty ()) Ġreturn @ Observer Ġ// TODO Ġdo Ġsomething Ġhere Ġto Ġtell Ġthe Ġview Ġthat Ġit Ġhas Ġan Ġerror Ġduring Ġweather Ġfetching ĊĠĠĠĠĠĠĠ Ġ_ weather Fetching State . post Value ( Weather Fetching State . Success ) ĊĠĠĠĠĠĠĠ Ġ_ weather List Ġ= Ġit ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġrequire Updated Location (){ ĊĠĠĠĠĠĠĠ Ġweather Location Manager . request Location () ĊĠĠĠĠĠĠĠ Ġweather Location Manager . current Location . observe Fore ver ( current Location Observer ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Cle ared () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Cle ared () ĊĠĠĠĠĠĠĠ Ġweather Location Manager . current Location . remove Observer ( current Location Observer ) ĊĠĠĠ Ġ} Ċ }