diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e66e15b85b..a13f476cd07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## Next Release + +### Fixes + +- Fix app crashing when trying to replacing the last screen during navigation + ## 2023-11-20-8926 ### Internal diff --git a/app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeSheet.kt b/app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeSheet.kt index da21d33053f..b2cda557a30 100644 --- a/app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeSheet.kt +++ b/app/src/main/java/org/simple/clinic/facility/alertchange/AlertFacilityChangeSheet.kt @@ -14,7 +14,6 @@ import org.simple.clinic.R import org.simple.clinic.databinding.SheetAlertFacilityChangeBinding import org.simple.clinic.di.injector import org.simple.clinic.facility.alertchange.Continuation.ContinueToActivity -import org.simple.clinic.facility.alertchange.Continuation.ContinueToScreen_Old import org.simple.clinic.facility.change.FacilityChangeScreen import org.simple.clinic.feature.Features import org.simple.clinic.mobius.ViewRenderer @@ -22,8 +21,6 @@ import org.simple.clinic.navigation.v2.Router import org.simple.clinic.navigation.v2.ScreenKey import org.simple.clinic.navigation.v2.ScreenResultBus import org.simple.clinic.navigation.v2.Succeeded -import org.simple.clinic.navigation.v2.compat.FullScreenKey -import org.simple.clinic.navigation.v2.compat.wrap import org.simple.clinic.navigation.v2.fragments.BaseBottomSheet import org.simple.clinic.util.resolveFloat import org.simple.clinic.util.setFragmentResultListener @@ -142,10 +139,6 @@ class AlertFacilityChangeSheet : private fun closeSheetWithContinuation() { when (continuation) { - is ContinueToScreen_Old -> { - val screenKey = (continuation as ContinueToScreen_Old).screenKey - router.replaceTop(screenKey.wrap()) - } is ContinueToActivity -> { val (intent, requestCode) = (continuation as ContinueToActivity).run { intent to requestCode @@ -191,9 +184,6 @@ class AlertFacilityChangeSheet : sealed class Continuation : Parcelable { - @Parcelize - data class ContinueToScreen_Old(val screenKey: FullScreenKey) : Continuation() - @Parcelize data class ContinueToScreen(val screenKey: ScreenKey) : Continuation() diff --git a/app/src/main/java/org/simple/clinic/navigation/v2/History.kt b/app/src/main/java/org/simple/clinic/navigation/v2/History.kt index 8fa56aefcd0..762fb8f91d2 100644 --- a/app/src/main/java/org/simple/clinic/navigation/v2/History.kt +++ b/app/src/main/java/org/simple/clinic/navigation/v2/History.kt @@ -23,7 +23,7 @@ data class History(val requests: List) : Parcelable { fun removeLast(): History { require(requests.size > 1) { val lastKey = requests.lastOrNull()?.key - "Cannot remove last key ($lastKey) when there is only one key left" + "Cannot remove last key (${lastKey?.analyticsName}) when there is only one key left" } return copy(requests = requests.dropLast(1)) diff --git a/app/src/main/java/org/simple/clinic/navigation/v2/Router.kt b/app/src/main/java/org/simple/clinic/navigation/v2/Router.kt index 3ea2d601a4b..d571bbfed41 100644 --- a/app/src/main/java/org/simple/clinic/navigation/v2/Router.kt +++ b/app/src/main/java/org/simple/clinic/navigation/v2/Router.kt @@ -90,9 +90,14 @@ class Router( } fun replaceTop(screenKey: ScreenKey, transactionOptions: TransactionOptions? = null) { + val navRequest = Normal(screenKey) + if (history.matchesTop(navRequest)) { + return + } + val newHistory = history .removeLast() - .add(Normal(screenKey)) + .add(navRequest) executeStateChange(newHistory, Direction.Replace, null, transactionOptions) } @@ -102,9 +107,14 @@ class Router( screenKey: ScreenKey, transactionOptions: TransactionOptions? = null ) { + val navRequest = ExpectingResult(requestType, screenKey) + if (history.matchesTop(navRequest)) { + return + } + val newHistory = history .removeLast() - .add(ExpectingResult(requestType, screenKey)) + .add(navRequest) executeStateChange(newHistory, Direction.Forward, null, transactionOptions) }