/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 3 ĠSimon ĠV ig ĠTh erk ild sen Ċ Ġ* Ċ Ġ* Ġ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 Ġnet . sim on vt . c ath ode . sync . scheduler Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . work . Work Manager Ċ import Ġkotlinx . coroutines . launch Ċ import Ġnet . sim on vt . c ath ode . api . body . Sync Items Ċ import Ġnet . sim on vt . c ath ode . api . util . Time Utils Ċ import Ġnet . sim on vt . c ath ode . job queue . Job Manager Ċ import Ġnet . sim on vt . c ath ode . provider . helper . Season Database Helper Ċ import Ġnet . sim on vt . c ath ode . provider . helper . Show Database Helper Ċ import Ġnet . sim on vt . c ath ode . remote . action . shows . Add Season To History Ċ import Ġnet . sim on vt . c ath ode . remote . action . shows . Collect Season Ċ import Ġnet . sim on vt . c ath ode . remote . action . shows . Remove Season From History Ċ import Ġnet . sim on vt . c ath ode . settings . Tr akt Link Settings Ċ import Ġnet . sim on vt . c ath ode . work . enqueue Now Ċ import Ġnet . sim on vt . c ath ode . work . user . Sync W atched Shows Worker Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Singleton Ċ class ĠSe ason Task Scheduler Ġ@ Inject Ċ constructor ( ĊĠ Ġcontext : ĠContext , ĊĠ Ġjob Manager : ĠJob Manager , ĊĠ Ġprivate Ġval Ġwork Manager : ĠWork Manager , ĊĠ Ġprivate Ġval Ġshow Helper : ĠShow Database Helper , ĊĠ Ġprivate Ġval Ġseason Helper : ĠSe ason Database Helper Ċ ) Ġ: ĠBase Task Scheduler ( context , Ġjob Manager ) Ġ{ ĊĊĠ Ġfun ĠaddTo History Now ( season Id : ĠLong ) Ġ{ ĊĠĠĠ ĠaddTo History ( season Id , ĠSystem . currentTimeMillis ()) ĊĠ Ġ} ĊĊĠ Ġfun ĠaddTo History On Release ( season Id : ĠLong ) Ġ{ ĊĠĠĠ ĠaddTo History ( season Id , ĠSync Items . TIME _ RELEASE D ) ĊĠ Ġ} ĊĊĠ Ġfun ĠaddTo History ( season Id : ĠLong , Ġw atched At : ĠLong ) Ġ{ ĊĠĠĠ Ġval Ġiso When Ġ= ĠTime Utils . get Iso Time ( w atched At ) ĊĠĠĠ ĠaddTo History ( season Id , Ġiso When ) ĊĠ Ġ} ĊĊĠ Ġfun ĠaddTo History ( ĊĠĠĠ Ġseason Id : ĠLong , ĊĠĠĠ Ġyear : ĠInt , ĊĠĠĠ Ġmonth : ĠInt , ĊĠĠĠ Ġday : ĠInt , ĊĠĠĠ Ġhour : ĠInt , ĊĠĠĠ Ġminute : ĠInt ĊĠ Ġ) Ġ{ ĊĠĠĠ ĠaddTo History ( season Id , ĠTime Utils . get Millis ( year , Ġmonth , Ġday , Ġhour , Ġminute )) ĊĠ Ġ} ĊĊĠ Ġfun ĠaddTo History ( season Id : ĠLong , Ġw atched At : ĠString ) Ġ{ ĊĠĠĠ Ġscope . launch Ġ{ ĊĠĠĠĠĠ Ġvar Ġw atched Ġ= ĠSe ason Database Helper . WATCH ED _ RELEASE ĊĠĠĠĠĠ Ġif Ġ( Sync Items . TIME _ RELEASE D Ġ!= Ġw atched At ) Ġ{ ĊĠĠĠĠĠĠĠ Ġw atched Ġ= ĠTime Utils . get Millis ( w atched At ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġseason Helper . addTo History ( season Id , Ġw atched ) ĊĊĠĠĠĠĠ Ġif Ġ( Tr akt Link Settings . is Linked ( context )) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġshow Id Ġ= Ġseason Helper . get Show Id ( season Id ) ĊĠĠĠĠĠĠĠ Ġval Ġtr akt Id Ġ= Ġshow Helper . get Tr akt Id ( show Id ) ĊĠĠĠĠĠĠĠ Ġval Ġseason Number Ġ= Ġseason Helper . getNumber ( season Id ) ĊĠĠĠĠĠĠĠ Ġqueue ( Add Season To History ( tr akt Id , Ġseason Number , Ġw atched At )) ĊĠĠĠĠĠĠĠ Ġ// ĠNo Ġdocumentation Ġon Ġhow Ġexactly Ġthe Ġtr akt Ġendpoint Ġis Ġimplemented , Ġso Ġsync Ġafter . ĊĠĠĠĠĠĠĠ Ġwork Manager . enqueue Now ( Sync W atched Shows Worker :: class . java ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġremove From History ( season Id : ĠLong ) Ġ{ ĊĠĠĠ Ġscope . launch Ġ{ ĊĠĠĠĠĠ Ġseason Helper . remove From History ( season Id ) ĊĊĠĠĠĠĠ Ġif Ġ( Tr akt Link Settings . is Linked ( context )) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġshow Id Ġ= Ġseason Helper . get Show Id ( season Id ) ĊĠĠĠĠĠĠĠ Ġval Ġtr akt Id Ġ= Ġshow Helper . get Tr akt Id ( show Id ) ĊĠĠĠĠĠĠĠ Ġval Ġseason Number Ġ= Ġseason Helper . getNumber ( season Id ) ĊĠĠĠĠĠĠĠ Ġqueue ( Remove Season From History ( tr akt Id , Ġseason Number )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġset In Collection ( season Id : ĠLong , Ġin Collection : ĠBoolean ) Ġ{ ĊĠĠĠ Ġscope . launch Ġ{ ĊĠĠĠĠĠ Ġvar Ġcollected At : ĠString ? Ġ= Ġnull ĊĠĠĠĠĠ Ġvar Ġcollected At Millis Ġ= Ġ 0 L ĊĠĠĠĠĠ Ġif Ġ( in Collection ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcollected At Ġ= ĠTime Utils . get Iso Time () ĊĠĠĠĠĠĠĠ Ġcollected At Millis Ġ= ĠTime Utils . get Millis ( collected At ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġseason Helper . set IsIn Collection ( season Id , Ġin Collection , Ġcollected At Millis ) ĊĊĠĠĠĠĠ Ġif Ġ( Tr akt Link Settings . is Linked ( context )) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġshow Id Ġ= Ġseason Helper . get Show Id ( season Id ) ĊĠĠĠĠĠĠĠ Ġval Ġtr akt Id Ġ= Ġshow Helper . get Tr akt Id ( show Id ) ĊĠĠĠĠĠĠĠ Ġval Ġseason Number Ġ= Ġseason Helper . getNumber ( season Id ) ĊĠĠĠĠĠĠĠ Ġqueue ( Collect Season ( tr akt Id , Ġseason Number , Ġin Collection , Ġcollected At )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ