From 91114e2afebbc2db06ed1a8f63e9b253643c5670 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Jun 2019 10:07:18 +0200 Subject: [PATCH] Quick and dirty implementation of password reveal on HomeScreen --- .../features/login/LoginActivity.kt | 25 ++++++++++++ vector/src/main/res/layout/activity_login.xml | 39 +++++++++++++------ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt index dc6f3aeb..ffadac11 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt @@ -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.sync.FilterService import im.vector.riotredesign.R +import im.vector.riotredesign.core.extensions.showPassword import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.features.home.HomeActivity import io.reactivex.Observable @@ -44,14 +45,20 @@ class LoginActivity : VectorBaseActivity() { private val authenticator = Matrix.getInstance().authenticator() + private var passwordShown = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) setupAuthButton() + setupPasswordReveal() homeServerField.setText(DEFAULT_HOME_SERVER_URI) } private fun authenticate() { + passwordShown = false + renderPasswordField() + val login = loginField.text?.trim().toString() val password = passwordField.text?.trim().toString() buildHomeServerConnectionConfig().fold( @@ -105,6 +112,24 @@ class LoginActivity : VectorBaseActivity() { 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() { val intent = HomeActivity.newIntent(this) startActivity(intent) diff --git a/vector/src/main/res/layout/activity_login.xml b/vector/src/main/res/layout/activity_login.xml index 1b1da727..c86ee6dc 100644 --- a/vector/src/main/res/layout/activity_login.xml +++ b/vector/src/main/res/layout/activity_login.xml @@ -42,21 +42,38 @@ android:maxLines="1" /> - - + android:orientation="horizontal"> - - + android:layout_marginTop="16dp" + android:layout_weight="1" + android:hint="@string/auth_password_placeholder"> + + + + + + +