Login screens: trim homeserver url
This commit is contained in:
parent
ee875b359b
commit
9bd4dbb65f
|
@ -20,10 +20,8 @@ import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import butterknife.OnClick
|
import butterknife.OnClick
|
||||||
import com.airbnb.mvrx.Fail
|
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
|
@ -104,7 +102,7 @@ class LoginServerUrlFormFragment @Inject constructor(
|
||||||
cleanupUi()
|
cleanupUi()
|
||||||
|
|
||||||
// Static check of homeserver url, empty, malformed, etc.
|
// Static check of homeserver url, empty, malformed, etc.
|
||||||
var serverUrl = loginServerUrlFormHomeServerUrl.text.toString()
|
var serverUrl = loginServerUrlFormHomeServerUrl.text.toString().trim()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
serverUrl.isBlank() -> {
|
serverUrl.isBlank() -> {
|
||||||
|
@ -113,8 +111,8 @@ class LoginServerUrlFormFragment @Inject constructor(
|
||||||
else -> {
|
else -> {
|
||||||
if (serverUrl.startsWith("http").not()) {
|
if (serverUrl.startsWith("http").not()) {
|
||||||
serverUrl = "https://$serverUrl"
|
serverUrl = "https://$serverUrl"
|
||||||
loginServerUrlFormHomeServerUrl.setText(serverUrl)
|
|
||||||
}
|
}
|
||||||
|
loginServerUrlFormHomeServerUrl.setText(serverUrl)
|
||||||
loginViewModel.handle(LoginAction.UpdateHomeServer(serverUrl))
|
loginViewModel.handle(LoginAction.UpdateHomeServer(serverUrl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,18 +124,11 @@ class LoginServerUrlFormFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(throwable: Throwable) {
|
override fun onError(throwable: Throwable) {
|
||||||
AlertDialog.Builder(requireActivity())
|
loginServerUrlFormHomeServerUrlTil.error = errorFormatter.toHumanReadable(throwable)
|
||||||
.setTitle(R.string.dialog_title_error)
|
|
||||||
.setMessage(errorFormatter.toHumanReadable(throwable))
|
|
||||||
.setPositiveButton(R.string.ok, null)
|
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(loginViewModel) { state ->
|
override fun invalidate() = withState(loginViewModel) { state ->
|
||||||
when (state.asyncHomeServerLoginFlowRequest) {
|
when (state.asyncHomeServerLoginFlowRequest) {
|
||||||
is Fail -> {
|
|
||||||
loginServerUrlFormHomeServerUrlTil.error = errorFormatter.toHumanReadable(state.asyncHomeServerLoginFlowRequest.error)
|
|
||||||
}
|
|
||||||
is Success -> {
|
is Success -> {
|
||||||
// The home server url is valid
|
// The home server url is valid
|
||||||
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved)
|
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved)
|
||||||
|
|
|
@ -530,7 +530,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
||||||
_viewEvents.post(LoginViewEvents.Error(failure))
|
_viewEvents.post(LoginViewEvents.Error(failure))
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
asyncHomeServerLoginFlowRequest = Fail(failure)
|
asyncHomeServerLoginFlowRequest = Uninitialized
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue