Commit aa4d03d4 authored by Valere's avatar Valere

Add cancel option to prompt password

parent a3ec358c
......@@ -28,7 +28,9 @@ import im.vector.extensions.showPassword
object DialogUtils {
fun promptPassword(context: Context, errorText: String? = null, defaultPwd: String? = null, done: (String) -> Unit) {
fun promptPassword(context: Context, errorText: String? = null, defaultPwd: String? = null,
done: (String) -> Unit,
cancel: (() -> Unit)? = null) {
val view: ViewGroup = LayoutInflater.from(context).inflate(R.layout.dialog_confirm_password, null) as ViewGroup
val showPassword: ImageView = view.findViewById(R.id.confirm_password_show_passwords)
......@@ -51,6 +53,14 @@ object DialogUtils {
.setPositiveButton(R.string._continue) { tv, _ ->
done(passwordText.text.toString())
}
.apply {
if (cancel != null) {
setNegativeButton(R.string.cancel) { _, _ ->
cancel()
}
}
}
.show()
}
......
......@@ -183,14 +183,17 @@ class PhoneNumberVerificationActivity : VectorAppCompatActivity(), TextView.OnEd
DialogUtils.promptPassword(this@PhoneNumberVerificationActivity,
invalidPassError,
(auth as? AuthParamsLoginPassword)?.let { auth.password }
) { password ->
val authParams = AuthParamsLoginPassword().apply {
this.user = mSession?.myUserId
this.password = password
}
registerAfterPhoneNumberValidation(pid, authParams)
}
(auth as? AuthParamsLoginPassword)?.let { auth.password },
{ password ->
val authParams = AuthParamsLoginPassword().apply {
this.user = mSession?.myUserId
this.password = password
}
registerAfterPhoneNumberValidation(pid, authParams)
},
{
onSubmitCodeError(getString(R.string.settings_add_3pid_authentication_needed))
})
} else {
//you can only do that on mobile
AlertDialog.Builder(this@PhoneNumberVerificationActivity)
......
......@@ -61,10 +61,7 @@ import im.vector.dialogs.ExportKeysDialog
import im.vector.extensions.getFingerprintHumanReadable
import im.vector.extensions.showPassword
import im.vector.extensions.withArgs
import im.vector.preference.ProgressBarPreference
import im.vector.preference.UserAvatarPreference
import im.vector.preference.VectorGroupPreference
import im.vector.preference.VectorPreference
import im.vector.preference.*
import im.vector.settings.FontScale
import im.vector.settings.VectorLocale
import im.vector.ui.themes.ThemeUtils
......@@ -2041,7 +2038,8 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
mSession.identityServerManager.checkAdd3pidInteractiveFlow(listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD),
object : ApiCallback<IdentityServerManager.SupportedFlowResult> {
override fun onSuccess(info: IdentityServerManager.SupportedFlowResult) {
addEmailBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
addEmailBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
|| info == IdentityServerManager.SupportedFlowResult.INTERACTIVE_AUTH_NOT_SUPPORTED
}
override fun onUnexpectedError(e: java.lang.Exception?) {
......@@ -2186,13 +2184,18 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
.takeIf { e.errcode == MatrixError.FORBIDDEN }
DialogUtils.promptPassword(requireContext(),
invalidPassError,
auth?.let { auth.password }) { password ->
val authParams = AuthParamsLoginPassword().apply {
this.user = mSession.myUserId
this.password = password
}
finalizeAdd(pid, authParams, fragmentActivity)
}
auth?.let { auth.password },
{ password ->
val authParams = AuthParamsLoginPassword().apply {
this.user = mSession.myUserId
this.password = password
}
finalizeAdd(pid, authParams, fragmentActivity)
},
{
onCommonDone(getString(R.string.settings_add_3pid_authentication_needed))
}
)
} else {
//you can only do that on mobile
AlertDialog.Builder(fragmentActivity)
......@@ -2360,6 +2363,7 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
object : ApiCallback<IdentityServerManager.SupportedFlowResult> {
override fun onSuccess(info: IdentityServerManager.SupportedFlowResult) {
addPhoneBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
|| info == IdentityServerManager.SupportedFlowResult.INTERACTIVE_AUTH_NOT_SUPPORTED
}
override fun onUnexpectedError(e: java.lang.Exception?) {
......
......@@ -632,6 +632,7 @@
<string name="settings_app_info_link_summary">Show the application info in the system settings.</string>
<string name="settings_add_3pid_confirm_password_title">Confirm your password</string>
<string name="settings_add_3pid_flow_not_supported">You can\'t do this from Riot mobile</string>
<string name="settings_add_3pid_authentication_needed">Authentication is required</string>
<string name="settings_notification_advanced">Advanced Notification Settings</string>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment