From e0741d4a138afcdde7217cdcdd2e41236126ba2b Mon Sep 17 00:00:00 2001 From: Johannes Krude Date: Thu, 29 Aug 2024 16:41:30 +0200 Subject: [PATCH] Casio2C2D: Reminders have no hour or minute --- .../activities/ConfigureReminders.java | 14 +++++++-- .../activities/ReminderDetails.java | 31 +++++++++++-------- .../adapter/GBReminderListAdapter.java | 9 ++++-- .../devices/AbstractDeviceCoordinator.java | 5 +++ .../devices/DeviceCoordinator.java | 5 +++ .../casio/Casio2C2DDeviceCoordinator.java | 28 +++++++++++++++++ .../gbx100/CasioGBX100DeviceCoordinator.java | 4 +-- .../CasioGWB5600DeviceCoordinator.java | 4 +-- .../devices/casio/Casio2C2DSupport.java | 2 +- .../res/layout/activity_reminder_details.xml | 3 +- 10 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/Casio2C2DDeviceCoordinator.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java index b1db23fe7..f62218c6c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureReminders.java @@ -1,4 +1,5 @@ -/* Copyright (C) 2021-2024 Arjan Schrijver, Daniel Dakhno, José Rebelo +/* Copyright (C) 2021-2024 Arjan Schrijver, Daniel Dakhno, José Rebelo, + Johannes Krude This file is part of Gadgetbridge. @@ -37,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Calendar; +import java.util.TimeZone; import java.util.List; import java.util.Locale; import java.util.UUID; @@ -64,7 +66,7 @@ public class ConfigureReminders extends AbstractGBActivity { private static final int REQ_CONFIGURE_REMINDER = 1; private GBReminderListAdapter mGBReminderListAdapter; - private GBDevice gbDevice; + public GBDevice gbDevice; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -154,7 +156,13 @@ public class ConfigureReminders extends AbstractGBActivity { private Reminder createDefaultReminder(@NonNull Device device, @NonNull User user) { final Reminder reminder = new Reminder(); reminder.setRepetition(Reminder.ONCE); - reminder.setDate(Calendar.getInstance().getTime()); + if (gbDevice.getDeviceCoordinator().getRemindersHaveTime()) { + reminder.setDate(Calendar.getInstance().getTime()); + } else { + Calendar noonGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + noonGMT.set(noonGMT.get(Calendar.YEAR), noonGMT.get(Calendar.MONTH), noonGMT.get(Calendar.DAY_OF_MONTH), 12, 0); + reminder.setDate(noonGMT.getTime()); + } reminder.setMessage(""); reminder.setDeviceId(device.getId()); reminder.setUserId(user.getId()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java index 007ebe91d..f836e2e10 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ReminderDetails.java @@ -1,4 +1,5 @@ -/* Copyright (C) 2021-2024 Arjan Schrijver, Daniel Dakhno, José Rebelo +/* Copyright (C) 2021-2024 Arjan Schrijver, Daniel Dakhno, José Rebelo, + Johannes Krude This file is part of Gadgetbridge. @@ -121,18 +122,22 @@ public class ReminderDetails extends AbstractGBActivity implements TimePickerDia }); final View cardTime = findViewById(R.id.card_time); - cardTime.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - new TimePickerDialog( - ReminderDetails.this, - ReminderDetails.this, - reminder.getDate().getHours(), - reminder.getDate().getMinutes(), - DateFormat.is24HourFormat(GBApplication.getContext()) - ).show(); - } - }); + if (coordinator.getRemindersHaveTime()) { + cardTime.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new TimePickerDialog( + ReminderDetails.this, + ReminderDetails.this, + reminder.getDate().getHours(), + reminder.getDate().getMinutes(), + DateFormat.is24HourFormat(GBApplication.getContext()) + ).show(); + } + }); + } else { + cardTime.setVisibility(View.GONE); + } reminderText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(coordinator.getMaximumReminderMessageLength())}); reminderText.addTextChangedListener(new TextWatcher() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBReminderListAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBReminderListAdapter.java index 385493cf6..57438156e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBReminderListAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBReminderListAdapter.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2021-2024 Arjan Schrijver, José Rebelo +/* Copyright (C) 2021-2024 Arjan Schrijver, José Rebelo, Johannes Krude This file is part of Gadgetbridge. @@ -100,7 +100,12 @@ public class GBReminderListAdapter extends RecyclerView.Adapter. */ +/* Based on code from BlueWatcher, https://github.com/masterjc/bluewatcher */ +package nodomain.freeyourgadget.gadgetbridge.devices.casio; + + +public abstract class Casio2C2DDeviceCoordinator extends CasioDeviceCoordinator { + + @Override + public boolean getRemindersHaveTime() { + return false; + } + +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java index 2b3c98e23..4a506817b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java @@ -34,7 +34,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; -import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.casio.Casio2C2DDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; @@ -43,7 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport; -public class CasioGBX100DeviceCoordinator extends CasioDeviceCoordinator { +public class CasioGBX100DeviceCoordinator extends Casio2C2DDeviceCoordinator { /** CASIO brand identifier in GB Device name */ public static final String CASIO_IDENTIFIER = "CASIO"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java index 6bfb25a46..39cc91dcb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gwb5600/CasioGWB5600DeviceCoordinator.java @@ -36,11 +36,11 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; -import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioDeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.casio.Casio2C2DDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gwb5600.CasioGWB5600DeviceSupport; -public class CasioGWB5600DeviceCoordinator extends CasioDeviceCoordinator { +public class CasioGWB5600DeviceCoordinator extends Casio2C2DDeviceCoordinator { @Override protected Pattern getSupportedDeviceName() { return Pattern.compile("CASIO GW-B5600"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java index c16aecfd0..dc7578ba4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java @@ -642,7 +642,7 @@ public abstract class Casio2C2DSupport extends CasioSupport { System.arraycopy(message, 0, data[2*pos], 2, Math.min(message.length, 18)); Arrays.fill(data[2*pos], 2+message.length, 20, (byte) 0); - LocalDate start = LocalDate.ofInstant(reminder.getDate().toInstant(), ZoneId.systemDefault()); + LocalDate start = LocalDate.ofInstant(reminder.getDate().toInstant(), ZoneId.of("GMT")); if (start.getYear() < 2000) { if (reminder.getRepetition() == Reminder.EVERY_WEEK) { final LocalDate first = LocalDate.of(2000, 1, 1); diff --git a/app/src/main/res/layout/activity_reminder_details.xml b/app/src/main/res/layout/activity_reminder_details.xml index 3df8e48b1..e53bfb2e6 100644 --- a/app/src/main/res/layout/activity_reminder_details.xml +++ b/app/src/main/res/layout/activity_reminder_details.xml @@ -92,6 +92,7 @@ android:layout_height="wrap_content" android:layout_margin="8dp" android:foreground="?android:attr/selectableItemBackground" + android:visibility="visible" app:cardBackgroundColor="?attr/cardview_background_color" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/card_date" @@ -134,7 +135,7 @@ app:cardBackgroundColor="?attr/cardview_background_color" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/card_time" + app:layout_constraintTop_toBottomOf="@id/card_date" card_view:cardElevation="3dp" card_view:contentPadding="4dp">