use of nodomain.freeyourgadget.gadgetbridge.entities.AlarmDao in project Gadgetbridge by Freeyourgadget.
the class DBHelper method getAlarms.
/**
* Returns all user-configurable alarms for the given user and device. The list is sorted by
* {@link Alarm#position}. Calendar events that may also be modeled as alarms are not stored
* in the database and hence not returned by this method.
* @param gbDevice the device for which the alarms shall be loaded
* @return the list of alarms for the given device
*/
@NonNull
public static List<Alarm> getAlarms(@NonNull GBDevice gbDevice) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int reservedSlots = prefs.getInt(DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR, 0);
int alarmSlots = coordinator.getAlarmSlotCount();
try (DBHandler db = GBApplication.acquireDB()) {
DaoSession daoSession = db.getDaoSession();
User user = getUser(daoSession);
Device dbDevice = DBHelper.findDevice(gbDevice, daoSession);
if (dbDevice != null) {
AlarmDao alarmDao = daoSession.getAlarmDao();
Long deviceId = dbDevice.getId();
QueryBuilder<Alarm> qb = alarmDao.queryBuilder();
qb.where(AlarmDao.Properties.UserId.eq(user.getId()), AlarmDao.Properties.DeviceId.eq(deviceId)).orderAsc(AlarmDao.Properties.Position).limit(alarmSlots - reservedSlots);
return qb.build().list();
}
} catch (Exception e) {
LOG.warn("Error reading alarms from db", e);
}
return Collections.emptyList();
}
Aggregations