diff --git a/app/src/main/java/org/mozilla/fenix/utils/Undo.kt b/app/src/main/java/org/mozilla/fenix/utils/Undo.kt index 88719a842d4a..71d04df7466b 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Undo.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Undo.kt @@ -14,9 +14,7 @@ import org.mozilla.fenix.components.FenixSnackbar import android.app.AlertDialog import org.mozilla.fenix.R import android.content.Context -import android.content.Context.ACCESSIBILITY_SERVICE import android.view.accessibility.AccessibilityManager -import androidx.core.content.ContextCompat.getSystemService import java.util.concurrent.atomic.AtomicBoolean internal const val UNDO_DELAY = 3000L @@ -47,11 +45,8 @@ fun CoroutineScope.allowUndo( // writing a volatile variable. val requestedUndo = AtomicBoolean(false) - // Check if accessibility is enabled and if so show a confirmation dialog instead - val am = view.context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager - val isAccessibilityEnabled = am.isEnabled - - if (isAccessibilityEnabled) { + // Launch an alert dialog for undo- for accessibility users + fun showUndoDialog() { val dialogBuilder = AlertDialog.Builder(view.context) dialogBuilder.setMessage(message).setCancelable(false).setPositiveButton(R.string.a11y_dialog_deleted_confirm) { _, _ -> launch { @@ -59,18 +54,15 @@ fun CoroutineScope.allowUndo( } }.setNegativeButton(R.string.a11y_dialog_deleted_undo){_,_ -> launch { - onCancel.invoke() + onCancel.invoke() } } - - // Create dialog box val alert = dialogBuilder.create() alert.show() } - else { - - // Launch an indefinite snackbar + // Launch an indefinite snackbar + fun showUndoSnackbar() { val snackbar = FenixSnackbar .make(view, FenixSnackbar.LENGTH_INDEFINITE) .setText(message) @@ -96,4 +88,17 @@ fun CoroutineScope.allowUndo( } } } + + // Check if accessibility is enabled + val isAccessibilityEnabled = accessibilityEnabled(view) + + // Show either Snackbar or dialog based on result + if (isAccessibilityEnabled) showUndoDialog() else showUndoSnackbar() +} + + + +fun accessibilityEnabled(view:View): Boolean { + val am = view.context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager + return am.isEnabled }