From 7bf1f50d786fad31cf14e72c0ecf0f74ed1b9c1c Mon Sep 17 00:00:00 2001 From: Kolya Opahle Date: Mon, 26 Oct 2020 13:50:35 +0100 Subject: [PATCH 1/2] Added new card to show redeemed tests on the home screen Signed-off-by: Kolya Opahle --- .../ui/main/home/HomeFragment.kt | 23 +++++++ .../ui/main/home/HomeFragmentEvents.kt | 2 + .../ui/main/home/HomeFragmentViewModel.kt | 13 ++++ .../ui/main/home/SubmissionCardState.kt | 24 ++++--- .../ui/view/TestResultCardFetchFailed.kt | 18 +++++ .../src/main/res/layout/fragment_home.xml | 13 +++- ...ew_submission_status_card_fetch_failed.xml | 65 +++++++++++++++++++ .../src/main/res/values-de/strings.xml | 6 ++ .../src/main/res/values/strings.xml | 6 ++ 9 files changed, 160 insertions(+), 10 deletions(-) create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCardFetchFailed.kt create mode 100644 Corona-Warn-App/src/main/res/layout/view_submission_status_card_fetch_failed.xml diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragment.kt index 5498587c096..1eea539fff2 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragment.kt @@ -1,11 +1,13 @@ package de.rki.coronawarnapp.ui.main.home +import android.app.AlertDialog import android.os.Bundle import android.view.View import android.view.accessibility.AccessibilityEvent import androidx.fragment.app.Fragment import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentHomeBinding +import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.ExternalActionHelper import de.rki.coronawarnapp.util.di.AutoInject import de.rki.coronawarnapp.util.errors.RecoveryByResetDialogFactory @@ -82,6 +84,21 @@ class HomeFragment : Fragment(R.layout.fragment_home), AutoInject { onDismiss = { vm.errorResetDialogDismissed() } ) } + HomeFragmentEvents.ShowDeleteTestDialog -> { + val removeTestDialog = DialogHelper.DialogInstance( + requireActivity(), + R.string.submission_test_result_dialog_remove_test_title, + R.string.submission_test_result_dialog_remove_test_message, + R.string.submission_test_result_dialog_remove_test_button_positive, + R.string.submission_test_result_dialog_remove_test_button_negative, + positiveButtonFunction = { + vm.deregisterWarningAccepted() + } + ) + DialogHelper.showDialog(removeTestDialog).apply { + getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(context.getColor(R.color.colorTextSemanticRed)) + } + } } } } @@ -133,6 +150,12 @@ class HomeFragment : Fragment(R.layout.fragment_home), AutoInject { submissionStatusCardPositive.setOnClickListener { toSubmissionResult() } submissionStatusCardPositiveButton.setOnClickListener { toSubmissionResult() } } + + mainTestFailed.apply { + setOnClickListener { + vm.removeTestPushed() + } + } } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentEvents.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentEvents.kt index cb0ea79e38f..26bee23f2ae 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentEvents.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentEvents.kt @@ -8,4 +8,6 @@ sealed class HomeFragmentEvents { ) : HomeFragmentEvents() object ShowErrorResetDialog : HomeFragmentEvents() + + object ShowDeleteTestDialog : HomeFragmentEvents() } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt index ff9ea407963..5e76fb27c18 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.asLiveData import com.squareup.inject.assisted.AssistedInject import de.rki.coronawarnapp.risk.TimeVariables +import de.rki.coronawarnapp.service.submission.SubmissionService import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.storage.SubmissionRepository import de.rki.coronawarnapp.storage.TracingRepository @@ -94,6 +95,18 @@ class HomeFragmentViewModel @AssistedInject constructor( tracingRepository.refreshDiagnosisKeys() } + fun removeTestPushed() { + popupEvents.postValue(HomeFragmentEvents.ShowDeleteTestDialog) + } + + fun deregisterWarningAccepted() { + SubmissionService.deleteTestGUID() + SubmissionService.deleteRegistrationToken() + LocalData.isAllowedToSubmitDiagnosisKeys(false) + LocalData.initialTestResultReceivedTimestamp(0L) + SubmissionRepository.refreshDeviceUIState() + } + @AssistedInject.Factory interface Factory : SimpleCWAViewModelFactory } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/SubmissionCardState.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/SubmissionCardState.kt index 8ec5f5556a1..81c4c6f4384 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/SubmissionCardState.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/SubmissionCardState.kt @@ -25,18 +25,24 @@ data class SubmissionCardState( fun isUnregisteredCardVisible(): Boolean = !isDeviceRegistered - fun isFetchingCardVisible(): Boolean = isDeviceRegistered && - (uiStateState == ApiRequestState.STARTED || uiStateState == ApiRequestState.FAILED) + fun isFetchingCardVisible(): Boolean = + isDeviceRegistered && (uiStateState == ApiRequestState.STARTED || uiStateState == ApiRequestState.FAILED) - fun isPositiveSubmissionCardVisible(): Boolean = deviceUiState == PAIRED_POSITIVE || - deviceUiState == PAIRED_POSITIVE_TELETAN + fun isFailedCardVisible(): Boolean = + isDeviceRegistered && uiStateState == ApiRequestState.SUCCESS && deviceUiState == PAIRED_REDEEMED - fun isSubmissionDoneCardVisible(): Boolean = deviceUiState == SUBMITTED_FINAL + fun isPositiveSubmissionCardVisible(): Boolean = uiStateState == ApiRequestState.SUCCESS && + (deviceUiState == PAIRED_POSITIVE || + deviceUiState == PAIRED_POSITIVE_TELETAN) - fun isContentCardVisible(): Boolean = deviceUiState == PAIRED_ERROR || - deviceUiState == PAIRED_NEGATIVE || - deviceUiState == PAIRED_NO_RESULT || - deviceUiState == PAIRED_REDEEMED + fun isSubmissionDoneCardVisible(): Boolean = + uiStateState == ApiRequestState.SUCCESS && deviceUiState == SUBMITTED_FINAL + + fun isContentCardVisible(): Boolean = + uiStateState == ApiRequestState.SUCCESS && (deviceUiState == PAIRED_ERROR || + deviceUiState == PAIRED_NEGATIVE || + deviceUiState == PAIRED_NO_RESULT || + deviceUiState == PAIRED_REDEEMED) fun getContentCardTitleText(c: Context): String = when (deviceUiState) { PAIRED_ERROR, PAIRED_REDEEMED, PAIRED_NEGATIVE -> R.string.submission_status_card_title_available diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCardFetchFailed.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCardFetchFailed.kt new file mode 100644 index 00000000000..c0ca58e56f5 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/TestResultCardFetchFailed.kt @@ -0,0 +1,18 @@ +package de.rki.coronawarnapp.ui.view + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.constraintlayout.widget.ConstraintLayout +import de.rki.coronawarnapp.databinding.ViewSubmissionStatusCardFetchFailedBinding + +class TestResultCardFetchFailed(context: Context, attrs: AttributeSet) : + ConstraintLayout(context, attrs) { + private val inflater = LayoutInflater.from(context) + private val binding = ViewSubmissionStatusCardFetchFailedBinding.inflate(inflater, this) + + override fun setOnClickListener(l: OnClickListener?) { + super.setOnClickListener(l) + binding.submissionStatusCardFetchFailedButton.setOnClickListener(l) + } +} diff --git a/Corona-Warn-App/src/main/res/layout/fragment_home.xml b/Corona-Warn-App/src/main/res/layout/fragment_home.xml index e8e4db7c797..2ea113515fa 100644 --- a/Corona-Warn-App/src/main/res/layout/fragment_home.xml +++ b/Corona-Warn-App/src/main/res/layout/fragment_home.xml @@ -173,6 +173,17 @@ app:layout_constraintStart_toStartOf="@+id/guideline_card_start" app:layout_constraintTop_toBottomOf="@id/main_test_result" /> + + + app:layout_constraintTop_toBottomOf="@+id/main_test_failed" /> + + + + + + + +