package Ġcom . art em che p . l iter ary clock . logic . view models Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . annotation . Ui Thread Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mediator LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . art em che p . l iter ary clock . analytics . Analytics Main Ċ import Ġcom . art em che p . l iter ary clock . logic . Single Live Event Ċ import Ġcom . art em che p . l iter ary clock . logic . live . Database State LiveData Ċ import Ġcom . art em che p . l iter ary clock . models . Moment Item Ċ import Ġcom . art em che p . l iter ary clock . models . Quote Item Ċ import Ġcom . art em che p . l iter ary clock . models . Time Ċ import Ġcom . art em che p . l iter ary clock . utils . ext . observe Once Ċ import Ġorg . kode in . di . instance Ċ Ċ /** Ċ Ġ* Ġ@ author ĠArt em ĠChe p urn oy Ċ Ġ*/ Ċ class ĠMain ViewModel ( application : ĠApplication ) Ġ: ĠBase ViewModel ( application ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġanalytics Ġby Ġinstance < Analytics Main >() ĊĊĠĠĠ Ġval Ġshare Quote Event Ġ= ĠSingle Live Event < Quote Item >() ĊĊĠĠĠ Ġval Ġedit Time Event Ġ= ĠSingle Live Event < Time >() ĊĊĠĠĠ Ġval Ġopen Url Event Ġ= ĠSingle Live Event < String >() ĊĊĠĠĠ Ġprivate Ġval ĠcurrentTime LiveData Ġby Ġinstance < LiveData < Time >>() ĊĊĠĠĠ Ġval Ġcustom Time LiveData Ġ= ĠMutable LiveData < Time >() ĊĊĠĠĠ Ġval Ġtime LiveData Ġ= ĠMed iator LiveData < Time >() ĊĠĠĠĠĠĠĠ Ġ. apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresolver Ġ= ĠObserver < Time > Ġ{ Ġ_ Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtime Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustom Time LiveData . value ?. take Unless Ġ{ Ġit . time Ġ< Ġ 0 Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: ĠcurrentTime LiveData . value ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtime ?. let (:: post Value ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Source ( currentTime LiveData , Ġresolver ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Source ( custom Time LiveData , Ġresolver ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġdatabase Is Updating LiveData Ġ= ĠDatabase State LiveData ( application ) ĊĊĠĠĠ Ġval Ġmoment LiveData Ġby Ġinstance < LiveData < Time >, ĠLive Data < Moment Item >>( arg Ġ= Ġtime LiveData ) ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠSets Ġthe Ġcustom Ġtime Ġif Ġthe Ġtime Ġis Ġnot Ġequal Ġto Ġthe Ġ[ current Ġtime ][ currentTime LiveData ], ĊĠĠĠĠ Ġ* Ġotherwise Ġclears Ġcustom Ġtime . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Ui Thread ĊĠĠĠ Ġfun Ġpost Time ( time : ĠTime ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvalue Ġ= Ġtime . take Unless Ġ{ ĠcurrentTime LiveData . value Ġ== Ġit Ġ} Ġ?: ĠTime (- 1 ) ĊĠĠĠĠĠĠĠ Ġcustom Time LiveData . value Ġ= Ġvalue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġedit Time () Ġ{ ĊĠĠĠĠĠĠĠ Ġtime LiveData . observe Once ( edit Time Event :: post Value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Ui Thread ĊĠĠĠ Ġfun Ġopen Quote ( quote : ĠQuote Item ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" http :// www . amazon . com / dp /${ quote . asin }". let ( open Url Event :: setValue ) ĊĠĠĠĠĠĠĠ Ġanalytics . log Quote Open ( quote ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Ui Thread ĊĠĠĠ Ġfun Ġshare Quote ( quote : ĠQuote Item ) Ġ{ ĊĠĠĠĠĠĠĠ Ġquote . let ( share Quote Event :: setValue ) ĊĠĠĠĠĠĠĠ Ġanalytics . log Quote Share ( quote ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ