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

Commit ca5f0626 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer Committed by Sumit Pundir
Browse files

Custom url

parent 106934e2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -9,12 +9,14 @@
package foundation.e.accountmanager.model

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

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
) {

    enum class Type {
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ class AccountDetailsFragment: Fragment() {
            	    LoginActivity.ACCOUNT_PROVIDER_EELO -> {
                        accountType = context!!.getString(R.string.eelo_account_type)
			addressBookAccountType = context!!.getString(R.string.account_type_eelo_address_book)
			baseURL = Constants.EELO_SYNC_URL
			baseURL = credentials.serverUri.toString()  
                    }
                    LoginActivity.ACCOUNT_PROVIDER_GOOGLE -> {
                        accountType = context!!.getString(R.string.google_account_type)
+53 −6
Original line number Diff line number Diff line
package foundation.e.accountmanager.ui.setup

import android.app.AlertDialog
import android.content.Context
import android.net.MailTo
import android.os.*
@@ -8,7 +9,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import android.net.Uri
import android.widget.EditText
import android.widget.LinearLayout
import android.net.ConnectivityManager

import foundation.e.accountmanager.R
@@ -29,6 +32,9 @@ class EeloAuthenticatorFragment : Fragment() {
    private lateinit var model: EeloAuthenticatorModel 
    private lateinit var loginModel: LoginModel

    val TOGGLE_BUTTON_CHECKED_KEY = "toggle_button_checked"
    var toggleButtonState = false

    private fun isNetworkAvailable(): Boolean {
        val connectivityManager = activity!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val activeNetworkInfo = connectivityManager.activeNetworkInfo
@@ -50,11 +56,33 @@ class EeloAuthenticatorFragment : Fragment() {
        v.lifecycleOwner = this
        v.model = model

	v.root.expand_collapse_button.setOnClickListener() { expandCollapse() }

	v.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) {
            v.root.expand_collapse_button.setChecked(toggleButtonState)
            v.root.urlpwd_server_uri_layout.setVisibility(View.VISIBLE)
            v.root.urlpwd_server_uri.setEnabled(true)
        }else{
            v.root.urlpwd_server_uri_layout.setVisibility(View.GONE)
            v.root.urlpwd_server_uri.setEnabled(false)
        }

        return v.root
    }

    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()
@@ -76,10 +104,19 @@ class EeloAuthenticatorFragment : Fragment() {
    private fun validate(): Boolean {
        var valid = false

	var serverUrl = foundation.e.accountmanager.Constants.EELO_SYNC_URL 

        fun validateUrl() {

	    if(toggleButtonState == true) {
            	serverUrl = view!!.urlpwd_server_uri.text.toString();
            } else {
                serverUrl = foundation.e.accountmanager.Constants.EELO_SYNC_URL 
            }

            model.baseUrlError.value = null
            try {
                val uri = URI(foundation.e.accountmanager.Constants.EELO_SYNC_URL)
                val uri = URI(serverUrl)
                if (uri.scheme.equals("http", true) || uri.scheme.equals("https", true)) {
                    valid = true
                    loginModel.baseURI = uri
@@ -109,10 +146,20 @@ class EeloAuthenticatorFragment : Fragment() {
        return valid
    }

    override fun onDestroy() {
        super.onDestroy()
    /**
     * 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;
        }
    }


}
+10 −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>
+10 −0
Original line number Diff line number Diff line
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="@color/grey500"
        android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
</vector>
Loading