From dd627f76bf21e5ce494c33a7b03f1bdb90f32b13 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 31 Aug 2019 14:05:41 +0200 Subject: [PATCH] make short vibrate in open chat configurable and respect phone silent mode --- .../pixart/messenger/services/NotificationService.java | 5 ++++- .../pixart/messenger/services/XmppConnectionService.java | 9 ++++++--- src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 2 ++ src/main/res/xml/preferences.xml | 5 +++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 939c95299..4d8c39d22 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -316,11 +316,14 @@ public class NotificationService { private void pushNow(final Message message) { mXmppConnectionService.updateUnreadCountBadge(); + final boolean isScreenOn = mXmppConnectionService.isInteractive(); if (!notify(message)) { + if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { + mXmppConnectionService.vibrate(); + } Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing notification because turned off"); return; } - final boolean isScreenOn = mXmppConnectionService.isInteractive(); if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { mXmppConnectionService.vibrate(); Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing notification because conversation is open"); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index a0d298d47..bb7162bb3 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -4172,9 +4172,12 @@ public class XmppConnectionService extends Service { } public void vibrate() { - Log.d(Config.LOGTAG, "Notification: short vibrate"); - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); - vibrator.vibrate(100); + final boolean vibrateInChat = getBooleanPreference("vibrate_in_chat", R.bool.vibrate_in_chat); + if (!isPhoneSilenced() && vibrateInChat) { + Log.d(Config.LOGTAG, "Notification: short vibrate"); + Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); + vibrator.vibrate(100); + } } private List threadSafeList(Set set) { diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 59b759636..c63e50a6a 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -118,6 +118,7 @@ true true true + true pix-art.de diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 287ccd23a..8b97b2af6 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -925,4 +925,6 @@ Share backup files Conversations backup Event + Vibrate when a new message arrives in an open chat + Vibrate in open chat diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index d8dd6c89e..d5ce35819 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -140,6 +140,11 @@ android:key="vibrate_on_notification" android:summary="@string/pref_vibrate_summary" android:title="@string/pref_vibrate" /> +