update + Fix
This commit is contained in:
Binary file not shown.
@@ -116,15 +116,9 @@ class DataMonitorService : LifecycleService() {
|
||||
private fun tick() {
|
||||
val settings = latestSettings
|
||||
|
||||
if (!settings.controlEnabled) {
|
||||
applyVpnMode(VpnMode.STOPPED, emptySet())
|
||||
stateHolder.update { it.copy(serviceRunning = false) }
|
||||
updateNotification(stateHolder.snapshot.value)
|
||||
return
|
||||
}
|
||||
|
||||
maybeAutoReset(settings)
|
||||
|
||||
// Le calcul de la consommation doit rester à jour même quand le contrôle est désactivé
|
||||
// (ex: pour refléter immédiatement une valeur définie manuellement dans Réglages), il ne
|
||||
// doit donc pas dépendre de settings.controlEnabled.
|
||||
val consumedBytes = usageRepository.consumedBytesSince(settings.baselineMobileBytesAtReset)
|
||||
if (usageRepository.hasCounterReset(settings.baselineMobileBytesAtReset)) {
|
||||
lifecycleScope.launch { settingsRepository.rebaseline(usageRepository.totalMobileBytes()) }
|
||||
@@ -135,6 +129,25 @@ class DataMonitorService : LifecycleService() {
|
||||
val estimatedTotal = settings.planPriceEuro + overageMo * settings.overagePricePerMoEuro
|
||||
val percent = if (settings.planLimitMo > 0) consumedMo.toFloat() / settings.planLimitMo else 0f
|
||||
|
||||
if (!settings.controlEnabled) {
|
||||
applyVpnMode(VpnMode.STOPPED, emptySet())
|
||||
stateHolder.update {
|
||||
it.copy(
|
||||
consumedMo = consumedMo,
|
||||
planLimitMo = settings.planLimitMo,
|
||||
overageMo = overageMo,
|
||||
estimatedTotalPriceEuro = estimatedTotal,
|
||||
dataState = if (percent >= WARNING_THRESHOLD) DataState.WARNING else DataState.OK,
|
||||
nextAutoResetDate = settings.nextAutoResetDate(),
|
||||
serviceRunning = false
|
||||
)
|
||||
}
|
||||
updateNotification(stateHolder.snapshot.value)
|
||||
return
|
||||
}
|
||||
|
||||
maybeAutoReset(settings)
|
||||
|
||||
val dataState: DataState
|
||||
var nextCutoffAt: Long? = null
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ fun DashboardScreen(systemActions: SystemActions) {
|
||||
else -> stringResource(R.string.dashboard_state_wifi)
|
||||
}
|
||||
|
||||
val consumedMo = if (snapshot.serviceRunning) snapshot.consumedMo else 0L
|
||||
val consumedMo = snapshot.consumedMo
|
||||
val planLimitMo = settings.planLimitMo.coerceAtLeast(1L)
|
||||
val progress = (consumedMo.toFloat() / planLimitMo.toFloat()).coerceIn(0f, 1f)
|
||||
val overageMo = (consumedMo - settings.planLimitMo).coerceAtLeast(0L)
|
||||
|
||||
Reference in New Issue
Block a user