From 15c24022605a20342dd20b8540c53258382b23c1 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 13 Jul 2022 20:39:37 +0200 Subject: [PATCH 1/3] Remove unnecessary parameter --- .../src/main/java/com/fsck/k9/activity/MessageList.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt index 56b054b5a..3740dcf98 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt @@ -1311,13 +1311,11 @@ open class MessageList : configureMenu(menu) } - private fun addMessageListFragment(fragment: MessageListFragment, addToBackStack: Boolean) { + private fun addMessageListFragment(fragment: MessageListFragment) { val fragmentTransaction = supportFragmentManager.beginTransaction() fragmentTransaction.replace(R.id.message_list_container, fragment) - if (addToBackStack) { - fragmentTransaction.addToBackStack(null) - } + fragmentTransaction.addToBackStack(null) messageListFragment = fragment @@ -1364,7 +1362,7 @@ open class MessageList : initializeFromLocalSearch(tmpSearch) val fragment = MessageListFragment.newInstance(tmpSearch, true, false) - addMessageListFragment(fragment, true) + addMessageListFragment(fragment) } private fun showMessageViewPlaceHolder() { From f78045c01f688aed93e820339d0c7f05231ca826 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 13 Jul 2022 20:54:13 +0200 Subject: [PATCH 2/3] Change method to clear the fragment back stack in `MessageList` --- .../java/com/fsck/k9/activity/MessageList.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt index 3740dcf98..53eb98707 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt @@ -105,7 +105,6 @@ open class MessageList : private var messageViewPlaceHolder: PlaceholderFragment? = null private var messageListFragment: MessageListFragment? = null private var messageViewFragment: MessageViewFragment? = null - private var firstBackStackId = -1 private var account: Account? = null private var search: LocalSearch? = null private var singleFolderMode = false @@ -224,10 +223,8 @@ open class MessageList : setIntent(intent) - if (firstBackStackId >= 0) { - supportFragmentManager.popBackStackImmediate(firstBackStackId, FragmentManager.POP_BACK_STACK_INCLUSIVE) - firstBackStackId = -1 - } + // Start with a fresh fragment back stack + supportFragmentManager.popBackStackImmediate(FIRST_FRAGMENT_TRANSACTION, FragmentManager.POP_BACK_STACK_INCLUSIVE) removeMessageListFragment() removeMessageViewFragment() @@ -565,7 +562,6 @@ open class MessageList : outState.putSerializable(STATE_DISPLAY_MODE, displayMode) outState.putBoolean(STATE_MESSAGE_VIEW_ONLY, messageViewOnly) outState.putBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED, messageListWasDisplayed) - outState.putInt(STATE_FIRST_BACK_STACK_ID, firstBackStackId) } public override fun onRestoreInstanceState(savedInstanceState: Bundle) { @@ -573,7 +569,6 @@ open class MessageList : messageViewOnly = savedInstanceState.getBoolean(STATE_MESSAGE_VIEW_ONLY) messageListWasDisplayed = savedInstanceState.getBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED) - firstBackStackId = savedInstanceState.getInt(STATE_FIRST_BACK_STACK_ID) } private fun initializeActionBar() { @@ -1315,7 +1310,12 @@ open class MessageList : val fragmentTransaction = supportFragmentManager.beginTransaction() fragmentTransaction.replace(R.id.message_list_container, fragment) - fragmentTransaction.addToBackStack(null) + fragmentTransaction.setReorderingAllowed(true) + if (supportFragmentManager.backStackEntryCount == 0) { + fragmentTransaction.addToBackStack(FIRST_FRAGMENT_TRANSACTION) + } else { + fragmentTransaction.addToBackStack(null) + } messageListFragment = fragment @@ -1323,10 +1323,7 @@ open class MessageList : lockDrawer() } - val transactionId = fragmentTransaction.commit() - if (transactionId >= 0 && firstBackStackId < 0) { - firstBackStackId = transactionId - } + fragmentTransaction.commit() } override fun startSearch(query: String, account: Account?, folderId: Long?): Boolean { @@ -1682,6 +1679,7 @@ open class MessageList : private const val STATE_MESSAGE_LIST_WAS_DISPLAYED = "messageListWasDisplayed" private const val STATE_FIRST_BACK_STACK_ID = "firstBackstackId" + private const val FIRST_FRAGMENT_TRANSACTION = "first" private const val FRAGMENT_TAG_MESSAGE_VIEW = "MessageViewFragment" private const val FRAGMENT_TAG_PLACEHOLDER = "MessageViewPlaceholder" From f0e81c6d4b5ebd4ca0e62225a13a62064de2c9a6 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 13 Jul 2022 20:56:16 +0200 Subject: [PATCH 3/3] Use extension function for fragment transaction --- .../java/com/fsck/k9/activity/MessageList.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt index 53eb98707..20adb1e2e 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt @@ -23,6 +23,7 @@ import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout.DrawerListener import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentTransaction +import androidx.fragment.app.commit import androidx.lifecycle.Observer import com.fsck.k9.Account import com.fsck.k9.Account.SortType @@ -1307,14 +1308,16 @@ open class MessageList : } private fun addMessageListFragment(fragment: MessageListFragment) { - val fragmentTransaction = supportFragmentManager.beginTransaction() + supportFragmentManager.commit { + replace(R.id.message_list_container, fragment) - fragmentTransaction.replace(R.id.message_list_container, fragment) - fragmentTransaction.setReorderingAllowed(true) - if (supportFragmentManager.backStackEntryCount == 0) { - fragmentTransaction.addToBackStack(FIRST_FRAGMENT_TRANSACTION) - } else { - fragmentTransaction.addToBackStack(null) + setReorderingAllowed(true) + + if (supportFragmentManager.backStackEntryCount == 0) { + addToBackStack(FIRST_FRAGMENT_TRANSACTION) + } else { + addToBackStack(null) + } } messageListFragment = fragment @@ -1322,8 +1325,6 @@ open class MessageList : if (isDrawerEnabled) { lockDrawer() } - - fragmentTransaction.commit() } override fun startSearch(query: String, account: Account?, folderId: Long?): Boolean {