/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 1 . Ġ- ĠLe bo gang ĠB ants ij ang Ċ Ġ* Ċ Ġ* ĠĠĠ Ġ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 . le bo gang . gens ys music . ui . local . view model Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . le bo gang . gens ys music . G ens ys App Ċ import Ġcom . le bo gang . gens ys music . database . local . Album Repository Ċ import Ġcom . le bo gang . gens ys music . database . local . F avour ite Repository Ċ import Ġcom . le bo gang . gens ys music . database . local . models . Album Ċ import Ġcom . le bo gang . gens ys music . database . local . models . F avour ite Ċ import Ġcom . le bo gang . gens ys music . database . local . scan . Local Content Ċ import Ġcom . le bo gang . gens ys music . database . local . scan . Media Store Observer Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠAlbum ViewModel ( private Ġval Ġalbum Repository : ĠAlbum Repository , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġfavour ite Repository : ĠF avour ite Repository ): ViewModel () Ġ{ ĊĠĠĠ Ġlateinit Ġvar Ġlocal Content : ĠLocal Content ĊĊĠĠĠ Ġprivate Ġval Ġmedia Store Observer Ġ= Ġobject Ġ: ĠMedia Store Observer (){ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Content Changed () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlocal Content . on Update () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Album s Preview () Ġ= Ġalbum Repository . get Album s Preview (). as LiveData () ĊĊĠĠĠ Ġfun Ġget Album s () Ġ= Ġalbum Repository . get Album s (). as LiveData () ĊĊĠĠĠ Ġfun Ġget F avour ite Album s () Ġ= Ġalbum Repository . getF avour ite Album s (). as LiveData () ĊĊĠĠĠ Ġfun Ġget Album s ( title : String ) Ġ= Ġalbum Repository . get Album s ( title ). as LiveData () ĊĊĠĠĠ Ġfun Ġget Album s ( id : Long ): LiveData < Album > Ġ= Ġalbum Repository . get Album s ( id ). as LiveData () ĊĊĠĠĠ Ġfun Ġget Album s ( name Array : Array < String >) Ġ= Ġalbum Repository . get Album s ( name Array ). as LiveData () ĊĊĠĠĠ Ġfun Ġadd Album ( album : ĠAlbum ) Ġ= ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( album . is F avour ite ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfavour ite Repository . add Media Id ( F avour ite ( album . id )) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfavour ite Repository . remove Media Id ( F avour ite ( album . id )) ĊĠĠĠĠĠĠĠ Ġalbum Repository . add Album ( album ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġregister Observer ( application : ĠG ens ys App ){ ĊĠĠĠĠĠĠĠ Ġlocal Content Ġ= Ġapplication . local Content ĊĠĠĠĠĠĠĠ Ġapplication . content Resolver . register Content Observer ( Local Content . Resolver Constants . AL BU M _ URI ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ, true , media Store Observer ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġunregister Observer ( application : ĠG ens ys App ){ ĊĠĠĠĠĠĠĠ Ġapplication . content Resolver . unregister Content Observer ( media Store Observer ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ