From fd15478a7a9efd2e1353beb0828c1d8c0d74d8f5 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 9 Feb 2019 00:03:50 +0100 Subject: [PATCH] Fix alarm corruption after user configured an alarm further down the list, leaving an unconfigured alarm in between configured alarms This was not fixable though the UI, this commit also heals already corrupted configurations Fixes #1419 --- .../gadgetbridge/activities/ConfigureAlarms.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java index 6388c2fc5..519ffb4d3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java @@ -115,8 +115,18 @@ public class ConfigureAlarms extends AbstractGBActivity { DaoSession daoSession = db.getDaoSession(); Device device = DBHelper.getDevice(getGbDevice(), daoSession); User user = DBHelper.getUser(daoSession); - while (supportedNumAlarms > alarms.size()) { - alarms.add(createDefaultAlarm(device, user, alarms.size())); + for (int position = 0; position < supportedNumAlarms; position++) { + boolean found = false; + for (Alarm alarm : alarms) { + if (alarm.getPosition() == position) { + found = true; + break; + } + } + if (!found) { + LOG.info("adding missing alarm at position " + position); + alarms.add(position, createDefaultAlarm(device, user, position)); + } } } catch (Exception e) { LOG.error("Error accessing database", e);