/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠGoogle ĠLLC Ċ Ġ* Ċ Ġ* Ġ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 Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttps :// 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 . google . samples . apps . ios ched . shared . data . config Ċ Ċ import Ġandroid . content . res . Resources . NotFoundException Ċ import Ġcom . google . firebase . remote config . Firebase Remote Config Ċ import Ġcom . google . firebase . remote config . Firebase Remote Config Settings Ċ import Ġcom . google . samples . apps . ios ched . model . Conference Wifi Info Ċ import Ġcom . google . samples . apps . ios ched . shared . Build Config Ċ import Ġcom . google . samples . apps . ios ched . shared . di . Io Dispatcher Ċ import Ġkotlinx . coroutines . Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . suspend C ancellable Coroutine Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġtim ber . log . Tim ber Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġjavax . inject . Inject Ċ import Ġkotlin . coroutines . resume Ċ Ċ class ĠRemote AppConfig DataSource Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġfirebase Remote Config : ĠFirebase Remote Config , ĊĠĠĠ Ġconfig Settings : ĠFirebase Remote Config Settings , ĊĠĠĠ Ġ@ Io Dispatcher Ġprivate Ġval Ġio Dispatcher : ĠCor outine Dispatcher Ċ ) Ġ: ĠApp Config DataSource Ġ{ ĊĊĠĠĠ Ġval Ġtimes Ġ= Ġmutable Map Of < String , ĠString >() ĊĊĠĠĠ Ġ// ĠSet Ġcache Ġexpiration Ġto Ġ 0 s Ġwhen Ġdebugging Ġto Ġallow Ġeasy Ġtesting , Ġotherwise ĊĠĠĠ Ġ// Ġuse Ġthe Ġdefault Ġvalue . ĊĠĠĠ Ġprivate Ġval Ġcache Expiry Seconds : ĠLong Ġ= Ġif Ġ( Build Config . DEBUG ) Ġ 0 Ġelse ĠDEFAULT _ CACHE _ EXPI RY _ S ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠDo Ġan Ġinitial Ġload Ġof Ġdefault Ġvalues ĊĠĠĠĠĠĠĠ Ġupdate Strings () ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . fetch ( cache Expiry Seconds ). add On Complete Listener Ġ{ Ġtask Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠAsync ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( task . is Successful ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfirebase Remote Config . activate (). add On Complete Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Strings () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Strings () Ġ{ ĊĠĠĠĠĠĠĠ ĠAg enda Timestamp s Key . values (). forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtimes [ it . key ] Ġ= Ġfirebase Remote Config . getString ( it . key ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġsync Strings () Ġ{ ĊĠĠĠĠĠĠĠ Ġwith Context ( io Dispatcher ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtask Ġ= Ġfirebase Remote Config . fetch ( cache Expiry Seconds ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuspend C ancellable Coroutine < Unit > Ġ{ Ġcontinuation Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtask . add On Complete Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfirebase Remote Config . activate (). add On Complete Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Strings () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontinuation . resume ( Unit ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}. add On Failure Listener Ġ{ Ġexception Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTim ber . w ( exception , Ġ" Sync Ġstrings Ġfailed ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtask . add On Failure Listener Ġ{ Ġexception Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTim ber . w ( exception , Ġ" Sync Ġstrings Ġfailed ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Timestamp ( key : ĠString ): ĠString Ġ= ĊĠĠĠĠĠĠĠ Ġtimes [ key ] Ġ?: Ġthrow ĠNotFound Exception (" Value Ġfor Ġ$ key Ġnot Ġfound ") ĊĊĠĠĠ Ġoverride Ġfun Ġget Wifi Info (): ĠConference Wifi Info Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConference Wifi Info ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġss id Ġ= Ġfirebase Remote Config . getString ( WIFI _ SSID _ KEY ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassword Ġ= Ġfirebase Remote Config . getString ( WIFI _ PASSWORD _ KEY ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġis Map Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( MAP _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Explore Ar Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( EXP LO RE _ AR _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis C odel abs Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( CODE LAB S _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Search Schedule Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( SEARCH _ SCHED ULE _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Search Using Room Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( SEARCH _ USING _ ROOM _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Assistant App Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( AS SIST ANT _ APP _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Reservation Feature Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( RESER V ATION _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġoverride Ġfun Ġis Feed Enabled (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġfirebase Remote Config . getBoolean ( FEED _ FEATURE _ ENABLED ) ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠW IFI _ SSID _ KEY Ġ= Ġ" wifi _ ssid " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠW IFI _ PASSWORD _ KEY Ġ= Ġ" wifi _ password " ĊĊĠĠĠĠĠĠĠ Ġconst Ġval ĠMAP _ FEATURE _ ENABLED Ġ= Ġ" map _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠEXP LO RE _ AR _ FEATURE _ ENABLED Ġ= Ġ" explore _ ar _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠCODE LAB S _ FEATURE _ ENABLED Ġ= Ġ" code labs _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠSEARCH _ SCHED ULE _ FEATURE _ ENABLED Ġ= Ġ" search _ schedule _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠSEARCH _ USING _ ROOM _ FEATURE _ ENABLED Ġ= Ġ" search _ using _ room _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠASS IST ANT _ APP _ FEATURE _ ENABLED Ġ= Ġ" io _ assistant _ app _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠRES ER V ATION _ FEATURE _ ENABLED Ġ= Ġ" reservation _ enabled " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠFE ED _ FEATURE _ ENABLED Ġ= Ġ" feed _ enabled " ĊĊĠĠĠĠĠĠĠ Ġval ĠDEFAULT _ CACHE _ EXPI RY _ S Ġ= ĠTimeUnit . MIN UTES . to Seconds ( 1 2 ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ enum Ġclass ĠAg enda Timestamp s Key ( val Ġkey : ĠString ) Ġ{ ĊĠĠĠ ĠBAD GE _ P ICK _ UP _ DAY 0 _ START _ TIME (" badge _ pick _ up _ day 0 _ start _ time "), ĊĠĠĠ ĠBAD GE _ P ICK _ UP _ DAY 0 _ END _ TIME (" badge _ pick _ up _ day 0 _ end _ time "), ĊĠĠĠ ĠBAD GE _ P ICK _ UP _ DAY 1 _ START _ TIME (" badge _ pick _ up _ day 1 _ start _ time "), ĊĠĠĠ ĠBAD GE _ P ICK _ UP _ DAY 1 _ END _ TIME (" badge _ pick _ up _ day 1 _ end _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 1 _ START _ TIME (" break fast _ day 1 _ start _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 1 _ END _ TIME (" break fast _ day 1 _ end _ time "), ĊĠĠĠ ĠGOOGLE _ KEY NOTE _ START _ TIME (" google _ key note _ start _ time "), ĊĠĠĠ ĠGOOGLE _ KEY NOTE _ END _ TIME (" google _ key note _ end _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 1 _ START _ TIME (" io _ store _ day 1 _ start _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 1 _ END _ TIME (" io _ store _ day 1 _ end _ time "), ĊĠĠĠ ĠL UNCH _ DAY 1 _ START _ TIME (" l unch _ day 1 _ start _ time "), ĊĠĠĠ ĠL UNCH _ DAY 1 _ END _ TIME (" l unch _ day 1 _ end _ time "), ĊĠĠĠ ĠDE VELO PER _ KEY NOTE _ START _ TIME (" developer _ key note _ start _ time "), ĊĠĠĠ ĠDE VELO PER _ KEY NOTE _ END _ TIME (" developer _ key note _ end _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 1 _ START _ TIME (" sessions _ day 1 _ start _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 1 _ END _ TIME (" sessions _ day 1 _ end _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 1 _ START _ TIME (" code labs _ day 1 _ start _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 1 _ END _ TIME (" code labs _ day 1 _ end _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 1 _ START _ TIME (" office _ hours _ day 1 _ start _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 1 _ END _ TIME (" office _ hours _ day 1 _ end _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 1 _ START _ TIME (" sandbox es _ day 1 _ start _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 1 _ END _ TIME (" sandbox es _ day 1 _ end _ time "), ĊĠĠĠ ĠAFTER _ DARK _ START _ TIME (" after _ dark _ start _ time "), ĊĠĠĠ ĠAFTER _ DARK _ END _ TIME (" after _ dark _ end _ time "), ĊĠĠĠ ĠBAD GE _ DEVICE _ P ICK _ UP _ DAY 2 _ START _ TIME (" badge _ device _ pick _ up _ day 2 _ start _ time "), ĊĠĠĠ ĠBAD GE _ DEVICE _ P ICK _ UP _ DAY 2 _ END _ TIME (" badge _ device _ pick _ up _ day 2 _ end _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 2 _ START _ TIME (" break fast _ day 2 _ start _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 2 _ END _ TIME (" break fast _ day 2 _ end _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 2 _ START _ TIME (" io _ store _ day 2 _ start _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 2 _ END _ TIME (" io _ store _ day 2 _ end _ time "), ĊĠĠĠ ĠL UNCH _ DAY 2 _ START _ TIME (" l unch _ day 2 _ start _ time "), ĊĠĠĠ ĠL UNCH _ DAY 2 _ END _ TIME (" l unch _ day 2 _ end _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 2 _ START _ TIME (" sessions _ day 2 _ start _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 2 _ END _ TIME (" sessions _ day 2 _ end _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 2 _ START _ TIME (" code labs _ day 2 _ start _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 2 _ END _ TIME (" code labs _ day 2 _ end _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 2 _ START _ TIME (" office _ hours _ day 2 _ start _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 2 _ END _ TIME (" office _ hours _ day 2 _ end _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 2 _ START _ TIME (" sandbox es _ day 2 _ start _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 2 _ END _ TIME (" sandbox es _ day 2 _ end _ time "), ĊĠĠĠ ĠCON CERT _ START _ TIME (" con cert _ start _ time "), ĊĠĠĠ ĠCON CERT _ END _ TIME (" con cert _ end _ time "), ĊĠĠĠ ĠBAD GE _ DEVICE _ P ICK _ UP _ DAY 3 _ START _ TIME (" badge _ device _ pick _ up _ day 3 _ start _ time "), ĊĠĠĠ ĠBAD GE _ DEVICE _ P ICK _ UP _ DAY 3 _ END _ TIME (" badge _ device _ pick _ up _ day 3 _ end _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 3 _ START _ TIME (" break fast _ day 3 _ start _ time "), ĊĠĠĠ ĠBRE AK FAST _ DAY 3 _ END _ TIME (" break fast _ day 3 _ end _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 3 _ START _ TIME (" io _ store _ day 3 _ start _ time "), ĊĠĠĠ ĠIO _ STORE _ DAY 3 _ END _ TIME (" io _ store _ day 3 _ end _ time "), ĊĠĠĠ ĠL UNCH _ DAY 3 _ START _ TIME (" l unch _ day 3 _ start _ time "), ĊĠĠĠ ĠL UNCH _ DAY 3 _ END _ TIME (" l unch _ day 3 _ end _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 3 _ START _ TIME (" sessions _ day 3 _ start _ time "), ĊĠĠĠ ĠS ESS IONS _ DAY 3 _ END _ TIME (" sessions _ day 3 _ end _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 3 _ START _ TIME (" code labs _ day 3 _ start _ time "), ĊĠĠĠ ĠCODE LAB S _ DAY 3 _ END _ TIME (" code labs _ day 3 _ end _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 3 _ START _ TIME (" office _ hours _ day 3 _ start _ time "), ĊĠĠĠ ĠOFF ICE _ HOUR S _ DAY 3 _ END _ TIME (" office _ hours _ day 3 _ end _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 3 _ START _ TIME (" sandbox es _ day 3 _ start _ time "), ĊĠĠĠ ĠS AN DB OX ES _ DAY 3 _ END _ TIME (" sandbox es _ day 3 _ end _ time "), Ċ } Ċ