use of nodomain.freeyourgadget.gadgetbridge.entities.Reminder in project Gadgetbridge by Freeyourgadget.
the class GBReminderListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
final Reminder reminder = reminderList.get(position);
holder.container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ConfigureReminders) mContext).configureReminder(reminder);
}
});
holder.container.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
new AlertDialog.Builder(v.getContext()).setTitle(R.string.reminder_delete_confirm_title).setMessage(R.string.reminder_delete_confirm_description).setIcon(R.drawable.ic_warning).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
((ConfigureReminders) mContext).deleteReminder(reminder);
}
}).setNegativeButton(android.R.string.no, null).show();
return true;
}
});
holder.reminderMessage.setText(reminder.getMessage());
final Date time = reminder.getDate();
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
int stringResId = 0;
switch(reminder.getRepetition()) {
case Reminder.ONCE:
stringResId = R.string.reminder_time_once;
break;
case Reminder.EVERY_DAY:
stringResId = R.string.reminder_time_every_day;
break;
case Reminder.EVERY_WEEK:
stringResId = R.string.reminder_time_every_week;
break;
case Reminder.EVERY_MONTH:
stringResId = R.string.reminder_time_every_month;
break;
case Reminder.EVERY_YEAR:
stringResId = R.string.reminder_time_every_year;
break;
}
final String reminderTimeText = mContext.getString(stringResId, format.format(time));
holder.reminderTime.setText(reminderTimeText);
}
use of nodomain.freeyourgadget.gadgetbridge.entities.Reminder in project Gadgetbridge by Freeyourgadget.
the class DBHelper method getReminders.
/**
* Returns all user-configurable reminders for the given user and device. The list is sorted by
* {@link Reminder#getDate}. Calendar events that may also be modeled as reminders 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 reminders for the given device
*/
@NonNull
public static List<Reminder> getReminders(@NonNull GBDevice gbDevice) {
final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
final Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int reservedSlots = prefs.getInt(DeviceSettingsPreferenceConst.PREF_RESERVER_REMINDERS_CALENDAR, 9);
final int reminderSlots = coordinator.getReminderSlotCount();
try (DBHandler db = GBApplication.acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final User user = getUser(daoSession);
final Device dbDevice = DBHelper.findDevice(gbDevice, daoSession);
if (dbDevice != null) {
final ReminderDao reminderDao = daoSession.getReminderDao();
final Long deviceId = dbDevice.getId();
final QueryBuilder<Reminder> qb = reminderDao.queryBuilder();
qb.where(ReminderDao.Properties.UserId.eq(user.getId()), ReminderDao.Properties.DeviceId.eq(deviceId)).orderAsc(ReminderDao.Properties.Date).limit(reminderSlots - reservedSlots);
return qb.build().list();
}
} catch (final Exception e) {
LOG.error("Error reading reminders from db", e);
}
return Collections.emptyList();
}
use of nodomain.freeyourgadget.gadgetbridge.entities.Reminder in project Gadgetbridge by Freeyourgadget.
the class ConfigureReminders method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configure_reminders);
gbDevice = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
mGBReminderListAdapter = new GBReminderListAdapter(this);
final RecyclerView remindersRecyclerView = findViewById(R.id.reminder_list);
remindersRecyclerView.setHasFixedSize(true);
remindersRecyclerView.setLayoutManager(new LinearLayoutManager(this));
remindersRecyclerView.setAdapter(mGBReminderListAdapter);
updateRemindersFromDB();
final FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
final Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int reservedSlots = prefs.getInt(DeviceSettingsPreferenceConst.PREF_RESERVER_REMINDERS_CALENDAR, 9);
int deviceSlots = coordinator.getReminderSlotCount() - reservedSlots;
if (mGBReminderListAdapter.getItemCount() >= deviceSlots) {
// No more free slots
new AlertDialog.Builder(v.getContext()).setTitle(R.string.reminder_no_free_slots_title).setMessage(getBaseContext().getString(R.string.reminder_no_free_slots_description, String.format(Locale.getDefault(), "%d", deviceSlots))).setIcon(R.drawable.ic_warning).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
}
}).show();
return;
}
final Reminder reminder;
try (DBHandler db = GBApplication.acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final Device device = DBHelper.getDevice(gbDevice, daoSession);
final User user = DBHelper.getUser(daoSession);
reminder = createDefaultReminder(device, user);
} catch (final Exception e) {
LOG.error("Error accessing database", e);
return;
}
configureReminder(reminder);
}
});
}
use of nodomain.freeyourgadget.gadgetbridge.entities.Reminder in project Gadgetbridge by Freeyourgadget.
the class ConfigureReminders method createDefaultReminder.
private Reminder createDefaultReminder(@NonNull Device device, @NonNull User user) {
final Reminder reminder = new Reminder();
reminder.setRepetition(Reminder.ONCE);
reminder.setDate(Calendar.getInstance().getTime());
reminder.setMessage("");
reminder.setDeviceId(device.getId());
reminder.setUserId(user.getId());
reminder.setReminderId(UUID.randomUUID().toString());
return reminder;
}
Aggregations