a11y: add custom action to be able to close the alert.

This commit is contained in:
Benoit Marty 2023-05-10 16:43:54 +02:00
parent fe3a41e4e9
commit 71a2a4d31a
1 changed files with 24 additions and 0 deletions

View File

@ -21,9 +21,11 @@ import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
import androidx.core.view.ViewCompat
import com.tapadoo.alerter.Alerter
import im.vector.app.R
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.features.MainActivity
import im.vector.app.features.analytics.ui.consent.AnalyticsOptInActivity
@ -46,6 +48,7 @@ import javax.inject.Singleton
@Singleton
class PopupAlertManager @Inject constructor(
private val clock: Clock,
private val stringProvider: StringProvider,
) {
companion object {
@ -282,6 +285,9 @@ class PopupAlertManager @Inject constructor(
}
currentIsDismissed()
}
.setOnShowListener {
handleAccessibility(activity)
}
.enableSwipeToDismiss()
.enableInfiniteDuration(true)
.apply {
@ -297,6 +303,24 @@ class PopupAlertManager @Inject constructor(
.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() {
// current alert has been hidden
if (currentAlerter?.isLight == false) {