From d7daca915093a1ef04aa17ead24a92ee304934e1 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 23 Aug 2022 10:36:52 +0200 Subject: [PATCH] Replaces try catch back handling with check for backstack root --- .../features/home/NewHomeDetailFragment.kt | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt index 99193af7d4..f94cb7e932 100644 --- a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt @@ -24,7 +24,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.core.view.isVisible -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel @@ -180,23 +179,11 @@ class NewHomeDetailFragment @Inject constructor( } } - private fun navigateBack() { - val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull() - val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull() - setCurrentSpace(previousSpaceId ?: parentSpaceId) - } - private fun setCurrentSpace(spaceId: String?) { spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false) sharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace) } - private fun handleCallStarted() { - dismissLoadingDialog() - val fragmentTag = HomeTab.DialPad.toFragmentTag() - (childFragmentManager.findFragmentByTag(fragmentTag) as? DialPadFragment)?.clear() - } - override fun onDestroyView() { currentCallsViewPresenter.unBind() super.onDestroyView() @@ -454,20 +441,13 @@ class NewHomeDetailFragment @Inject constructor( } } - private fun DialPadFragment.applyCallback(): DialPadFragment { - callback = object : DialPadFragment.Callback { - override fun onOkClicked(formatted: String?, raw: String?) { - if (raw.isNullOrEmpty()) return - viewModel.handle(HomeDetailAction.StartCallWithPhoneNumber(raw)) - } - } - return this + override fun onBackPressed(toolbarButton: Boolean) = if (spaceStateHandler.isRoot()) { + false + } else { + val lastSpace = spaceStateHandler.popSpaceBackstack() + spaceStateHandler.setCurrentSpace(lastSpace, isForwardNavigation = false) + true } - override fun onBackPressed(toolbarButton: Boolean) = if (spaceStateHandler.getCurrentSpace() != null) { - navigateBack() - true - } catch (e: NoSuchElementException) { - false - } + private fun SpaceStateHandler.isRoot() = getSpaceBackstack().isEmpty() }