Commit cf776605 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch '5443-main-compute_domain' into 'master'

AccountManager: autocompute domain on login and use specirfic url if present

See merge request !45
parents d4eeeb8b 9349cf21
Pipeline #186247 passed with stage
in 2 minutes and 39 seconds
......@@ -44,6 +44,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
dataBinding.enabled = true
flavorDimensions "distribution"
......
......@@ -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"
}
......@@ -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() {
......
......@@ -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">
<com.google.android.material.textfield.TextInputEditText
......@@ -151,7 +152,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="@string/login_server_uri"
android:inputType="textUri"
android:textAlignment="textStart"
android:textColor="@color/primaryTextColor" />
......
......@@ -194,6 +194,7 @@
<string name="set_custom_server_url">Use custom server</string>
<string name="login_server_uri">Server URL (https://server_url)</string>
<string name="login_server_uri_custom">Server URL (%s)</string>
<string name="login_server_uri_error">Valid server URL address required</string>
<string name="login_eelo_server_uri_title">Use a specific server</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment