From 21eada4caa56ab5cb380944f12c3567d52a9661d Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 24 Dec 2019 01:27:57 +0100 Subject: [PATCH] Allow to set alarms to unused when long tapping This helps clearing up a cluttered alarms list on devices like the Mi Band 4 Difference between disabling and setting to usused: Unsused alarms cant be enabled from the Band, disabled can. Closes #1747 --- .../gadgetbridge/daogen/GBDaoGenerator.java | 5 +-- .../activities/ConfigureAlarms.java | 9 +++-- .../adapter/GBAlarmListAdapter.java | 21 +++++++--- .../schema/GadgetbridgeUpdate_22.java | 39 +++++++++++++++++++ .../gadgetbridge/model/Alarm.java | 2 + .../service/devices/huami/HuamiSupport.java | 12 ++++-- .../gadgetbridge/util/AlarmUtils.java | 4 +- 7 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_22.java diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 13868d787..f9a0a697e 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -15,8 +15,6 @@ */ package nodomain.freeyourgadget.gadgetbridge.daogen; -import java.util.Date; - import de.greenrobot.daogenerator.DaoGenerator; import de.greenrobot.daogenerator.Entity; import de.greenrobot.daogenerator.Index; @@ -45,7 +43,7 @@ public class GBDaoGenerator { public static void main(String[] args) throws Exception { - Schema schema = new Schema(21, MAIN_PACKAGE + ".entities"); + Schema schema = new Schema(22, MAIN_PACKAGE + ".entities"); Entity userAttributes = addUserAttributes(schema); Entity user = addUserInfo(schema, userAttributes); @@ -378,6 +376,7 @@ public class GBDaoGenerator { ); alarm.addIntProperty("hour").notNull(); alarm.addIntProperty("minute").notNull(); + alarm.addBooleanProperty("unused").notNull(); alarm.addToOne(user, userId); alarm.addToOne(device, deviceId); } 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 6293cb03c..de8f4c31a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java @@ -21,14 +21,15 @@ import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter; @@ -136,7 +137,7 @@ public class ConfigureAlarms extends AbstractGBActivity { } private Alarm createDefaultAlarm(@NonNull Device device, @NonNull User user, int position) { - return new Alarm(device.getId(), user.getId(), position, false, false,0, 6, 30); + return new Alarm(device.getId(), user.getId(), position, false, false, 0, 6, 30, false); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBAlarmListAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBAlarmListAdapter.java index 07500a8b4..7725d1bf2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBAlarmListAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBAlarmListAdapter.java @@ -27,12 +27,13 @@ import android.widget.CompoundButton; import android.widget.Switch; import android.widget.TextView; -import java.util.ArrayList; -import java.util.List; - import androidx.annotation.NonNull; import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; @@ -71,7 +72,7 @@ public class GBAlarmListAdapter extends RecyclerView.Adapter. */ +package nodomain.freeyourgadget.gadgetbridge.database.schema; + +import android.database.sqlite.SQLiteDatabase; + +import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; +import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript; +import nodomain.freeyourgadget.gadgetbridge.entities.AlarmDao; +import nodomain.freeyourgadget.gadgetbridge.entities.No1F1ActivitySampleDao; + +public class GadgetbridgeUpdate_22 implements DBUpdateScript { + @Override + public void upgradeSchema(SQLiteDatabase db) { + if (!DBHelper.existsColumn(AlarmDao.TABLENAME, AlarmDao.Properties.Unused.columnName, db)) { + String ADD_COLUMN_UNUSED = "ALTER TABLE " + AlarmDao.TABLENAME + " ADD COLUMN " + + AlarmDao.Properties.Unused.columnName + " INTEGER NOT NULL DEFAULT 0;"; + db.execSQL(ADD_COLUMN_UNUSED); + } + } + + @Override + public void downgradeSchema(SQLiteDatabase db) { + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java index 5a4c22d3d..5805d3072 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/Alarm.java @@ -37,6 +37,8 @@ public interface Alarm extends Serializable { boolean getEnabled(); + boolean getUnused(); + boolean getSmartWakeup(); int getRepetition(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index ef827101e..5af18112f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -1487,13 +1487,17 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { } int base = 0; - if (alarm.getEnabled()) { + int daysMask = 0; + if (alarm.getEnabled() && !alarm.getUnused()) { base = 128; } - int daysMask = alarm.getRepetition(); - if (!alarm.isRepetitive()) { - daysMask = 128; + if (!alarm.getUnused()) { + daysMask = alarm.getRepetition(); + if (!alarm.isRepetitive()) { + daysMask = 128; + } } + byte[] alarmMessage = new byte[] { (byte) 0x2, // TODO what is this? (byte) (base + alarm.getPosition()), // 128 is the base, alarm slot is added diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java index 22b9e9e8c..47a6bc46a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/AlarmUtils.java @@ -48,7 +48,7 @@ public class AlarmUtils { * @return */ public static nodomain.freeyourgadget.gadgetbridge.model.Alarm createSingleShot(int index, boolean smartWakeup, Calendar calendar) { - return new Alarm(-1, -1, index, true, smartWakeup, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE)); + return new Alarm(-1, -1, index, true, smartWakeup, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false); } /** @@ -127,7 +127,7 @@ public class AlarmUtils { int hour = Integer.parseInt(tokens[4]); int minute = Integer.parseInt(tokens[5]); - return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, repetition, hour, minute); + return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, repetition, hour, minute, false); } private static Comparator createComparator() {