From c04b3e40d256ad04bde58d35f212b6173a7fe3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Mon, 2 Oct 2023 12:21:04 +0200 Subject: [PATCH] Add negative e-mail validation in school input on support dialog (#2315) --- .../login/support/LoginSupportDialog.kt | 38 +++++++++++++------ app/src/main/res/values/strings.xml | 3 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/support/LoginSupportDialog.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/support/LoginSupportDialog.kt index d2b1d2ce..fcf7f51c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/support/LoginSupportDialog.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/support/LoginSupportDialog.kt @@ -1,6 +1,7 @@ package io.github.wulkanowy.ui.modules.login.support import android.os.Bundle +import android.util.Patterns import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -64,21 +65,36 @@ class LoginSupportDialog : BaseDialogFragment() { error = null } } - dialogLoginSupportSubmit.setOnClickListener { - if (dialogLoginSupportSchoolInput.text.isNullOrBlank()) { - with(dialogLoginSupportSchoolLayout) { - isErrorEnabled = true - error = getString(R.string.error_field_required) - } - } else { - onSubmitClick() - dismiss() - } - } + dialogLoginSupportSubmit.setOnClickListener { onSubmitClick() } } } private fun onSubmitClick() { + when { + binding.dialogLoginSupportSchoolInput.text.isNullOrBlank() -> { + with(binding.dialogLoginSupportSchoolLayout) { + isErrorEnabled = true + error = getString(R.string.error_field_required) + } + } + + Patterns.EMAIL_ADDRESS.matcher( + binding.dialogLoginSupportSchoolInput.text.toString() + ).matches() -> { + with(binding.dialogLoginSupportSchoolLayout) { + isErrorEnabled = true + error = getString(R.string.login_support_school_invalid) + } + } + + else -> { + openEmailClientWithFilledTemplate() + dismiss() + } + } + } + + private fun openEmailClientWithFilledTemplate() { with(binding) { context?.openEmailClient( chooserTitle = requireContext().getString(R.string.login_email_intent_title), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08e3ebe6..0ba9c997 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,8 +87,9 @@ No active students found Enter a different symbol Get help - Full school name (required) + Full school name with the town (required) Np. ZSTiO Jarosław lub SP nr 99 w Łodzi + Enter correct name of the school Additional information in Polish (optional) Np. \"Ostatnio zmieniłem szkołę i…\" albo \"Jestem rodzicem i nie widzę drugiego dziecka…\" Submit