From 2ec37fa77ac99f4498b2d9bfbc67055d16101a96 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 18 Dec 2024 23:30:59 +0100 Subject: [PATCH] Dashboard: Make today widget data loading more efficient --- .../activities/dashboard/DashboardTodayWidget.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java index 0f361036f..7e1f58b64 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java @@ -44,7 +44,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import java.util.stream.Collectors; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; @@ -400,7 +402,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { } private class FillDataAsyncTask extends AsyncTask { - private final TreeMap activityTimestamps = new TreeMap<>(); + private final HashMap activityTimestamps = new HashMap<>(); /** * Add per-second activities to `activityTimestamps` @@ -507,7 +509,11 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { long currentTime = Calendar.getInstance().getTimeInMillis() / 1000; long midDaySecond = dashboardData.timeTo - (12 * 60 * 60); DashboardFragment.DashboardData.GeneralizedActivity previous = null; - for (Map.Entry activity : activityTimestamps.entrySet()) { + List> sortedActivityTimestamps = activityTimestamps.entrySet() + .stream() + .sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toList()); + for (Map.Entry activity : sortedActivityTimestamps) { long timestamp = activity.getKey(); ActivityKind activityKind = activity.getValue(); // Start a new merged activity on certain conditions