From a6286ff8c8c523337175b1b9f4d51de1f9c60ef3 Mon Sep 17 00:00:00 2001 From: Matthias Urhahn <matthias.urhahn@sap.com> Date: Fri, 11 Dec 2020 13:29:57 +0100 Subject: [PATCH] Adjust "abort warn others" dialog (EXPOSUREAPP-4253) (#1874) * Change dialog cancel behavior. Stay on screen. * Switch dialog button. The "positive" action is always in reference to the dialog's question. So positive here means to not warn others, while "warn others" is the negative action that cancels the dialog. * Remove unused code. * Simplify fragment init. * LINTs Co-authored-by: Ralf Gehrer <ralfgehrer@users.noreply.github.com> --- .../SubmissionTestResultNoConsentFragment.kt | 24 ++++++++--------- .../SubmissionTestResultNoConsentViewModel.kt | 26 +++---------------- .../main/home/SubmissionCardStateTest.kt | 7 +++-- .../coronawarnapp/update/UpdateCheckerTest.kt | 1 - 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentFragment.kt index a6ef006d2..b9f965dc5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentFragment.kt @@ -44,15 +44,16 @@ class SubmissionTestResultNoConsentFragment : Fragment(R.layout.fragment_submiss .setTestResultSection(it.deviceUiState, it.testResultReceivedDate) } - binding.submissionTestResultConsentGivenHeader.headerButtonBack.buttonIcon.setOnClickListener { - showCancelDialog() - } - - binding.submissionTestResultPositiveNoConsentButtonAbort.setOnClickListener { - showCancelDialog() - } - binding.submissionTestResultPositiveNoConsentButtonWarnOthers.setOnClickListener { - navigateToWarnOthers() + binding.apply { + submissionTestResultConsentGivenHeader.headerButtonBack.buttonIcon.setOnClickListener { + showCancelDialog() + } + submissionTestResultPositiveNoConsentButtonAbort.setOnClickListener { + showCancelDialog() + } + submissionTestResultPositiveNoConsentButtonWarnOthers.setOnClickListener { + navigateToWarnOthers() + } } } @@ -65,10 +66,9 @@ class SubmissionTestResultNoConsentFragment : Fragment(R.layout.fragment_submiss AlertDialog.Builder(requireContext()).apply { setTitle(R.string.submission_test_result_positive_no_consent_dialog_title) setMessage(R.string.submission_test_result_positive_no_consent_dialog_message) - setPositiveButton(R.string.submission_test_result_positive_no_consent_dialog_positive_button) { _, _ -> - navigateToWarnOthers() + setNegativeButton(R.string.submission_test_result_positive_no_consent_dialog_positive_button) { _, _ -> } - setNegativeButton(R.string.submission_test_result_positive_no_consent_dialog_negative_button) { _, _ -> + setPositiveButton(R.string.submission_test_result_positive_no_consent_dialog_negative_button) { _, _ -> navigateToHome() } }.show() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentViewModel.kt index b1c7f3e7a..4e639d566 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/positive/SubmissionTestResultNoConsentViewModel.kt @@ -5,44 +5,24 @@ import androidx.lifecycle.asLiveData import com.squareup.inject.assisted.AssistedInject import de.rki.coronawarnapp.storage.SubmissionRepository import de.rki.coronawarnapp.ui.submission.testresult.TestResultUIState -import de.rki.coronawarnapp.util.DeviceUIState -import de.rki.coronawarnapp.util.NetworkRequestWrapper.Companion.withSuccess -import de.rki.coronawarnapp.util.ui.SingleLiveEvent +import de.rki.coronawarnapp.util.flow.combine import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.combineTransform -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock class SubmissionTestResultNoConsentViewModel @AssistedInject constructor( val submissionRepository: SubmissionRepository ) : CWAViewModel() { - private val showRedeemedTokenWarning = SingleLiveEvent<Unit>() - private var wasRedeemedTokenErrorShown = false - private val tokenErrorMutex = Mutex() - - val uiState: LiveData<TestResultUIState> = combineTransform( + val uiState: LiveData<TestResultUIState> = combine( submissionRepository.deviceUIStateFlow, submissionRepository.testResultReceivedDateFlow ) { deviceUiState, resultDate -> - tokenErrorMutex.withLock { - if (!wasRedeemedTokenErrorShown) { - deviceUiState.withSuccess { - if (it == DeviceUIState.PAIRED_REDEEMED) { - wasRedeemedTokenErrorShown = true - showRedeemedTokenWarning.postValue(Unit) - } - } - } - } - TestResultUIState( deviceUiState = deviceUiState, testResultReceivedDate = resultDate - ).let { emit(it) } + ) }.asLiveData(context = Dispatchers.Default) fun onTestOpened() { diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/main/home/SubmissionCardStateTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/main/home/SubmissionCardStateTest.kt index f2dafb9ec..f098d2cb1 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/main/home/SubmissionCardStateTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/main/home/SubmissionCardStateTest.kt @@ -10,7 +10,6 @@ import de.rki.coronawarnapp.util.NetworkRequestWrapper import io.kotest.matchers.shouldBe import io.mockk.MockKAnnotations import io.mockk.clearAllMocks -import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.mockk import io.mockk.verify @@ -42,7 +41,11 @@ class SubmissionCardStateTest : BaseTest() { ) = when (uiStateState) { ApiRequestState.SUCCESS -> - SubmissionCardState(NetworkRequestWrapper.RequestSuccessful(deviceUiState), isDeviceRegistered, hasResultBeenSeen) + SubmissionCardState( + NetworkRequestWrapper.RequestSuccessful(deviceUiState), + isDeviceRegistered, + hasResultBeenSeen + ) ApiRequestState.FAILED -> SubmissionCardState(NetworkRequestWrapper.RequestFailed(mockk()), isDeviceRegistered, hasResultBeenSeen) ApiRequestState.STARTED -> diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/update/UpdateCheckerTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/update/UpdateCheckerTest.kt index 5a783eb05..e4fe8adbb 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/update/UpdateCheckerTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/update/UpdateCheckerTest.kt @@ -29,7 +29,6 @@ class UpdateCheckerTest : BaseTest() { MockKAnnotations.init(this) mockkObject(BuildConfigWrap) - coEvery { appConfigProvider.getAppConfig() } returns configData } -- GitLab