Commit bc63559a authored by Ricki Hirner's avatar Ricki Hirner

Login activity

* use TextInputLayout for input fields
* use support library instead of custom EditPassword widget
* improve client certificate UI
parent 3689df13
Pipeline #16168248 passed with stage
in 3 minutes and 50 seconds
......@@ -11,12 +11,15 @@ package at.bitfire.davdroid.ui.setup
import android.app.Fragment
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.security.KeyChain
import android.security.KeyChainAliasCallback
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import android.widget.Toast
import at.bitfire.dav4android.Constants
import at.bitfire.davdroid.R
import kotlinx.android.synthetic.main.login_credentials_fragment.view.*
......@@ -52,10 +55,12 @@ class DefaultLoginCredentialsFragment: Fragment(), CompoundButton.OnCheckedChang
}
v.urlcert_select_cert.setOnClickListener {
val baseUrl = Uri.parse(view.urlcert_base_url.text.toString())
KeyChain.choosePrivateKeyAlias(activity, KeyChainAliasCallback { alias ->
v.urlcert_cert_alias.text = alias
}, null, null, baseUrl.host, baseUrl.port,view.urlcert_cert_alias.text.toString())
Handler(Looper.getMainLooper()).post({
v.urlcert_cert_alias.text = alias
v.urlcert_cert_alias.error = null
})
}, null, null, null, -1, view.urlcert_cert_alias.text.toString())
}
v.login.setOnClickListener {
......@@ -105,7 +110,7 @@ class DefaultLoginCredentialsFragment: Fragment(), CompoundButton.OnCheckedChang
val password = view.email_password.getText().toString()
if (password.isEmpty()) {
view.email_password.setError(getString(R.string.login_password_required))
view.email_password.error = getString(R.string.login_password_required)
valid = false
}
......@@ -132,9 +137,9 @@ class DefaultLoginCredentialsFragment: Fragment(), CompoundButton.OnCheckedChang
valid = false
}
val password = view.urlpwd_password.getText().toString()
val password = view.urlpwd_password.text.toString()
if (password.isEmpty()) {
view.urlpwd_password.setError(getString(R.string.login_password_required))
view.urlpwd_password.error = getString(R.string.login_password_required)
valid = false
}
......@@ -155,8 +160,10 @@ class DefaultLoginCredentialsFragment: Fragment(), CompoundButton.OnCheckedChang
})
val alias = view.urlcert_cert_alias.text.toString()
if (alias.isEmpty())
if (alias.isEmpty()) {
view.urlcert_cert_alias.error = ""
valid = false
}
if (valid && uri != null)
return LoginInfo(uri, certificateAlias = alias)
......
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui.widget
import android.content.Context
import android.util.AttributeSet
import android.view.inputmethod.EditorInfo
import android.widget.CompoundButton
import android.widget.LinearLayout
import at.bitfire.davdroid.R
import kotlinx.android.synthetic.main.edit_password.view.*
class EditPassword(
context: Context,
attrs: AttributeSet?
): LinearLayout(context, attrs) {
val NS_ANDROID = "http://schemas.android.com/apk/res/android"
constructor(context: Context): this(context, null)
init {
inflate(context, R.layout.edit_password, this)
attrs?.let {
password.setHint(it.getAttributeResourceValue(NS_ANDROID, "hint", 0))
password.setText(it.getAttributeValue(NS_ANDROID, "text"))
}
show_password.setOnCheckedChangeListener({ _: CompoundButton, isChecked: Boolean ->
var inputType = password.inputType and EditorInfo.TYPE_MASK_VARIATION.inv()
inputType = inputType or if (isChecked) EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD else EditorInfo.TYPE_TEXT_VARIATION_PASSWORD
password.inputType = inputType
})
}
fun getText() = password.text!!
fun setText(text: CharSequence?) = password.setText(text)
fun setError(error: CharSequence?) {
password.error = error
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/ic_visibility_dark" />
<item android:state_checked="false"
android:drawable="@drawable/ic_visibility_off_dark" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPassword"/>
<CheckBox
android:id="@+id/show_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:button="@drawable/password_eye_button"
android:checked="false"/>
</LinearLayout>
\ No newline at end of file
......@@ -9,6 +9,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -46,19 +47,31 @@
android:id="@+id/login_type_email_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="vertical">
<EditText
android:id="@+id/email_address"
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_email_address"
android:inputType="textEmailAddress"/>
<at.bitfire.davdroid.ui.widget.EditPassword
android:id="@+id/email_password"
android:hint="@string/login_password"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/email_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_email_address"
android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/email_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_password"
android:fontFamily="monospace"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioButton
......@@ -73,25 +86,41 @@
android:id="@+id/login_type_urlpwd_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="vertical">
<EditText
android:id="@+id/urlpwd_base_url"
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_base_url"
android:inputType="textUri"/>
<EditText
android:id="@+id/urlpwd_user_name"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/urlpwd_base_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_base_url"
android:inputType="textUri"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_user_name"
android:inputType="textEmailAddress"/>
<at.bitfire.davdroid.ui.widget.EditPassword
android:id="@+id/urlpwd_password"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/urlpwd_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_user_name"
android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_password"/>
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/urlpwd_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:inputType="textPassword"
android:hint="@string/login_password"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioButton
......@@ -105,24 +134,42 @@
android:id="@+id/login_type_urlcert_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="vertical">
<EditText
android:id="@+id/urlcert_base_url"
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_base_url"
android:inputType="textUri"/>
<Button
android:id="@+id/urlcert_select_cert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_select_certificate"/>
<TextView
android:id="@+id/urlcert_cert_alias"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/urlcert_base_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_base_url"
android:inputType="textUri"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content">
<TextView
android:id="@+id/urlcert_cert_alias"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingRight="3dp"
style="@style/Base.TextAppearance.AppCompat.Body1"
android:textSize="16sp"/>
<Button
android:id="@+id/urlcert_select_cert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:text="@string/login_select_certificate"/>
</LinearLayout>
</LinearLayout>
......
Markdown is supported
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