1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 01:55:50 +01:00

Handle one shot alarm for Fossil watch

This commit is contained in:
vanous 2022-06-09 14:50:49 +02:00
parent 8ec9d0b2bd
commit 8bfe37e61f
5 changed files with 37 additions and 28 deletions

View File

@ -141,7 +141,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
this.getString(R.string.appwidget_setting_alarm, hours, minutes),
Toast.LENGTH_SHORT, GB.INFO);
Alarm alarm = AlarmUtils.createSingleShot(0, true, false, calendar);
Alarm alarm = AlarmUtils.createSingleShot(0, true, true, calendar);
ArrayList<Alarm> alarms = new ArrayList<>(1);
alarms.add(alarm);
GBApplication.deviceService().onSetAlarms(alarms);

View File

@ -956,33 +956,9 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport {
// this device doesn't have concept of on-off alarm, so use the last slot for this and store
// this alarm in the database so the user knows what is going on and can disable it
if (alarms.toArray().length == 1 && alarms.get(0).getRepetition() == 0) {
if (alarms.toArray().length == 1 && alarms.get(0).getRepetition() == 0) { //single shot?
Alarm oneshot = alarms.get(0);
DBHandler db = null;
try {
db = GBApplication.acquireDB();
DaoSession daoSession = db.getDaoSession();
Device device = DBHelper.getDevice(gbDevice, daoSession);
User user = DBHelper.getUser(daoSession);
nodomain.freeyourgadget.gadgetbridge.entities.Alarm tmpAlarm =
new nodomain.freeyourgadget.gadgetbridge.entities.Alarm(
device.getId(),
user.getId(),
7,
true,
false,
false,
0,
oneshot.getHour(),
oneshot.getMinute(),
true, //kind of indicate the specialty of this alarm
"",
"");
daoSession.insertOrReplace(tmpAlarm);
GBApplication.releaseDB();
} catch (GBException e) {
LOG.error("error storing one shot quick alarm");
}
alarms = (ArrayList<? extends Alarm>) AlarmUtils.mergeOneshotToDeviceAlarms(gbDevice, (nodomain.freeyourgadget.gadgetbridge.entities.Alarm) oneshot, 7);
}
try {

View File

@ -78,6 +78,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.mis
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.RequestHandControlRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.SaveCalibrationRequest;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
@ -516,6 +517,16 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
// handle one-shot alarm from the widget:
// this device doesn't have concept of on-off alarm, so use the last slot for this and store
// this alarm in the database so the user knows what is going on and can disable it
if (alarms.toArray().length == 1 && alarms.get(0).getRepetition() == 0) { //single shot?
Alarm oneshot = alarms.get(0);
alarms = (ArrayList<? extends Alarm>) AlarmUtils.mergeOneshotToDeviceAlarms(getDeviceSupport().getDevice(), (nodomain.freeyourgadget.gadgetbridge.entities.Alarm) oneshot, 5);
}
// throw new RuntimeException("noope");
ArrayList<nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.alarm.Alarm> activeAlarms = new ArrayList<>();
for (Alarm alarm : alarms) {

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
@ -50,7 +51,7 @@ public class AlarmUtils {
* @return
*/
public static nodomain.freeyourgadget.gadgetbridge.model.Alarm createSingleShot(int index, boolean smartWakeup, boolean snooze, Calendar calendar) {
return new Alarm(-1, -1, index, true, smartWakeup, snooze, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, null, null);
return new Alarm(-1, -1, index, true, smartWakeup, snooze, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false, GBApplication.getContext().getString(R.string.quick_alarm), GBApplication.getContext().getString(R.string.quick_alarm_description));
}
/**
@ -144,4 +145,23 @@ public class AlarmUtils {
}
};
}
public static List<Alarm> mergeOneshotToDeviceAlarms(GBDevice gbDevice, Alarm oneshot, int position) {
List<Alarm> all_alarms = new ArrayList<>();
try {
DBHandler db = GBApplication.acquireDB();
DaoSession daoSession = db.getDaoSession();
Device device = DBHelper.getDevice(gbDevice, daoSession);
User user = DBHelper.getUser(daoSession);
oneshot.setPosition(position);
oneshot.setDeviceId(device.getId());
oneshot.setUserId(user.getId());
daoSession.insertOrReplace(oneshot);
all_alarms = DBHelper.getAlarms(gbDevice);
GBApplication.releaseDB();
} catch (Exception e) {
GB.log("error storing one shot quick alarm", GB.ERROR, e);
}
return all_alarms;
}
}

View File

@ -1135,6 +1135,8 @@
<string name="widget_10_minutes">10 minutes</string>
<string name="widget_20_minutes">20 minutes</string>
<string name="widget_1_hour">1 hour</string>
<string name="quick_alarm">Quick alarm</string>
<string name="quick_alarm_description">Alarm from widget</string>
<string name="icon_placeholder" translatable="false">Icon</string>
<string name="watch_not_connected">Watch not connected</string>
<string name="qhybrid_vibration_strength">vibration strength:</string>