Skip to content

Commit

Permalink
Showing 62 changed files with 280 additions and 1,051 deletions.
1 change: 1 addition & 0 deletions changelog.d/3545.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reveal password: use facility from com.google.android.material.textfield.TextInputLayout instead of manual handling.
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
package im.vector.lib.ui.styles.debug

import android.os.Bundle
import android.text.InputType
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import im.vector.lib.ui.styles.databinding.ActivityDebugTextViewBinding

@@ -27,5 +29,20 @@ abstract class DebugVectorTextViewActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val views = ActivityDebugTextViewBinding.inflate(layoutInflater)
setContentView(views.root)

views.debugShowPassword.setOnClickListener {
views.debugTextInputEditText.showPassword(true)
}
views.debugHidePassword.setOnClickListener {
views.debugTextInputEditText.showPassword(false)
}
}

private fun EditText.showPassword(visible: Boolean) {
if (visible) {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
} else {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:ignore="HardcodedText">

<TextView
@@ -65,4 +67,34 @@
android:layout_height="wrap_content"
android:text="Default (TextAppearance.Vector.Body)\nline 2" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/debugTextInputLayout"
style="@style/Widget.Vector.TextInputLayout.Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Password"
app:errorEnabled="true">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/debugTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLines="1" />

</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/debugShowPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show password" />

<Button
android:id="@+id/debugHidePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hide password" />

</LinearLayout>
5 changes: 5 additions & 0 deletions library/ui-styles/src/main/res/values/styles_edit_text.xml
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@
<!-- Default style for TextInputLayout -->
<style name="Widget.Vector.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox" />

<style name="Widget.Vector.TextInputLayout.Password">
<item name="endIconMode">password_toggle</item>
<item name="endIconTint">?vctr_content_secondary</item>
</style>

<style name="Widget.Vector.EditText.Composer" parent="Widget.AppCompat.EditText">
<item name="android:background">@android:color/transparent</item>
<item name="android:inputType">textCapSentences|textMultiLine</item>
Original file line number Diff line number Diff line change
@@ -20,14 +20,11 @@ import android.app.Activity
import android.text.Editable
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.extensions.showPassword
import im.vector.app.core.platform.SimpleTextWatcher
import im.vector.app.databinding.DialogExportE2eKeysBinding

class ExportKeysDialog {

private var passwordVisible = false

fun show(activity: Activity, exportKeyDialogListener: ExportKeyDialogListener) {
val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_export_e2e_keys, null)
val views = DialogExportE2eKeysBinding.bind(dialogLayout)
@@ -57,13 +54,6 @@ class ExportKeysDialog {
views.exportDialogEt.addTextChangedListener(textWatcher)
views.exportDialogEtConfirm.addTextChangedListener(textWatcher)

views.exportDialogShowPassword.setOnClickListener {
passwordVisible = !passwordVisible
views.exportDialogEt.showPassword(passwordVisible)
views.exportDialogEtConfirm.showPassword(passwordVisible)
views.exportDialogShowPassword.render(passwordVisible)
}

val exportDialog = builder.show()

views.exportDialogSubmit.setOnClickListener {

This file was deleted.

Original file line number Diff line number Diff line change
@@ -40,13 +40,8 @@ fun SearchView.withoutLeftMargin() {
}
}

fun EditText.showPassword(visible: Boolean, updateCursor: Boolean = true) {
if (visible) {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
} else {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
}
if (updateCursor) setSelection(text?.length ?: 0)
fun EditText.hidePassword() {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
}

fun View.getMeasurements(): Pair<Int, Int> {

This file was deleted.

15 changes: 2 additions & 13 deletions vector/src/main/java/im/vector/app/features/auth/PromptFragment.kt
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ import androidx.core.view.isVisible
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import im.vector.app.R
import im.vector.app.core.extensions.showPassword
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentReauthConfirmBinding
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
@@ -41,13 +40,6 @@ class PromptFragment : VectorBaseFragment<FragmentReauthConfirmBinding>() {
views.reAuthConfirmButton.debouncedClicks {
onButtonClicked()
}
views.passwordReveal.debouncedClicks {
viewModel.handle(ReAuthActions.StartSSOFallback)
}

views.passwordReveal.debouncedClicks {
viewModel.handle(ReAuthActions.TogglePassVisibility)
}
}

private fun onButtonClicked() = withState(viewModel) { state ->
@@ -74,21 +66,18 @@ class PromptFragment : VectorBaseFragment<FragmentReauthConfirmBinding>() {
override fun invalidate() = withState(viewModel) {
when (it.flowType) {
LoginFlowTypes.SSO -> {
views.passwordContainer.isVisible = false
views.passwordFieldTil.isVisible = false
views.reAuthConfirmButton.text = getString(R.string.auth_login_sso)
}
LoginFlowTypes.PASSWORD -> {
views.passwordContainer.isVisible = true
views.passwordFieldTil.isVisible = true
views.reAuthConfirmButton.text = getString(R.string._continue)
}
else -> {
// This login flow is not supported, you should use web?
}
}

views.passwordField.showPassword(it.passwordVisible)
views.passwordReveal.render(it.passwordVisible)

if (it.lastErrorCode != null) {
when (it.flowType) {
LoginFlowTypes.SSO -> {
Original file line number Diff line number Diff line change
@@ -22,6 +22,5 @@ sealed class ReAuthActions : VectorViewModelAction {
object StartSSOFallback : ReAuthActions()
object FallBackPageLoaded : ReAuthActions()
object FallBackPageClosed : ReAuthActions()
object TogglePassVisibility : ReAuthActions()
data class ReAuthWithPass(val password: String) : ReAuthActions()
}
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ data class ReAuthState(
val session: String? = null,
val flowType: String? = null,
val ssoFallbackPageWasShown: Boolean = false,
val passwordVisible: Boolean = false,
val lastErrorCode: String? = null,
val resultKeyStoreAlias: String = ""
) : MvRxState {
Original file line number Diff line number Diff line change
@@ -65,13 +65,6 @@ class ReAuthViewModel @AssistedInject constructor(
ReAuthActions.FallBackPageClosed -> {
// Should we do something here?
}
ReAuthActions.TogglePassVisibility -> {
setState {
copy(
passwordVisible = !state.passwordVisible
)
}
}
is ReAuthActions.ReAuthWithPass -> {
val safeForIntentCypher = ByteArrayOutputStream().also {
it.use {
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ import android.view.inputmethod.EditorInfo
import androidx.core.text.set
import androidx.core.widget.doOnTextChanged
import im.vector.app.R
import im.vector.app.core.extensions.showPassword
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentKeysBackupRestoreFromPassphraseBinding

@@ -40,10 +39,6 @@ class KeysBackupRestoreFromPassphraseFragment @Inject constructor() : VectorBase
private lateinit var viewModel: KeysBackupRestoreFromPassphraseViewModel
private lateinit var sharedViewModel: KeysBackupRestoreSharedViewModel

private fun toggleVisibilityMode() {
viewModel.showPasswordMode.value = !(viewModel.showPasswordMode.value ?: false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

@@ -56,12 +51,6 @@ class KeysBackupRestoreFromPassphraseFragment @Inject constructor() : VectorBase

views.helperTextWithLink.text = spannableStringForHelperText()

viewModel.showPasswordMode.observe(viewLifecycleOwner) {
val shouldBeVisible = it ?: false
views.keysBackupPassphraseEnterEdittext.showPassword(shouldBeVisible)
views.keysBackupViewShowPassword.render(shouldBeVisible)
}

views.keysBackupPassphraseEnterEdittext.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
onRestoreBackup()
@@ -70,7 +59,6 @@ class KeysBackupRestoreFromPassphraseFragment @Inject constructor() : VectorBase
return@setOnEditorActionListener false
}

views.keysBackupViewShowPassword.setOnClickListener { toggleVisibilityMode() }
views.helperTextWithLink.setOnClickListener { onUseRecoveryKey() }
views.keysBackupRestoreWithPassphraseSubmit.setOnClickListener { onRestoreBackup() }
views.keysBackupPassphraseEnterEdittext.doOnTextChanged { text, _, _, _ -> onPassphraseTextEditChange(text) }
Original file line number Diff line number Diff line change
@@ -30,12 +30,10 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor(

var passphrase: MutableLiveData<String> = MutableLiveData()
var passphraseErrorText: MutableLiveData<String> = MutableLiveData()
var showPasswordMode: MutableLiveData<Boolean> = MutableLiveData()

init {
passphrase.value = null
passphraseErrorText.value = null
showPasswordMode.value = false
}

// ========= Actions =========
Loading

0 comments on commit 7257736

Please sign in to comment.