From 1c4ba6f6eed5b7c306352c0e2da1b1dd65d0e696 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 2 Jan 2018 21:41:39 +0100 Subject: [PATCH] Fix issues and add support for ringtone Signed-off-by: Mario Danic --- .../talk/activities/CallActivity.java | 57 ++++++++++++++++--- .../MagicFirebaseMessagingService.java | 10 +++- .../talk/utils/NotificationUtils.java | 13 ++++- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index f4c6b20cd..bfacb59fa 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -33,7 +33,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.os.Bundle; -import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; @@ -56,6 +55,8 @@ import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.helpers.api.ApiHelper; import com.nextcloud.talk.api.models.json.call.CallOverall; import com.nextcloud.talk.api.models.json.generic.GenericOverall; +import com.nextcloud.talk.api.models.json.rooms.Room; +import com.nextcloud.talk.api.models.json.rooms.RoomsOverall; import com.nextcloud.talk.api.models.json.signaling.DataChannelMessage; import com.nextcloud.talk.api.models.json.signaling.NCIceCandidate; import com.nextcloud.talk.api.models.json.signaling.NCMessagePayload; @@ -221,14 +222,14 @@ public class CallActivity extends AppCompatActivity { ButterKnife.bind(this); roomToken = getIntent().getExtras().getString("roomToken", ""); - userEntity = Parcels.unwrap((Parcelable) getIntent().getExtras().get("userEntity")); + userEntity = Parcels.unwrap(getIntent().getExtras().getParcelable("userEntity")); callSession = "0"; credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken()); callControls.setZ(100.0f); basicInitialization(); - if (userUtils.getCurrentUser() != null && userUtils.getCurrentUser() != userEntity) { + if (!userEntity.getCurrent()) { userUtils.createOrUpdateUser(userEntity.getUsername(), userEntity.getToken(), userEntity.getBaseUrl(), null, null, true) @@ -242,8 +243,12 @@ public class CallActivity extends AppCompatActivity { public void onNext(UserEntity userEntity) { cookieManager.getCookieStore().removeAll(); userUtils.disableAllUsersWithoutId(userEntity.getId()); - initViews(); - checkPermissions(); + if (getIntent().getExtras().containsKey("fromNotification")) { + handleFromNotification(); + } else { + initViews(); + checkPermissions(); + } } @Override @@ -257,13 +262,50 @@ public class CallActivity extends AppCompatActivity { } }); + } else if (getIntent().getExtras().containsKey("fromNotification")) { + handleFromNotification(); } else { initViews(); checkPermissions(); } - } + private void handleFromNotification() { + ncApi.getRooms(credentials, ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl())) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(RoomsOverall roomsOverall) { + for (Room room : roomsOverall.getOcs().getData()) { + if (roomToken.equals(room.getRoomId())) { + roomToken = room.getToken(); + break; + } + } + + initViews(); + checkPermissions(); + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + } + + private void toggleMedia(boolean enable, boolean video) { String message; if (video) { @@ -731,6 +773,7 @@ public class CallActivity extends AppCompatActivity { @Override public void onError(Throwable e) { + Log.d("MARIO_DEBUG", e.getLocalizedMessage()); dispose(signalingDisposable); } @@ -745,7 +788,7 @@ public class CallActivity extends AppCompatActivity { @Override public void onError(Throwable e) { - + Log.d("MARIO_DEBUG", e.getLocalizedMessage()); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java b/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java index 64b9b249d..eaaf9581b 100644 --- a/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java +++ b/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java @@ -46,6 +46,8 @@ import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.PushUtils; import com.nextcloud.talk.utils.bundle.BundleBuilder; +import org.parceler.Parcels; + import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; @@ -93,7 +95,9 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService { Intent intent = new Intent(this, CallActivity.class); BundleBuilder bundleBuilder = new BundleBuilder(new Bundle()); bundleBuilder.putString("roomToken", decryptedPushMessage.getId()); - bundleBuilder.putParcelable("userEntity", signatureVerification.getUserEntity()); + bundleBuilder.putParcelable("userEntity", Parcels.wrap(signatureVerification + .getUserEntity())); + bundleBuilder.putBoolean("fromNotification", true); intent.putExtras(bundleBuilder.build()); PendingIntent pendingIntent = PendingIntent.getActivity(this, @@ -155,7 +159,7 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService { NotificationUtils.NOTIFICATION_CHANNEL_CALLS, getResources().getString(R .string.nc_notification_channel_calls), getResources().getString (R.string.nc_notification_channel_calls_description), true, - NotificationManager.IMPORTANCE_HIGH); + NotificationManager.IMPORTANCE_HIGH, soundUri); notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_CALLS); } else { @@ -163,7 +167,7 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService { NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES, getResources().getString(R .string.nc_notification_channel_messages), getResources().getString (R.string.nc_notification_channel_messages_description), true, - NotificationManager.IMPORTANCE_DEFAULT); + NotificationManager.IMPORTANCE_DEFAULT, soundUri); notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES); } diff --git a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java index 98c28ad2a..523105dff 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.java @@ -25,6 +25,8 @@ import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.graphics.Color; +import android.media.AudioAttributes; +import android.net.Uri; import android.os.Build; public class NotificationUtils { @@ -36,7 +38,7 @@ public class NotificationUtils { public static void createNotificationChannel(NotificationManager notificationManager, String channelId, String channelName, String channelDescription, boolean vibrate, - int importance) { + int importance, Uri soundUri) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O && notificationManager.getNotificationChannel(channelId) == null) { @@ -44,6 +46,15 @@ public class NotificationUtils { NotificationChannel channel = new NotificationChannel(channelId, channelName, importance); + int usage; + + if (channelId.equals(NotificationUtils.NOTIFICATION_CHANNEL_CALLS)) { + usage = AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST; + } else { + usage = AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT; + } + + channel.setSound(soundUri, new AudioAttributes.Builder().setUsage(usage).build()); channel.setDescription(channelDescription); channel.enableLights(vibrate); channel.enableVibration(vibrate);