update + Fix

This commit is contained in:
Johnny
2026-07-03 08:21:43 +02:00
parent ecdb915da8
commit 80d53d325c
3 changed files with 23 additions and 10 deletions

Binary file not shown.

View File

@@ -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

View File

@@ -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)