Fix chat controller backstack ordering

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-06-26 09:04:57 +02:00
parent 842f2c2380
commit bc089e9ee8
6 changed files with 87 additions and 19 deletions

View File

@ -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())) ConductorRemapping.remapChatController(router, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1),
.pushChangeHandler(new HorizontalChangeHandler()) intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN), intent.getExtras(), false);
.popChangeHandler(new HorizontalChangeHandler())); ;
} }
} }
} }

View File

@ -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)) ConductorRemapping.remapChatController(getRouter(), conversationUser.getId(),
.pushChangeHandler(new HorizontalChangeHandler()) roomOverall.getOcs().getData().getToken(), bundle, false);
.popChangeHandler(new HorizontalChangeHandler())));
} else { } else {
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
startActivity(conversationIntent); startActivity(conversationIntent);

View File

@ -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)) ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
.pushChangeHandler(new HorizontalChangeHandler()) roomOverall.getOcs().getData().getToken(), bundle, true);
.popChangeHandler(new HorizontalChangeHandler())));
} 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()) ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
.popChangeHandler(new HorizontalChangeHandler()))); roomOverall.getOcs().getData().getToken(), bundle, true);
} else { } else {
startActivity(conversationIntent); startActivity(conversationIntent);
new Handler().postDelayed(() -> getRouter().popCurrentController(), 100); new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);

View File

@ -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)) ConductorRemapping.remapChatController(getRouter(), currentUser.getId(),
.pushChangeHandler(new HorizontalChangeHandler()) conversation.getToken(), bundle, false);
.popChangeHandler(new HorizontalChangeHandler())));
} else { } else {
overridePushHandler(new NoOpControllerChangeHandler()); overridePushHandler(new NoOpControllerChangeHandler());
overridePopHandler(new NoOpControllerChangeHandler()); overridePopHandler(new NoOpControllerChangeHandler());

View File

@ -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)) ConductorRemapping.remapChatController(getParentController().getRouter(), conversationUser.getId(),
.pushChangeHandler(new HorizontalChangeHandler()) conversation.getToken(), bundle, true);
.popChangeHandler(new HorizontalChangeHandler()));
} }
} else { } else {
initiateCall(); initiateCall();

View File

@ -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));
}
}
}
}