Browse Source

Fix issues and add support for ringtone

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
1c4ba6f6ee

+ 49 - 6
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.IntentFilter;
 import android.content.res.Configuration;
 import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.Bundle;
-import android.os.Parcelable;
 import android.support.annotation.NonNull;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 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.helpers.api.ApiHelper;
 import com.nextcloud.talk.api.models.json.call.CallOverall;
 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.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.DataChannelMessage;
 import com.nextcloud.talk.api.models.json.signaling.NCIceCandidate;
 import com.nextcloud.talk.api.models.json.signaling.NCIceCandidate;
 import com.nextcloud.talk.api.models.json.signaling.NCMessagePayload;
 import com.nextcloud.talk.api.models.json.signaling.NCMessagePayload;
@@ -221,14 +222,14 @@ public class CallActivity extends AppCompatActivity {
         ButterKnife.bind(this);
         ButterKnife.bind(this);
 
 
         roomToken = getIntent().getExtras().getString("roomToken", "");
         roomToken = getIntent().getExtras().getString("roomToken", "");
-        userEntity = Parcels.unwrap((Parcelable) getIntent().getExtras().get("userEntity"));
+        userEntity = Parcels.unwrap(getIntent().getExtras().getParcelable("userEntity"));
         callSession = "0";
         callSession = "0";
         credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken());
         credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken());
 
 
         callControls.setZ(100.0f);
         callControls.setZ(100.0f);
         basicInitialization();
         basicInitialization();
 
 
-        if (userUtils.getCurrentUser() != null && userUtils.getCurrentUser() != userEntity) {
+        if (!userEntity.getCurrent()) {
             userUtils.createOrUpdateUser(userEntity.getUsername(),
             userUtils.createOrUpdateUser(userEntity.getUsername(),
                     userEntity.getToken(), userEntity.getBaseUrl(), null,
                     userEntity.getToken(), userEntity.getBaseUrl(), null,
                     null, true)
                     null, true)
@@ -242,8 +243,12 @@ public class CallActivity extends AppCompatActivity {
                         public void onNext(UserEntity userEntity) {
                         public void onNext(UserEntity userEntity) {
                             cookieManager.getCookieStore().removeAll();
                             cookieManager.getCookieStore().removeAll();
                             userUtils.disableAllUsersWithoutId(userEntity.getId());
                             userUtils.disableAllUsersWithoutId(userEntity.getId());
-                            initViews();
-                            checkPermissions();
+                            if (getIntent().getExtras().containsKey("fromNotification")) {
+                                handleFromNotification();
+                            } else {
+                                initViews();
+                                checkPermissions();
+                            }
                         }
                         }
 
 
                         @Override
                         @Override
@@ -257,13 +262,50 @@ public class CallActivity extends AppCompatActivity {
                         }
                         }
                     });
                     });
 
 
+        } else if (getIntent().getExtras().containsKey("fromNotification")) {
+            handleFromNotification();
         } else {
         } else {
             initViews();
             initViews();
             checkPermissions();
             checkPermissions();
         }
         }
+    }
+
+    private void handleFromNotification() {
+        ncApi.getRooms(credentials, ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl()))
+                .subscribeOn(Schedulers.newThread())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new Observer<RoomsOverall>() {
+                    @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) {
     private void toggleMedia(boolean enable, boolean video) {
         String message;
         String message;
         if (video) {
         if (video) {
@@ -731,6 +773,7 @@ public class CallActivity extends AppCompatActivity {
 
 
                                                     @Override
                                                     @Override
                                                     public void onError(Throwable e) {
                                                     public void onError(Throwable e) {
+                                                        Log.d("MARIO_DEBUG", e.getLocalizedMessage());
                                                         dispose(signalingDisposable);
                                                         dispose(signalingDisposable);
                                                     }
                                                     }
 
 
@@ -745,7 +788,7 @@ public class CallActivity extends AppCompatActivity {
 
 
                                     @Override
                                     @Override
                                     public void onError(Throwable e) {
                                     public void onError(Throwable e) {
-
+                                        Log.d("MARIO_DEBUG", e.getLocalizedMessage());
                                     }
                                     }
 
 
                                     @Override
                                     @Override

+ 7 - 3
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.PushUtils;
 import com.nextcloud.talk.utils.bundle.BundleBuilder;
 import com.nextcloud.talk.utils.bundle.BundleBuilder;
 
 
+import org.parceler.Parcels;
+
 import java.security.InvalidKeyException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.PrivateKey;
@@ -93,7 +95,9 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService {
                             Intent intent = new Intent(this, CallActivity.class);
                             Intent intent = new Intent(this, CallActivity.class);
                             BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
                             BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
                             bundleBuilder.putString("roomToken", decryptedPushMessage.getId());
                             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());
                             intent.putExtras(bundleBuilder.build());
 
 
                             PendingIntent pendingIntent = PendingIntent.getActivity(this,
                             PendingIntent pendingIntent = PendingIntent.getActivity(this,
@@ -155,7 +159,7 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService {
                                             NotificationUtils.NOTIFICATION_CHANNEL_CALLS, getResources().getString(R
                                             NotificationUtils.NOTIFICATION_CHANNEL_CALLS, getResources().getString(R
                                                     .string.nc_notification_channel_calls), getResources().getString
                                                     .string.nc_notification_channel_calls), getResources().getString
                                                     (R.string.nc_notification_channel_calls_description), true,
                                                     (R.string.nc_notification_channel_calls_description), true,
-                                            NotificationManager.IMPORTANCE_HIGH);
+                                            NotificationManager.IMPORTANCE_HIGH, soundUri);
 
 
                                     notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
                                     notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
                                 } else {
                                 } else {
@@ -163,7 +167,7 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService {
                                             NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES, getResources().getString(R
                                             NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES, getResources().getString(R
                                                     .string.nc_notification_channel_messages), getResources().getString
                                                     .string.nc_notification_channel_messages), getResources().getString
                                                     (R.string.nc_notification_channel_messages_description), true,
                                                     (R.string.nc_notification_channel_messages_description), true,
-                                            NotificationManager.IMPORTANCE_DEFAULT);
+                                            NotificationManager.IMPORTANCE_DEFAULT, soundUri);
 
 
                                     notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
                                     notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
                                 }
                                 }

+ 12 - 1
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.NotificationChannelGroup;
 import android.app.NotificationManager;
 import android.app.NotificationManager;
 import android.graphics.Color;
 import android.graphics.Color;
+import android.media.AudioAttributes;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Build;
 
 
 public class NotificationUtils {
 public class NotificationUtils {
@@ -36,7 +38,7 @@ public class NotificationUtils {
     public static void createNotificationChannel(NotificationManager notificationManager,
     public static void createNotificationChannel(NotificationManager notificationManager,
                                                  String channelId, String channelName,
                                                  String channelId, String channelName,
                                                  String channelDescription, boolean vibrate,
                                                  String channelDescription, boolean vibrate,
-                                                 int importance) {
+                                                 int importance, Uri soundUri) {
 
 
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
                 && notificationManager.getNotificationChannel(channelId) == null) {
                 && notificationManager.getNotificationChannel(channelId) == null) {
@@ -44,6 +46,15 @@ public class NotificationUtils {
             NotificationChannel channel = new NotificationChannel(channelId, channelName,
             NotificationChannel channel = new NotificationChannel(channelId, channelName,
                     importance);
                     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.setDescription(channelDescription);
             channel.enableLights(vibrate);
             channel.enableLights(vibrate);
             channel.enableVibration(vibrate);
             channel.enableVibration(vibrate);