summaryrefslogtreecommitdiffhomepage
path: root/ui/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-03-27 17:59:00 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-27 17:59:00 +0200
commit54dfa7bdd79f4d848bd5ed741bc2604c738fb150 (patch)
tree62fe0e8e798e59e4939759a4632b358348a7c542 /ui/src
parente5a75307c2cf766be85965d96df1bfafc27ada00 (diff)
ui: cancel actionmode when pressing back button
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src')
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt8
1 files changed, 8 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt
index 8928fb21..5f3d3950 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt
@@ -16,6 +16,8 @@ import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Toast
+import androidx.activity.OnBackPressedCallback
+import androidx.activity.addCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
@@ -46,6 +48,7 @@ import kotlinx.coroutines.launch
class TunnelListFragment : BaseFragment() {
private val actionModeListener = ActionModeListener()
private var actionMode: ActionMode? = null
+ private var backPressedCallback: OnBackPressedCallback? = null
private var binding: TunnelListFragmentBinding? = null
private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { data ->
if (data == null) return@registerForActivityResult
@@ -114,6 +117,9 @@ class TunnelListFragment : BaseFragment() {
}
executePendingBindings()
}
+ backPressedCallback = requireActivity().onBackPressedDispatcher.addCallback(this) { actionMode?.finish() }
+ backPressedCallback?.isEnabled = false
+
return binding?.root
}
@@ -238,6 +244,7 @@ class TunnelListFragment : BaseFragment() {
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
actionMode = mode
+ backPressedCallback?.isEnabled = true
if (activity != null) {
resources = activity!!.resources
}
@@ -249,6 +256,7 @@ class TunnelListFragment : BaseFragment() {
override fun onDestroyActionMode(mode: ActionMode) {
actionMode = null
+ backPressedCallback?.isEnabled = false
resources = null
animateFab(binding?.createFab, true)
checkedItems.clear()