From 38cc02d8e2424fa3e6a4138cb56e1eb0a027e5f7 Mon Sep 17 00:00:00 2001
From: Oliver Zimmerman <oezimmerman@gmail.com>
Date: Sun, 29 Nov 2020 14:11:57 +0000
Subject: [PATCH] Set up Fragment / ViewModel / Module and added empty String
 for translation

---
 ...ubmissionTestResultConsentGivenFragment.kt | 81 +++++++++++++++++++
 .../SubmissionTestResultConsentGivenModule.kt | 18 +++++
 ...bmissionTestResultConsentGivenViewModel.kt | 33 ++++++++
 .../src/main/res/values/strings.xml           |  2 +
 4 files changed, 134 insertions(+)
 create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenFragment.kt
 create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenModule.kt
 create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenViewModel.kt

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenFragment.kt
new file mode 100644
index 000000000..e3611dff7
--- /dev/null
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenFragment.kt
@@ -0,0 +1,81 @@
+package de.rki.coronawarnapp.ui.submission.testresult
+
+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.FragmentSubmissionTestResultConsentGivenBinding
+import de.rki.coronawarnapp.ui.submission.viewmodel.SubmissionNavigationEvents
+import de.rki.coronawarnapp.util.di.AutoInject
+import de.rki.coronawarnapp.util.ui.doNavigate
+import de.rki.coronawarnapp.util.ui.observe2
+import de.rki.coronawarnapp.util.ui.viewBindingLazy
+import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider
+import de.rki.coronawarnapp.util.viewmodel.cwaViewModels
+import javax.inject.Inject
+
+class SubmissionTestResultConsentGivenFragment : Fragment(R.layout.fragment_submission_test_result_consent_given), AutoInject {
+
+    @Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory
+    private val viewModel: SubmissionTestResultConsentGivenViewModel by cwaViewModels { viewModelFactory }
+
+    private val binding: FragmentSubmissionTestResultConsentGivenBinding by viewBindingLazy()
+
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        super.onViewCreated(view, savedInstanceState)
+
+        setButtonOnClickListener()
+
+        viewModel.showCancelDialog.observe2(this) {
+            showCancelDialog()
+        }
+
+        viewModel.routeToScreen.observe2(this) {
+            when (it) {
+                is SubmissionNavigationEvents.NavigateToSymptomIntroduction ->
+                    doNavigate(
+                        SubmissionTestResultFragmentConsentGivenDirections
+                            .actionSubmissionResultFragmentToSubmissionSymptomIntroductionFragment()
+                    )
+                is SubmissionNavigationEvents.NavigateToMainActivity ->
+                    doNavigate(
+                        SubmissionTestResultFragmentConsentGivenDirections
+                            .actionSubmissionResultFragmentToSubmissionResultPositiveOtherWarningFragment()
+                    )
+            }
+
+        }
+    }
+
+    override fun onResume() {
+        super.onResume()
+        binding.submissionTestResultContainer.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT)
+    }
+
+    private fun setButtonOnClickListener() {
+            binding.submissionTestResultButtonConsentGivenContinue.setOnClickListener {
+                viewModel.onContinuePressed()
+
+            }
+
+            binding.submissionTestResultButtonConsentGivenContinueWithoutSymptoms.setOnClickListener {
+                viewModel.onShowCancelDialog()
+            }
+    }
+
+    private fun showCancelDialog() {
+        AlertDialog.Builder(requireContext()).apply {
+            setTitle(R.string.submission_error_dialog_confirm_cancellation_title)
+            setMessage(R.string.submission_error_dialog_confirm_cancellation_body)
+            setPositiveButton(R.string.submission_error_dialog_confirm_cancellation_button_positive) { _, _ ->
+                viewModel.cancelTestSubmission()
+            }
+            setNegativeButton(R.string.submission_error_dialog_confirm_cancellation_button_negative) { _, _ ->
+                // NOOP
+            }
+        }.show()
+    }
+
+    }
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenModule.kt
new file mode 100644
index 000000000..da01d964c
--- /dev/null
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenModule.kt
@@ -0,0 +1,18 @@
+package de.rki.coronawarnapp.ui.submission.testresult
+
+import dagger.Binds
+import dagger.Module
+import dagger.multibindings.IntoMap
+import de.rki.coronawarnapp.util.viewmodel.CWAViewModel
+import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactory
+import de.rki.coronawarnapp.util.viewmodel.CWAViewModelKey
+
+@Module
+abstract class SubmissionTestResultConsentGivenModule {
+    @Binds
+    @IntoMap
+    @CWAViewModelKey(SubmissionTestResultConsentGivenViewModel::class)
+    abstract fun submissionTestResultConsentGivenFragment(
+        factory: SubmissionTestResultConsentGivenViewModel.Factory
+    ): CWAViewModelFactory<out CWAViewModel>
+}
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenViewModel.kt
new file mode 100644
index 000000000..ac8bcd931
--- /dev/null
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/testresult/SubmissionTestResultConsentGivenViewModel.kt
@@ -0,0 +1,33 @@
+package de.rki.coronawarnapp.ui.submission.testresult
+
+import com.squareup.inject.assisted.AssistedInject
+import de.rki.coronawarnapp.ui.submission.viewmodel.SubmissionNavigationEvents
+import de.rki.coronawarnapp.util.ui.SingleLiveEvent
+import de.rki.coronawarnapp.util.viewmodel.CWAViewModel
+import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory
+import timber.log.Timber
+
+class SubmissionTestResultConsentGivenViewModel @AssistedInject constructor() : CWAViewModel() {
+
+    val routeToScreen: SingleLiveEvent<SubmissionNavigationEvents> = SingleLiveEvent()
+
+    val showCancelDialog = SingleLiveEvent<Unit>()
+
+    fun onContinuePressed(){
+        Timber.d("Beginning symptom flow")
+        routeToScreen.postValue(SubmissionNavigationEvents.NavigateToSymptomIntroduction)
+    }
+
+    fun onShowCancelDialog() {
+        showCancelDialog.postValue(Unit)
+    }
+
+    fun cancelTestSubmission() {
+        Timber.d("Submission was cancelled.")
+        routeToScreen.postValue(SubmissionNavigationEvents.NavigateToMainActivity)
+    }
+
+
+    @AssistedInject.Factory
+    interface Factory : SimpleCWAViewModelFactory<SubmissionTestResultConsentGivenViewModel>
+}
diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml
index 7d4ea7632..348d6892b 100644
--- a/Corona-Warn-App/src/main/res/values/strings.xml
+++ b/Corona-Warn-App/src/main/res/values/strings.xml
@@ -928,6 +928,8 @@
     <string name="submission_test_result_consent_given_subtitle">""</string>
     <!-- YTXT: body text for test result card with consent given -->
     <string name="submission_test_result_consent_given_body">""</string>
+    <!-- XBUT: button text for the 'break up' button option on test result consent given page -->
+    <string name="submission_test_result_consent_given_breakup_button">""</string>
 
 
     <!-- Submission Tan -->
-- 
GitLab