diff --git a/app/src/main/java/dgca/verifier/app/android/data/local/DefaultEnginePreferences.kt b/app/src/main/java/dgca/verifier/app/android/data/local/DefaultEnginePreferences.kt new file mode 100644 index 00000000..d0b2ddbe --- /dev/null +++ b/app/src/main/java/dgca/verifier/app/android/data/local/DefaultEnginePreferences.kt @@ -0,0 +1,35 @@ +/* + * ---license-start + * eu-digital-green-certificates / dgca-verifier-app-android + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * 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. + * ---license-end + * + * Created by osarapulov on 11/15/21, 4:01 PM + */ + +package dgca.verifier.app.android.data.local + +import dgca.verifier.app.engine.data.source.local.EnginePreferences + +class DefaultEnginePreferences(private val preferences: Preferences): EnginePreferences { + override fun setLastCountriesSync(millis: Long) { + preferences.lastCountriesSyncTimeMillis = millis + } + + override fun getLastCountriesSync(): Long = preferences.lastCountriesSyncTimeMillis + + override fun getSelectedCountryIsoCode(): String? = preferences.selectedCountryIsoCode +} \ No newline at end of file diff --git a/app/src/main/java/dgca/verifier/app/android/data/local/Preferences.kt b/app/src/main/java/dgca/verifier/app/android/data/local/Preferences.kt index 19df4efa..58d4fef1 100644 --- a/app/src/main/java/dgca/verifier/app/android/data/local/Preferences.kt +++ b/app/src/main/java/dgca/verifier/app/android/data/local/Preferences.kt @@ -35,6 +35,8 @@ interface Preferences { var lastKeysSyncTimeMillis: Long + var lastCountriesSyncTimeMillis: Long + var selectedCountryIsoCode: String? var debugModeState: String? @@ -59,6 +61,13 @@ class PreferencesImpl(context: Context) : Preferences { KEY_LAST_KEYS_SYNC_TIME_MILLIS, -1 ) + + override var lastCountriesSyncTimeMillis by LongPreference( + preferences, + KEY_COUNTRIES_KEYS_SYNC_TIME_MILLIS, + -1 + ) + override var selectedCountryIsoCode: String? by StringPreference( preferences, KEY_SELECTED_COUNTRY_ISO_CODE @@ -80,6 +89,7 @@ class PreferencesImpl(context: Context) : Preferences { private const val USER_PREF = "dgca.verifier.app.pref" private const val KEY_RESUME_TOKEN = "resume_token" private const val KEY_LAST_KEYS_SYNC_TIME_MILLIS = "last_keys_sync_time_millis" + private const val KEY_COUNTRIES_KEYS_SYNC_TIME_MILLIS = "last_countries_sync_time_millis" private const val KEY_SELECTED_COUNTRY_ISO_CODE = "selected_country_iso_code" private const val KEY_DEBUG_MODE_STATE = "debug_mode_state" private const val KEY_DEBUG_MODE_SELECTED_COUNTRIES_CODES = diff --git a/app/src/main/java/dgca/verifier/app/android/data/local/countries/DefaultCountriesLocalDataSource.kt b/app/src/main/java/dgca/verifier/app/android/data/local/countries/DefaultCountriesLocalDataSource.kt index a1a1ff7f..0e7a5ca3 100644 --- a/app/src/main/java/dgca/verifier/app/android/data/local/countries/DefaultCountriesLocalDataSource.kt +++ b/app/src/main/java/dgca/verifier/app/android/data/local/countries/DefaultCountriesLocalDataSource.kt @@ -23,12 +23,15 @@ package dgca.verifier.app.android.data.local.countries import dgca.verifier.app.android.data.local.model.CountryLocal +import dgca.verifier.app.engine.data.source.local.EnginePreferences import dgca.verifier.app.engine.data.source.local.countries.CountriesLocalDataSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import java.util.* -class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) : CountriesLocalDataSource { +class DefaultCountriesLocalDataSource( + private val countriesDao: CountriesDao, private val enginePreferences: EnginePreferences +) : CountriesLocalDataSource { override suspend fun updateCountries(countriesIsoCodes: List) { countriesDao.apply { @@ -39,6 +42,10 @@ class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) : override fun getCountries(): Flow> = countriesDao.getAll().map { it.map { countryLocal -> countryLocal.toCountry() } } + + override fun getLastCountriesSync(): Long = enginePreferences.getLastCountriesSync() + + override fun getSelectedCountryIsoCode(): String? = enginePreferences.getSelectedCountryIsoCode() } fun String.toCountryLocal(): CountryLocal = CountryLocal(isoCode = toLowerCase(Locale.ROOT)) diff --git a/app/src/main/java/dgca/verifier/app/android/di/EngineModule.kt b/app/src/main/java/dgca/verifier/app/android/di/EngineModule.kt index a1d6de48..eefb2651 100644 --- a/app/src/main/java/dgca/verifier/app/android/di/EngineModule.kt +++ b/app/src/main/java/dgca/verifier/app/android/di/EngineModule.kt @@ -30,6 +30,8 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent +import dgca.verifier.app.android.data.local.DefaultEnginePreferences +import dgca.verifier.app.android.data.local.Preferences import dgca.verifier.app.android.data.local.countries.CountriesDao import dgca.verifier.app.android.data.local.countries.DefaultCountriesLocalDataSource import dgca.verifier.app.android.data.local.rules.DefaultRulesLocalDataSource @@ -47,6 +49,7 @@ import dgca.verifier.app.decoder.JSON_SCHEMA_V1 import dgca.verifier.app.engine.* import dgca.verifier.app.engine.data.source.countries.CountriesRepository import dgca.verifier.app.engine.data.source.countries.DefaultCountriesRepository +import dgca.verifier.app.engine.data.source.local.EnginePreferences import dgca.verifier.app.engine.data.source.local.countries.CountriesLocalDataSource import dgca.verifier.app.engine.data.source.local.rules.RulesLocalDataSource import dgca.verifier.app.engine.data.source.local.valuesets.ValueSetsLocalDataSource @@ -132,8 +135,16 @@ object EngineModule { @Singleton @Provides - fun provideCountriesLocalDataSource(countriesDao: CountriesDao): CountriesLocalDataSource = - DefaultCountriesLocalDataSource(countriesDao) + fun provideEnginePreferences(preferences: Preferences): EnginePreferences = + DefaultEnginePreferences(preferences) + + @Singleton + @Provides + fun provideCountriesLocalDataSource( + countriesDao: CountriesDao, + enginePreferences: EnginePreferences + ): CountriesLocalDataSource = + DefaultCountriesLocalDataSource(countriesDao, enginePreferences) @Singleton @Provides