Skip to content
Snippets Groups Projects
Unverified Commit 2694ec1e authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Remove FromatterAccessibilityHelper.kt and replace with BindingAdapters to...

Remove FromatterAccessibilityHelper.kt and replace with BindingAdapters to remove static app context access. (#1349)
parent 94bb1ade
No related branches found
No related tags found
No related merge requests found
Showing
with 75 additions and 87 deletions
@file:JvmName("FormatterAccessibilityHelper")
package de.rki.coronawarnapp.util.formatter
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.R
fun formatSuffix(string: String?, suffix: Int): String {
val appContext = CoronaWarnApplication.getAppContext()
return if (string != null) {
"$string ${appContext.getString(suffix)}"
} else ""
}
fun formatButton(string: String?): String = formatSuffix(string, R.string.suffix_button)
fun formatImage(string: String?): String = formatSuffix(string, R.string.suffix_image)
package de.rki.coronawarnapp.util.ui.bindingadapters
import android.content.Context
import android.view.View
import android.widget.ImageView
import androidx.annotation.StringRes
import androidx.databinding.BindingAdapter
import de.rki.coronawarnapp.R
private fun formatSuffix(context: Context, prefix: String, @StringRes suffix: Int): String {
return "$prefix ${context.getString(suffix)}"
}
@BindingAdapter("cwaContentDescription")
fun ImageView.setCWAContentDescription(description: String) {
contentDescription = formatSuffix(context, description, R.string.suffix_image)
}
@BindingAdapter("cwaContentDescription")
fun View.setCWAContentDescription(description: String) {
contentDescription = formatSuffix(context, description, R.string.suffix_button)
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data> <data>
...@@ -9,8 +10,6 @@ ...@@ -9,8 +10,6 @@
<import type="de.rki.coronawarnapp.util.formatter.FormatterSubmissionHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterSubmissionHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="submissionViewModel" name="submissionViewModel"
type="de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel" /> type="de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel" />
...@@ -50,14 +49,15 @@ ...@@ -50,14 +49,15 @@
android:id="@+id/main_header_logo" android:id="@+id/main_header_logo"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(@string/accessibility_logo)}" bind:cwaContentDescription="@{@string/accessibility_logo}"
android:scaleType="fitStart" android:scaleType="fitStart"
android:src="@drawable/ic_main_header" android:src="@drawable/ic_main_header"
android:focusable="true" android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/main_header_share" app:layout_constraintEnd_toStartOf="@+id/main_header_share"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<include <include
android:id="@+id/main_header_share" android:id="@+id/main_header_share"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
...@@ -9,8 +10,6 @@ ...@@ -9,8 +10,6 @@
<import type="de.rki.coronawarnapp.util.formatter.FormatterRiskHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterRiskHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<import type="android.view.View" /> <import type="android.view.View" />
<variable <variable
...@@ -51,12 +50,13 @@ ...@@ -51,12 +50,13 @@
style="@style/icon" style="@style/icon"
android:layout_width="@dimen/icon_size_button" android:layout_width="@dimen/icon_size_button"
android:layout_height="@dimen/icon_size_button" android:layout_height="@dimen/icon_size_button"
android:contentDescription="@{FormatterAccessibilityHelper.formatButton(@string/accessibility_back)}" bind:cwaContentDescription="@{@string/accessibility_back}"
android:src="@{@drawable/ic_close}" android:src="@{@drawable/ic_close}"
android:tint="@{FormatterRiskHelper.formatStableTextColor(tracingViewModel.riskLevel)}" android:tint="@{FormatterRiskHelper.formatStableTextColor(tracingViewModel.riskLevel)}"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
<data> xmlns:tools="http://schemas.android.com/tools">
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/submission_qr_code_scan_container" android:id="@+id/submission_qr_code_scan_container"
...@@ -74,12 +70,13 @@ ...@@ -74,12 +70,13 @@
style="@style/iconStable" style="@style/iconStable"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(@string/accessibility_close)" bind:cwaContentDescription="@{@string/accessibility_close}"
android:src="@drawable/ic_close" android:src="@drawable/ic_close"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data> <data>
<import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="icon" name="icon"
type="android.graphics.drawable.Drawable" /> type="android.graphics.drawable.Drawable" />
...@@ -21,7 +20,7 @@ ...@@ -21,7 +20,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/button_icon" android:id="@+id/button_icon"
style="@style/buttonIcon" style="@style/buttonIcon"
android:contentDescription="@{FormatterAccessibilityHelper.formatButton(iconDescription)}" bind:cwaContentDescription="@{iconDescription}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="headline" name="headline"
type="String" /> type="String" />
...@@ -66,7 +65,7 @@ ...@@ -66,7 +65,7 @@
android:layout_marginEnd="@dimen/spacing_small" android:layout_marginEnd="@dimen/spacing_small"
android:layout_marginBottom="@dimen/spacing_normal" android:layout_marginBottom="@dimen/spacing_normal"
android:text="@{body}" android:text="@{body}"
android:contentDescription="@{FormatterAccessibilityHelper.formatButton(body)}" bind:cwaContentDescription="@{body}"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/dispatcher_card_illustration" app:layout_constraintEnd_toStartOf="@+id/dispatcher_card_illustration"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
...@@ -7,8 +8,6 @@ ...@@ -7,8 +8,6 @@
<import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="illustration" name="illustration"
type="android.graphics.drawable.Drawable" /> type="android.graphics.drawable.Drawable" />
...@@ -34,13 +33,14 @@ ...@@ -34,13 +33,14 @@
android:id="@+id/information_details_header_illustration" android:id="@+id/information_details_header_illustration"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(illustrationDescription)}" bind:cwaContentDescription="@{illustrationDescription}"
android:focusable="true" android:focusable="true"
android:src="@{illustration}" android:src="@{illustration}"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_illustration_tracing_on" /> tools:src="@drawable/ic_illustration_tracing_on"
tools:ignore="ContentDescription" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="illustration" name="illustration"
type="android.graphics.drawable.Drawable" /> type="android.graphics.drawable.Drawable" />
...@@ -79,13 +78,14 @@ ...@@ -79,13 +78,14 @@
android:id="@+id/onboarding_illustration" android:id="@+id/onboarding_illustration"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(illustrationDescription)}" bind:cwaContentDescription="@{illustrationDescription}"
android:focusable="true" android:focusable="true"
android:src="@{illustration}" android:src="@{illustration}"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_illustration_together" /> tools:src="@drawable/ic_illustration_together"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/onboarding_headline" android:id="@+id/onboarding_headline"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
<data> xmlns:tools="http://schemas.android.com/tools">
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
</data>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -21,11 +17,12 @@ ...@@ -21,11 +17,12 @@
android:layout_width="@dimen/match_constraint" android:layout_width="@dimen/match_constraint"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/ic_submission_illustration_hotline" android:src="@drawable/ic_submission_illustration_hotline"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(@string/information_contact_illustration_description)}"
android:focusable="true" android:focusable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
bind:cwaContentDescription="@{@string/information_contact_illustration_description}"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/submission_contact_body" android:id="@+id/submission_contact_body"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
<data> xmlns:tools="http://schemas.android.com/tools">
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
</data>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -21,12 +17,13 @@ ...@@ -21,12 +17,13 @@
android:id="@+id/submission_done_hero_illustration" android:id="@+id/submission_done_hero_illustration"
android:layout_width="@dimen/match_constraint" android:layout_width="@dimen/match_constraint"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(@string/submission_done_illustration_description)}"
android:focusable="true" android:focusable="true"
android:src="@drawable/ic_submission_illustration_thanks" android:src="@drawable/ic_submission_illustration_thanks"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
bind:cwaContentDescription="@{@string/submission_done_illustration_description}"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/submission_done_headline" android:id="@+id/submission_done_headline"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
<data> xmlns:tools="http://schemas.android.com/tools">
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
</data>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -18,14 +14,15 @@ ...@@ -18,14 +14,15 @@
<ImageView <ImageView
android:id="@+id/submission_intro_hero_illustration" android:id="@+id/submission_intro_hero_illustration"
android:contentDescription="@{FormatterAccessibilityHelper.formatImage(@string/submission_intro_illustration_description)}"
android:layout_width="@dimen/match_constraint" android:layout_width="@dimen/match_constraint"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/ic_illustration_test" android:src="@drawable/ic_illustration_test"
android:focusable="true" android:focusable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
bind:cwaContentDescription="@{@string/submission_intro_illustration_description}"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/submission_intro_headline" android:id="@+id/submission_intro_headline"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data> <data>
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<variable <variable
name="countryData" name="countryData"
type="java.util.List&lt;de.rki.coronawarnapp.ui.Country&gt;" /> type="java.util.List&lt;de.rki.coronawarnapp.ui.Country&gt;" />
...@@ -24,11 +24,12 @@ ...@@ -24,11 +24,12 @@
android:id="@+id/submission_positive_other_warning_hero_illustration" android:id="@+id/submission_positive_other_warning_hero_illustration"
android:layout_width="@dimen/match_constraint" android:layout_width="@dimen/match_constraint"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@{FormatterAccessibilityHelper.formatButton(@string/submission_positive_other_illustration_description)}" bind:cwaContentDescription="@{@string/submission_positive_other_illustration_description}"
android:src="@drawable/ic_submission_illustration_other_warning" android:src="@drawable/ic_submission_illustration_other_warning"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView <TextView
android:id="@+id/submission_positive_other_warning_headline" android:id="@+id/submission_positive_other_warning_headline"
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
<import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<import type="android.view.View" /> <import type="android.view.View" />
<variable <variable
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
<import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" /> <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
<import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
<import type="android.view.View" /> <import type="android.view.View" />
<variable <variable
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment