Use setBackstack when starting new MainActivity from notification

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
Dariusz Olszewski 2022-04-02 20:58:07 +02:00 committed by Marcel Hibbe
parent a37d0476cf
commit 5dca8bcb7d
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 31 additions and 22 deletions

View File

@ -112,22 +112,11 @@ class MainActivity : BaseActivity(), ActionBarProvider {
} }
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
if (!router!!.hasRootController()) {
router!!.setRoot(
RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
}
onNewIntent(intent) onNewIntent(intent)
} else if (!router!!.hasRootController()) { } else if (!router!!.hasRootController()) {
if (hasDb) { if (hasDb) {
if (userUtils.anyUserExists()) { if (userUtils.anyUserExists()) {
router!!.setRoot( setDefaultRootController()
RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
} else { } else {
if (!TextUtils.isEmpty(resources.getString(R.string.weblogin_url))) { if (!TextUtils.isEmpty(resources.getString(R.string.weblogin_url))) {
router!!.pushController( router!!.pushController(
@ -191,14 +180,18 @@ class MainActivity : BaseActivity(), ActionBarProvider {
super.onStop() super.onStop()
} }
fun resetConversationsList() { private fun setDefaultRootController() {
if (userUtils.anyUserExists()) {
router!!.setRoot( router!!.setRoot(
RouterTransaction.with(ConversationsListController(Bundle())) RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler()) .pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler())
) )
} }
fun resetConversationsList() {
if (userUtils.anyUserExists()) {
setDefaultRootController()
}
} }
fun openSettings() { fun openSettings() {
@ -343,6 +336,9 @@ class MainActivity : BaseActivity(), ActionBarProvider {
handleActionFromContact(intent) handleActionFromContact(intent)
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) { if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
if (!router!!.hasRootController()) {
setDefaultRootController()
}
val callNotificationIntent = Intent(this, CallNotificationActivity::class.java) val callNotificationIntent = Intent(this, CallNotificationActivity::class.java)
intent.extras?.let { callNotificationIntent.putExtras(it) } intent.extras?.let { callNotificationIntent.putExtras(it) }
startActivity(callNotificationIntent) startActivity(callNotificationIntent)

View File

@ -26,6 +26,7 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import com.nextcloud.talk.controllers.ChatController import com.nextcloud.talk.controllers.ChatController
import com.nextcloud.talk.controllers.ConversationsListController
object ConductorRemapping { object ConductorRemapping {
@ -68,11 +69,23 @@ object ConductorRemapping {
HorizontalChangeHandler() HorizontalChangeHandler()
} }
if (!replaceTop) { if (!replaceTop) {
if (!router.hasRootController()) {
val newBackstack = listOf(
RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()),
RouterTransaction.with(ChatController(bundle))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()).tag(tag)
)
router.setBackstack(newBackstack, SimpleSwapChangeHandler())
} else {
router.pushController( router.pushController(
RouterTransaction.with(ChatController(bundle)) RouterTransaction.with(ChatController(bundle))
.pushChangeHandler(pushChangeHandler) .pushChangeHandler(pushChangeHandler)
.popChangeHandler(HorizontalChangeHandler()).tag(tag) .popChangeHandler(HorizontalChangeHandler()).tag(tag)
) )
}
} else { } else {
router.replaceTopController( router.replaceTopController(
RouterTransaction.with(ChatController(bundle)) RouterTransaction.with(ChatController(bundle))