Quick and dirty implementation of password reveal on HomeScreen

This commit is contained in:
Benoit Marty 2019-06-05 10:07:18 +02:00
parent e058fa9069
commit 91114e2afe
2 changed files with 53 additions and 11 deletions

View file

@ -29,6 +29,7 @@ import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.sync.FilterService import im.vector.matrix.android.api.session.sync.FilterService
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.showPassword
import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.core.platform.VectorBaseActivity
import im.vector.riotredesign.features.home.HomeActivity import im.vector.riotredesign.features.home.HomeActivity
import io.reactivex.Observable import io.reactivex.Observable
@ -44,14 +45,20 @@ class LoginActivity : VectorBaseActivity() {
private val authenticator = Matrix.getInstance().authenticator() private val authenticator = Matrix.getInstance().authenticator()
private var passwordShown = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login) setContentView(R.layout.activity_login)
setupAuthButton() setupAuthButton()
setupPasswordReveal()
homeServerField.setText(DEFAULT_HOME_SERVER_URI) homeServerField.setText(DEFAULT_HOME_SERVER_URI)
} }
private fun authenticate() { private fun authenticate() {
passwordShown = false
renderPasswordField()
val login = loginField.text?.trim().toString() val login = loginField.text?.trim().toString()
val password = passwordField.text?.trim().toString() val password = passwordField.text?.trim().toString()
buildHomeServerConnectionConfig().fold( buildHomeServerConnectionConfig().fold(
@ -105,6 +112,24 @@ class LoginActivity : VectorBaseActivity() {
authenticateButton.setOnClickListener { authenticate() } authenticateButton.setOnClickListener { authenticate() }
} }
private fun setupPasswordReveal() {
passwordShown = false
passwordReveal.setOnClickListener {
passwordShown = !passwordShown
renderPasswordField()
}
renderPasswordField()
}
private fun renderPasswordField() {
passwordField.showPassword(passwordShown)
passwordReveal.setImageResource(if (passwordShown) R.drawable.ic_eye_closed_black else R.drawable.ic_eye_black)
}
private fun goToHome() { private fun goToHome() {
val intent = HomeActivity.newIntent(this) val intent = HomeActivity.newIntent(this)
startActivity(intent) startActivity(intent)

View file

@ -42,11 +42,16 @@
android:maxLines="1" /> android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<LinearLayout
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_weight="1"
android:hint="@string/auth_password_placeholder"> android:hint="@string/auth_password_placeholder">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -58,6 +63,18 @@
android:maxLines="1" /> android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/passwordReveal"
android:layout_width="@dimen/layout_touch_size"
android:layout_height="@dimen/layout_touch_size"
android:layout_marginTop="16dp"
android:background="?attr/selectableItemBackground"
android:scaleType="center"
android:src="@drawable/ic_eye_black"
android:tint="?attr/colorAccent" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"