make in-chat-sounds respect notification- and mute-settings

This commit is contained in:
B. Petersen 2020-05-23 13:10:01 +02:00
parent f30da6e912
commit 050c358859
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
4 changed files with 15 additions and 13 deletions

View file

@ -53,6 +53,7 @@
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_key_inthread_notifications"
android:dependency="pref_key_enable_notifications"
android:title="@string/pref_in_chat_sounds"
android:defaultValue="true" />

View file

@ -93,7 +93,6 @@ import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.mms.MediaConstraints;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.notifications.InChatSounds;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
import org.thoughtcrime.securesms.recipients.Recipient;
@ -1443,7 +1442,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
else {
processComposeControls(ACTION_SEND_OUT);
InChatSounds.getInstance(ConversationActivity.this).playSendSound();
dcContext.notificationCenter.maybePlaySendSound(dcChat);
}
}

View file

@ -41,9 +41,7 @@ public class InChatSounds {
public void playSendSound() {
try {
if (Prefs.isInChatNotifications(appContext)) {
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
}
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
} catch(Exception e) {
Log.e(TAG, "cannot play send sound", e);
}
@ -51,9 +49,7 @@ public class InChatSounds {
public void playIncomingSound() {
try {
if (Prefs.isInChatNotifications(appContext)) {
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
}
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
} catch(Exception e) {
Log.e(TAG, "cannot play incoming sound", e);
}

View file

@ -289,14 +289,14 @@ public class NotificationCenter {
DcChat dcChat = dcContext.getChat(chatId);
if (chatId == visibleChatId) {
// in-chat sounds are not related to notifications,
// they can be enabled/disabled independently
InChatSounds.getInstance(context).playIncomingSound();
if (!Prefs.isNotificationsEnabled(context) || dcChat.isMuted()) {
return;
}
if (!Prefs.isNotificationsEnabled(context) || dcChat.isMuted()) {
if (chatId == visibleChatId) {
if (Prefs.isInChatNotifications(context)) {
InChatSounds.getInstance(context).playIncomingSound();
}
return;
}
@ -482,4 +482,10 @@ public class NotificationCenter {
});
}
public void maybePlaySendSound(DcChat dcChat) {
if (Prefs.isNotificationsEnabled(context) && !dcChat.isMuted()) {
InChatSounds.getInstance(context).playSendSound();
}
}
}