FIx / use password textedit

This commit is contained in:
Valere 2020-02-02 00:04:15 +01:00
parent fb838e5407
commit 845f3f5ad1
3 changed files with 26 additions and 15 deletions

View File

@ -15,8 +15,9 @@
*/
package im.vector.riotx.features.settings.crosssigning
import android.content.DialogInterface
import android.os.Bundle
import android.text.InputType
import android.view.KeyEvent
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
@ -31,6 +32,7 @@ import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.utils.toast
import kotlinx.android.synthetic.main.fragment_generic_recycler.*
import javax.inject.Inject
@ -91,27 +93,36 @@ class CrossSigningSettingsFragment @Inject constructor(
}
private fun requestPassword(sessionId: String) {
// Ask for password
val inflater = this.layoutInflater
val layout = inflater.inflate(R.layout.dialog_base_edit_text, null)
val input = layout.findViewById<EditText>(R.id.edit_text).also {
it.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD
}
val inflater = requireActivity().layoutInflater
val layout = inflater.inflate(R.layout.dialog_prompt_password, null)
val passwordEditText = layout.findViewById<EditText>(R.id.prompt_password)
AlertDialog.Builder(requireContext())
.setTitle("Confirm password")
AlertDialog.Builder(requireActivity())
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.devices_delete_dialog_title)
.setView(layout)
.setPositiveButton(R.string.ok) { _, _ ->
val pass = input.text.toString()
.setPositiveButton(R.string.auth_submit, DialogInterface.OnClickListener { _, _ ->
if (passwordEditText.toString().isEmpty()) {
requireActivity().toast(R.string.error_empty_field_your_password)
return@OnClickListener
}
val pass = passwordEditText.text.toString()
// TODO sessionId should never get out the ViewModel
viewModel.handle(CrossSigningAction.InitializeCrossSigning(UserPasswordAuth(
session = sessionId,
password = pass
)))
}
})
.setNegativeButton(R.string.cancel, null)
.setOnKeyListener(DialogInterface.OnKeyListener { dialog, keyCode, event ->
if (event.action == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
dialog.cancel()
return@OnKeyListener true
}
false
})
.show()
}

View File

@ -168,8 +168,8 @@ class VectorSettingsDevicesFragment @Inject constructor(
viewModel.handle(DevicesAction.Password(mAccountPassword))
} else {
val inflater = requireActivity().layoutInflater
val layout = inflater.inflate(R.layout.dialog_device_delete, null)
val passwordEditText = layout.findViewById<EditText>(R.id.delete_password)
val layout = inflater.inflate(R.layout.dialog_prompt_password, null)
val passwordEditText = layout.findViewById<EditText>(R.id.prompt_password)
AlertDialog.Builder(requireActivity())
.setIcon(android.R.drawable.ic_dialog_alert)

View File

@ -31,7 +31,7 @@
android:textStyle="bold" />
<EditText
android:id="@+id/delete_password"
android:id="@+id/prompt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"