From 5ed891fd878d7bc6da660c79e25d58476fcd9664 Mon Sep 17 00:00:00 2001 From: dokeraj Date: Sat, 1 Jan 2022 10:09:56 +0100 Subject: [PATCH] if the user don't input `http` or `https` in the login url editbox, display appropriate message --- .../java/com/dokeraj/androtainer/HomeFragment.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/dokeraj/androtainer/HomeFragment.kt b/app/src/main/java/com/dokeraj/androtainer/HomeFragment.kt index 65aace1..415e7a4 100644 --- a/app/src/main/java/com/dokeraj/androtainer/HomeFragment.kt +++ b/app/src/main/java/com/dokeraj/androtainer/HomeFragment.kt @@ -62,7 +62,7 @@ class HomeFragment : Fragment(R.layout.fragment_home) { etUrl.setOnFocusChangeListener { _, hasFocus -> if (!hasFocus) { - when (Patterns.WEB_URL.matcher(etUrl.text.toString()).matches()) { + when (Patterns.WEB_URL.matcher(etUrl.text.toString()).matches() && (etUrl.text.toString().toLowerCase().startsWith("http") || etUrl.text.toString().toLowerCase().startsWith("https"))) { true -> { etUrl.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_web_link, 0, @@ -151,15 +151,21 @@ class HomeFragment : Fragment(R.layout.fragment_home) { lgnBtn.setOnClickListener { disableDrawerSwipe = true btnLoginState.changeBtnState(false) - if (Patterns.WEB_URL.matcher(etUrl.text.toString()).matches()) { + if (Patterns.WEB_URL.matcher(etUrl.text.toString()).matches() && (etUrl.text.toString().toLowerCase().startsWith("http") || etUrl.text.toString().toLowerCase().startsWith("https"))) { authenticate(etUrl.text.toString(), etUser.text.toString(), etPass.text.toString(), btnLoginState) } else { + + val errText = if (!etUrl.text.toString().toLowerCase().startsWith("http") && !etUrl.text.toString().toLowerCase().startsWith("https")) + "The URL must start with http:// or https://" + else + "Invalid URL!" + btnLoginState.changeBtnState(true) globActivity.showGenericSnack(requireContext(), requireView(), - "Invalid URL!", + errText, R.color.white, R.color.orange_warning) }