Commit a3ec358c authored by Valere's avatar Valere

Code review

parent 07cda823
......@@ -18,7 +18,6 @@ package im.vector.activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
......@@ -39,13 +38,11 @@ object DialogUtils {
var passwordShown = false
showPassword.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
passwordShown = !passwordShown
passwordText.showPassword(passwordShown)
showPassword.setImageResource(if (passwordShown) R.drawable.ic_eye_closed_black else R.drawable.ic_eye_black)
}
})
showPassword.setOnClickListener {
passwordShown = !passwordShown
passwordText.showPassword(passwordShown)
showPassword.setImageResource(if (passwordShown) R.drawable.ic_eye_closed_black else R.drawable.ic_eye_black)
}
passwordTil.error = errorText
......
......@@ -38,6 +38,7 @@ import org.matrix.androidsdk.core.JsonUtils
import org.matrix.androidsdk.core.Log
import org.matrix.androidsdk.core.callback.ApiCallback
import org.matrix.androidsdk.core.model.MatrixError
import org.matrix.androidsdk.rest.client.LoginRestClient
import org.matrix.androidsdk.rest.model.SuccessResult
import org.matrix.androidsdk.rest.model.login.AuthParams
import org.matrix.androidsdk.rest.model.login.AuthParamsLoginPassword
......@@ -173,7 +174,7 @@ class PhoneNumberVerificationActivity : VectorAppCompatActivity(), TextView.OnEd
if (e.mStatus == 401 && e.mErrorBodyAsString.isNullOrBlank().not()) {
val flow = JsonUtils.toRegistrationFlowResponse(e.mErrorBodyAsString)
if (flow != null) {
val supportsLoginPassword = flow.flows.any { it.stages == listOf("m.login.password") }
val supportsLoginPassword = flow.flows.any { it.stages == listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD) }
if (supportsLoginPassword) {
//we prompt for it
......@@ -196,7 +197,7 @@ class PhoneNumberVerificationActivity : VectorAppCompatActivity(), TextView.OnEd
.setTitle(R.string.dialog_title_error)
.setMessage(R.string.settings_add_3pid_flow_not_supported)
.setPositiveButton(R.string._continue) { _, _ ->
registerAfterPhoneNumberValidation(pid, auth)
hideWaitingView()
}
.show()
......
......@@ -89,6 +89,7 @@ import org.matrix.androidsdk.data.MyUser
import org.matrix.androidsdk.data.Pusher
import org.matrix.androidsdk.data.RoomMediaMessage
import org.matrix.androidsdk.db.MXMediaCache
import org.matrix.androidsdk.features.identityserver.IdentityServerManager
import org.matrix.androidsdk.features.integrationmanager.IntegrationManager
import org.matrix.androidsdk.listeners.MXEventListener
import org.matrix.androidsdk.listeners.MXMediaUploadListener
......@@ -2038,9 +2039,9 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
addEmailBtn.isEnabled = false
//We need to check if the password flow is available
mSession.identityServerManager.checkAdd3pidInteractiveFlow(listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD),
object : ApiCallback<Boolean?> {
override fun onSuccess(info: Boolean?) {
addEmailBtn.isEnabled = info == null || info == true
object : ApiCallback<IdentityServerManager.SupportedFlowResult> {
override fun onSuccess(info: IdentityServerManager.SupportedFlowResult) {
addEmailBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
}
override fun onUnexpectedError(e: java.lang.Exception?) {
......@@ -2069,6 +2070,7 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
* @param errorMessage the error message
*/
private fun onCommonDone(errorMessage: String?) {
if (!isAdded) return
activity?.runOnUiThread {
if (!TextUtils.isEmpty(errorMessage) && errorMessage != null) {
VectorApp.getInstance().toast(errorMessage)
......@@ -2137,22 +2139,27 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
this.password = password
}
}
AlertDialog.Builder(fragmentActivity)
.setTitle(R.string.account_email_validation_title)
.setMessage(R.string.account_email_validation_message)
.setPositiveButton(R.string._continue) { _, _ ->
finalizeAdd(pid, auth, fragmentActivity)
}
.setNegativeButton(R.string.cancel) { _, _ ->
hideLoadingView()
}
.show()
showEmailValidationDialog(fragmentActivity, pid, auth)
}
}
private fun showEmailValidationDialog(fragmentActivity: FragmentActivity, pid: ThreePid, auth: AuthParamsLoginPassword?) {
AlertDialog.Builder(fragmentActivity)
.setTitle(R.string.account_email_validation_title)
.setMessage(R.string.account_email_validation_message)
.setPositiveButton(R.string._continue) { _, _ ->
finalizeAdd(pid, auth, fragmentActivity)
}
.setNegativeButton(R.string.cancel) { _, _ ->
hideLoadingView()
}
.show()
}
private fun finalizeAdd(pid: ThreePid, auth: AuthParamsLoginPassword?, fragmentActivity: FragmentActivity) {
mSession.identityServerManager.finalize3pidAddSession(pid, auth, object : ApiCallback<Void?> {
override fun onSuccess(info: Void?) {
if (!isAdded) return
fragmentActivity.runOnUiThread {
hideLoadingView()
mSession.myUser.refreshThirdPartyIdentifiers(object : SimpleApiCallback<Void?>() {
......@@ -2168,10 +2175,11 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
}
override fun onMatrixError(e: MatrixError) {
if (!isAdded) return
if (e.mStatus == 401 && e.mErrorBodyAsString.isNullOrBlank().not()) {
val flow = JsonUtils.toRegistrationFlowResponse(e.mErrorBodyAsString)
if (flow != null) {
val supportsLoginPassword = flow.flows.any { it.stages == listOf("m.login.password") }
val supportsLoginPassword = flow.flows.any { it.stages == listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD) }
if (supportsLoginPassword) {
//we prompt for it
val invalidPassError = requireContext().getString(R.string.login_error_forbidden)
......@@ -2190,9 +2198,6 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
AlertDialog.Builder(fragmentActivity)
.setMessage(R.string.settings_add_3pid_flow_not_supported)
.setPositiveButton(R.string._continue) { _, _ ->
finalizeAdd(pid, auth, fragmentActivity)
}
.setNegativeButton(R.string.cancel) { _, _ ->
onCommonDone(null)
}
.show()
......@@ -2206,17 +2211,7 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
fragmentActivity.runOnUiThread {
fragmentActivity.toast(R.string.account_email_validation_error)
//Re-display the popup so that not everything is lost
AlertDialog.Builder(fragmentActivity)
.setTitle(R.string.account_email_validation_title)
.setMessage(R.string.account_email_validation_message)
.setPositiveButton(R.string._continue) { _, _ ->
finalizeAdd(pid, auth, fragmentActivity)
}
.setNegativeButton(R.string.cancel) { _, _ ->
hideLoadingView()
}
.show()
showEmailValidationDialog(requireActivity(), pid, auth)
}
} else {
onCommonDone(e.localizedMessage)
......@@ -2362,9 +2357,9 @@ class VectorSettingsPreferencesFragment : PreferenceFragmentCompat(), SharedPref
addPhoneBtn.isEnabled = false
//We need to check if the password flow is available
mSession.identityServerManager.checkAdd3pidInteractiveFlow(listOf(LoginRestClient.LOGIN_FLOW_TYPE_PASSWORD),
object : ApiCallback<Boolean?> {
override fun onSuccess(info: Boolean?) {
addPhoneBtn.isEnabled = info == null || info == true
object : ApiCallback<IdentityServerManager.SupportedFlowResult> {
override fun onSuccess(info: IdentityServerManager.SupportedFlowResult) {
addPhoneBtn.isEnabled = info == IdentityServerManager.SupportedFlowResult.SUPPORTED
}
override fun onUnexpectedError(e: java.lang.Exception?) {
......
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