mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 11:05:49 +01:00
Huami: Fix updating alarm times when not toggling, other logic fixes
This commit is contained in:
parent
47f7f22df4
commit
6046152153
@ -1835,7 +1835,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
boolean[] alarmsEnabled = new boolean[maxAlarms];
|
boolean[] alarmsEnabled = new boolean[maxAlarms];
|
||||||
byte[] alarmsMinute = new byte[maxAlarms];
|
byte[] alarmsMinute = new byte[maxAlarms];
|
||||||
byte[] alarmsHour = new byte[maxAlarms];
|
byte[] alarmsHour = new byte[maxAlarms];
|
||||||
byte[] alarmsRepeat = new byte[maxAlarms];
|
byte[] alarmsRepetition = new byte[maxAlarms];
|
||||||
|
|
||||||
int nr_alarms;
|
int nr_alarms;
|
||||||
byte enable_flag;
|
byte enable_flag;
|
||||||
@ -1850,9 +1850,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
int offset;
|
int offset;
|
||||||
if (withTimes) {
|
if (withTimes) {
|
||||||
offset = i * 4;
|
offset = i * 4;
|
||||||
alarmsHour[i] = response[offset + 1];
|
|
||||||
alarmsMinute[i] = response[offset + 2];
|
|
||||||
alarmsRepeat[i] = response[offset + 3];
|
|
||||||
} else {
|
} else {
|
||||||
offset = 9 + i;
|
offset = 9 + i;
|
||||||
}
|
}
|
||||||
@ -1865,20 +1862,26 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
alarmsInUse[index] = true;
|
alarmsInUse[index] = true;
|
||||||
boolean enabled = (alarm_data & enable_flag) == enable_flag;
|
boolean enabled = (alarm_data & enable_flag) == enable_flag;
|
||||||
alarmsEnabled[index] = enabled;
|
alarmsEnabled[index] = enabled;
|
||||||
|
if (withTimes) {
|
||||||
|
alarmsHour[index] = response[offset + 1];
|
||||||
|
alarmsMinute[index] = response[offset + 2];
|
||||||
|
alarmsRepetition[index] = response[offset + 3];
|
||||||
|
}
|
||||||
|
|
||||||
LOG.info("alarm " + index + " is enabled:" + enabled);
|
LOG.info("alarm " + index + " is enabled:" + enabled);
|
||||||
}
|
}
|
||||||
for (nodomain.freeyourgadget.gadgetbridge.entities.Alarm alarm : alarms) {
|
for (nodomain.freeyourgadget.gadgetbridge.entities.Alarm alarm : alarms) {
|
||||||
int pos = alarm.getPosition();
|
int pos = alarm.getPosition();
|
||||||
boolean enabled = alarmsEnabled[pos];
|
boolean enabled = alarmsEnabled[pos];
|
||||||
boolean unused = !alarmsInUse[pos];
|
boolean unused = !alarmsInUse[pos];
|
||||||
if (alarm.getEnabled() != enabled || alarm.getUnused() != unused) {
|
if (alarm.getEnabled() != enabled || alarm.getUnused() != unused || (withTimes && !unused && (alarm.getHour() != alarmsHour[pos] || alarm.getMinute() != alarmsMinute[pos] || alarm.getRepetition() != alarmsRepetition[pos]))) {
|
||||||
LOG.info("updating alarm index " + pos + " unused=" + unused + ", enabled=" + enabled);
|
LOG.info("updating alarm index " + pos + " unused=" + unused + ", enabled=" + enabled);
|
||||||
alarm.setEnabled(enabled);
|
alarm.setEnabled(enabled);
|
||||||
alarm.setUnused(unused);
|
alarm.setUnused(unused);
|
||||||
if (withTimes) {
|
if (withTimes && !unused) {
|
||||||
alarm.setHour(alarmsHour[pos]);
|
alarm.setHour(alarmsHour[pos]);
|
||||||
alarm.setMinute(alarmsMinute[pos]);
|
alarm.setMinute(alarmsMinute[pos]);
|
||||||
alarm.setRepetition(alarmsRepeat[pos]);
|
alarm.setRepetition(alarmsRepetition[pos]);
|
||||||
}
|
}
|
||||||
DBHelper.store(alarm);
|
DBHelper.store(alarm);
|
||||||
Intent intent = new Intent(DeviceService.ACTION_SAVE_ALARMS);
|
Intent intent = new Intent(DeviceService.ACTION_SAVE_ALARMS);
|
||||||
|
Loading…
Reference in New Issue
Block a user