package Ġde . nic id ien ase . chaos flix . touch . event details Ċ Ċ import Ġandroid . app . Download Manager Ċ import Ġandroid . arch . lifecycle . LiveData Ċ import Ġandroid . arch . lifecycle . Mutable LiveData Ċ import Ġandroid . arch . lifecycle . ViewModel Ċ import Ġandroid . content . Context Ċ import Ġandroid . database . sqlite . SQLite Constraint Exception Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Environment Ċ import Ġandroid . util . Log Ċ import Ġde . nic id ien ase . chaos flix . common . entities . Ch aos flix Database Ċ import Ġde . nic id ien ase . chaos flix . common . entities . download . Offline Event Ċ import Ġde . nic id ien ase . chaos flix . common . entities . recording . persistence . Persistent Conference Ċ import Ġde . nic id ien ase . chaos flix . common . entities . recording . persistence . Persistent Event Ċ import Ġde . nic id ien ase . chaos flix . common . entities . recording . persistence . Persistent Recording Ċ import Ġde . nic id ien ase . chaos flix . common . entities . userdata . Watch list Item Ċ import Ġde . nic id ien ase . chaos flix . common . network . Recording Service Ċ import Ġde . nic id ien ase . chaos flix . common . network . Streaming Service Ċ import Ġde . nic id ien ase . chaos flix . touch . Ch aos flix Application Ċ import Ġde . nic id ien ase . chaos flix . touch . Offline Item Manager Ċ import Ġde . nic id ien ase . chaos flix . touch . sync . Downloader Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġjava . io . File Ċ Ċ class ĠDetails ViewModel ( Ċĉ ĉ val Ġdatabase : ĠCh aos flix Database , Ċĉ ĉ val Ġrecording Api : ĠRecord ing Service , Ċĉ ĉ val Ġstreaming Api : ĠStreaming Service Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊ ĉ val Ġdown loader Ġ= ĠDown loader ( recording Api , Ġdatabase ) Ċ ĉ var Ġwrite External Storage Allowed : ĠBoolean Ġ= Ġfalse Ċ ĉ val Ġoffline Item Manager : ĠOff line Item Manager Ġ= ĠOff line Item Manager () ĊĊ ĉ fun Ġget Event ById ( eventId : ĠLong ): ĠLive Data < Persistent Event > Ġ{ Ċĉ ĉ downloader . update Record ings For Event ( eventId ) Ċĉ ĉ return Ġdatabase . event Dao (). find Event ById ( eventId ) Ċ ĉ } ĊĊ ĉ fun Ġget Events ById s ( ids : ĠLong Array ) Ġ= Ġdatabase . event Dao (). find Events ById s ( ids ) ĊĊ ĉ fun Ġget Recording For Event ( id : ĠLong ): ĠLive Data < List < Persistent Recording >> Ġ{ Ċĉ ĉ downloader . update Record ings For Event ( id ) Ċĉ ĉ return Ġdatabase . recording Dao (). find Recording By Event ( id ) Ċ ĉ } ĊĊ ĉ fun Ġget Bookmark For Event ( id : ĠLong ): ĠLive Data < Watch list Item > Ġ= Ġdatabase . watch list Item Dao (). getItem For Event ( id ) ĊĊ ĉ fun Ġcreate Bookmark ( api Id : ĠLong ) Ġ{ Ċĉ ĉ Comp letable . from Action Ġ{ Ċĉĉ ĉ database . watch list Item Dao (). save Item ( Watch list Item ( eventId Ġ= Ġapi Id )) Ċĉ ĉ }. subscribe On ( Schedulers . io ()). subscribe () Ċ ĉ } ĊĊ ĉ fun Ġremove Bookmark ( api ID : ĠLong ) Ġ{ Ċĉ ĉ Comp letable . from Action Ġ{ Ċĉĉ ĉ database . watch list Item Dao (). delete Item ( api ID ) Ċĉ ĉ }. subscribe On ( Schedulers . io ()). subscribe () Ċ ĉ } ĊĊ ĉ fun Ġdownload ( event : ĠPersistent Event , Ġrecording : ĠPersistent Recording ) Ċĉĉ ĉ = Ġoffline Item Manager . download ( event , Ġrecording ) ĊĊ ĉ fun Ġget Offline Item ( eventId : ĠLong ) Ġ= Ġdatabase . offline Event Dao (). getBy EventId ( eventId ) ĊĊ ĉ fun Ġoffline Item Exists ( eventId : ĠLong ): ĠLive Data < Boolean > Ġ{ Ċĉ ĉ val Ġresult Ġ= ĠMutable LiveData < Boolean >() Ċĉ ĉ get Offline Item ( eventId ). observe Fore ver ({ Ġevent : ĠOff line Event ? Ġ-> Ċĉĉ ĉ result . post Value ( event Ġ!= Ġnull ) Ċĉ ĉ }) Ċĉ ĉ return Ġresult Ċ ĉ } ĊĊ ĉ fun Ġfile Exists ( eventId : ĠLong ): ĠLive Data < Boolean > Ġ{ Ċĉ ĉ val Ġresult Ġ= ĠMutable LiveData < Boolean >() Ċĉ ĉ get Offline Item ( eventId ). observe Fore ver ({ Ġevent : ĠOff line Event ? Ġ-> Ċĉĉ ĉ result . post Value ( if Ġ( event Ġ!= Ġnull ) ĠFile ( event . local Path ). exists () Ġelse Ġfalse ) Ċĉ ĉ }) Ċĉ ĉ return Ġresult Ċ ĉ } ĊĊ ĉ fun Ġdelete Offline Item ( item : ĠOff line Event ) Ġ{ Ċĉ ĉ Comp letable . from Action Ġ{ Ċĉĉ ĉ offline Item Manager . delete Offline Item ( item ) Ċĉ ĉ }. subscribe On ( Schedulers . io ()). subscribe () Ċ ĉ } ĊĊ ĉ fun Ġdelete Offline Item ( itemId : ĠLong ): ĠLive Data < Boolean > Ġ{ Ċĉ ĉ val Ġresult Ġ= ĠMutable LiveData < Boolean >() Ċĉ ĉ Comp letable . from Action Ġ{ Ċĉĉ ĉ val Ġoffline Event Ġ= Ġdatabase . offline Event Dao (). getBy EventId S ynchronous ( itemId ) Ċĉĉ ĉ delete Offline Item ( offline Event ); Ċĉĉ ĉ result . post Value ( true ); Ċĉ ĉ }. subscribe On ( Schedulers . io ()). subscribe () Ċĉ ĉ return Ġresult Ċ ĉ } ĊĊĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ val ĠTAG Ġ= ĠDetails ViewModel :: class . simple Name Ċ ĉ } Ċ }