Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: update widgets on time changed

Ammar Ahmed71cae07dc02c
diff --git a/apps/mobile/android/app/src/main/AndroidManifest.xml b/apps/mobile/android/app/src/main/AndroidManifest.xml
index 4b6724133..a3267c669 100644
--- a/apps/mobile/android/app/src/main/AndroidManifest.xml
+++ b/apps/mobile/android/app/src/main/AndroidManifest.xml
@@ -96,6 +96,15 @@
android:resource="@xml/note_widget_info" />
</receiver>
+ <receiver
+ android:name=".WidgetTimeChangeReceiver"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.TIME_SET" />
+ <action android:name="android.intent.action.TIMEZONE_CHANGED" />
+ </intent-filter>
+ </receiver>
+
<receiver
android:name=".ReminderWidgetProvider"
android:exported="false"
diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetTimeChangeReceiver.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetTimeChangeReceiver.java
new file mode 100644
index 000000000..957f6769a
--- /dev/null
+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/WidgetTimeChangeReceiver.java
@@ -0,0 +1,28 @@
+package com.streetwriters.notesnook;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * Redraws the widgets when the clock or timezone changes.
+ *
+ * Reminder rows are described relative to the current time ("Upcoming"/"Last", "Today"/"Tomorrow"),
+ * and a reminder that has passed drops off the list entirely. All of that is decided when the
+ * widget is drawn, so moving the clock leaves the previous drawing in place: a reminder can still
+ * read "Upcoming" long after its time has gone by.
+ *
+ * The app normally redraws the list when a reminder notification is delivered, but that does not
+ * happen if the reminder never fires, which is exactly the case when the clock jumps past it.
+ *
+ * Only TIME_SET and TIMEZONE_CHANGED are handled here: DATE_CHANGED is not exempt from the
+ * Android 8 limits on manifest-registered implicit broadcasts, so a receiver for it would never
+ * run. Crossing midnight is instead picked up by the widget's own periodic update.
+ */
+public class WidgetTimeChangeReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ WidgetUtils.refreshAll(context);
+ }
+}