From e1617431b4d1ef72c96d89d0754d42ed0e2cdb24 Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Thu, 29 Jun 2023 01:09:51 +0100 Subject: Return log value if step counter value isn't sane --- qmlplugin/stepsDataLoader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'qmlplugin') diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp index bbc9b29..44b15bb 100644 --- a/qmlplugin/stepsDataLoader.cpp +++ b/qmlplugin/stepsDataLoader.cpp @@ -36,7 +36,11 @@ StepsDataLoader::StepsDataLoader() : QObject() int StepsDataLoader::getTodayTotal() { QSettings settings("asteroid", "sensorlogd"); - return m_stepcounterSensor->reading()->steps() - settings.value("StepCounterPrivate/stepsOffset", 0).toInt(); + int total = m_stepcounterSensor->reading()->steps() - settings.value("StepCounterPrivate/stepsOffset", 0).toInt(); + if (total < 0) { + return getTotalForDate(QDate::currentDate()); + } + return total; } int StepsDataLoader::getTotalForDate(QDate date) { // This is obvious garbage. This should really be abstracted and cached, so that every page doesn't have to reload the file from scratch. -- cgit v1.2.3-54-g00ecf