Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

More accurate timestamps on risk card (EXPOSUREAPP-1991) #1487

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class TracingCardState(
override val matchedKeyCount: Int,
override val daysSinceLastExposure: Int,
override val activeTracingDaysInRetentionPeriod: Long,
override val lastTimeDiagnosisKeysFetched: Date?,
override val lastENFCalculation: Date?,
override val isBackgroundJobEnabled: Boolean,
override val isManualKeyRetrievalEnabled: Boolean,
override val manualKeyRetrievalTime: Long,
Expand Down Expand Up @@ -190,10 +190,10 @@ data class TracingCardState(
return when (riskLevelScore) {
RiskLevelConstants.LOW_LEVEL_RISK,
RiskLevelConstants.INCREASED_RISK -> {
if (lastTimeDiagnosisKeysFetched != null) {
if (lastENFCalculation != null) {
c.getString(
R.string.risk_card_body_time_fetched,
formatRelativeDateTimeString(c, lastTimeDiagnosisKeysFetched)
formatRelativeDateTimeString(c, lastENFCalculation)
)
} else {
c.getString(R.string.risk_card_body_not_yet_fetched)
Expand All @@ -206,10 +206,10 @@ data class TracingCardState(
RiskLevelConstants.LOW_LEVEL_RISK,
RiskLevelConstants.INCREASED_RISK,
RiskLevelConstants.UNKNOWN_RISK_INITIAL -> {
if (lastTimeDiagnosisKeysFetched != null) {
if (lastENFCalculation != null) {
c.getString(
R.string.risk_card_body_time_fetched,
formatRelativeDateTimeString(c, lastTimeDiagnosisKeysFetched)
formatRelativeDateTimeString(c, lastENFCalculation)
)
} else {
c.getString(R.string.risk_card_body_not_yet_fetched)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.rki.coronawarnapp.ui.tracing.card

import dagger.Reusable
import de.rki.coronawarnapp.nearby.ENFClient
import de.rki.coronawarnapp.storage.ExposureSummaryRepository
import de.rki.coronawarnapp.storage.RiskLevelRepository
import de.rki.coronawarnapp.storage.SettingsRepository
Expand All @@ -9,6 +10,7 @@ import de.rki.coronawarnapp.tracing.GeneralTracingStatus
import de.rki.coronawarnapp.util.BackgroundModeStatus
import de.rki.coronawarnapp.util.flow.combine
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
Expand All @@ -20,7 +22,8 @@ class TracingCardStateProvider @Inject constructor(
tracingStatus: GeneralTracingStatus,
backgroundModeStatus: BackgroundModeStatus,
settingsRepository: SettingsRepository,
tracingRepository: TracingRepository
tracingRepository: TracingRepository,
enfClient: ENFClient
) {

// TODO Refactor these singletons away
Expand All @@ -46,8 +49,8 @@ class TracingCardStateProvider @Inject constructor(
tracingRepository.activeTracingDaysInRetentionPeriod.onEach {
Timber.v("activeTracingDaysInRetentionPeriod: $it")
},
tracingRepository.lastTimeDiagnosisKeysFetched.onEach {
Timber.v("lastTimeDiagnosisKeysFetched: $it")
enfClient.latestFinishedCalculation().onEach {
Timber.v("latestFinishedCalculation: $it")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
backgroundModeStatus.isAutoModeEnabled.onEach {
Timber.v("isAutoModeEnabled: $it")
Expand All @@ -65,17 +68,22 @@ class TracingCardStateProvider @Inject constructor(
matchedKeyCount,
daysSinceLastExposure,
activeTracingDaysInRetentionPeriod,
lastTimeDiagnosisKeysFetched,
lastENFCalculation,
isBackgroundJobEnabled,
isManualKeyRetrievalEnabled,
manualKeyRetrievalTime ->

// TODO Remove a later version (1.7+), when everyone likely has tracked calc data
// When the update with this change hits, there will not yet be a last tracked calculation
val lastUpdateDate = lastENFCalculation?.finishedAt?.toDate()
?: tracingRepository.lastTimeDiagnosisKeysFetched.first()

TracingCardState(
tracingStatus = status,
riskLevelScore = riskLevelScore,
isRefreshing = isRefreshing,
lastRiskLevelScoreCalculated = riskLevelScoreLastSuccessfulCalculated,
lastTimeDiagnosisKeysFetched = lastTimeDiagnosisKeysFetched,
lastENFCalculation = lastUpdateDate,
matchedKeyCount = matchedKeyCount,
daysSinceLastExposure = daysSinceLastExposure,
activeTracingDaysInRetentionPeriod = activeTracingDaysInRetentionPeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class BaseTracingState {
abstract val matchedKeyCount: Int
abstract val daysSinceLastExposure: Int
abstract val activeTracingDaysInRetentionPeriod: Long
abstract val lastTimeDiagnosisKeysFetched: Date?
abstract val lastENFCalculation: Date?
abstract val isBackgroundJobEnabled: Boolean
abstract val showDetails: Boolean // Only true for riskdetailsfragment
abstract val isManualKeyRetrievalEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class TracingDetailsState(
override val matchedKeyCount: Int,
override val daysSinceLastExposure: Int,
override val activeTracingDaysInRetentionPeriod: Long,
override val lastTimeDiagnosisKeysFetched: Date?,
override val lastENFCalculation: Date?,
override val isBackgroundJobEnabled: Boolean,
override val isManualKeyRetrievalEnabled: Boolean,
override val manualKeyRetrievalTime: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.rki.coronawarnapp.ui.tracing.details

import dagger.Reusable
import de.rki.coronawarnapp.nearby.ENFClient
import de.rki.coronawarnapp.storage.ExposureSummaryRepository
import de.rki.coronawarnapp.storage.RiskLevelRepository
import de.rki.coronawarnapp.storage.SettingsRepository
Expand All @@ -9,6 +10,7 @@ import de.rki.coronawarnapp.tracing.GeneralTracingStatus
import de.rki.coronawarnapp.util.BackgroundModeStatus
import de.rki.coronawarnapp.util.flow.combine
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
Expand All @@ -21,7 +23,8 @@ class TracingDetailsStateProvider @Inject constructor(
tracingStatus: GeneralTracingStatus,
backgroundModeStatus: BackgroundModeStatus,
settingsRepository: SettingsRepository,
tracingRepository: TracingRepository
tracingRepository: TracingRepository,
enfClient: ENFClient
) {

// TODO Refactore these singletons away
Expand All @@ -33,7 +36,9 @@ class TracingDetailsStateProvider @Inject constructor(
ExposureSummaryRepository.matchedKeyCount,
ExposureSummaryRepository.daysSinceLastExposure,
tracingRepository.activeTracingDaysInRetentionPeriod,
tracingRepository.lastTimeDiagnosisKeysFetched,
enfClient.latestFinishedCalculation().onEach {
Timber.v("latestFinishedCalculation: $it")
},
backgroundModeStatus.isAutoModeEnabled,
settingsRepository.isManualKeyRetrievalEnabledFlow,
settingsRepository.manualKeyRetrievalTimeFlow
Expand All @@ -42,7 +47,7 @@ class TracingDetailsStateProvider @Inject constructor(
riskLevelScoreLastSuccessfulCalculated,
isRefreshing, matchedKeyCount,
daysSinceLastExposure, activeTracingDaysInRetentionPeriod,
lastTimeDiagnosisKeysFetched,
lastENFCalculation,
isBackgroundJobEnabled,
isManualKeyRetrievalEnabled,
manualKeyRetrievalTime ->
Expand All @@ -52,8 +57,13 @@ class TracingDetailsStateProvider @Inject constructor(
)
val isInformationBodyNoticeVisible =
riskDetailPresenter.isInformationBodyNoticeVisible(
riskLevelScore
)
riskLevelScore
)

// TODO Remove a later version (1.7+), when everyone likely has tracked calc data
// When the update with this change hits, there will not yet be a last tracked calculation
val lastUpdateDate = lastENFCalculation?.finishedAt?.toDate()
?: tracingRepository.lastTimeDiagnosisKeysFetched.first()

TracingDetailsState(
tracingStatus = status,
Expand All @@ -63,7 +73,7 @@ class TracingDetailsStateProvider @Inject constructor(
matchedKeyCount = matchedKeyCount,
daysSinceLastExposure = daysSinceLastExposure,
activeTracingDaysInRetentionPeriod = activeTracingDaysInRetentionPeriod,
lastTimeDiagnosisKeysFetched = lastTimeDiagnosisKeysFetched,
lastENFCalculation = lastUpdateDate,
isBackgroundJobEnabled = isBackgroundJobEnabled,
isManualKeyRetrievalEnabled = isManualKeyRetrievalEnabled,
manualKeyRetrievalTime = manualKeyRetrievalTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TracingCardStateTest : BaseTest() {
matchedKeyCount = matchedKeyCount,
daysSinceLastExposure = daysSinceLastExposure,
activeTracingDaysInRetentionPeriod = activeTracingDaysInRetentionPeriod,
lastTimeDiagnosisKeysFetched = lastTimeDiagnosisKeysFetched,
lastENFCalculation = lastTimeDiagnosisKeysFetched,
isBackgroundJobEnabled = isBackgroundJobEnabled,
isManualKeyRetrievalEnabled = isManualKeyRetrievalEnabled,
manualKeyRetrievalTime = manualKeyRetrievalTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BaseTracingStateTest : BaseTest() {
override val matchedKeyCount: Int = matchedKeyCount
override val daysSinceLastExposure: Int = daysSinceLastExposure
override val activeTracingDaysInRetentionPeriod = activeTracingDaysInRetentionPeriod
override val lastTimeDiagnosisKeysFetched: Date? = lastTimeDiagnosisKeysFetched
override val lastENFCalculation: Date? = lastTimeDiagnosisKeysFetched
override val isBackgroundJobEnabled: Boolean = isBackgroundJobEnabled
override val showDetails: Boolean = showDetails
override val isManualKeyRetrievalEnabled: Boolean = isManualKeyRetrievalEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TracingDetailsStateTest : BaseTest() {
matchedKeyCount = matchedKeyCount,
daysSinceLastExposure = daysSinceLastExposure,
activeTracingDaysInRetentionPeriod = activeTracingDaysInRetentionPeriod,
lastTimeDiagnosisKeysFetched = lastTimeDiagnosisKeysFetched,
lastENFCalculation = lastTimeDiagnosisKeysFetched,
isBackgroundJobEnabled = isBackgroundJobEnabled,
isManualKeyRetrievalEnabled = isManualKeyRetrievalEnabled,
manualKeyRetrievalTime = manualKeyRetrievalTime,
Expand Down