Skip to content

Commit

Permalink
Countries handling update (eu-digital-green-certificates#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrsarapulovgl authored Nov 15, 2021
1 parent ea24686 commit 4556a26
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface Preferences {

var lastKeysSyncTimeMillis: Long

var lastCountriesSyncTimeMillis: Long

var selectedCountryIsoCode: String?

var debugModeState: String?
Expand All @@ -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
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
countriesDao.apply {
Expand All @@ -39,6 +42,10 @@ class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) :

override fun getCountries(): Flow<List<String>> =
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))
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/dgca/verifier/app/android/di/EngineModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4556a26

Please sign in to comment.