Improve code

This commit is contained in:
Benoit Marty 2020-05-11 00:10:41 +02:00
parent 34cf9903dc
commit b659cb60a2

View file

@ -33,7 +33,6 @@ import im.vector.riotx.core.epoxy.attributes.ButtonType
import im.vector.riotx.core.epoxy.attributes.IconMode import im.vector.riotx.core.epoxy.attributes.IconMode
import im.vector.riotx.core.epoxy.loadingItem import im.vector.riotx.core.epoxy.loadingItem
import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import timber.log.Timber import timber.log.Timber
@ -244,44 +243,40 @@ class DiscoverySettingsController @Inject constructor(
if (pidInfo.isShared is Fail) { if (pidInfo.isShared is Fail) {
buildSharedFail(pidInfo) buildSharedFail(pidInfo)
} } else if (pidInfo.isShared() == SharedState.BINDING_IN_PROGRESS) {
when (pidInfo.isShared()) { val errorText = if (pidInfo.finalRequest is Fail) {
SharedState.BINDING_IN_PROGRESS -> { val error = pidInfo.finalRequest.error
val errorText = if (pidInfo.finalRequest is Fail) { // Deal with error 500
val error = pidInfo.finalRequest.error // Ref: https://github.com/matrix-org/sydent/issues/292
// Deal with error 500 if (error is Failure.ServerError
// Ref: https://github.com/matrix-org/sydent/issues/292 && error.httpCode == HttpsURLConnection.HTTP_INTERNAL_ERROR /* 500 */) {
if (error is Failure.ServerError stringProvider.getString(R.string.settings_text_message_sent_wrong_code)
&& error.httpCode == HttpsURLConnection.HTTP_INTERNAL_ERROR /* 500 */) {
stringProvider.getString(R.string.settings_text_message_sent_wrong_code)
} else {
errorFormatter.toHumanReadable(error)
}
} else { } else {
null errorFormatter.toHumanReadable(error)
} }
settingsEditTextItem { } else {
id("msisdnVerification${pidInfo.threePid.value}") null
descriptionText(stringProvider.getString(R.string.settings_text_message_sent, phoneNumber))
errorText(errorText)
inProgress(pidInfo.finalRequest is Loading)
interactionListener(object : SettingsEditTextItem.Listener {
override fun onValidate() {
val code = codes[pidInfo.threePid]
if (pidInfo.threePid is ThreePid.Msisdn && code != null) {
listener?.sendMsisdnVerificationCode(pidInfo.threePid, code)
}
}
override fun onCodeChange(code: String) {
codes[pidInfo.threePid] = code
}
})
}
buildContinueCancel(pidInfo.threePid)
} }
else -> Unit settingsEditTextItem {
}.exhaustive id("msisdnVerification${pidInfo.threePid.value}")
descriptionText(stringProvider.getString(R.string.settings_text_message_sent, phoneNumber))
errorText(errorText)
inProgress(pidInfo.finalRequest is Loading)
interactionListener(object : SettingsEditTextItem.Listener {
override fun onValidate() {
val code = codes[pidInfo.threePid]
if (pidInfo.threePid is ThreePid.Msisdn && code != null) {
listener?.sendMsisdnVerificationCode(pidInfo.threePid, code)
}
}
override fun onCodeChange(code: String) {
codes[pidInfo.threePid] = code
}
})
}
buildContinueCancel(pidInfo.threePid)
}
} }
private fun buildThreePid(pidInfo: PidInfo, title: String = pidInfo.threePid.value) { private fun buildThreePid(pidInfo: PidInfo, title: String = pidInfo.threePid.value) {