diff options
Diffstat (limited to 'ui/src/main')
3 files changed, 15 insertions, 6 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt index bec673db..cfd34e42 100644 --- a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt @@ -25,8 +25,11 @@ abstract class BaseActivity : AppCompatActivity() { if (oldTunnel == value) return field = value if (created) { - onSelectedTunnelChanged(oldTunnel, value) - selectionChangeRegistry.notifyCallbacks(oldTunnel, 0, value) + if (!onSelectedTunnelChanged(oldTunnel, value)) { + field = oldTunnel + } else { + selectionChangeRegistry.notifyCallbacks(oldTunnel, 0, value) + } } } @@ -61,7 +64,7 @@ abstract class BaseActivity : AppCompatActivity() { super.onSaveInstanceState(outState) } - protected abstract fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) + protected abstract fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?): Boolean fun removeOnSelectedTunnelChangedListener( listener: OnSelectedTunnelChangedListener) { diff --git a/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt b/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt index 1566c129..b6c67e88 100644 --- a/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt @@ -96,13 +96,17 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener } override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, - newTunnel: ObservableTunnel?) { + newTunnel: ObservableTunnel?): Boolean { val fragmentManager = supportFragmentManager + if (fragmentManager.isStateSaved) { + return false + } + val backStackEntries = fragmentManager.backStackEntryCount if (newTunnel == null) { // Clear everything off the back stack (all editors and detail fragments). fragmentManager.popBackStackImmediate(0, FragmentManager.POP_BACK_STACK_INCLUSIVE) - return + return true } if (backStackEntries == 2) { // Pop the editor off the back stack to reveal the detail fragment. Use the immediate @@ -116,5 +120,6 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener addToBackStack(null) } } + return true } } diff --git a/ui/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.kt b/ui/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.kt index b3fccee3..bdf798ca 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.kt @@ -22,7 +22,8 @@ class TunnelCreatorActivity : BaseActivity() { } } - override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) { + override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?): Boolean { finish() + return true } } |