Widgets: use the support library edit password widget.

tmp
Tom Hacohen 5 years ago
parent 6ef78085bd
commit 0b21502645

@ -9,6 +9,7 @@
package com.etesync.syncadapter.ui.setup
import android.os.Bundle
import android.support.design.widget.TextInputLayout
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
@ -18,10 +19,9 @@ import android.widget.TextView
import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.R
import com.etesync.syncadapter.ui.widget.EditPassword
class EncryptionDetailsFragment : Fragment() {
internal var editPassword: EditPassword? = null
internal lateinit var editPassword: TextInputLayout
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -35,7 +35,7 @@ class EncryptionDetailsFragment : Fragment() {
val accountName = v.findViewById<View>(R.id.account_name) as TextView
accountName.text = getString(R.string.login_encryption_account_label) + " " + config.userName
editPassword = v.findViewById<View>(R.id.encryption_password) as EditPassword
editPassword = v.findViewById<View>(R.id.encryption_password) as TextInputLayout
val btnCreate = v.findViewById<View>(R.id.create_account) as Button
btnCreate.setOnClickListener(View.OnClickListener {
@ -54,9 +54,9 @@ class EncryptionDetailsFragment : Fragment() {
private fun validateEncryptionData(config: BaseConfigurationFinder.Configuration): BaseConfigurationFinder.Configuration? {
var valid = true
val password = editPassword!!.text.toString()
val password = editPassword.editText?.text.toString()
if (password.isEmpty()) {
editPassword!!.setError(getString(R.string.login_password_required))
editPassword.error = getString(R.string.login_password_required)
valid = false
}

@ -9,6 +9,7 @@
package com.etesync.syncadapter.ui.setup
import android.os.Bundle
import android.support.design.widget.TextInputLayout
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
@ -20,14 +21,13 @@ import android.widget.TextView
import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.R
import com.etesync.syncadapter.ui.WebViewActivity
import com.etesync.syncadapter.ui.widget.EditPassword
import net.cachapa.expandablelayout.ExpandableLayout
import okhttp3.HttpUrl
import java.net.URI
class LoginCredentialsFragment : Fragment() {
internal lateinit var editUserName: EditText
internal lateinit var editUrlPassword: EditPassword
internal lateinit var editUrlPassword: TextInputLayout
internal lateinit var showAdvanced: CheckedTextView
internal lateinit var customServer: EditText
@ -37,7 +37,7 @@ class LoginCredentialsFragment : Fragment() {
val v = inflater.inflate(R.layout.login_credentials_fragment, container, false)
editUserName = v.findViewById<View>(R.id.user_name) as EditText
editUrlPassword = v.findViewById<View>(R.id.url_password) as EditPassword
editUrlPassword = v.findViewById<View>(R.id.url_password) as TextInputLayout
showAdvanced = v.findViewById<View>(R.id.show_advanced) as CheckedTextView
customServer = v.findViewById<View>(R.id.custom_server) as EditText
@ -50,7 +50,7 @@ class LoginCredentialsFragment : Fragment() {
val password = intent.getStringExtra(LoginActivity.EXTRA_PASSWORD)
editUserName.setText(username)
editUrlPassword.setText(password)
editUrlPassword.editText?.setText(password)
}
}
@ -94,9 +94,9 @@ class LoginCredentialsFragment : Fragment() {
valid = false
}
val password = editUrlPassword.text.toString()
val password = editUrlPassword.editText?.text.toString()
if (password.isEmpty()) {
editUrlPassword.setError(getString(R.string.login_password_required))
editUrlPassword.error = getString(R.string.login_password_required)
valid = false
}

@ -1,60 +0,0 @@
/*
* 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
*/
package com.etesync.syncadapter.ui.widget
import android.content.Context
import android.text.Editable
import android.util.AttributeSet
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.CheckBox
import android.widget.EditText
import android.widget.LinearLayout
import com.etesync.syncadapter.R
class EditPassword : LinearLayout {
internal var editPassword: EditText
val text: Editable
get() = editPassword.text
init {
View.inflate(context, R.layout.edit_password, this)
editPassword = findViewById<View>(R.id.password) as EditText
}
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
editPassword.setHint(attrs.getAttributeResourceValue(NS_ANDROID, "hint", 0))
editPassword.setText(attrs.getAttributeValue(NS_ANDROID, "text"))
val checkShowPassword = findViewById<View>(R.id.show_password) as CheckBox
checkShowPassword.setOnCheckedChangeListener { buttonView, isChecked ->
var inputType = editPassword.inputType and EditorInfo.TYPE_MASK_VARIATION.inv()
inputType = inputType or if (isChecked) EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD else EditorInfo.TYPE_TEXT_VARIATION_PASSWORD
editPassword.inputType = inputType
}
}
fun setError(error: CharSequence) {
editPassword.error = error
}
fun setText(text: CharSequence) {
editPassword.setText(text)
}
companion object {
private val NS_ANDROID = "http://schemas.android.com/apk/res/android"
}
}

@ -1,15 +0,0 @@
<?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>

@ -1,29 +0,0 @@
<?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>

@ -8,10 +8,11 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
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">
<ScrollView android:layout_width="match_parent"
android:layout_height="0dp"
@ -41,12 +42,19 @@
android:layout_height="wrap_content"
android:hint="@string/login_email_address"
android:inputType="textEmailAddress"/>
<com.etesync.syncadapter.ui.widget.EditPassword
<android.support.design.widget.TextInputLayout
android:id="@+id/url_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:hint="@string/login_password" />
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
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>
<TextView
android:id="@+id/forgot_password"

@ -8,9 +8,10 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
@ -35,11 +36,18 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.etesync.syncadapter.ui.widget.EditPassword
<android.support.design.widget.TextInputLayout
android:id="@+id/encryption_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_encryption_password"/>
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:inputType="textPassword"
android:hint="@string/login_encryption_password"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="match_parent"

Loading…
Cancel
Save