package Ġcom . luc iang h imp u . match me fy . presentation Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġcom . luc iang h imp u . match me fy . app Services . Connectivity . Connectivity Service Ċ import Ġcom . luc iang h imp u . match me fy . app Services . Connectivity . Connectivity Service Listener Ċ import Ġcom . luc iang h imp u . match me fy . app Services . Preferences Service Ċ import Ġcom . luc iang h imp u . match me fy . data . data Models . User Ċ import Ġcom . luc iang h imp u . match me fy . presentation . search . Search Fragment Directions Ċ import Ġcom . luc iang h imp u . match me fy . utilities . Event Ċ import Ġcom . luc iang h imp u . match me fy . utilities . Preferences Constants . USER _ PROFILE _ KEY Ċ Ċ /** Ċ Ġ* ĠAssigned Ġto Ġthe Ġ[ MainActivity ] Ċ Ġ* ĠUsed Ġto Ġhandle Ġandroid Ġscenarios Ġlike ĠOn Activity Result Ċ Ġ* Ġbeing Ġcaught Ġin Ġthe ĠActivity Ġbut Ġthe Ġhandling Ġshould Ġbe Ġdone Ġin Ġa ĠFragment Ċ Ġ*/ Ċ class ĠMainActivity ViewModel ( ĊĠĠĠ Ġapplication : ĠApplication , ĊĠĠĠ Ġpreferences Service : ĠPreferences Service , ĊĠĠĠ Ġconnectivity Service : ĠConnect ivity Service Ċ ) Ġ: ĠBase ViewModel ( application , Ġpreferences Service ) Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġ_ connectivity Changed Event Ġ= ĠMutable LiveData < Event < Boolean >>() ĊĠĠĠ Ġval Ġconnectivity Changed Event : ĠLive Data < Event < Boolean >> ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ connectivity Changed Event ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġget Ġuser Ġprofile Ġfrom Ġpreferences ĠOR Ġredirect Ġto Ġlogin ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= Ġpreferences Service . getObject ( USER _ PROFILE _ KEY , ĠUser :: class ) ĊĠĠĠĠĠĠĠ Ġif Ġ( user Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate ( Search Fragment Directions . action Search Fragment To Login Fragment ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġconnectivity Service . set Connectivity Listener ( object Ġ: ĠConnect ivity Service Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Connectivity Changed ( has Connection : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ connectivity Changed Event . post Value ( Event ( has Connection )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ċ }