1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-05 09:47:01 +01:00

Merge pull request #1222 from joserebelo/notifications-timeout

Support minimum time between notifications
This commit is contained in:
Carsten Pfeiffer 2018-08-20 22:45:18 +02:00 committed by GitHub
commit 52b6b8db73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 0 deletions

View File

@ -50,6 +50,7 @@ import android.support.v7.graphics.Palette;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@ -86,6 +87,8 @@ public class NotificationListener extends NotificationListenerService {
private LimitedQueue mActionLookup = new LimitedQueue(16);
private HashMap<String, Long> notificationTimes = new HashMap<>();
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@ -191,6 +194,8 @@ public class NotificationListener extends NotificationListenerService {
if (shouldIgnore(sbn))
return;
Prefs prefs = GBApplication.getPrefs();
switch (GBApplication.getGrantedInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
break;
@ -265,6 +270,18 @@ public class NotificationListener extends NotificationListenerService {
return;
}
// Ignore too frequent notifications, according to user preference
long min_timeout = prefs.getInt("notifications_timeout", 0) * 1000;
Long cur_time = System.currentTimeMillis();
if (notificationTimes.containsKey(source)) {
Long last_time = notificationTimes.get(source);
if (cur_time - last_time < min_timeout) {
LOG.info("Ignoring frequent notification, last one was " + (cur_time - last_time) + "ms ago");
return;
}
}
notificationTimes.put(source, cur_time);
GBApplication.deviceService().onNotification(notificationSpec);
}

View File

@ -387,4 +387,28 @@
<item>1800</item>
<item>3600</item>
</string-array>
<string-array name="notifications_timeout">
<item>@string/no_limit</item>
<item>@string/seconds_5</item>
<item>@string/seconds_10</item>
<item>@string/seconds_20</item>
<item>@string/seconds_30</item>
<item>@string/minutes_1</item>
<item>@string/minutes_5</item>
<item>@string/minutes_10</item>
<item>@string/minutes_30</item>
</string-array>
<string-array name="notifications_timeout_values">
<item>0</item>
<item>5</item>
<item>10</item>
<item>20</item>
<item>30</item>
<item>60</item>
<item>300</item>
<item>600</item>
<item>1800</item>
</string-array>
</resources>

View File

@ -94,6 +94,7 @@
<string name="pref_title_notifications_repetitions">Repetitions</string>
<string name="pref_title_notifications_call">Phone Calls</string>
<string name="pref_title_notifications_sms">SMS</string>
<string name="pref_title_notifications_timeout">Minimum time between notifications</string>
<string name="pref_title_notifications_pebblemsg">Pebble Messages</string>
<string name="pref_summary_notifications_pebblemsg">Support for apps that send notifications to the Pebble via PebbleKit.</string>
<string name="pref_title_notifications_generic">Generic notification support</string>
@ -368,6 +369,15 @@
<string name="heart_rate">Heart rate</string>
<string name="battery">Battery</string>
<string name="no_limit">No limit</string>
<string name="seconds_5">5 seconds</string>
<string name="seconds_10">10 seconds</string>
<string name="seconds_20">20 seconds</string>
<string name="seconds_30">30 seconds</string>
<string name="minutes_1">1 minute</string>
<string name="minutes_5">5 minutes</string>
<string name="minutes_10">10 minutes</string>
<string name="minutes_30">30 minutes</string>
<string name="liveactivity_live_activity">Live activity</string>
<string name="weeksteps_today_steps_description">Steps today, target: %1$s</string>

View File

@ -155,6 +155,14 @@
android:key="notifications_generic_whenscreenon"
android:title="@string/pref_title_whenscreenon" />
<ListPreference
android:defaultValue="0"
android:entries="@array/notifications_timeout"
android:entryValues="@array/notifications_timeout_values"
android:key="notifications_timeout"
android:title="@string/pref_title_notifications_timeout"
android:summary="%s" />
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="false"