package Ġid . fa h riz al . mv v mand roid . presentation . home Ċ Ċ import Ġandroidx . annotation . String Res Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġdagger . h ilt . android . lifecycle . H ilt ViewModel Ċ import Ġid . fa h riz al . mv v mand roid . data . networking . Coroutine Dispatcher Provider Ċ import Ġid . fa h riz al . mv v mand roid . domain . schedule . model . Pr ay Schedule Request Ċ import Ġid . fa h riz al . mv v mand roid . domain . schedule . use case . Get Pr ay Schedules Ċ import Ġid . fa h riz al . mv v mand roid . util . Exception Parser Ċ import Ġid . fa h riz al . mv v mand roid . util . Time Util Ċ import Ġkotlinx . coroutines . flow . Mutable State Flow Ċ import Ġkotlinx . coroutines . flow . State Flow Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjava . util .* Ċ import Ġjavax . inject . Inject Ċ Ċ @ H ilt ViewModel Ċ class ĠHome ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġget Pr ay Schedules : ĠGet Pr ay Schedules , ĊĠĠĠ Ġprivate Ġval Ġcoroutine Dispatcher Provider : ĠCor outine Dispatcher Provider Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġ_ ui State Ġ= ĠMutable State Flow < Pr ay Ui State >( Pr ay Ui State . Empty ) ĊĠĠĠ Ġval Ġui State : ĠState Flow < Pr ay Ui State > Ġ= Ġ_ ui State ĊĊĠĠĠ Ġfun Ġget Pr ay Schedule () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ ui State . value Ġ= ĠPr ay Ui State . Loading ĊĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( coroutine Dispatcher Provider . IO ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcity Ġ= Ġ" J ak arta " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrequest Param Ġ= ĠPr ay Schedule Request ( city , Ġget Today Date ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Pr ay Schedules . execute ( request Param ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ ui State . value Ġ= ĠPr ay Ui State . Loaded ( Home Item Ui State ( city , Ġresult )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( error : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ ui State . value Ġ= ĠPr ay Ui State . Error ( Exception Parser . getMessage ( error )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Today Date () Ġ= ĠTime Util . get DateFormat ted ( Date ()) ĊĊĠĠĠ Ġsealed Ġclass ĠPr ay Ui State Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠEmpty Ġ: ĠPr ay Ui State () ĊĠĠĠĠĠĠĠ Ġobject ĠLoading Ġ: ĠPr ay Ui State () ĊĠĠĠĠĠĠĠ Ġclass ĠLoaded ( val Ġitem State : ĠHome Item Ui State ) Ġ: ĠPr ay Ui State () ĊĠĠĠĠĠĠĠ Ġclass ĠError (@ String Res Ġval Ġmessage : ĠInt ) Ġ: ĠPr ay Ui State () ĊĠĠĠ Ġ} Ċ }