package Ġcom . yo es uv . inf omal ang bat u . main . view models Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Intent Ċ import Ġandroidx . databinding . Observable Field Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġandroidx . room . Room Ċ import Ġcom . yo es uv . inf omal ang bat u . Build Config Ċ import Ġcom . yo es uv . inf omal ang bat u . R Ċ import Ġcom . yo es uv . inf omal ang bat u . data . App Constants Ċ import Ġcom . yo es uv . inf omal ang bat u . databases . App Database Ċ import Ġcom . yo es uv . inf omal ang bat u . databases . gallery . G aler i Room Ċ import Ġcom . yo es uv . inf omal ang bat u . databases . map . Map P ins Room Ċ import Ġcom . yo es uv . inf omal ang bat u . databases . place . Place Room Ċ import Ġcom . yo es uv . inf omal ang bat u . main . views . MainActivity Ċ import Ġcom . yo es uv . inf omal ang bat u . menu . gallery . models . Gallery Model Ċ import Ġcom . yo es uv . inf omal ang bat u . menu . list place . models . Place Model Ċ import Ġcom . yo es uv . inf omal ang bat u . menu . maps . models . Pin Model Ċ import Ġcom . yo es uv . inf omal ang bat u . networks . App Repository Ċ import Ġcom . yo es uv . inf omal ang bat u . utils . App Helper Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠSpl ash ViewModel ( application : ĠApplication ) Ġ: ĠAndroid ViewModel ( application ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġapp Repository Ġ= ĠApp Repository ( viewModel Scope ) ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġapp Database : ĠApp Database ĊĊĠĠĠ Ġvar Ġversion : ĠObservable Field < String > Ġ= ĠObservable Field () ĊĊĠĠĠ Ġfun Ġsetup Properties ( activity : ĠActivity ) Ġ{ ĊĠĠĠĠĠĠĠ Ġversion . set ( activity . getString ( R . string . info _ app _ version , ĠBuild Config . VERSION _ NAME )) ĊĠĠĠĠĠĠĠ Ġapp Database Ġ= ĠRoom . database Builder ( activity , ĠApp Database :: class . java , ĠApp Constants . DATABASE _ NAME ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. fallback To Dest ruct ive Migration () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġinit Data Base ( activity : ĠActivity ) Ġ{ ĊĠĠĠĠĠĠĠ Ġapp Repository . get AppData ({ Ġplaces , Ġg all eries , Ġpins Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsetup Places ( places ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsetup G all eries ( g all eries ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsetup Map P ins ( pins ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġopen Application ( activity ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApp Helper . display Toast Error ( activity , activity . getString ( R . string . toast _ error _ get _ list _ place )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . finish () ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġsetup Places ( places : ĠMutable List < Place Model > ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġapp Database . place Dao Access (). delete All Place () ĊĠĠĠĠĠĠĠ Ġplaces ?. forEach Ġ{ Ġplace Model Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġplace Room Ġ= ĠPlace Room ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġplace Model . name , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġplace Model . location , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġplace Model . description , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġplace Model . thumbnail , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġplace Model . image ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapp Database . place Dao Access (). insert Place ( place Room ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġsetup G all eries ( g all eries : ĠMutable List < Gallery Model > ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġapp Database . gallery Dao Access (). delete All Db Gallery () ĊĠĠĠĠĠĠĠ Ġg all eries ?. forEach Ġ{ gallery Model Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġg aler i Room Ġ= ĠG aler i Room ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgallery Model . caption , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgallery Model . thumbnail , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgallery Model . image ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapp Database . gallery Dao Access (). insert Db Gallery ( gal eri Room ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġsetup Map P ins ( pins : ĠMutable List < Pin Model > ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġapp Database . map Pin Dao Access (). delete All Db Map P ins () ĊĠĠĠĠĠĠĠ Ġpins ?. forEach Ġ{ Ġpin Model Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmap Pin Room Ġ= ĠMap P ins Room ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpin Model . name , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpin Model . location , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpin Model . latitude , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpin Model . longitude ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapp Database . map Pin Dao Access (). insert Db Map P ins ( map Pin Room ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġopen Application ( activity : ĠActivity ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( activity , ĠMainActivity :: class . java ) ĊĠĠĠĠĠĠĠ Ġintent . add Flags ( Intent . FLAG _ ACTIVITY _ CLEAR _ TASK ) ĊĠĠĠĠĠĠĠ Ġintent . add Flags ( Intent . FLAG _ ACTIVITY _ CLEAR _ TOP ) ĊĠĠĠĠĠĠĠ Ġactivity . startActivity ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity . finish () ĊĠĠĠ Ġ} Ċ }