Search in sources :

Example 1 with GBReminderListAdapter

use of nodomain.freeyourgadget.gadgetbridge.adapter.GBReminderListAdapter 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)

Aggregations

DialogInterface (android.content.DialogInterface)1 View (android.view.View)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 GBReminderListAdapter (nodomain.freeyourgadget.gadgetbridge.adapter.GBReminderListAdapter)1 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)1 DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)1 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 Reminder (nodomain.freeyourgadget.gadgetbridge.entities.Reminder)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)1