simplify: backend derives lifetime from day totals, app stops sending it

- backend daily PUT: no longer $set lifetime (app's local counter is unreliable after APK wipe)
- backend history GET: derives lifetime as sum of all days' totals, returns it at response level
- app: stops sending lifetime in chunks; reads it from history response
- app: refresh button on consumption pane + 'Şimdi yükle' on log pane (manual cache flush)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
TCFDONMEZ
2026-10-09 21:41:15 +03:00
co-authored by Claude
parent 8b25799d55
commit 06265bacc9
8 changed files with 144 additions and 27 deletions
@@ -3,6 +3,7 @@ package com.evsuite.abrp;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.util.Log;
import com.evsuite.hardware.telemetry.EnergySnapshot;
@@ -204,6 +205,22 @@ final class ConsumptionTracker {
return missing ? lifetime.snapshot() : stored;
}
/**
* Sets the local lifetime baseline from the cloud's last known lifetime, but only when
* the cloud value is higher — an APK wipe zeroes the local counter, and without this the
* car would re-upload a small lifetime that overwrites the real one in the cloud.
* Called once after the first history fetch succeeds.
*/
synchronized void syncLifetimeBaseline(Totals cloudLifetime) {
Totals local = lifetime.snapshot();
if (cloudLifetime.km > local.km) {
lifetime.set(cloudLifetime.km, cloudLifetime.kwh, cloudLifetime.hours, cloudLifetime.soc);
persist();
Log.i("FatihsMG4.Consumption", "Lifetime baseline synced from cloud: "
+ cloudLifetime.km + " km (was " + local.km + " km)");
}
}
synchronized LocalDate nextStoredDayAfter(LocalDate lastUploaded) {
rollDayIfNeeded();
LocalDate latestComplete = LocalDate.now().minusDays(1);
@@ -355,6 +372,13 @@ final class ConsumptionTracker {
km.reset(); kwh.reset(); hours.reset(); soc.reset();
}
void set(double kmVal, double kwhVal, double hoursVal, double socVal) {
km.setTotal(kmVal);
kwh.setTotal(kwhVal);
hours.setTotal(hoursVal);
soc.setTotal(socVal);
}
Totals snapshot() {
return new Totals(km.get(), kwh.get(), hours.get(), soc.get());
}