Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Submission ui alignment #25

Merged
merged 10 commits into from
May 30, 2020
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package de.rki.coronawarnapp.ui.submission

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.FragmentSubmissionDispatcherBinding
import de.rki.coronawarnapp.ui.BaseFragment
import de.rki.coronawarnapp.util.CameraPermissionHelper

class SubmissionDispatcherFragment : BaseFragment() {

companion object {
private const val REQUEST_CAMERA_PERMISSION_CODE = 1
private val TAG: String? = SubmissionDispatcherFragment::class.simpleName
}

Expand All @@ -33,10 +39,7 @@ class SubmissionDispatcherFragment : BaseFragment() {

private fun setButtonOnClickListener() {
binding.submissionDispatcherQr.dispatcherCard.setOnClickListener {
doNavigate(
SubmissionDispatcherFragmentDirections
.actionSubmissionDispatcherFragmentToSubmissionQRCodeScanFragment()
)
checkForCameraPermission()
}
binding.submissionDispatcherTanCode.dispatcherCard.setOnClickListener {
doNavigate(
Expand All @@ -48,4 +51,77 @@ class SubmissionDispatcherFragment : BaseFragment() {
Log.i(TAG, "TAN tele pressed")
}
}

private fun checkForCameraPermission() {
if (!CameraPermissionHelper.hasCameraPermission(requireActivity())) {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
showCameraPermissionRationaleDialog()
} else {
requestPermissions(
arrayOf(Manifest.permission.CAMERA),
REQUEST_CAMERA_PERMISSION_CODE
)
}
} else {
cameraPermissionIsGranted()
}
}

private fun showCameraPermissionRationaleDialog() {
val alertDialog: AlertDialog = requireActivity().let {
kolyaopahle marked this conversation as resolved.
Show resolved Hide resolved
val builder = AlertDialog.Builder(it)
builder.apply {
setTitle(R.string.submission_qr_code_scan_permission_rationale_dialog_headline)
setMessage(R.string.submission_qr_code_scan_permission_rationale_dialog_body)
setPositiveButton(
R.string.submission_qr_code_scan_permission_rationale_dialog_button_positive
) { _, _ ->
requestPermissions(
arrayOf(Manifest.permission.CAMERA),
REQUEST_CAMERA_PERMISSION_CODE
)
}
setNegativeButton(
R.string.submission_qr_code_scan_permission_rationale_dialog_button_negative
) { _, _ -> }
}
builder.create()
}
alertDialog.show()
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
cameraPermissionIsGranted()
} else {
showCameraPermissionDeniedDialog()
}
}

private fun showCameraPermissionDeniedDialog() {
val alertDialog: AlertDialog = requireActivity().let {
kolyaopahle marked this conversation as resolved.
Show resolved Hide resolved
val builder = AlertDialog.Builder(it)
builder.apply {
setTitle(R.string.submission_qr_code_scan_permission_denied_dialog_headline)
setMessage(R.string.submission_qr_code_scan_permission_denied_dialog_body)
setPositiveButton(
R.string.submission_qr_code_scan_permission_denied_dialog_button_positive
) { _, _ -> }
}
builder.create()
}
alertDialog.show()
}

private fun cameraPermissionIsGranted() {
doNavigate(
SubmissionDispatcherFragmentDirections
.actionSubmissionDispatcherFragmentToSubmissionQRCodeScanFragment()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ class SubmissionDoneFragment : BaseFragment() {

private fun setButtonOnClickListener() {
binding.submissionDoneHeader.informationHeader.headerButtonBack.buttonIcon.setOnClickListener {
TODO("Integrate this fragment into new ui")
doNavigate(
SubmissionDoneFragmentDirections.actionSubmissionDoneFragmentToMainFragment()
)
}
binding.submissionDoneButtonDone.setOnClickListener {
TODO("Integrate this fragment into new ui")
doNavigate(
SubmissionDoneFragmentDirections.actionSubmissionDoneFragmentToMainFragment()
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.rki.coronawarnapp.ui.submission

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -16,7 +14,6 @@ import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.FragmentSubmissionQrCodeScanBinding
import de.rki.coronawarnapp.ui.BaseFragment
import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel
import de.rki.coronawarnapp.util.CameraPermissionHelper

/**
* A simple [BaseFragment] subclass.
Expand All @@ -25,7 +22,6 @@ class SubmissionQRCodeScanFragment : BaseFragment() {

companion object {
private val TAG: String? = SubmissionQRCodeScanFragment::class.simpleName
private const val REQUEST_CAMERA_PERMISSION_CODE = 1
}

private val viewModel: SubmissionViewModel by viewModels()
Expand All @@ -52,8 +48,6 @@ class SubmissionQRCodeScanFragment : BaseFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

checkForCameraPermission()

binding.submissionQrCodeScanTorch.setOnCheckedChangeListener { _, isChecked ->
binding.submissionQrCodeScanPreview.setTorch(
isChecked
Expand All @@ -77,13 +71,12 @@ class SubmissionQRCodeScanFragment : BaseFragment() {
showInvalidScanDialog()
}
})

startDecode()
}

private fun navigateToDispatchScreen() =
doNavigate(
SubmissionQRCodeScanFragmentDirections.actionSubmissionQRCodeScanFragmentToSubmissionDispatcherFragment()
SubmissionQRCodeScanFragmentDirections
.actionSubmissionQRCodeScanFragmentToSubmissionDispatcherFragment()
)

private fun showSuccessfulScanDialog() {
Expand Down Expand Up @@ -134,84 +127,10 @@ class SubmissionQRCodeScanFragment : BaseFragment() {
alertDialog.show()
kolyaopahle marked this conversation as resolved.
Show resolved Hide resolved
}

private fun checkForCameraPermission() {
if (!CameraPermissionHelper.hasCameraPermission(requireActivity())) {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
showCameraPermissionRationaleDialog()
} else {
requestPermissions(
arrayOf(Manifest.permission.CAMERA),
REQUEST_CAMERA_PERMISSION_CODE
)
}
} else {
cameraPermissionIsGranted()
}
}

private fun cameraPermissionIsGranted() {
binding.submissionQrCodeScanPreview.resume()
startDecode()
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
cameraPermissionIsGranted()
} else {
showCameraPermissionDeniedDialog()
}
}

private fun showCameraPermissionRationaleDialog() {
val alertDialog: AlertDialog = requireActivity().let {
val builder = AlertDialog.Builder(it)
builder.apply {
setTitle(R.string.submission_qr_code_scan_permission_rationale_dialog_headline)
setMessage(R.string.submission_qr_code_scan_permission_rationale_dialog_body)
setPositiveButton(
R.string.submission_qr_code_scan_permission_rationale_dialog_button_positive
) { _, _ ->
requestPermissions(
arrayOf(Manifest.permission.CAMERA),
REQUEST_CAMERA_PERMISSION_CODE
)
}
setNegativeButton(
R.string.submission_qr_code_scan_permission_rationale_dialog_button_negative
) { _, _ ->
navigateToDispatchScreen()
}
}
builder.create()
}
alertDialog.show()
}

private fun showCameraPermissionDeniedDialog() {
val alertDialog: AlertDialog = requireActivity().let {
val builder = AlertDialog.Builder(it)
builder.apply {
setTitle(R.string.submission_qr_code_scan_permission_denied_dialog_headline)
setMessage(R.string.submission_qr_code_scan_permission_denied_dialog_body)
setPositiveButton(
R.string.submission_qr_code_scan_permission_denied_dialog_button_positive
) { _, _ ->
navigateToDispatchScreen()
}
}
builder.create()
}
alertDialog.show()
}

override fun onResume() {
super.onResume()
binding.submissionQrCodeScanPreview.resume()
startDecode()
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package de.rki.coronawarnapp.ui.submission

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.FragmentSubmissionPositiveOtherWarningBinding
import de.rki.coronawarnapp.ui.BaseFragment
import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel

class SubmissionResultPositiveOtherWarningFragment : BaseFragment() {

companion object {
private val TAG: String? = SubmissionResultPositiveOtherWarningFragment::class.simpleName
}

private val viewModel: SubmissionViewModel by activityViewModels()
private lateinit var binding: FragmentSubmissionPositiveOtherWarningBinding

override fun onCreateView(
Expand All @@ -31,16 +34,34 @@ class SubmissionResultPositiveOtherWarningFragment : BaseFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setButtonOnClickListener()

// TODO Maybe move this to a discrete transaction containing both steps
viewModel.authCodeState.observe(viewLifecycleOwner, Observer {
if (it == ApiRequestState.SUCCESS) {
viewModel.submitDiagnosisKeys()
}
})

viewModel.submissionState.observe(viewLifecycleOwner, Observer {
if (it == ApiRequestState.SUCCESS) {
doNavigate(
SubmissionResultPositiveOtherWarningFragmentDirections
.actionSubmissionResultPositiveOtherWarningFragmentToSubmissionDoneFragment()
)
}
})
}

private fun setButtonOnClickListener() {
binding.submissionPositiveOtherWarningButton.setOnClickListener {
Log.i(TAG, "Weiter pressed")
showShareIDConfirmationDialog()
}
binding.submissionPositiveOtherWarningHeader
.informationHeader.headerButtonBack.buttonIcon.setOnClickListener {
Log.i(TAG, "Back button pressed")
doNavigate(
SubmissionResultPositiveOtherWarningFragmentDirections
.actionSubmissionResultPositiveOtherWarningFragmentToSubmissionResultFragment()
)
}
}

Expand All @@ -53,14 +74,11 @@ class SubmissionResultPositiveOtherWarningFragment : BaseFragment() {
setPositiveButton(
kolyaopahle marked this conversation as resolved.
Show resolved Hide resolved
R.string.submission_positive_dialog_confirmation_positive
) { _, _ ->
Log.i(TAG, "Agreed")
// Navigate to next screen
viewModel.requestAuthCode()
}
setNegativeButton(
R.string.submission_positive_dialog_confirmation_negative
) { _, _ ->
Log.i(TAG, "Declined")
}
) { _, _ -> }
}
builder.create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class SubmissionTestResultFragment : BaseFragment() {
}

binding.submissionTestResultButtonPositiveContinue.setOnClickListener {
viewModel.submitDiagnosisKeys()
doNavigate(
SubmissionTestResultFragmentDirections
.actionSubmissionResultFragmentToSubmissionResultPositiveOtherWarningFragment()
)
}

binding.submissionTestResultButtonInvalidRemoveTest.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import java.util.Date
fun formatTestResultStatusVisibility(testResultStatus: TestResultStatus?): Int =
formatVisibility(testResultStatus != TestResultStatus.SUCCESS)

fun formatTestResultHeadingTextVisible(testResult: TestResult?): Int =
formatVisibility(testResult != PENDING)

fun formatTestResultVirusNameTextVisible(testResult: TestResult?): Int {
return when (testResult) {
POSITIVE, NEGATIVE -> View.VISIBLE
Expand Down Expand Up @@ -56,23 +53,19 @@ fun formatTestStatusIcon(testResult: TestResult?): Drawable? {
val appContext = CoronaWarnApplication.getAppContext()
// TODO Replace with real drawables when design is finished
return when (testResult) {
PENDING -> appContext.getDrawable(R.drawable.ic_risk_details_stethoscope)
POSITIVE -> appContext.getDrawable(R.drawable.rectangle)
NEGATIVE -> appContext.getDrawable(R.drawable.circle)
INVALID -> appContext.getDrawable(R.drawable.button)
else -> appContext.getDrawable(R.drawable.button)
PENDING -> appContext.getDrawable(R.drawable.ic_test_result_illustration_pending)
POSITIVE -> appContext.getDrawable(R.drawable.ic_test_result_illustration_positive)
NEGATIVE -> appContext.getDrawable(R.drawable.ic_main_illustration_negative)
INVALID -> appContext.getDrawable(R.drawable.ic_test_result_illustration_invalid)
else -> appContext.getDrawable(R.drawable.ic_test_result_illustration_invalid)
}
}

fun formatTestResultInvalidStatusTextVisible(testResult: TestResult?): Int =
formatVisibility(testResult == INVALID)

fun formatTestResultRegisteredAtVisible(testResult: TestResult?): Int {
return when (testResult) {
POSITIVE, NEGATIVE, INVALID -> View.VISIBLE
else -> View.GONE
}
}
fun formatTestResultPendingStatusTextVisible(testResult: TestResult?): Int =
formatVisibility(testResult == PENDING)

fun formatTestResultRegisteredAtText(registeredAt: Date?): String {
val appContext = CoronaWarnApplication.getAppContext()
Expand Down
Loading