From 60cac62a448b4068e75c6578f8ad930c271fb80c Mon Sep 17 00:00:00 2001 From: Oliver Zimmerman <oezimmerman@gmail.com> Date: Thu, 26 Nov 2020 14:48:35 +0000 Subject: [PATCH] Rename custom view to Section instead of Card to avoid confusion with existing views --- .../coronawarnapp/ui/view/TestResultCard.kt | 32 ---------------- .../ui/view/TestResultSection.kt | 38 +++++++++++++++++++ ..._card.xml => view_test_result_section.xml} | 18 ++++----- Corona-Warn-App/src/main/res/values/attrs.xml | 10 ++--- 4 files changed, 52 insertions(+), 46 deletions(-) delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCard.kt create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultSection.kt rename Corona-Warn-App/src/main/res/layout/{view_test_result_card.xml => view_test_result_section.xml} (87%) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCard.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCard.kt deleted file mode 100644 index 68c98ebb1..000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCard.kt +++ /dev/null @@ -1,32 +0,0 @@ -package de.rki.coronawarnapp.ui.view - -import android.content.Context -import android.util.AttributeSet -import androidx.appcompat.content.res.AppCompatResources.getDrawable -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.content.withStyledAttributes -import de.rki.coronawarnapp.R -import kotlinx.android.synthetic.main.view_test_result_card.view.* - -/** - * The [TestResultCard] Displays the appropriate test result. - */ -class TestResultCard @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr) { - - init { - inflate(context, R.layout.view_test_result_card, this) - context.withStyledAttributes(attrs, R.styleable.TestResultCard) { - test_result_card_headline.text = getString(R.styleable.TestResultCard_test_result_card_headline) - test_result_card_content.text = getString(R.styleable.TestResultCard_test_result_card_content) - test_result_card_registered_at_text.text = - getString(R.styleable.TestResultCard_test_result_card_registered_at_text) - val resultIconId = getResourceId(R.styleable.TestResultCard_test_result_card_status_icon, 0) - if (resultIconId != 0) { - val drawable = getDrawable(context, resultIconId) - test_result_card_status_icon.setImageDrawable(drawable) - } - } - } -} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultSection.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultSection.kt new file mode 100644 index 000000000..d9e0d5443 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultSection.kt @@ -0,0 +1,38 @@ +package de.rki.coronawarnapp.ui.view + +import android.content.Context +import android.text.SpannableString +import android.util.AttributeSet +import androidx.appcompat.content.res.AppCompatResources.getDrawable +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.withStyledAttributes +import de.rki.coronawarnapp.R +import kotlinx.android.synthetic.main.view_test_result_section.view.* + +/** + * The [TestResultSection] Displays the appropriate test result. + */ +class TestResultSection @JvmOverloads +constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + init { + inflate(context, R.layout.view_test_result_section, this) + context.withStyledAttributes(attrs, R.styleable.TestResultSection) { + test_result_section_headline.text = getString(R.styleable.TestResultSection_test_result_section_headline) + test_result_section_content.text = SpannableString(getString(R.styleable.TestResultSection_test_result_section_content)) + test_result_section_registered_at_text.text = + getString(R.styleable.TestResultSection_test_result_section_registered_at_text) + val resultIconId = getResourceId(R.styleable.TestResultSection_test_result_section_status_icon, 0) + if (resultIconId != 0) { + val drawable = getDrawable(context, resultIconId) + test_result_section_status_icon.setImageDrawable(drawable) + } + } + } +} + + + + diff --git a/Corona-Warn-App/src/main/res/layout/view_test_result_card.xml b/Corona-Warn-App/src/main/res/layout/view_test_result_section.xml similarity index 87% rename from Corona-Warn-App/src/main/res/layout/view_test_result_card.xml rename to Corona-Warn-App/src/main/res/layout/view_test_result_section.xml index 9e8414baf..946edfe59 100644 --- a/Corona-Warn-App/src/main/res/layout/view_test_result_card.xml +++ b/Corona-Warn-App/src/main/res/layout/view_test_result_section.xml @@ -12,32 +12,32 @@ android:padding="@dimen/card_padding"> <TextView - android:id="@+id/test_result_card_headline" + android:id="@+id/test_result_section_headline" style="@style/body2" android:accessibilityHeading="true" android:layout_width="@dimen/match_constraint" android:layout_height="wrap_content" android:layout_marginEnd="@dimen/spacing_small" - app:layout_constraintEnd_toStartOf="@id/test_result_card_status_icon" + app:layout_constraintEnd_toStartOf="@id/test_result_section_status_icon" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="Ihr Befund"/> <TextView - android:id="@+id/test_result_card_content" + android:id="@+id/test_result_section_content" style="@style/headline5" android:layout_width="@dimen/match_constraint" android:layout_height="wrap_content" android:layout_marginEnd="@dimen/spacing_small" android:layout_marginBottom="@dimen/spacing_normal" - app:layout_constraintBottom_toTopOf="@id/test_result_card_registered_at_text" - app:layout_constraintEnd_toStartOf="@id/test_result_card_status_icon" + app:layout_constraintBottom_toTopOf="@id/test_result_section_registered_at_text" + app:layout_constraintEnd_toStartOf="@id/test_result_section_status_icon" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/test_result_card_headline" + app:layout_constraintTop_toBottomOf="@id/test_result_section_headline" tools:text="SARS-CoV-2 Negativ" /> <ImageView - android:id="@+id/test_result_card_status_icon" + android:id="@+id/test_result_section_status_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:importantForAccessibility="no" @@ -46,14 +46,14 @@ tools:src="@drawable/ic_test_result_illustration_negative" /> <TextView - android:id="@+id/test_result_card_registered_at_text" + android:id="@+id/test_result_section_registered_at_text" style="@style/body2" android:layout_width="@dimen/match_constraint" android:layout_height="wrap_content" android:layout_marginTop="@dimen/spacing_normal" android:layout_marginEnd="@dimen/spacing_small" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@id/test_result_card_status_icon" + app:layout_constraintEnd_toStartOf="@id/test_result_section_status_icon" app:layout_constraintStart_toStartOf="parent" tools:text="@string/test_result_card_registered_at_text" /> diff --git a/Corona-Warn-App/src/main/res/values/attrs.xml b/Corona-Warn-App/src/main/res/values/attrs.xml index 382ee2730..02f64f4b6 100644 --- a/Corona-Warn-App/src/main/res/values/attrs.xml +++ b/Corona-Warn-App/src/main/res/values/attrs.xml @@ -19,10 +19,10 @@ <declare-styleable name="BulletPointList"> <attr name="entries" format="reference" /> </declare-styleable> - <declare-styleable name="TestResultCard"> - <attr name="test_result_card_headline" format="string" /> - <attr name="test_result_card_content" format="string" /> - <attr name="test_result_card_status_icon" format="reference" /> - <attr name="test_result_card_registered_at_text" format="string" /> + <declare-styleable name="TestResultSection"> + <attr name="test_result_section_headline" format="string" /> + <attr name="test_result_section_content" format="string" /> + <attr name="test_result_section_status_icon" format="reference" /> + <attr name="test_result_section_registered_at_text" format="string" /> </declare-styleable> </resources> \ No newline at end of file -- GitLab