Loading app/src/main/java/app/fedilab/android/helper/PushHelper.java +20 −13 Original line number Diff line number Diff line Loading @@ -84,32 +84,39 @@ public class PushHelper { WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); break; case "REPEAT_NOTIFICATIONS": setRepeat(context); break; case "NO_NOTIFICATIONS": WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); new Thread(() -> { List<BaseAccount> accounts = new Account(context).getPushNotificationAccounts(); if (accounts != null) { for (BaseAccount account : accounts) { ((Activity) context).runOnUiThread(() -> { UnifiedPush.unregisterApp(context, account.user_id + "@" + account.instance); }); } } }).start(); new PeriodicWorkRequest.Builder(NotificationsWorker.class, 20, TimeUnit.MINUTES) .addTag(Helper.WORKER_REFRESH_NOTIFICATION) .build(); break; case "NO_NOTIFICATIONS": } } public static void setRepeat(Context context) { WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); new Thread(() -> { List<BaseAccount> accounts = new Account(context).getPushNotificationAccounts(); if (accounts != null) { for (BaseAccount account : accounts) { ((Activity) context).runOnUiThread(() -> { UnifiedPush.unregisterApp(context, account.user_id + "@" + account.instance); }); } }).start(); break; } }).start(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String value = prefs.getString(context.getString(R.string.SET_NOTIFICATION_DELAY_VALUE), "15"); new PeriodicWorkRequest.Builder(NotificationsWorker.class, Long.parseLong(value), TimeUnit.MINUTES) .addTag(Helper.WORKER_REFRESH_NOTIFICATION) .build(); } Loading app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java +18 −0 Original line number Diff line number Diff line Loading @@ -92,7 +92,21 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl if (notification_time_slot != null) { preferenceScreen.removePreference(notification_time_slot); } ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference("SET_NOTIFICATION_DELAY_VALUE"); if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } return; } else if (SET_NOTIFICATION_TYPE != null && SET_NOTIFICATION_TYPE.getValue().equals(notificationValues[1])) { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference(getString(R.string.SET_NOTIFICATION_DELAY_VALUE)); if (SET_NOTIFICATION_DELAY_VALUE != null) { SET_NOTIFICATION_DELAY_VALUE.getContext().setTheme(Helper.dialogStyle()); } } else { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference("SET_NOTIFICATION_DELAY_VALUE"); if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } } Preference button_mention = findPreference("button_mention"); Loading Loading @@ -178,6 +192,10 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl createPref(); PushHelper.startStreaming(requireActivity()); } if (key.compareToIgnoreCase(getString(R.string.SET_NOTIFICATION_DELAY_VALUE)) == 0) { createPref(); PushHelper.setRepeat(requireActivity()); } if (key.compareToIgnoreCase(getString(R.string.SET_LED_COLOUR_VAL)) == 0) { try { int value = Integer.parseInt(key); Loading app/src/main/res/values/strings.xml +22 −1 Original line number Diff line number Diff line Loading @@ -744,6 +744,14 @@ <item>No notifications</item> </string-array> <string-array name="set_notification_delay_values"> <item>15 minutes</item> <item>30 minutes</item> <item>1 hour</item> <item>2 hours</item> <item>6 hours</item> <item>12 hours</item> </string-array> <string name="SET_COOKIES" translatable="false">SET_COOKIES</string> <string name="SET_PROXY_ENABLED" translatable="false">SET_PROXY_ENABLED</string> Loading @@ -758,11 +766,21 @@ <string name="SET_CUSTOM_USER_AGENT" translatable="false">SET_CUSTOM_USER_AGENT</string> <string name="SET_NSFW_TIMEOUT" translatable="false">SET_NSFW_TIMEOUT</string> <string name="SET_NOTIFICATION_TYPE" translatable="false">SET_NOTIFICATION_TYPE</string> <string name="SET_NOTIFICATION_DELAY_VALUE" translatable="false">SET_NOTIFICATION_DELAY_VALUE</string> <string-array name="SET_NOTIFICATION_TYPE_VALUE" translatable="false"> <item>PUSH_NOTIFICATIONS</item> <item>REPEAT_NOTIFICATIONS</item> <item>NO_NOTIFICATIONS</item> </string-array> <string-array name="SET_NOTIFICATION_DELAYS_VALUES" translatable="false"> <item>15</item> <item>30</item> <item>60</item> <item>120</item> <item>360</item> <item>720</item> </string-array> <string name="SET_PICTURE_COMPRESSED" translatable="false">SET_PICTURE_COMPRESSED</string> <string name="SET_VIDEO_COMPRESSED" translatable="false">SET_VIDEO_COMPRESSED</string> <string name="SET_FORWARD_TAGS_IN_REPLY" translatable="false">SET_FORWARD_TAGS_IN_REPLY</string> Loading Loading @@ -994,6 +1012,9 @@ <string name="toast_token">The app failed to get a token</string> <string name="media_cannot_be_uploaded">Media cannot be uploaded!</string> <string name="open_draft">Open draft</string> <string name="set_push_notifications_delay">Set the delay between each new fetch</string> <string name="refresh_every">Fetch notifications every:</string> <string name="type_of_notifications_delay_title">Notifications fetch time</string> <string-array name="photo_editor_emoji" translatable="false"> <!-- Smiles --> Loading app/src/main/res/xml/pref_notifications.xml +11 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,17 @@ app:dialogTitle="@string/type_of_notifications" app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> <ListPreference app:defaultValue="15" app:dialogTitle="@string/refresh_every" app:entries="@array/set_notification_delay_values" app:entryValues="@array/SET_NOTIFICATION_DELAYS_VALUES" app:iconSpaceReserved="false" app:key="@string/SET_NOTIFICATION_DELAY_VALUE" app:summary="@string/set_push_notifications_delay" app:title="@string/type_of_notifications_delay_title" app:useSimpleSummaryProvider="true" /> </PreferenceCategory> Loading Loading
app/src/main/java/app/fedilab/android/helper/PushHelper.java +20 −13 Original line number Diff line number Diff line Loading @@ -84,32 +84,39 @@ public class PushHelper { WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); break; case "REPEAT_NOTIFICATIONS": setRepeat(context); break; case "NO_NOTIFICATIONS": WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); new Thread(() -> { List<BaseAccount> accounts = new Account(context).getPushNotificationAccounts(); if (accounts != null) { for (BaseAccount account : accounts) { ((Activity) context).runOnUiThread(() -> { UnifiedPush.unregisterApp(context, account.user_id + "@" + account.instance); }); } } }).start(); new PeriodicWorkRequest.Builder(NotificationsWorker.class, 20, TimeUnit.MINUTES) .addTag(Helper.WORKER_REFRESH_NOTIFICATION) .build(); break; case "NO_NOTIFICATIONS": } } public static void setRepeat(Context context) { WorkManager.getInstance(context).cancelAllWorkByTag(Helper.WORKER_REFRESH_NOTIFICATION); new Thread(() -> { List<BaseAccount> accounts = new Account(context).getPushNotificationAccounts(); if (accounts != null) { for (BaseAccount account : accounts) { ((Activity) context).runOnUiThread(() -> { UnifiedPush.unregisterApp(context, account.user_id + "@" + account.instance); }); } }).start(); break; } }).start(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String value = prefs.getString(context.getString(R.string.SET_NOTIFICATION_DELAY_VALUE), "15"); new PeriodicWorkRequest.Builder(NotificationsWorker.class, Long.parseLong(value), TimeUnit.MINUTES) .addTag(Helper.WORKER_REFRESH_NOTIFICATION) .build(); } Loading
app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java +18 −0 Original line number Diff line number Diff line Loading @@ -92,7 +92,21 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl if (notification_time_slot != null) { preferenceScreen.removePreference(notification_time_slot); } ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference("SET_NOTIFICATION_DELAY_VALUE"); if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } return; } else if (SET_NOTIFICATION_TYPE != null && SET_NOTIFICATION_TYPE.getValue().equals(notificationValues[1])) { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference(getString(R.string.SET_NOTIFICATION_DELAY_VALUE)); if (SET_NOTIFICATION_DELAY_VALUE != null) { SET_NOTIFICATION_DELAY_VALUE.getContext().setTheme(Helper.dialogStyle()); } } else { ListPreference SET_NOTIFICATION_DELAY_VALUE = findPreference("SET_NOTIFICATION_DELAY_VALUE"); if (SET_NOTIFICATION_DELAY_VALUE != null) { preferenceScreen.removePreferenceRecursively("SET_NOTIFICATION_DELAY_VALUE"); } } Preference button_mention = findPreference("button_mention"); Loading Loading @@ -178,6 +192,10 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl createPref(); PushHelper.startStreaming(requireActivity()); } if (key.compareToIgnoreCase(getString(R.string.SET_NOTIFICATION_DELAY_VALUE)) == 0) { createPref(); PushHelper.setRepeat(requireActivity()); } if (key.compareToIgnoreCase(getString(R.string.SET_LED_COLOUR_VAL)) == 0) { try { int value = Integer.parseInt(key); Loading
app/src/main/res/values/strings.xml +22 −1 Original line number Diff line number Diff line Loading @@ -744,6 +744,14 @@ <item>No notifications</item> </string-array> <string-array name="set_notification_delay_values"> <item>15 minutes</item> <item>30 minutes</item> <item>1 hour</item> <item>2 hours</item> <item>6 hours</item> <item>12 hours</item> </string-array> <string name="SET_COOKIES" translatable="false">SET_COOKIES</string> <string name="SET_PROXY_ENABLED" translatable="false">SET_PROXY_ENABLED</string> Loading @@ -758,11 +766,21 @@ <string name="SET_CUSTOM_USER_AGENT" translatable="false">SET_CUSTOM_USER_AGENT</string> <string name="SET_NSFW_TIMEOUT" translatable="false">SET_NSFW_TIMEOUT</string> <string name="SET_NOTIFICATION_TYPE" translatable="false">SET_NOTIFICATION_TYPE</string> <string name="SET_NOTIFICATION_DELAY_VALUE" translatable="false">SET_NOTIFICATION_DELAY_VALUE</string> <string-array name="SET_NOTIFICATION_TYPE_VALUE" translatable="false"> <item>PUSH_NOTIFICATIONS</item> <item>REPEAT_NOTIFICATIONS</item> <item>NO_NOTIFICATIONS</item> </string-array> <string-array name="SET_NOTIFICATION_DELAYS_VALUES" translatable="false"> <item>15</item> <item>30</item> <item>60</item> <item>120</item> <item>360</item> <item>720</item> </string-array> <string name="SET_PICTURE_COMPRESSED" translatable="false">SET_PICTURE_COMPRESSED</string> <string name="SET_VIDEO_COMPRESSED" translatable="false">SET_VIDEO_COMPRESSED</string> <string name="SET_FORWARD_TAGS_IN_REPLY" translatable="false">SET_FORWARD_TAGS_IN_REPLY</string> Loading Loading @@ -994,6 +1012,9 @@ <string name="toast_token">The app failed to get a token</string> <string name="media_cannot_be_uploaded">Media cannot be uploaded!</string> <string name="open_draft">Open draft</string> <string name="set_push_notifications_delay">Set the delay between each new fetch</string> <string name="refresh_every">Fetch notifications every:</string> <string name="type_of_notifications_delay_title">Notifications fetch time</string> <string-array name="photo_editor_emoji" translatable="false"> <!-- Smiles --> Loading
app/src/main/res/xml/pref_notifications.xml +11 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,17 @@ app:dialogTitle="@string/type_of_notifications" app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> <ListPreference app:defaultValue="15" app:dialogTitle="@string/refresh_every" app:entries="@array/set_notification_delay_values" app:entryValues="@array/SET_NOTIFICATION_DELAYS_VALUES" app:iconSpaceReserved="false" app:key="@string/SET_NOTIFICATION_DELAY_VALUE" app:summary="@string/set_push_notifications_delay" app:title="@string/type_of_notifications_delay_title" app:useSimpleSummaryProvider="true" /> </PreferenceCategory> Loading