diff --git a/app/build.gradle b/app/build.gradle index fd0c4f21546fb57a60a7a9597e6b8b176d614541..d921defa86e7e70a43862f500121119f296ec0ac 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 28d08cc4f708f4da09785769fd853fdef9613d8f..259c52bdf19dd2533066769c3177ef9d249e9156 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 dcb6972e19bba444a20300084150496a170070b0..407ea7f1683c1fbb7408d8e51e4998ff970a5285 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 2b62454b22c48f110d81a7de82d0101c4c57ba01..8e08ae5ec4ccc56fb67f350f390714c6c8191732 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 d6e68e8a1685a2a8cf1fe90f74a986d1f62bf1e1..ae49ab8adff028a875fd30d3f512b48dc93ae6d1 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