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

Test profile input validation (EXPOSUREAPP-8524) #3771

Merged
merged 13 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package de.rki.coronawarnapp.ui.coronatest.rat.profile.create

import android.os.Bundle
import android.telephony.PhoneNumberFormattingTextWatcher
import android.util.Patterns
import android.view.View
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointBackward
import com.google.android.material.datepicker.MaterialDatePicker
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.contactdiary.util.hideKeyboard
Expand Down Expand Up @@ -55,10 +59,41 @@ class RATProfileCreateFragment : Fragment(R.layout.rat_profile_create_fragment),
zipCodeInputEdit.doAfterTextChanged { viewModel.zipCodeChanged(it.toString()) }

// Phone
phoneInputEdit.doAfterTextChanged { viewModel.phoneChanged(it.toString()) }
phoneInputEdit.doAfterTextChanged {
// Propagate phone number to view model if it matches the pattern
if (Patterns.PHONE.matcher(it.toString()).matches()) {
viewModel.phoneChanged(it.toString())
} else {
viewModel.phoneChanged("")
}
}
phoneInputEdit.setOnFocusChangeListener { _, hasFocus ->
// Validate phone number
if (!hasFocus && !Patterns.PHONE.matcher(phoneInputEdit.text.toString()).matches()) {
phoneInputLayout.error = getRoot().getResources().getString(R.string.rat_profile_create_phone_error)
} else {
phoneInputLayout.error = null
}
}
phoneInputEdit.addTextChangedListener(PhoneNumberFormattingTextWatcher())

// E-mail
emailInputEdit.addEmojiFilter().doAfterTextChanged { viewModel.emailChanged(it.toString()) }
emailInputEdit.addEmojiFilter().doAfterTextChanged {
// Propagate email to view model if it matches the pattern
if (Patterns.EMAIL_ADDRESS.matcher(it.toString()).matches()) {
viewModel.emailChanged(it.toString())
} else {
viewModel.emailChanged("")
}
}
emailInputEdit.setOnFocusChangeListener { _, hasFocus ->
// Validate email
if (!hasFocus && !Patterns.EMAIL_ADDRESS.matcher(emailInputEdit.text.toString()).matches()) {
emailInputLayout.error = getRoot().getResources().getString(R.string.rat_profile_create_email_error)
} else {
emailInputLayout.error = null
}
}

viewModel.profile.observe(viewLifecycleOwner) { profileSaveButton.isEnabled = it.isValid }
viewModel.latestProfile.observe(viewLifecycleOwner) { it?.let { bindProfile(it) } }
Expand Down Expand Up @@ -88,8 +123,13 @@ class RATProfileCreateFragment : Fragment(R.layout.rat_profile_create_fragment),
}

private fun openDatePicker() {
// Only allow date selections in the past
val constraintsBuilder = CalendarConstraints.Builder()
.setValidator(DateValidatorPointBackward.now())

MaterialDatePicker.Builder
.datePicker()
.setCalendarConstraints(constraintsBuilder.build())
.build()
.apply {
addOnPositiveButtonClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:maxLength="5"
android:imeOptions="actionNext|flagNoPersonalizedLearning"
android:inputType="number" />

Expand Down
4 changes: 4 additions & 0 deletions Corona-Warn-App/src/main/res/values-de/antigen_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
<string name="rat_profile_create_phone_hint">Telefonnummer</string>
<!-- XTXT: Create RAT profile email hint -->
<string name="rat_profile_create_email_hint">E-Mail-Adresse</string>
<!-- XTXT: Create RAT profile phone error message -->
<string name="rat_profile_create_phone_error">"Ungültige Telefonnummer"</string>
<!-- XTXT: Create RAT profile email error message -->
<string name="rat_profile_create_email_error">"Ungültige E-Mail-Adresse"</string>

<!--RAT profile onboarding-->
<string name="rat_profile_onboarding_image_content_description">Eine Frau mit einem Smartphone in der Hand steht vor einem Gebäude. Ein QR-Code symbolisiert das zu scannende Schnelltest-Profil.</string>
Expand Down
4 changes: 4 additions & 0 deletions Corona-Warn-App/src/main/res/values/antigen_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
<string name="rat_profile_create_phone_hint">"Phone Number"</string>
<!-- XTXT: Create RAT profile email hint -->
<string name="rat_profile_create_email_hint">"E-Mail Address"</string>
<!-- XTXT: Create RAT profile phone error message -->
<string name="rat_profile_create_phone_error">"Invalid Phone Number"</string>
<!-- XTXT: Create RAT profile email error message -->
<string name="rat_profile_create_email_error">"Invalid E-Mail Address"</string>

<!--RAT profile onboarding-->
<string name="rat_profile_onboarding_image_content_description">"A woman with a smartphone in her hand is standing in front of a building. A QR code symbolizes the rapid test profile to be scanned."</string>
Expand Down