Search in sources :

Example 1 with Reminder

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);
}
Also used : AlertDialog(android.app.AlertDialog) Reminder(nodomain.freeyourgadget.gadgetbridge.entities.Reminder) DialogInterface(android.content.DialogInterface) ConfigureReminders(nodomain.freeyourgadget.gadgetbridge.activities.ConfigureReminders) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Reminder

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();
}
Also used : User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) Reminder(nodomain.freeyourgadget.gadgetbridge.entities.Reminder) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) IOException(java.io.IOException) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession) ReminderDao(nodomain.freeyourgadget.gadgetbridge.entities.ReminderDao) NonNull(androidx.annotation.NonNull)

Example 3 with Reminder

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);
        }
    });
}
Also used : Reminder(nodomain.freeyourgadget.gadgetbridge.entities.Reminder) User(nodomain.freeyourgadget.gadgetbridge.entities.User) DialogInterface(android.content.DialogInterface) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) GBReminderListAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.GBReminderListAdapter) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Example 4 with 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;
}
Also used : Reminder(nodomain.freeyourgadget.gadgetbridge.entities.Reminder)

Aggregations

Reminder (nodomain.freeyourgadget.gadgetbridge.entities.Reminder)4 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)2 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)2 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)2 User (nodomain.freeyourgadget.gadgetbridge.entities.User)2 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 AlertDialog (android.app.AlertDialog)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 CardView (androidx.cardview.widget.CardView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ConfigureReminders (nodomain.freeyourgadget.gadgetbridge.activities.ConfigureReminders)1