Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26b3f360 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer Committed by Nihar Thakkar
Browse files

Custom url

parent 44826058
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ package foundation.e.accountmanager.model

import net.openid.appauth.AuthState
import java.io.Serializable
import java.net.URI

/**
 * Authors: Nihar Thakkar and others
@@ -19,7 +20,8 @@ class Credentials(
        val userName: String? = null,
        val password: String? = null,
        val authState: AuthState? = null,
        val certificateAlias: String? = null
        val certificateAlias: String? = null,
        val serverUri: URI? = null
) : Serializable {

    enum class Type {
+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ class AccountDetailsFragment : Fragment(), LoaderManager.LoaderCallbacks<CreateS
                LoginActivity.ACCOUNT_PROVIDER_EELO -> {
                    accountType = applicationContext.getString(R.string.eelo_account_type)
                    addressBookAccountType = applicationContext.getString(R.string.account_type_eelo_address_book)
                    baseURL = Constants.EELO_SYNC_URL
                    baseURL = config.credentials.serverUri.toString()
                }
                LoginActivity.ACCOUNT_PROVIDER_GOOGLE -> {
                    accountType = applicationContext.getString(R.string.google_account_type)
+54 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
 */
package foundation.e.accountmanager.ui.setup

import android.app.AlertDialog
import android.content.Context
import android.os.*
import android.support.v4.app.Fragment
@@ -17,6 +18,8 @@ import android.view.ViewGroup
import foundation.e.accountmanager.R
import android.net.ConnectivityManager
import android.net.Uri
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.Toast
import foundation.e.dav4android.Constants
import kotlinx.android.synthetic.main.fragment_eelo_authenticator.*
@@ -31,6 +34,9 @@ import java.util.logging.Level
 */

class EeloAuthenticatorFragment : Fragment() {
    var serverUrl = foundation.e.accountmanager.Constants.EELO_SYNC_URL
    val TOGGLE_BUTTON_CHECKED_KEY = "toggle_button_checked"
    var toggleButtonState = false

    private fun isNetworkAvailable(): Boolean {
        val connectivityManager = activity!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
@@ -42,11 +48,34 @@ class EeloAuthenticatorFragment : Fragment() {
                              savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.fragment_eelo_authenticator, container, false)

        view.expand_collapse_button.setOnClickListener(){ expandCollapse() }

        view.login.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){
            toggleButtonState = savedInstanceState.getBoolean(TOGGLE_BUTTON_CHECKED_KEY, false)
        }

        if(toggleButtonState == true) {
            view.expand_collapse_button.setChecked(toggleButtonState)
            view.urlpwd_server_uri_layout.setVisibility(View.VISIBLE)
            view.urlpwd_server_uri.setEnabled(true)
        }else{
            view.urlpwd_server_uri_layout.setVisibility(View.GONE)
            view.urlpwd_server_uri.setEnabled(false)
        }

        return view
    }

    override fun onSaveInstanceState(outState: Bundle) {
        outState.putBoolean(TOGGLE_BUTTON_CHECKED_KEY, toggleButtonState)
        super.onSaveInstanceState(outState)
    }


    private fun login() {
        if (!isNetworkAvailable()) {
            Toast.makeText(context, "Please check your internet connection", Toast.LENGTH_LONG).show()
@@ -65,7 +94,12 @@ class EeloAuthenticatorFragment : Fragment() {
    private fun validateLoginData(): LoginInfo? {
        var valid = true

        val baseUrl = Uri.parse(foundation.e.accountmanager.Constants.EELO_SYNC_URL)
        if(toggleButtonState == true){
            serverUrl = view!!.urlpwd_server_uri.text.toString();
        }else{
            serverUrl = foundation.e.accountmanager.Constants.EELO_SYNC_URL
        }
        val baseUrl = Uri.parse(serverUrl)
        val uri = validateBaseUrl(baseUrl, false) { message ->
            Toast.makeText(context, "Something went wrong. Please try again later", Toast.LENGTH_LONG).show()
            valid = false
@@ -117,4 +151,23 @@ class EeloAuthenticatorFragment : Fragment() {
                R.string.login_url_must_be_http_or_https))
        return uri
    }



    /**
     * Show/Hide panel containing server's uri input field.
     */
    private fun expandCollapse(){
        if(expand_collapse_button.isChecked) {
            urlpwd_server_uri_layout.setVisibility(View.VISIBLE)
            urlpwd_server_uri.setEnabled(true)
            toggleButtonState = true;
        }
        else {
            urlpwd_server_uri_layout.setVisibility(View.GONE)
            urlpwd_server_uri.setEnabled(false)
            toggleButtonState = false;
        }
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ data class LoginInfo(

    constructor(uri: URI, userName: String? = null, password: String? = null, authState: AuthState? = null,
                certificateAlias: String? = null) :
            this(uri, Credentials(userName, password, authState, certificateAlias))
            this(uri, Credentials(userName, password, authState, certificateAlias, uri))

    override fun describeContents() = 0

+9 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/ic_expand_more"
        android:state_checked="false" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/ic_expand_less"
        android:state_checked="true"/>
</selector>
Loading