/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 9 Ġsky do ves Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . sky do ves . all in one . view . ui . water dr ink Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . switch Map Ċ import Ġcom . sky do ves . all in one . R Ċ import Ġcom . sky do ves . all in one . extension . ml Ċ import Ġcom . sky do ves . all in one . models . Todo Type Ċ import Ġcom . sky do ves . all in one . models . entities . Todo Ċ import Ġcom . sky do ves . all in one . models . entities . Water Dr ink Ċ import Ġcom . sky do ves . all in one . persistence . preference . Preference Component _ Preference Component Ċ import Ġcom . sky do ves . all in one . persistence . room . dao . Todo Dao Ċ import Ġcom . sky do ves . all in one . persistence . room . dao . Water Dr ink Dao Ċ import Ġcom . sky do ves . all in one . utils . Absent LiveData Ċ import Ġcom . sky do ves . all in one . utils . Local Utils Ċ import Ġcom . sky do ves . all in one . utils . Water Dr ink Item Utils Ċ import Ġorg . th reet en . bp . Offset DateTime Ċ import Ġtim ber . log . Tim ber Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠWater Dr ink ViewModel Ġ@ Inject Ċ constructor ( ĊĠ Ġprivate Ġval Ġwater Dr ink Dao : ĠWater Dr ink Dao , ĊĠ Ġprivate Ġval Ġtodo Dao : ĠTodo Dao Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠ Ġprivate Ġval Ġsetting Ġ= ĠPreference Component _ Preference Component . getInstance (). Settings () ĊĠ Ġprivate Ġval Ġweather Ġ= ĠPreference Component _ Preference Component . getInstance (). We athers () ĊĊĠ Ġprivate Ġval Ġwater Dr ink LiveData : ĠMutable LiveData < Water Dr ink > Ġ= ĠMutable LiveData () ĊĠ Ġprivate Ġval Ġwater Dr inks : ĠLive Data < List < Water Dr ink >> ĊĊĠ Ġinit Ġ{ ĊĠĠĠ ĠTim ber . d (" injection ĠWater Dr ink ViewModel ") ĊĊĠĠĠ Ġwater Dr ink LiveData . value Ġ= ĠWater Dr ink Item Utils . get Dummy Water Dr ink () ĊĠĠĠ Ġwater Dr inks Ġ= Ġwater Dr ink LiveData . switch Map Ġ{ ĊĠĠĠĠĠ Ġwater Dr ink LiveData . value ?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġwater Dr ink Dao . get Water Dr ink sBy Date ( Water Dr ink Item Utils . getDate String ( Offset DateTime . now ())) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ?: ĠAbs ent LiveData . create () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget Water Goal () Ġ= Ġsetting . water Goal ĊĊĠ Ġfun Ġget Today Water Dr inks () Ġ= Ġwater Dr inks ĊĊĠ Ġfun Ġget Water Dr inks From Date ( date : ĠString ) Ġ= Ġwater Dr ink Dao . get Water Dr inks From Today ( date ) ĊĊĠ Ġfun Ġget Recommend Water () Ġ= Ġget Water Goal () Ġ+ ĠLocal Utils . get Recommend Dr ink By Air ( weather ) ĊĊĠ Ġfun Ġget Water Drop Color () Ġ= Ġsetting . water Color ĊĊĠ Ġfun Ġset Water Drop Color ( color : ĠInt ) Ġ= Ġsetting . put Water Color ( color ) ĊĊĠ Ġfun Ġtake Water Dr ink ( context : ĠContext , Ġwater Dr ink : ĠWater Dr ink ) Ġ{ ĊĠĠĠ Ġval Ġnow Ġ= ĠOffset DateTime . now () ĊĠĠĠ Ġwater Dr ink . time Stamp Ġ= Ġnow ĊĠĠĠ Ġwater Dr ink Dao . insert Water Dr ink ( water Dr ink ) ĊĠĠĠ Ġwater Dr ink LiveData . post Value ( water Dr ink ) ĊĠĠĠ Ġval Ġtodo Ġ= ĠTodo ( ĊĠĠĠĠĠĠĠ Ġid Ġ= Ġ 0 , ĊĠĠĠĠĠĠĠ Ġtime Stamp Ġ= Ġnow , ĊĠĠĠĠĠĠĠ Ġtitle Ġ= Ġcontext . getString ( R . string . label _ take _ water ), ĊĠĠĠĠĠĠĠ Ġcontents Ġ= Ġ"${ water Dr ink . amount . toString (). ml ()} Ġ${ context . getString ( R . string . label _ take _ water )} ", ĊĠĠĠĠĠĠĠ Ġcolor Ġ= ĠContext Compat . getColor ( context , ĠR . color . water Blue ), ĊĠĠĠĠĠĠĠ Ġicon Ġ= ĠWater Dr ink Item Utils . get Water Dr ink Icon ( water Dr ink . amount ), ĊĠĠĠĠĠĠĠ Ġprogress Ġ= Ġ 1 0 0 , ĊĠĠĠĠĠĠĠ Ġalarm Stamp Ġ= Ġnull , ĊĠĠĠĠĠĠĠ Ġtodo Type Ġ= ĠTodo Type . Water Dr ink . ordinal ) ĊĠĠĠ Ġtodo Dao . insert Todo ( todo ) ĊĠ Ġ} Ċ } Ċ