From 8ec1677d04c96fc5ff5128f3fa719460b6d32983 Mon Sep 17 00:00:00 2001 From: Dinar Khakimov <85668474+mdrlzy@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:21:30 +0500 Subject: [PATCH] Change currency rates update interval to 2 hours (#116) * Change currency rates update interval to 2 hours * Extract rates update interval as constant and reuse in bg workers --- .../rate/data/repo/currency/CurrencyRepoImpl.kt | 7 ++++--- app/src/main/java/dev/arkbuilders/rate/domain/AppConfig.kt | 5 +++++ app/src/main/java/dev/arkbuilders/rate/presentation/App.kt | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/dev/arkbuilders/rate/domain/AppConfig.kt diff --git a/app/src/main/java/dev/arkbuilders/rate/data/repo/currency/CurrencyRepoImpl.kt b/app/src/main/java/dev/arkbuilders/rate/data/repo/currency/CurrencyRepoImpl.kt index f3cdda12a..1fd6ecf5b 100644 --- a/app/src/main/java/dev/arkbuilders/rate/data/repo/currency/CurrencyRepoImpl.kt +++ b/app/src/main/java/dev/arkbuilders/rate/data/repo/currency/CurrencyRepoImpl.kt @@ -3,6 +3,7 @@ package dev.arkbuilders.rate.data.repo.currency import arrow.core.Either import arrow.core.left import arrow.core.right +import dev.arkbuilders.rate.domain.AppConfig import dev.arkbuilders.rate.domain.model.CurrencyName import dev.arkbuilders.rate.domain.model.CurrencyRate import dev.arkbuilders.rate.domain.model.CurrencyType @@ -18,7 +19,6 @@ import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import java.time.Duration import java.time.OffsetDateTime -import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Singleton @@ -96,7 +96,8 @@ class CurrencyRepoImpl @Inject constructor( private fun hasUpdateIntervalPassed(updatedDate: OffsetDateTime?) = updatedDate == null || Duration.between(updatedDate, OffsetDateTime.now()) - .toMillis() > dayInMillis + .toMillis() > updateInterval - private val dayInMillis = TimeUnit.DAYS.toMillis(1) + private val updateInterval = + Duration.ofHours(AppConfig.CURRENCY_RATES_UPDATE_INTERVAL_HOURS).toMillis() } diff --git a/app/src/main/java/dev/arkbuilders/rate/domain/AppConfig.kt b/app/src/main/java/dev/arkbuilders/rate/domain/AppConfig.kt new file mode 100644 index 000000000..b0784411e --- /dev/null +++ b/app/src/main/java/dev/arkbuilders/rate/domain/AppConfig.kt @@ -0,0 +1,5 @@ +package dev.arkbuilders.rate.domain + +object AppConfig { + const val CURRENCY_RATES_UPDATE_INTERVAL_HOURS = 2L +} diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/App.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/App.kt index 75dd1c98e..f17fd36e8 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/App.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/App.kt @@ -14,6 +14,7 @@ import dev.arkbuilders.rate.BuildConfig import dev.arkbuilders.rate.data.worker.CurrencyMonitorWorker import dev.arkbuilders.rate.data.worker.QuickPairsWidgetRefreshWorker import dev.arkbuilders.rate.di.DIManager +import dev.arkbuilders.rate.domain.AppConfig import dev.arkbuilders.rate.domain.repo.PreferenceKey import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -57,7 +58,7 @@ class App : Application(), Configuration.Provider { val workRequest = PeriodicWorkRequest.Builder( workerClass, - 8L, + AppConfig.CURRENCY_RATES_UPDATE_INTERVAL_HOURS, TimeUnit.HOURS, ).setConstraints(constraints) .build()