From 9349cf219612d9a0f2dae4219275989fd8bc7d08 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Mon, 16 May 2022 13:31:40 +0530 Subject: [PATCH] AccountManager: autocompute domain on login and use specirfic url if present --- app/build.gradle | 4 +++ .../foundation/e/accountmanager/Constants.kt | 4 +-- .../ui/setup/EeloAuthenticatorFragment.kt | 36 ++++++++++++------- .../layout/fragment_eelo_authenticator.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fd0c4f215..d921defa8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,6 +44,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + dataBinding.enabled = true flavorDimensions "distribution" diff --git a/app/src/main/java/foundation/e/accountmanager/Constants.kt b/app/src/main/java/foundation/e/accountmanager/Constants.kt index 28d08cc4f..259c52bdf 100644 --- a/app/src/main/java/foundation/e/accountmanager/Constants.kt +++ b/app/src/main/java/foundation/e/accountmanager/Constants.kt @@ -31,8 +31,6 @@ object Constants { const val AUTH_TOKEN_TYPE = "oauth2-access-token" - const val EELO_SYNC_SCHEME = "https://" const val EELO_SYNC_HOST = "ecloud.global" - const val E_SYNC_URL = EELO_SYNC_SCHEME + "e.email" - const val EELO_SYNC_URL = EELO_SYNC_SCHEME + EELO_SYNC_HOST + const val E_SYNC_URL = "e.email" } diff --git a/app/src/main/java/foundation/e/accountmanager/ui/setup/EeloAuthenticatorFragment.kt b/app/src/main/java/foundation/e/accountmanager/ui/setup/EeloAuthenticatorFragment.kt index dcb6972e1..407ea7f16 100644 --- a/app/src/main/java/foundation/e/accountmanager/ui/setup/EeloAuthenticatorFragment.kt +++ b/app/src/main/java/foundation/e/accountmanager/ui/setup/EeloAuthenticatorFragment.kt @@ -7,6 +7,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.core.widget.doOnTextChanged import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProviders import foundation.e.accountmanager.Constants @@ -49,20 +50,17 @@ class EeloAuthenticatorFragment : Fragment() { v.root.server_toggle_button.setOnClickListener() { expandCollapse() } - v.root.urlpwd_user_name.setOnFocusChangeListener() { v, hasFocus -> - if (!hasFocus) { - if (v.urlpwd_user_name.text.toString().contains("@")) { - val dns = v.urlpwd_user_name.text.toString().substringAfter("@") - val pre_custom_url = "https://" + dns - requireView().urlpwd_server_uri.setText(pre_custom_url) - } else { - requireView().urlpwd_server_uri.setText("") - } + v.root.sign_in.setOnClickListener { login() } + + v.root.urlpwd_user_name.doOnTextChanged { text, _, _, _ -> + val domain = computeDomain(text) + if (domain.isEmpty()) { + requireView().urlpwd_server_uri_layout.hint = getString(R.string.login_server_uri) + } else { + requireView().urlpwd_server_uri_layout.hint = getString(R.string.login_server_uri_custom, domain) } } - v.root.sign_in.setOnClickListener { login() } - // code below is to draw toggle button in its correct state and show or hide server url input field //add by Vincent, 18/02/2019 if (savedInstanceState != null) { @@ -94,6 +92,18 @@ class EeloAuthenticatorFragment : Fragment() { super.onSaveInstanceState(outState) } + private fun computeDomain(username: CharSequence?) : String { + var domain = "" + if (!username.isNullOrEmpty() && username.toString().contains("@")) { + var dns = username.toString().substringAfter("@") + if (dns == Constants.E_SYNC_URL) { + dns = Constants.EELO_SYNC_HOST + } + domain = "https://$dns" + } + return domain + } + private fun login() { if (!isNetworkAvailable()) { Toast.makeText(context, "Please check your internet connection", Toast.LENGTH_LONG).show() @@ -117,8 +127,8 @@ class EeloAuthenticatorFragment : Fragment() { var serverUrl = requireView().urlpwd_server_uri.text.toString() - if (serverUrl == Constants.E_SYNC_URL) { - serverUrl = Constants.EELO_SYNC_URL + if (serverUrl.isEmpty()) { + serverUrl = computeDomain(requireView().urlpwd_user_name.text.toString()) } fun validateUrl() { diff --git a/app/src/main/res/layout/fragment_eelo_authenticator.xml b/app/src/main/res/layout/fragment_eelo_authenticator.xml index 2b62454b2..8e08ae5ec 100644 --- a/app/src/main/res/layout/fragment_eelo_authenticator.xml +++ b/app/src/main/res/layout/fragment_eelo_authenticator.xml @@ -144,6 +144,7 @@ android:paddingEnd="16dp" app:hintTextColor="@color/edittext" app:boxStrokeColor="@color/edittext" + android:hint="@string/login_server_uri" android:theme="@style/edittext_holder_theme"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6e68e8a1..ae49ab8ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,6 +194,7 @@ Use custom server Server URL (https://server_url) + Server URL (%s) Valid server URL address required Use a specific server -- GitLab