mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-11 06:44:09 +01:00
Change mute call behaviour
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
b508e3b6f0
commit
a93a2cdb6b
@ -38,6 +38,7 @@ import android.service.notification.StatusBarNotification;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
@ -47,7 +48,7 @@ import androidx.core.graphics.drawable.IconCompat;
|
|||||||
import androidx.work.Data;
|
import androidx.work.Data;
|
||||||
import androidx.work.Worker;
|
import androidx.work.Worker;
|
||||||
import androidx.work.WorkerParameters;
|
import androidx.work.WorkerParameters;
|
||||||
import autodagger.AutoInjector;
|
|
||||||
import com.bluelinelabs.logansquare.LoganSquare;
|
import com.bluelinelabs.logansquare.LoganSquare;
|
||||||
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
||||||
import com.facebook.common.references.CloseableReference;
|
import com.facebook.common.references.CloseableReference;
|
||||||
@ -68,26 +69,23 @@ import com.nextcloud.talk.models.SignatureVerification;
|
|||||||
import com.nextcloud.talk.models.database.ArbitraryStorageEntity;
|
import com.nextcloud.talk.models.database.ArbitraryStorageEntity;
|
||||||
import com.nextcloud.talk.models.database.UserEntity;
|
import com.nextcloud.talk.models.database.UserEntity;
|
||||||
import com.nextcloud.talk.models.json.chat.ChatUtils;
|
import com.nextcloud.talk.models.json.chat.ChatUtils;
|
||||||
|
import com.nextcloud.talk.models.json.conversations.Conversation;
|
||||||
|
import com.nextcloud.talk.models.json.conversations.RoomOverall;
|
||||||
import com.nextcloud.talk.models.json.notifications.NotificationOverall;
|
import com.nextcloud.talk.models.json.notifications.NotificationOverall;
|
||||||
import com.nextcloud.talk.models.json.push.DecryptedPushMessage;
|
import com.nextcloud.talk.models.json.push.DecryptedPushMessage;
|
||||||
import com.nextcloud.talk.models.json.push.NotificationUser;
|
import com.nextcloud.talk.models.json.push.NotificationUser;
|
||||||
import com.nextcloud.talk.models.json.conversations.Conversation;
|
import com.nextcloud.talk.utils.ApiUtils;
|
||||||
import com.nextcloud.talk.models.json.conversations.RoomOverall;
|
import com.nextcloud.talk.utils.DisplayUtils;
|
||||||
import com.nextcloud.talk.utils.*;
|
import com.nextcloud.talk.utils.DoNotDisturbUtils;
|
||||||
|
import com.nextcloud.talk.utils.NotificationUtils;
|
||||||
|
import com.nextcloud.talk.utils.PushUtils;
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||||
import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils;
|
import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageUtils;
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||||
import io.reactivex.Observer;
|
|
||||||
import io.reactivex.disposables.Disposable;
|
|
||||||
import okhttp3.JavaNetCookieJar;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import org.parceler.Parcels;
|
|
||||||
import retrofit2.Retrofit;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import org.parceler.Parcels;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.CookieManager;
|
import java.net.CookieManager;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
@ -96,6 +94,17 @@ import java.security.PrivateKey;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.NoSuchPaddingException;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import autodagger.AutoInjector;
|
||||||
|
import io.reactivex.Observer;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import okhttp3.JavaNetCookieJar;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class NotificationWorker extends Worker {
|
public class NotificationWorker extends Worker {
|
||||||
public static final String TAG = "NotificationWorker";
|
public static final String TAG = "NotificationWorker";
|
||||||
@ -120,6 +129,7 @@ public class NotificationWorker extends Worker {
|
|||||||
private String conversationType = "one2one";
|
private String conversationType = "one2one";
|
||||||
|
|
||||||
private String credentials;
|
private String credentials;
|
||||||
|
private boolean muteCall = false;
|
||||||
|
|
||||||
public NotificationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
public NotificationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||||
super(context, workerParams);
|
super(context, workerParams);
|
||||||
@ -129,55 +139,52 @@ public class NotificationWorker extends Worker {
|
|||||||
UserEntity userEntity = signatureVerification.getUserEntity();
|
UserEntity userEntity = signatureVerification.getUserEntity();
|
||||||
|
|
||||||
ArbitraryStorageEntity arbitraryStorageEntity;
|
ArbitraryStorageEntity arbitraryStorageEntity;
|
||||||
boolean muteCalls = false;
|
|
||||||
|
|
||||||
if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(),
|
if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(userEntity.getId(),
|
||||||
"mute_calls", intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) {
|
"mute_calls", intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) {
|
||||||
muteCalls = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
|
muteCall = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!muteCalls) {
|
ncApi.getRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(),
|
||||||
ncApi.getRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(),
|
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())))
|
||||||
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())))
|
.blockingSubscribe(new Observer<RoomOverall>() {
|
||||||
.blockingSubscribe(new Observer<RoomOverall>() {
|
@Override
|
||||||
@Override
|
public void onSubscribe(Disposable d) {
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(RoomOverall roomOverall) {
|
public void onNext(RoomOverall roomOverall) {
|
||||||
Conversation conversation = roomOverall.getOcs().getData();
|
Conversation conversation = roomOverall.getOcs().getData();
|
||||||
|
|
||||||
intent.putExtra(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation));
|
intent.putExtra(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation));
|
||||||
if (conversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) ||
|
if (conversation.getType().equals(Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) ||
|
||||||
(!TextUtils.isEmpty(conversation.getObjectType()) && "share:password".equals
|
(!TextUtils.isEmpty(conversation.getObjectType()) && "share:password".equals
|
||||||
(conversation.getObjectType()))) {
|
(conversation.getObjectType()))) {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
if (conversation.getType().equals(Conversation.ConversationType.ROOM_GROUP_CALL)) {
|
||||||
|
conversationType = "group";
|
||||||
} else {
|
} else {
|
||||||
if (conversation.getType().equals(Conversation.ConversationType.ROOM_GROUP_CALL)) {
|
conversationType = "public";
|
||||||
conversationType = "group";
|
}
|
||||||
} else {
|
if (decryptedPushMessage.getNotificationId() != Long.MIN_VALUE) {
|
||||||
conversationType = "public";
|
showNotificationWithObjectData(intent);
|
||||||
}
|
} else {
|
||||||
if (decryptedPushMessage.getNotificationId() != Long.MIN_VALUE) {
|
showNotification(intent);
|
||||||
showNotificationWithObjectData(intent);
|
|
||||||
} else {
|
|
||||||
showNotification(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNotificationWithObjectData(Intent intent) {
|
private void showNotificationWithObjectData(Intent intent) {
|
||||||
@ -443,58 +450,60 @@ public class NotificationWorker extends Worker {
|
|||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||||
notificationManager.notify(notificationId, notification);
|
notificationManager.notify(notificationId, notification);
|
||||||
|
|
||||||
String ringtonePreferencesString;
|
if (!muteCall) {
|
||||||
Uri soundUri;
|
String ringtonePreferencesString;
|
||||||
|
Uri soundUri;
|
||||||
|
|
||||||
ringtonePreferencesString = appPreferences.getMessageRingtoneUri();
|
ringtonePreferencesString = appPreferences.getMessageRingtoneUri();
|
||||||
if (TextUtils.isEmpty(ringtonePreferencesString)) {
|
if (TextUtils.isEmpty(ringtonePreferencesString)) {
|
||||||
soundUri = Uri.parse("android.resource://" + context.getPackageName() +
|
|
||||||
"/raw/librem_by_feandesign_message");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
RingtoneSettings ringtoneSettings = LoganSquare.parse
|
|
||||||
(ringtonePreferencesString, RingtoneSettings.class);
|
|
||||||
soundUri = ringtoneSettings.getRingtoneUri();
|
|
||||||
} catch (IOException exception) {
|
|
||||||
soundUri = Uri.parse("android.resource://" + context.getPackageName() +
|
soundUri = Uri.parse("android.resource://" + context.getPackageName() +
|
||||||
"/raw/librem_by_feandesign_message");
|
"/raw/librem_by_feandesign_message");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (soundUri != null & !ApplicationWideCurrentRoomHolder.getInstance().isInCall() &&
|
|
||||||
DoNotDisturbUtils.INSTANCE.shouldPlaySound()) {
|
|
||||||
AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder().setContentType
|
|
||||||
(AudioAttributes.CONTENT_TYPE_SONIFICATION);
|
|
||||||
|
|
||||||
if (decryptedPushMessage.getType().equals("chat") || decryptedPushMessage.getType().equals("room")) {
|
|
||||||
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT);
|
|
||||||
} else {
|
} else {
|
||||||
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST);
|
try {
|
||||||
|
RingtoneSettings ringtoneSettings = LoganSquare.parse
|
||||||
|
(ringtonePreferencesString, RingtoneSettings.class);
|
||||||
|
soundUri = ringtoneSettings.getRingtoneUri();
|
||||||
|
} catch (IOException exception) {
|
||||||
|
soundUri = Uri.parse("android.resource://" + context.getPackageName() +
|
||||||
|
"/raw/librem_by_feandesign_message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
if (soundUri != null & !ApplicationWideCurrentRoomHolder.getInstance().isInCall() &&
|
||||||
try {
|
DoNotDisturbUtils.INSTANCE.shouldPlaySound()) {
|
||||||
mediaPlayer.setDataSource(context, soundUri);
|
AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder().setContentType
|
||||||
mediaPlayer.setAudioAttributes(audioAttributesBuilder.build());
|
(AudioAttributes.CONTENT_TYPE_SONIFICATION);
|
||||||
|
|
||||||
mediaPlayer.setOnPreparedListener(mp -> mediaPlayer.start());
|
if (decryptedPushMessage.getType().equals("chat") || decryptedPushMessage.getType().equals("room")) {
|
||||||
mediaPlayer.setOnCompletionListener(MediaPlayer::release);
|
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT);
|
||||||
|
|
||||||
mediaPlayer.prepareAsync();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Failed to set data source");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (DoNotDisturbUtils.INSTANCE.shouldVibrate(appPreferences.getShouldVibrateSetting())) {
|
|
||||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
|
||||||
|
|
||||||
if (vibrator != null) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
vibrator.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
|
|
||||||
} else {
|
} else {
|
||||||
vibrator.vibrate(500);
|
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||||
|
try {
|
||||||
|
mediaPlayer.setDataSource(context, soundUri);
|
||||||
|
mediaPlayer.setAudioAttributes(audioAttributesBuilder.build());
|
||||||
|
|
||||||
|
mediaPlayer.setOnPreparedListener(mp -> mediaPlayer.start());
|
||||||
|
mediaPlayer.setOnCompletionListener(MediaPlayer::release);
|
||||||
|
|
||||||
|
mediaPlayer.prepareAsync();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Failed to set data source");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (DoNotDisturbUtils.INSTANCE.shouldVibrate(appPreferences.getShouldVibrateSetting())) {
|
||||||
|
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
|
if (vibrator != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
vibrator.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
|
||||||
|
} else {
|
||||||
|
vibrator.vibrate(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
apc:mp_default_value="false"
|
apc:mp_default_value="false"
|
||||||
apc:mp_key="mute_calls"
|
apc:mp_key="mute_calls"
|
||||||
apc:mp_title="@string/nc_mute_calls" />
|
apc:mp_title="@string/nc_mute_calls"
|
||||||
|
apc:mp_summary="@string/nc_mute_calls_desc"/>
|
||||||
|
|
||||||
</com.yarolegovich.mp.MaterialPreferenceCategory>
|
</com.yarolegovich.mp.MaterialPreferenceCategory>
|
||||||
|
|
||||||
|
@ -200,6 +200,7 @@
|
|||||||
<string name="nc_notify_me_mention">Notify when mentioned</string>
|
<string name="nc_notify_me_mention">Notify when mentioned</string>
|
||||||
<string name="nc_notify_me_never">Never notify</string>
|
<string name="nc_notify_me_never">Never notify</string>
|
||||||
<string name="nc_mute_calls">Mute calls</string>
|
<string name="nc_mute_calls">Mute calls</string>
|
||||||
|
<string name="nc_mute_calls_desc">Incoming calls will be silenced</string>
|
||||||
|
|
||||||
<!-- Bottom sheet menu -->
|
<!-- Bottom sheet menu -->
|
||||||
<string name="nc_failed_to_perform_operation">Sorry, something went wrong!</string>
|
<string name="nc_failed_to_perform_operation">Sorry, something went wrong!</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user