notification sound throttling setting
This commit is contained in:
parent
3db7413bf2
commit
de9874fdf7
|
@ -28,6 +28,7 @@ import android.text.style.StyleSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.app.NotificationCompat.BigPictureStyle;
|
import androidx.core.app.NotificationCompat.BigPictureStyle;
|
||||||
|
@ -61,6 +62,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -120,6 +122,8 @@ public class NotificationService {
|
||||||
private Ringtone currentlyPlayingRingtone = null;
|
private Ringtone currentlyPlayingRingtone = null;
|
||||||
private ScheduledFuture<?> vibrationFuture;
|
private ScheduledFuture<?> vibrationFuture;
|
||||||
|
|
||||||
|
private SharedPreferences lastNotificationTimeByConversation = null;
|
||||||
|
|
||||||
NotificationService(final XmppConnectionService service) {
|
NotificationService(final XmppConnectionService service) {
|
||||||
this.mXmppConnectionService = service;
|
this.mXmppConnectionService = service;
|
||||||
}
|
}
|
||||||
|
@ -390,6 +394,7 @@ public class NotificationService {
|
||||||
conversations = getBacklogConversations(account);
|
conversations = getBacklogConversations(account);
|
||||||
count = getBacklogMessageCount(account);
|
count = getBacklogMessageCount(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNotification(count > 0, conversations);
|
updateNotification(count > 0, conversations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -727,8 +732,13 @@ public class NotificationService {
|
||||||
final boolean doNotify =
|
final boolean doNotify =
|
||||||
(!(this.mIsInForeground && this.mOpenConversation == null) || isScreenLocked)
|
(!(this.mIsInForeground && this.mOpenConversation == null) || isScreenLocked)
|
||||||
&& !account.inGracePeriod()
|
&& !account.inGracePeriod()
|
||||||
&& !this.inMiniGracePeriod(account);
|
&& !this.inMiniGracePeriod(account) &&
|
||||||
|
!shouldNotificationSoundBeThrottled(conversation);
|
||||||
|
|
||||||
updateNotification(doNotify, Collections.singletonList(conversation.getUuid()));
|
updateNotification(doNotify, Collections.singletonList(conversation.getUuid()));
|
||||||
|
|
||||||
|
ensureLastNotificationTimeByConversation()
|
||||||
|
.edit().putLong(conversation.getUuid(), System.currentTimeMillis()).apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,6 +940,39 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldNotificationSoundBeThrottled(@Nullable Conversational conversation) {
|
||||||
|
if (conversation == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long throttlingPeriod = mXmppConnectionService.getLongPreference("notification_throttling_period", 0);
|
||||||
|
|
||||||
|
if (throttlingPeriod <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lastNotificationTimestamp = ensureLastNotificationTimeByConversation().getLong(conversation.getUuid(), 0L);
|
||||||
|
|
||||||
|
return (System.currentTimeMillis() - lastNotificationTimestamp) > throttlingPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SharedPreferences ensureLastNotificationTimeByConversation() {
|
||||||
|
if (lastNotificationTimeByConversation == null) {
|
||||||
|
lastNotificationTimeByConversation = mXmppConnectionService.getApplicationContext().getSharedPreferences("lastNotificationTimeByConversation", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
Map<String, ?> allValues = lastNotificationTimeByConversation.getAll();
|
||||||
|
|
||||||
|
Long now = System.currentTimeMillis();
|
||||||
|
SharedPreferences.Editor editor = lastNotificationTimeByConversation.edit();
|
||||||
|
allValues.forEach((BiConsumer<String, Object>) (s, o) -> {
|
||||||
|
if (o instanceof Long && (now - (Long) o) > 3600000) {
|
||||||
|
editor.remove(s);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void modifyForSoundVibrationAndLight(
|
private void modifyForSoundVibrationAndLight(
|
||||||
Builder mBuilder, boolean notify, boolean quietHours, SharedPreferences preferences) {
|
Builder mBuilder, boolean notify, boolean quietHours, SharedPreferences preferences) {
|
||||||
final Resources resources = mXmppConnectionService.getResources();
|
final Resources resources = mXmppConnectionService.getResources();
|
||||||
|
|
|
@ -26,6 +26,33 @@
|
||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</integer-array>
|
</integer-array>
|
||||||
|
|
||||||
|
<string-array name="notification_throttling_periods_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>5000</item>
|
||||||
|
<item>15000</item>
|
||||||
|
<item>30000</item>
|
||||||
|
<item>60000</item>
|
||||||
|
<item>120000</item>
|
||||||
|
<item>180000</item>
|
||||||
|
<item>300000</item>
|
||||||
|
<item>600000</item>
|
||||||
|
<item>900000</item>
|
||||||
|
<item>1800000</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="notification_throttling_periods">
|
||||||
|
<item>@string/never</item>
|
||||||
|
<item>5 sec</item>
|
||||||
|
<item>15 sec</item>
|
||||||
|
<item>30 sec</item>
|
||||||
|
<item>1 min</item>
|
||||||
|
<item>2 min</item>
|
||||||
|
<item>3 min</item>
|
||||||
|
<item>5 min</item>
|
||||||
|
<item>10 min</item>
|
||||||
|
<item>15 min</item>
|
||||||
|
<item>30 min</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="quick_actions">
|
<string-array name="quick_actions">
|
||||||
<item>@string/none</item>
|
<item>@string/none</item>
|
||||||
<item>@string/recently_used</item>
|
<item>@string/recently_used</item>
|
||||||
|
|
|
@ -297,6 +297,8 @@
|
||||||
<string name="title_pref_enable_quiet_hours">Enable quiet hours</string>
|
<string name="title_pref_enable_quiet_hours">Enable quiet hours</string>
|
||||||
<string name="pref_quiet_hours_summary">Notifications will be silenced during quiet hours</string>
|
<string name="pref_quiet_hours_summary">Notifications will be silenced during quiet hours</string>
|
||||||
<string name="pref_expert_options_other">Other</string>
|
<string name="pref_expert_options_other">Other</string>
|
||||||
|
<string name="pref_noisy_notifications_throttling">Throttle noisy notifications</string>
|
||||||
|
<string name="pref_noisy_notifications_throttling_summary">Throttle sound and vibration for notifications received from one conversation during short period of time</string>
|
||||||
<string name="pref_autojoin">Synchronize bookmarks</string>
|
<string name="pref_autojoin">Synchronize bookmarks</string>
|
||||||
<string name="pref_autojoin_summary">Set “autojoin” flag when entering or leaving a MUC and react to modifications made by other clients.</string>
|
<string name="pref_autojoin_summary">Set “autojoin” flag when entering or leaving a MUC and react to modifications made by other clients.</string>
|
||||||
<string name="toast_message_omemo_fingerprint">OMEMO fingerprint copied to clipboard</string>
|
<string name="toast_message_omemo_fingerprint">OMEMO fingerprint copied to clipboard</string>
|
||||||
|
|
|
@ -79,6 +79,13 @@
|
||||||
android:key="grace_period_length"
|
android:key="grace_period_length"
|
||||||
android:summary="@string/pref_notification_grace_period_summary"
|
android:summary="@string/pref_notification_grace_period_summary"
|
||||||
android:title="@string/pref_notification_grace_period" />
|
android:title="@string/pref_notification_grace_period" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/notification_throttling_periods"
|
||||||
|
android:entryValues="@array/notification_throttling_periods_values"
|
||||||
|
android:key="notification_throttling_period"
|
||||||
|
android:summary="@string/pref_noisy_notifications_throttling_summary"
|
||||||
|
android:title="@string/pref_noisy_notifications_throttling" />
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:key="quiet_hours"
|
android:key="quiet_hours"
|
||||||
android:summary="@string/pref_quiet_hours_summary"
|
android:summary="@string/pref_quiet_hours_summary"
|
||||||
|
|
Loading…
Reference in a new issue