Skip to content
Snippets Groups Projects
Unverified Commit 3baa2b39 authored by Ralf Gehrer's avatar Ralf Gehrer Committed by GitHub
Browse files

Remove manual refresh of last fetched timestamp (EXPOSUREAPP-3843) #1648

parent d38c1067
No related branches found
No related tags found
No related merge requests found
...@@ -5,9 +5,11 @@ import androidx.core.content.edit ...@@ -5,9 +5,11 @@ import androidx.core.content.edit
import de.rki.coronawarnapp.CoronaWarnApplication import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.R import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.risk.RiskLevel import de.rki.coronawarnapp.risk.RiskLevel
import de.rki.coronawarnapp.util.preferences.createFlowPreference
import de.rki.coronawarnapp.util.security.SecurityHelper.globalEncryptedSharedPreferencesInstance import de.rki.coronawarnapp.util.security.SecurityHelper.globalEncryptedSharedPreferencesInstance
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import java.util.Date import java.util.Date
/** /**
...@@ -399,6 +401,12 @@ object LocalData { ...@@ -399,6 +401,12 @@ object LocalData {
return Date(time) return Date(time)
} }
fun lastTimeDiagnosisKeysFromServerFetchFlow() =
getSharedPreferenceInstance()
.createFlowPreference<Long?>(CoronaWarnApplication.getAppContext()
.getString(R.string.preference_timestamp_diagnosis_keys_fetch), 0L).flow
.map { if (it != null && it != 0L) Date(it) else null }
/** /**
* Sets the last time the server fetched the diagnosis keys from the server as Date object * Sets the last time the server fetched the diagnosis keys from the server as Date object
* from the EncryptedSharedPrefs * from the EncryptedSharedPrefs
......
...@@ -49,22 +49,11 @@ class TracingRepository @Inject constructor( ...@@ -49,22 +49,11 @@ class TracingRepository @Inject constructor(
private val timeStamper: TimeStamper private val timeStamper: TimeStamper
) { ) {
private val internalLastTimeDiagnosisKeysFetched = MutableStateFlow<Date?>(null) val lastTimeDiagnosisKeysFetched: Flow<Date?> = LocalData.lastTimeDiagnosisKeysFromServerFetchFlow()
val lastTimeDiagnosisKeysFetched: Flow<Date?> = internalLastTimeDiagnosisKeysFetched
private val internalActiveTracingDaysInRetentionPeriod = MutableStateFlow(0L) private val internalActiveTracingDaysInRetentionPeriod = MutableStateFlow(0L)
val activeTracingDaysInRetentionPeriod: Flow<Long> = internalActiveTracingDaysInRetentionPeriod val activeTracingDaysInRetentionPeriod: Flow<Long> = internalActiveTracingDaysInRetentionPeriod
/**
* Refresh the last time diagnosis keys fetched date with the current shared preferences state.
*
* @see LocalData
*/
fun refreshLastTimeDiagnosisKeysFetchedDate() {
internalLastTimeDiagnosisKeysFetched.value =
LocalData.lastTimeDiagnosisKeysFromServerFetch()
}
private val internalIsRefreshing = private val internalIsRefreshing =
taskController.tasks.map { it.isDownloadDiagnosisKeysTaskRunning() || it.isRiskLevelTaskRunning() } taskController.tasks.map { it.isDownloadDiagnosisKeysTaskRunning() || it.isRiskLevelTaskRunning() }
...@@ -104,7 +93,6 @@ class TracingRepository @Inject constructor( ...@@ -104,7 +93,6 @@ class TracingRepository @Inject constructor(
) )
) )
taskController.submit(DefaultTaskRequest(RiskLevelTask::class)) taskController.submit(DefaultTaskRequest(RiskLevelTask::class))
refreshLastTimeDiagnosisKeysFetchedDate()
TimerHelper.startManualKeyRetrievalTimer() TimerHelper.startManualKeyRetrievalTimer()
} }
} }
...@@ -152,7 +140,6 @@ class TracingRepository @Inject constructor( ...@@ -152,7 +140,6 @@ class TracingRepository @Inject constructor(
DownloadDiagnosisKeysTask.Arguments() DownloadDiagnosisKeysTask.Arguments()
) )
) )
refreshLastTimeDiagnosisKeysFetchedDate()
TimerHelper.checkManualKeyRetrievalTimer() TimerHelper.checkManualKeyRetrievalTimer()
taskController.submit(DefaultTaskRequest(RiskLevelTask::class)) taskController.submit(DefaultTaskRequest(RiskLevelTask::class))
......
...@@ -104,7 +104,6 @@ class HomeFragmentViewModel @AssistedInject constructor( ...@@ -104,7 +104,6 @@ class HomeFragmentViewModel @AssistedInject constructor(
// TODO the ordering here is weird, do we expect these to run in sequence? // TODO the ordering here is weird, do we expect these to run in sequence?
tracingRepository.refreshRiskLevel() tracingRepository.refreshRiskLevel()
tracingRepository.refreshExposureSummary() tracingRepository.refreshExposureSummary()
tracingRepository.refreshLastTimeDiagnosisKeysFetchedDate()
tracingRepository.refreshActiveTracingDaysInRetentionPeriod() tracingRepository.refreshActiveTracingDaysInRetentionPeriod()
TimerHelper.checkManualKeyRetrievalTimer() TimerHelper.checkManualKeyRetrievalTimer()
tracingRepository.refreshLastSuccessfullyCalculatedScore() tracingRepository.refreshLastSuccessfullyCalculatedScore()
......
...@@ -37,7 +37,6 @@ class RiskDetailsFragmentViewModel @AssistedInject constructor( ...@@ -37,7 +37,6 @@ class RiskDetailsFragmentViewModel @AssistedInject constructor(
fun refreshData() { fun refreshData() {
tracingRepository.refreshRiskLevel() tracingRepository.refreshRiskLevel()
tracingRepository.refreshExposureSummary() tracingRepository.refreshExposureSummary()
tracingRepository.refreshLastTimeDiagnosisKeysFetchedDate()
TimerHelper.checkManualKeyRetrievalTimer() TimerHelper.checkManualKeyRetrievalTimer()
tracingRepository.refreshActiveTracingDaysInRetentionPeriod() tracingRepository.refreshActiveTracingDaysInRetentionPeriod()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment