a11y: add custom action to be able to close the alert.
This commit is contained in:
parent
fe3a41e4e9
commit
71a2a4d31a
|
@ -21,9 +21,11 @@ import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
import com.tapadoo.alerter.Alerter
|
import com.tapadoo.alerter.Alerter
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.utils.isAnimationEnabled
|
import im.vector.app.core.utils.isAnimationEnabled
|
||||||
import im.vector.app.features.MainActivity
|
import im.vector.app.features.MainActivity
|
||||||
import im.vector.app.features.analytics.ui.consent.AnalyticsOptInActivity
|
import im.vector.app.features.analytics.ui.consent.AnalyticsOptInActivity
|
||||||
|
@ -46,6 +48,7 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
class PopupAlertManager @Inject constructor(
|
class PopupAlertManager @Inject constructor(
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
|
private val stringProvider: StringProvider,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -282,6 +285,9 @@ class PopupAlertManager @Inject constructor(
|
||||||
}
|
}
|
||||||
currentIsDismissed()
|
currentIsDismissed()
|
||||||
}
|
}
|
||||||
|
.setOnShowListener {
|
||||||
|
handleAccessibility(activity)
|
||||||
|
}
|
||||||
.enableSwipeToDismiss()
|
.enableSwipeToDismiss()
|
||||||
.enableInfiniteDuration(true)
|
.enableInfiniteDuration(true)
|
||||||
.apply {
|
.apply {
|
||||||
|
@ -297,6 +303,24 @@ class PopupAlertManager @Inject constructor(
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* a11y */
|
||||||
|
private fun handleAccessibility(activity: Activity) {
|
||||||
|
activity.window.decorView.findViewById<View>(R.id.llAlertBackground)?.let { alertView ->
|
||||||
|
alertView.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
|
||||||
|
|
||||||
|
// Add close action for a11y (same action than swipe). User can select the action by swiping on the screen vertically,
|
||||||
|
// and double tap to perform the action
|
||||||
|
ViewCompat.addAccessibilityAction(
|
||||||
|
alertView,
|
||||||
|
stringProvider.getString(R.string.action_close)
|
||||||
|
) { _, _ ->
|
||||||
|
currentIsDismissed()
|
||||||
|
Alerter.hide()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun currentIsDismissed() {
|
private fun currentIsDismissed() {
|
||||||
// current alert has been hidden
|
// current alert has been hidden
|
||||||
if (currentAlerter?.isLight == false) {
|
if (currentAlerter?.isLight == false) {
|
||||||
|
|
Loading…
Reference in New Issue