mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 09:49:21 +02:00
move in-chat sounds to InChatSounds class
This commit is contained in:
parent
84c35c7483
commit
48f1693420
4 changed files with 85 additions and 9 deletions
|
@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.connect.NetworkStateReceiver;
|
|||
import org.thoughtcrime.securesms.crypto.PRNGFixes;
|
||||
import org.thoughtcrime.securesms.geolocation.DcLocationManager;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||
import org.thoughtcrime.securesms.notifications.InChatSounds;
|
||||
import org.thoughtcrime.securesms.util.AndroidSignalProtocolLogger;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.ScreenLockUtil;
|
||||
|
@ -71,6 +72,7 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
|
|||
initializeLogging();
|
||||
initializeJobManager();
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||
InChatSounds.getInstance(this);
|
||||
|
||||
dcLocationManager = new DcLocationManager(this);
|
||||
try {
|
||||
|
|
|
@ -93,6 +93,7 @@ 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;
|
||||
|
@ -1442,7 +1443,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||
}
|
||||
else {
|
||||
processComposeControls(ACTION_SEND_OUT);
|
||||
dcContext.notificationManger.playSendSound();
|
||||
InChatSounds.getInstance(ConversationActivity.this).playSendSound();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package org.thoughtcrime.securesms.notifications;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.SoundPool;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
|
||||
public class InChatSounds {
|
||||
private static final String TAG = InChatSounds.class.getSimpleName();
|
||||
private static volatile InChatSounds instance;
|
||||
|
||||
private Context appContext = null;
|
||||
private SoundPool soundPool = null;
|
||||
private int soundIn = 0;
|
||||
private int soundOut = 0;
|
||||
|
||||
static public InChatSounds getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
synchronized (InChatSounds.class) {
|
||||
if (instance == null) {
|
||||
instance = new InChatSounds(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private InChatSounds(Context context) {
|
||||
try {
|
||||
appContext = context.getApplicationContext();
|
||||
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
|
||||
soundIn = soundPool.load(context, R.raw.sound_in, 1);
|
||||
soundOut = soundPool.load(context, R.raw.sound_out, 1);
|
||||
} catch(Exception e) {
|
||||
Log.e(TAG, "cannot initialize sounds", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void playSendSound() {
|
||||
try {
|
||||
if (Prefs.isInChatNotifications(appContext)) {
|
||||
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Log.e(TAG, "cannot play send sound", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void playIncomingSound() {
|
||||
try {
|
||||
if (Prefs.isInChatNotifications(appContext)) {
|
||||
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Log.e(TAG, "cannot play incoming sound", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,34 @@
|
|||
package org.thoughtcrime.securesms.notifications;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class MsgNotificationManager {
|
||||
@NonNull private DcContext dcContext;
|
||||
private static final String TAG = InChatSounds.class.getSimpleName();
|
||||
@NonNull private ApplicationDcContext dcContext;
|
||||
private volatile int visibleChatId = 0;
|
||||
|
||||
public MsgNotificationManager(DcContext dcContext) {
|
||||
public MsgNotificationManager(ApplicationDcContext dcContext) {
|
||||
this.dcContext = dcContext;
|
||||
}
|
||||
|
||||
public void addNotification(int chatId, int msgId) {
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
|
||||
if (Prefs.isChatMuted(dcContext.context, chatId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (chatId == visibleChatId) {
|
||||
InChatSounds.getInstance(dcContext.context).playIncomingSound();
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -27,11 +40,10 @@ public class MsgNotificationManager {
|
|||
|
||||
public void updateVisibleChat(int chatId) {
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
|
||||
visibleChatId = chatId;
|
||||
removeNotifications(chatId);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void playSendSound() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue