Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
kglazko committed Nov 12, 2019
1 parent e1f3611 commit 4203614
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
68 changes: 52 additions & 16 deletions app/src/main/java/org/mozilla/fenix/utils/Undo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

package org.mozilla.fenix.utils

import android.accessibilityservice.AccessibilityServiceInfo
import android.view.View
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.mozilla.fenix.components.FenixSnackbar
import android.app.AlertDialog
import org.mozilla.fenix.R
import android.content.Context
import android.view.accessibility.AccessibilityManager
import java.util.concurrent.atomic.AtomicBoolean

internal const val UNDO_DELAY = 3000L
Expand Down Expand Up @@ -40,29 +45,60 @@ fun CoroutineScope.allowUndo(
// writing a volatile variable.
val requestedUndo = AtomicBoolean(false)

// Launch an indefinite snackbar.
val snackbar = FenixSnackbar
.make(view, FenixSnackbar.LENGTH_INDEFINITE)
.setText(message)
.setAnchorView(anchorView)
.setAction(undoActionTitle) {
requestedUndo.set(true)
// 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 {
operation.invoke()
}
}.setNegativeButton(R.string.a11y_dialog_deleted_undo){_,_ ->
launch {
onCancel.invoke()
}
}
val alert = dialogBuilder.create()
alert.show()
}

// If user engages with the snackbar, it'll get automatically dismissed.
snackbar.show()
// Launch an indefinite snackbar
fun showUndoSnackbar() {
val snackbar = FenixSnackbar
.make(view, FenixSnackbar.LENGTH_INDEFINITE)
.setText(message)
.setAnchorView(anchorView)
.setAction(undoActionTitle) {
requestedUndo.set(true)
launch {
onCancel.invoke()
}
}

// If user engages with the snackbar, it'll get automatically dismissed.
snackbar.show()

// Wait a bit, and if user didn't request cancellation, proceed with
// requested operation and hide the snackbar.
launch {
delay(UNDO_DELAY)
// Wait a bit, and if user didn't request cancellation, proceed with
// requested operation and hide the snackbar.
launch {
delay(UNDO_DELAY)

if (!requestedUndo.get()) {
snackbar.dismiss()
operation.invoke()
if (!requestedUndo.get()) {
snackbar.dismiss()
operation.invoke()
}
}
}

// 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
}
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@
<string name="snackbar_private_tabs_deleted">Private tabs deleted</string>
<!-- Text for action to undo deleting a tab or collection shown in snackbar -->
<string name="snackbar_deleted_undo">UNDO</string>
<!-- Text for action to undo deleting a tab or collection shown in a11y dialog -->
<string name="a11y_dialog_deleted_undo">Undo</string>
<!-- Text for action to confirm deleting a tab or collection shown in a11y dialog -->
<string name="a11y_dialog_deleted_confirm">Confirm</string>
<!-- QR code scanner prompt which appears after scanning a code, but before navigating to it
First parameter is the name of the app, second parameter is the URL or text scanned-->
<string name="qr_scanner_confirmation_dialog_message">Allow %1$s to open %2$s</string>
Expand Down

2 comments on commit 4203614

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting the task to Taskcluster failed. Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

[
  "assume:repo:github.com/mozilla-mobile/fenix:pull-request",
  "queue:route:checks",
  "queue:scheduler-id:taskcluster-github"
]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AnyOf": [
    {
      "AnyOf": [
        "queue:create-task:highest:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:very-high:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:high:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:medium:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:low:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:very-low:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:lowest:aws-provisioner-v1/mobile-1-decision"
      ]
    },
    {
      "AnyOf": [
        "queue:create-task:aws-provisioner-v1/mobile-1-decision",
        {
          "AllOf": [
            "queue:define-task:aws-provisioner-v1/mobile-1-decision",
            "queue:task-group-id:mobile-level-1/YZDImr3fRAKxbtW-FnrIQg",
            "queue:schedule-task:mobile-level-1/YZDImr3fRAKxbtW-FnrIQg/YZDImr3fRAKxbtW-FnrIQg"
          ]
        }
      ]
    }
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "assume:repo:github.com/mozilla-mobile/fenix:pull-request",
    "queue:route:checks",
    {
      "AnyOf": [
        {
          "AllOf": [
            "queue:scheduler-id:mobile-level-1",
            {
              "AnyOf": [
                "queue:create-task:highest:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:very-high:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:high:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:medium:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:low:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:very-low:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:lowest:aws-provisioner-v1/mobile-1-decision"
              ]
            }
          ]
        },
        {
          "AnyOf": [
            "queue:create-task:aws-provisioner-v1/mobile-1-decision",
            {
              "AllOf": [
                "queue:define-task:aws-provisioner-v1/mobile-1-decision",
                "queue:task-group-id:mobile-level-1/YZDImr3fRAKxbtW-FnrIQg",
                "queue:schedule-task:mobile-level-1/YZDImr3fRAKxbtW-FnrIQg/YZDImr3fRAKxbtW-FnrIQg"
              ]
            }
          ]
        }
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2019-11-12T23:31:06.749Z

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting the task to Taskcluster failed. Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

[
  "assume:repo:github.com/mozilla-mobile/fenix:pull-request",
  "queue:route:checks",
  "queue:scheduler-id:taskcluster-github"
]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AnyOf": [
    {
      "AnyOf": [
        "queue:create-task:highest:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:very-high:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:high:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:medium:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:low:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:very-low:aws-provisioner-v1/mobile-1-decision",
        "queue:create-task:lowest:aws-provisioner-v1/mobile-1-decision"
      ]
    },
    {
      "AnyOf": [
        "queue:create-task:aws-provisioner-v1/mobile-1-decision",
        {
          "AllOf": [
            "queue:define-task:aws-provisioner-v1/mobile-1-decision",
            "queue:task-group-id:mobile-level-1/JcUAETitTDOsyYk0CE5uEA",
            "queue:schedule-task:mobile-level-1/JcUAETitTDOsyYk0CE5uEA/JcUAETitTDOsyYk0CE5uEA"
          ]
        }
      ]
    }
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "assume:repo:github.com/mozilla-mobile/fenix:pull-request",
    "queue:route:checks",
    {
      "AnyOf": [
        {
          "AllOf": [
            "queue:scheduler-id:mobile-level-1",
            {
              "AnyOf": [
                "queue:create-task:highest:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:very-high:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:high:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:medium:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:low:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:very-low:aws-provisioner-v1/mobile-1-decision",
                "queue:create-task:lowest:aws-provisioner-v1/mobile-1-decision"
              ]
            }
          ]
        },
        {
          "AnyOf": [
            "queue:create-task:aws-provisioner-v1/mobile-1-decision",
            {
              "AllOf": [
                "queue:define-task:aws-provisioner-v1/mobile-1-decision",
                "queue:task-group-id:mobile-level-1/JcUAETitTDOsyYk0CE5uEA",
                "queue:schedule-task:mobile-level-1/JcUAETitTDOsyYk0CE5uEA/JcUAETitTDOsyYk0CE5uEA"
              ]
            }
          ]
        }
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2019-11-12T23:45:12.885Z

Please sign in to comment.