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

View File

@ -42,21 +42,38 @@
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>


<com.google.android.material.textfield.TextInputLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/auth_password_placeholder">
android:orientation="horizontal">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/passwordField"
android:layout_width="match_parent"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
android:layout_marginTop="16dp"
android:layout_weight="1"
android:hint="@string/auth_password_placeholder">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/passwordField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1" />
</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
android:layout_width="match_parent"