Browse Source

Fix chat controller backstack ordering

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 5 years ago
parent
commit
bc089e9ee8

+ 10 - 3
app/src/main/java/com/nextcloud/talk/activities/MainActivity.java

@@ -26,12 +26,15 @@ import android.content.Intent;
 import android.os.Build;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.ViewGroup;
 import android.view.ViewGroup;
+
 import androidx.annotation.RequiresApi;
 import androidx.annotation.RequiresApi;
 import androidx.appcompat.widget.Toolbar;
 import androidx.appcompat.widget.Toolbar;
 import autodagger.AutoInjector;
 import autodagger.AutoInjector;
 import butterknife.BindView;
 import butterknife.BindView;
 import butterknife.ButterKnife;
 import butterknife.ButterKnife;
+
 import com.bluelinelabs.conductor.Conductor;
 import com.bluelinelabs.conductor.Conductor;
+import com.bluelinelabs.conductor.Controller;
 import com.bluelinelabs.conductor.Router;
 import com.bluelinelabs.conductor.Router;
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
@@ -40,9 +43,13 @@ import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.controllers.*;
 import com.nextcloud.talk.controllers.*;
 import com.nextcloud.talk.controllers.base.providers.ActionBarProvider;
 import com.nextcloud.talk.controllers.base.providers.ActionBarProvider;
+import com.nextcloud.talk.utils.ConductorRemapping;
 import com.nextcloud.talk.utils.SecurityUtils;
 import com.nextcloud.talk.utils.SecurityUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.nextcloud.talk.utils.database.user.UserUtils;
+
+import java.util.List;
+
 import io.requery.Persistable;
 import io.requery.Persistable;
 import io.requery.android.sqlcipher.SqlCipherDatabaseSource;
 import io.requery.android.sqlcipher.SqlCipherDatabaseSource;
 import io.requery.reactivex.ReactiveEntityStore;
 import io.requery.reactivex.ReactiveEntityStore;
@@ -150,9 +157,9 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide
                         .pushChangeHandler(new HorizontalChangeHandler())
                         .pushChangeHandler(new HorizontalChangeHandler())
                         .popChangeHandler(new HorizontalChangeHandler()));
                         .popChangeHandler(new HorizontalChangeHandler()));
             } else {
             } else {
-                router.pushController(RouterTransaction.with(new ChatController(intent.getExtras()))
-                        .pushChangeHandler(new HorizontalChangeHandler())
-                        .popChangeHandler(new HorizontalChangeHandler()));
+                ConductorRemapping.remapChatController(router, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1),
+                        intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN), intent.getExtras(), false);
+                ;
             }
             }
         }
         }
     }
     }

+ 3 - 3
app/src/main/java/com/nextcloud/talk/controllers/ChatController.java

@@ -1184,9 +1184,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
                                         Parcels.wrap(roomOverall.getOcs().getData()));
                                         Parcels.wrap(roomOverall.getOcs().getData()));
                                 conversationIntent.putExtras(bundle);
                                 conversationIntent.putExtras(bundle);
 
 
-                                getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
-                                        .pushChangeHandler(new HorizontalChangeHandler())
-                                        .popChangeHandler(new HorizontalChangeHandler())));
+                                ConductorRemapping.remapChatController(getRouter(), conversationUser.getId(),
+                                        roomOverall.getOcs().getData().getToken(), bundle, false);
+
                             } else {
                             } else {
                                 conversationIntent.putExtras(bundle);
                                 conversationIntent.putExtras(bundle);
                                 startActivity(conversationIntent);
                                 startActivity(conversationIntent);

+ 7 - 7
app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java

@@ -70,6 +70,7 @@ import com.nextcloud.talk.models.json.rooms.RoomOverall;
 import com.nextcloud.talk.models.json.sharees.Sharee;
 import com.nextcloud.talk.models.json.sharees.Sharee;
 import com.nextcloud.talk.models.json.sharees.ShareesOverall;
 import com.nextcloud.talk.models.json.sharees.ShareesOverall;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.ConductorRemapping;
 import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.nextcloud.talk.utils.database.user.UserUtils;
@@ -266,10 +267,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
                             if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                             if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                                 bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
                                 bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
                                         Parcels.wrap(roomOverall.getOcs().getData()));
                                         Parcels.wrap(roomOverall.getOcs().getData()));
-                                conversationIntent.putExtras(bundle);
-                                getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle))
-                                        .pushChangeHandler(new HorizontalChangeHandler())
-                                        .popChangeHandler(new HorizontalChangeHandler())));
+
+                                ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
+                                        roomOverall.getOcs().getData().getToken(), bundle, true);
                             } else {
                             } else {
                                 conversationIntent.putExtras(bundle);
                                 conversationIntent.putExtras(bundle);
                                 startActivity(conversationIntent);
                                 startActivity(conversationIntent);
@@ -848,9 +848,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
                                     if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                                     if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                                         bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
                                         bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION,
                                                 Parcels.wrap(roomOverall.getOcs().getData()));
                                                 Parcels.wrap(roomOverall.getOcs().getData()));
-                                        getRouter().replaceTopController((RouterTransaction.with(new ChatController(bundle))
-                                                .pushChangeHandler(new HorizontalChangeHandler())
-                                                .popChangeHandler(new HorizontalChangeHandler())));
+
+                                        ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
+                                                roomOverall.getOcs().getData().getToken(), bundle, true);
                                     } else {
                                     } else {
                                         startActivity(conversationIntent);
                                         startActivity(conversationIntent);
                                         new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
                                         new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);

+ 3 - 3
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -81,6 +81,7 @@ import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.json.participants.Participant;
 import com.nextcloud.talk.models.json.participants.Participant;
 import com.nextcloud.talk.models.json.rooms.Conversation;
 import com.nextcloud.talk.models.json.rooms.Conversation;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.ConductorRemapping;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.animations.SharedElementTransition;
 import com.nextcloud.talk.utils.animations.SharedElementTransition;
@@ -626,9 +627,8 @@ public class ConversationsListController extends BaseController implements Searc
 
 
                 if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                 if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
                     bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation));
                     bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation));
-                    getRouter().pushController((RouterTransaction.with(new ChatController(bundle))
-                            .pushChangeHandler(new HorizontalChangeHandler())
-                            .popChangeHandler(new HorizontalChangeHandler())));
+                    ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
+                            conversation.getToken(), bundle, false);
                 } else {
                 } else {
                     overridePushHandler(new NoOpControllerChangeHandler());
                     overridePushHandler(new NoOpControllerChangeHandler());
                     overridePopHandler(new NoOpControllerChangeHandler());
                     overridePopHandler(new NoOpControllerChangeHandler());

+ 3 - 3
app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java

@@ -60,6 +60,7 @@ import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
 import com.nextcloud.talk.models.json.rooms.Conversation;
 import com.nextcloud.talk.models.json.rooms.Conversation;
 import com.nextcloud.talk.models.json.rooms.RoomOverall;
 import com.nextcloud.talk.models.json.rooms.RoomOverall;
 import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.ConductorRemapping;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.nextcloud.talk.utils.database.user.UserUtils;
@@ -634,9 +635,8 @@ public class OperationsMenuController extends BaseController {
             conversationIntent.putExtras(bundle);
             conversationIntent.putExtras(bundle);
 
 
             if (getParentController() != null) {
             if (getParentController() != null) {
-                getParentController().getRouter().replaceTopController(RouterTransaction.with(new ChatController(bundle))
-                        .pushChangeHandler(new HorizontalChangeHandler())
-                        .popChangeHandler(new HorizontalChangeHandler()));
+                ConductorRemapping.remapChatController(getParentController().getRouter(), conversationUser.getId(),
+                        conversation.getToken(), bundle, true);
             }
             }
         } else {
         } else {
             initiateCall();
             initiateCall();

+ 61 - 0
app/src/main/java/com/nextcloud/talk/utils/ConductorRemapping.java

@@ -0,0 +1,61 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.utils;
+
+import android.os.Bundle;
+
+import com.bluelinelabs.conductor.Router;
+import com.bluelinelabs.conductor.RouterTransaction;
+import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
+import com.nextcloud.talk.controllers.ChatController;
+import com.nextcloud.talk.utils.bundle.BundleKeys;
+
+import java.util.List;
+
+public class ConductorRemapping {
+    public static void remapChatController(Router router, long internalUserId, String roomTokenOrId, Bundle bundle, boolean replaceTop) {
+        String tag = internalUserId + "@" + roomTokenOrId;
+        if (router.getControllerWithTag(tag) != null) {
+            List<RouterTransaction> backstack = router.getBackstack();
+            RouterTransaction routerTransaction = null;
+            for (int i = 0; i < router.getBackstackSize(); i++) {
+                if (tag.equals(backstack.get(i).tag())) {
+                    routerTransaction = backstack.get(i);
+                    backstack.remove(routerTransaction);
+                    break;
+                }
+            }
+
+            backstack.add(routerTransaction);
+            router.setBackstack(backstack, new HorizontalChangeHandler());
+        } else {
+            if (!replaceTop) {
+                router.pushController(RouterTransaction.with(new ChatController(bundle))
+                        .pushChangeHandler(new HorizontalChangeHandler())
+                        .popChangeHandler(new HorizontalChangeHandler()).tag(tag));
+            } else {
+                router.replaceTopController(RouterTransaction.with(new ChatController(bundle))
+                        .pushChangeHandler(new HorizontalChangeHandler())
+                        .popChangeHandler(new HorizontalChangeHandler()).tag(tag));
+            }
+        }
+    }
+}