Эх сурвалжийг харах

Reimplement breakout rooms for usage of Activity instead of Controller

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 жил өмнө
parent
commit
48a4fbc3cc

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -221,6 +221,7 @@
         <activity
             android:name=".chat.ChatActivity"
             android:theme="@style/AppTheme"
+            android:launchMode="singleInstance"
             android:screenOrientation="portrait" />
 
         <receiver android:name=".receivers.PackageReplacedReceiver"

+ 8 - 15
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -66,6 +66,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.call.CallParticipant;
 import com.nextcloud.talk.call.CallParticipantList;
 import com.nextcloud.talk.call.CallParticipantModel;
+import com.nextcloud.talk.chat.ChatActivity;
 import com.nextcloud.talk.data.user.model.User;
 import com.nextcloud.talk.databinding.CallActivityBinding;
 import com.nextcloud.talk.events.ConfigurationChangeEvent;
@@ -182,7 +183,8 @@ import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_PARTICIPANT_PERMISS
 import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE;
 import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID;
 import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN;
-import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL;
+import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH;
+import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM;
 import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY;
 
 @AutoInjector(NextcloudTalkApplication.class)
@@ -1917,8 +1919,8 @@ public class CallActivity extends CallBaseActivity {
             removeCallParticipant(sessionId);
         }
 
+        ApplicationWideCurrentRoomHolder.getInstance().clear();
         hangupNetworkCalls(shutDownView);
-        ApplicationWideCurrentRoomHolder.getInstance().setInCall(false);
     }
 
     private void hangupNetworkCalls(boolean shutDownView) {
@@ -1942,26 +1944,17 @@ public class CallActivity extends CallBaseActivity {
                 @Override
                 public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOverall) {
                     if (!switchToRoomToken.isEmpty()) {
-                        Intent intent = new Intent(context, MainActivity.class);
-
-                        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+                        Intent intent = new Intent(context, ChatActivity.class);
+                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
                         Bundle bundle = new Bundle();
-                        bundle.putBoolean(KEY_SWITCH_TO_ROOM_AND_START_CALL, true);
+                        bundle.putBoolean(KEY_SWITCH_TO_ROOM, true);
+                        bundle.putBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, true);
                         bundle.putString(KEY_ROOM_TOKEN, switchToRoomToken);
                         bundle.putParcelable(KEY_USER_ENTITY, conversationUser);
                         bundle.putBoolean(KEY_CALL_VOICE_ONLY, isVoiceOnlyCall);
                         intent.putExtras(bundle);
                         startActivity(intent);
-
-                        if (isBreakoutRoom) {
-                            Toast.makeText(context, context.getResources().getString(R.string.switch_to_main_room),
-                                           Toast.LENGTH_LONG).show();
-                        } else {
-                            Toast.makeText(context, context.getResources().getString(R.string.switch_to_breakout_room),
-                                           Toast.LENGTH_LONG).show();
-                        }
-
                         finish();
                     } else if (shutDownView) {
                         finish();

+ 0 - 26
app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt

@@ -349,24 +349,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
     private fun handleIntent(intent: Intent) {
         handleActionFromContact(intent)
 
-        if (intent.getBooleanExtra(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL, false)) {
-            logRouterBackStack(router!!)
-            // remapChatController(
-            //     router!!,
-            //     intent.getParcelableExtra<User>(KEY_USER_ENTITY)!!.id!!,
-            //     intent.getStringExtra(KEY_ROOM_TOKEN)!!,
-            //     intent.extras!!,
-            //     true,
-            //     true
-            // )
-
-            val chatIntent = Intent(context, ChatActivity::class.java)
-            chatIntent.putExtras(intent.extras!!)
-            startActivity(chatIntent)
-
-            logRouterBackStack(router!!)
-        }
-
         if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
             if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
                 if (!router!!.hasRootController()) {
@@ -377,14 +359,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
                 startActivity(callNotificationIntent)
             } else {
                 logRouterBackStack(router!!)
-                // remapChatController(
-                //     router!!,
-                //     intent.getParcelableExtra<User>(KEY_USER_ENTITY)!!.id!!,
-                //     intent.getStringExtra(KEY_ROOM_TOKEN)!!,
-                //     intent.extras!!,
-                //     true,
-                //     true
-                // )
 
                 val chatIntent = Intent(context, ChatActivity::class.java)
                 chatIntent.putExtras(intent.extras!!)

+ 49 - 38
app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

@@ -169,6 +169,7 @@ import com.nextcloud.talk.utils.ParticipantPermissions
 import com.nextcloud.talk.utils.VibrationUtils
 import com.nextcloud.talk.utils.bundle.BundleKeys
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CALL_VOICE_ONLY
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_PATHS
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
@@ -177,6 +178,8 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_MODERATOR
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
 import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew
 import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
@@ -295,7 +298,11 @@ class ChatActivity :
     private val localParticipantMessageListener = object : SignalingMessageReceiver.LocalParticipantMessageListener {
         override fun onSwitchTo(token: String?) {
             if (token != null) {
-                switchToRoom(token)
+                if (CallActivity.active) {
+                    Log.d(TAG, "CallActivity is running. Ignore to switch chat in ChatActivity...")
+                } else {
+                    switchToRoom(token, false, false)
+                }
             }
         }
     }
@@ -309,6 +316,34 @@ class ChatActivity :
         setupSystemColors()
         setContentView(binding.root)
 
+        handleIntent(intent)
+
+        binding.progressBar.visibility = View.VISIBLE
+
+        initAdapter()
+        binding.messagesListView.setAdapter(adapter)
+    }
+
+    override fun onNewIntent(intent: Intent) {
+        super.onNewIntent(intent)
+        val extras: Bundle? = intent.extras
+
+        val requestedRoomSwitch = extras?.getBoolean(KEY_SWITCH_TO_ROOM, false) == true
+
+        if (requestedRoomSwitch) {
+            val newRoomToken = extras?.getString(KEY_ROOM_TOKEN).orEmpty()
+            val startCallAfterRoomSwitch = extras?.getBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, false) == true
+            val isVoiceOnlyCall = extras?.getBoolean(KEY_CALL_VOICE_ONLY, false) == true
+
+            if (newRoomToken != roomToken) {
+                switchToRoom(newRoomToken, startCallAfterRoomSwitch, isVoiceOnlyCall)
+            }
+        } else {
+            handleIntent(intent)
+        }
+    }
+
+    private fun handleIntent(intent: Intent) {
         val extras: Bundle? = intent.extras
 
         conversationUser = extras?.getParcelable(KEY_USER_ENTITY)
@@ -336,14 +371,9 @@ class ChatActivity :
         }
 
         startCallFromNotification = extras?.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false) == true
-        startCallFromRoomSwitch = extras?.getBoolean(BundleKeys.KEY_SWITCH_TO_ROOM_AND_START_CALL, false) == true
-
-        voiceOnly = extras?.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false) == true
+        startCallFromRoomSwitch = extras?.getBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, false) == true
 
-        binding.progressBar.visibility = View.VISIBLE
-
-        initAdapter()
-        binding.messagesListView.setAdapter(adapter)
+        voiceOnly = extras?.getBoolean(KEY_CALL_VOICE_ONLY, false) == true
     }
 
     override fun onStart() {
@@ -1010,12 +1040,7 @@ class ChatActivity :
         currentConversation?.type == Conversation.ConversationType
         .ROOM_TYPE_ONE_TO_ONE_CALL
 
-    private fun switchToRoom(token: String) {
-        if (CallActivity.active) {
-            Log.d(TAG, "CallActivity is running. Ignore to switch chat in ChatController...")
-            return
-        }
-
+    private fun switchToRoom(token: String, startCallAfterRoomSwitch: Boolean, isVoiceOnlyCall: Boolean) {
         if (conversationUser != null) {
             runOnUiThread {
                 if (currentConversation?.objectType == Conversation.ObjectType.ROOM) {
@@ -1037,6 +1062,11 @@ class ChatActivity :
             bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
             bundle.putString(KEY_ROOM_TOKEN, token)
 
+            if (startCallAfterRoomSwitch) {
+                bundle.putBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, true)
+                bundle.putBoolean(KEY_CALL_VOICE_ONLY, isVoiceOnlyCall)
+            }
+
             leaveRoom {
                 val chatIntent = Intent(context, ChatActivity::class.java)
                 chatIntent.putExtras(bundle)
@@ -1926,7 +1956,7 @@ class ChatActivity :
     override fun onPause() {
         super.onPause()
 
-        logConversationInfos("onDetach")
+        logConversationInfos("onPause")
 
         eventBus.unregister(this)
 
@@ -1995,24 +2025,6 @@ class ChatActivity :
     }
 
     private fun joinRoomWithPassword() {
-        if (CallActivity.active &&
-            roomToken != ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken
-        ) {
-            Toast.makeText(
-                context,
-                context.getString(R.string.restrict_join_other_room_while_call),
-                Toast.LENGTH_LONG
-            ).show()
-
-            Log.e(
-                TAG,
-                "Restricted to open chat controller because a call in another room is active. This is an " +
-                    "edge case which is not properly handled yet."
-            )
-            finish()
-            return
-        }
-
         // if ApplicationWideCurrentRoomHolder contains a session (because a call is active), then keep the sessionId
         if (ApplicationWideCurrentRoomHolder.getInstance().currentRoomId ==
             currentConversation!!.roomId
@@ -2080,6 +2092,7 @@ class ChatActivity :
                         }
 
                         if (startCallFromRoomSwitch) {
+                            startCallFromRoomSwitch = false
                             startACall(voiceOnly, true)
                         }
                     }
@@ -2160,8 +2173,6 @@ class ChatActivity :
                     if (funToCallWhenLeaveSuccessful != null) {
                         Log.d(TAG, "a callback action was set and is now executed because room was left successfully")
                         funToCallWhenLeaveSuccessful()
-                    } else {
-                        Log.d(TAG, "remapChatController was not set")
                     }
                 }
 
@@ -2872,7 +2883,7 @@ class ChatActivity :
             )
 
             if (isVoiceOnlyCall) {
-                bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true)
+                bundle.putBoolean(KEY_CALL_VOICE_ONLY, true)
             }
             if (callWithoutNotification) {
                 bundle.putBoolean(BundleKeys.KEY_CALL_WITHOUT_NOTIFICATION, true)
@@ -3509,7 +3520,7 @@ class ChatActivity :
     private fun logConversationInfos(methodName: String) {
         Log.d(TAG, " |-----------------------------------------------")
         Log.d(TAG, " | method: $methodName")
-        Log.d(TAG, " | ChatController: " + System.identityHashCode(this).toString())
+        Log.d(TAG, " | ChatActivity: " + System.identityHashCode(this).toString())
         Log.d(TAG, " | roomToken: $roomToken")
         Log.d(TAG, " | currentConversation?.displayName: ${currentConversation?.displayName}")
         Log.d(TAG, " | sessionIdAfterRoomJoined: $sessionIdAfterRoomJoined")
@@ -3517,7 +3528,7 @@ class ChatActivity :
     }
 
     companion object {
-        private const val TAG = "ChatController"
+        private val TAG = ChatActivity::class.simpleName
         private const val CONTENT_TYPE_SYSTEM_MESSAGE: Byte = 1
         private const val CONTENT_TYPE_UNREAD_NOTICE_MESSAGE: Byte = 2
         private const val CONTENT_TYPE_LOCATION: Byte = 3

+ 2 - 1
app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt

@@ -80,7 +80,8 @@ object BundleKeys {
     const val KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO = "KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO"
     const val KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO = "KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO"
     const val KEY_IS_MODERATOR = "KEY_IS_MODERATOR"
-    const val KEY_SWITCH_TO_ROOM_AND_START_CALL = "KEY_SWITCH_TO_ROOM_AND_START_CALL"
+    const val KEY_SWITCH_TO_ROOM = "KEY_SWITCH_TO_ROOM"
+    const val KEY_START_CALL_AFTER_ROOM_SWITCH = "KEY_START_CALL_AFTER_ROOM_SWITCH"
     const val KEY_IS_BREAKOUT_ROOM = "KEY_IS_BREAKOUT_ROOM"
     const val KEY_NOTIFICATION_RESTRICT_DELETION = "KEY_NOTIFICATION_RESTRICT_DELETION"
     const val KEY_DISMISS_RECORDING_URL = "KEY_DISMISS_RECORDING_URL"

+ 1 - 1
scripts/analysis/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 108 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 109 warnings</span>