Skip to content
Snippets Groups Projects
Commit a8f7c7ea authored by Oliver Zimmerman's avatar Oliver Zimmerman
Browse files

Cleanup of uiState uasge in Custom View formatters/setters after merge

parent c4cfe5c4
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,10 @@ class SubmissionTestResultFragment : Fragment(R.layout.fragment_submission_test_ ...@@ -76,7 +76,10 @@ class SubmissionTestResultFragment : Fragment(R.layout.fragment_submission_test_
viewModel.uiState.observe2(this) { viewModel.uiState.observe2(this) {
binding.uiState = it binding.uiState = it
binding.submissionTestResultContent.submissionTestResultSection.setTestResultSection(binding.uiState) with(binding) {
submissionTestResultContent.submissionTestResultSection
.setTestResultSection(uiState?.deviceUiState, uiState?.testResultReceivedDate)
}
it.deviceUiState.withFailure { it.deviceUiState.withFailure {
if (it is CwaWebException) { if (it is CwaWebException) {
DialogHelper.showDialog(buildErrorDialog(it)) DialogHelper.showDialog(buildErrorDialog(it))
......
...@@ -9,8 +9,9 @@ import androidx.appcompat.content.res.AppCompatResources.getDrawable ...@@ -9,8 +9,9 @@ import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.withStyledAttributes import androidx.core.content.withStyledAttributes
import de.rki.coronawarnapp.R import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.ui.submission.testresult.TestResultUIState
import de.rki.coronawarnapp.util.DeviceUIState import de.rki.coronawarnapp.util.DeviceUIState
import de.rki.coronawarnapp.util.NetworkRequestWrapper
import de.rki.coronawarnapp.util.NetworkRequestWrapper.Companion.withSuccess
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toUIFormat import de.rki.coronawarnapp.util.TimeAndDateExtensions.toUIFormat
import de.rki.coronawarnapp.util.formatter.formatTestResult import de.rki.coronawarnapp.util.formatter.formatTestResult
import kotlinx.android.synthetic.main.view_test_result_section.view.* import kotlinx.android.synthetic.main.view_test_result_section.view.*
...@@ -43,30 +44,25 @@ constructor( ...@@ -43,30 +44,25 @@ constructor(
} }
} }
fun setTestResultSection(uiState: TestResultUIState?) { fun setTestResultSection(uiState: NetworkRequestWrapper<DeviceUIState, Throwable>?, registeredAt: Date?) {
val deviceUIState = uiState?.deviceUiState
val registeredAt = uiState?.testResultReceivedDate
test_result_section_registered_at_text.text = formatTestResultRegisteredAtText(registeredAt) test_result_section_registered_at_text.text = formatTestResultRegisteredAtText(registeredAt)
val testResultIcon = formatTestStatusIcon(deviceUIState) val testResultIcon = formatTestStatusIcon(uiState)
test_result_section_status_icon.setImageDrawable(testResultIcon) test_result_section_status_icon.setImageDrawable(testResultIcon)
test_result_section_content.text = formatTestResultSectionContent(deviceUIState) test_result_section_content.text = formatTestResultSectionContent(uiState)
} }
private fun formatTestStatusIcon(uiState: DeviceUIState?): Drawable? { private fun formatTestStatusIcon(uiState: NetworkRequestWrapper<DeviceUIState, Throwable>?): Drawable? {
return when (uiState) { return uiState.withSuccess(R.drawable.ic_test_result_illustration_invalid) {
DeviceUIState.PAIRED_NO_RESULT -> when (it) {
context.getDrawable(R.drawable.ic_test_result_illustration_pending) DeviceUIState.PAIRED_NO_RESULT -> R.drawable.ic_test_result_illustration_pending
DeviceUIState.PAIRED_POSITIVE_TELETAN, DeviceUIState.PAIRED_POSITIVE_TELETAN,
DeviceUIState.PAIRED_POSITIVE -> DeviceUIState.PAIRED_POSITIVE -> R.drawable.ic_test_result_illustration_positive
context.getDrawable(R.drawable.ic_test_result_illustration_positive) DeviceUIState.PAIRED_NEGATIVE -> R.drawable.ic_test_result_illustration_negative
DeviceUIState.PAIRED_NEGATIVE -> DeviceUIState.PAIRED_ERROR,
context.getDrawable(R.drawable.ic_test_result_illustration_negative) DeviceUIState.PAIRED_REDEEMED -> R.drawable.ic_test_result_illustration_invalid
DeviceUIState.PAIRED_ERROR, else -> R.drawable.ic_test_result_illustration_invalid
DeviceUIState.PAIRED_REDEEMED -> }
context.getDrawable(R.drawable.ic_test_result_illustration_invalid) }.let { context.getDrawable(it) }
else -> context.getDrawable(R.drawable.ic_test_result_illustration_invalid)
}
} }
private fun formatTestResultRegisteredAtText(registeredAt: Date?): String { private fun formatTestResultRegisteredAtText(registeredAt: Date?): String {
...@@ -74,18 +70,20 @@ constructor( ...@@ -74,18 +70,20 @@ constructor(
.format(registeredAt?.toUIFormat(context)) .format(registeredAt?.toUIFormat(context))
} }
private fun formatTestResultSectionContent(uiState: DeviceUIState?): Spannable { private fun formatTestResultSectionContent(uiState: NetworkRequestWrapper<DeviceUIState, Throwable>?): Spannable {
return when (uiState) { return uiState.withSuccess(SpannableString("")) {
DeviceUIState.PAIRED_NO_RESULT -> when (it) {
SpannableString(context.getString(R.string.test_result_card_status_pending)) DeviceUIState.PAIRED_NO_RESULT ->
DeviceUIState.PAIRED_ERROR, SpannableString(context.getString(R.string.test_result_card_status_pending))
DeviceUIState.PAIRED_REDEEMED -> DeviceUIState.PAIRED_ERROR,
SpannableString(context.getString(R.string.test_result_card_status_invalid)) DeviceUIState.PAIRED_REDEEMED ->
SpannableString(context.getString(R.string.test_result_card_status_invalid))
DeviceUIState.PAIRED_POSITIVE, DeviceUIState.PAIRED_POSITIVE,
DeviceUIState.PAIRED_POSITIVE_TELETAN, DeviceUIState.PAIRED_POSITIVE_TELETAN,
DeviceUIState.PAIRED_NEGATIVE -> formatTestResult(uiState) DeviceUIState.PAIRED_NEGATIVE -> formatTestResult(uiState)
else -> SpannableString("") else -> SpannableString("")
}
} }
} }
} }
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
style="?android:attr/progressBarStyle" style="?android:attr/progressBarStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="@{FormatterSubmissionHelper.formatTestResultSpinnerVisible(uiState.apiRequestState)}" android:visibility="@{FormatterSubmissionHelper.formatTestResultSpinnerVisible(uiState.deviceUiState)}"
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"
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
android:layout_width="@dimen/match_constraint" android:layout_width="@dimen/match_constraint"
android:layout_height="@dimen/match_constraint" android:layout_height="@dimen/match_constraint"
android:layout_marginBottom="@dimen/button_padding_top_bottom" android:layout_marginBottom="@dimen/button_padding_top_bottom"
android:visibility="@{FormatterSubmissionHelper.formatTestResultVisible(uiState.apiRequestState)}" android:visibility="@{FormatterSubmissionHelper.formatTestResultVisible(uiState.deviceUiState)}"
app:layout_constraintBottom_toTopOf="@+id/include_submission_test_result_consent_given_buttons" app:layout_constraintBottom_toTopOf="@+id/include_submission_test_result_consent_given_buttons"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
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