package Ġdev . ke ader . corre io str acker . view . home Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . lifecycle .* Ċ import Ġandroidx . work . Work Info Ċ import Ġdagger . h ilt . android . lifecycle . H ilt ViewModel Ċ import Ġdagger . h ilt . android . qual ifiers . ApplicationContext Ċ import Ġdev . ke ader . corre io str acker . model . Event Ċ import Ġdev . ke ader . corre io str acker . model . combine With Ċ import Ġdev . ke ader . corre io str acker . repository . Tracking Repository Ċ import Ġdev . ke ader . corre io str acker . work . Refresh Tracks Worker Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ Ċ @ H ilt ViewModel Ċ class ĠHome ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġrepository : ĠTracking Repository , ĊĠĠĠ Ġ@ ApplicationContext Ġcontext : ĠContext ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġtracks Ġ= Ġrepository . getAll Items With Tracks () ĊĊĠĠĠ Ġprivate Ġval Ġ_ event Navigate To Track Detail Ġ= ĠMutable LiveData < Event < String >>() ĊĠĠĠ Ġval Ġevent Navigate To Track Detail : ĠLive Data < Event < String >> ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ event Navigate To Track Detail ĊĊĠĠĠ Ġprivate Ġval Ġ_ event Swipe Refresh Running Ġ= ĠMutable LiveData ( false ) ĊĊĠĠĠ Ġprivate Ġval Ġ_ is Refresh Work Running Ġ= ĠTransform ations . map ( Refresh Tracks Worker . get Work Info LiveData ( context )) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( it . isEmpty ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn @ map Ġfalse ĊĠĠĠĠĠĠĠ Ġreturn @ map Ġit . first (). state Ġ== ĠWork Info . State . RUNNING ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġevent Refresh Running Ġ= Ġ_ is Refresh Work Running . combine With (_ event Swipe Refresh Running ) Ġ{ Ġa , Ġb Ġ-> ĊĠĠĠĠĠĠĠ Ġreturn @ combine With Ġa Ġ== Ġtrue Ġ|| Ġb Ġ== Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon Item Track Clicked ( code : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ event Navigate To Track Detail . value Ġ= ĠEvent ( code ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon Refresh Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ event Swipe Refresh Running . value Ġ= Ġtrue ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrepository . refresh Tracks () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ event Swipe Refresh Running . value Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ