From 36ad59dc0f863d2c90c7bcd965a84e31d2b5f488 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 13 Apr 2022 16:52:12 +0100 Subject: [PATCH] handling server urls as texturis to avoid auto spacing and applying errors to the input field error section --- .../FtueAuthCombinedServerSelectionFragment.kt | 18 ++++++++++++++++++ ...fragment_ftue_server_selection_combined.xml | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt index d1560d7be0..97e2db2123 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt @@ -21,6 +21,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo +import androidx.lifecycle.lifecycleScope import im.vector.app.R import im.vector.app.core.extensions.content import im.vector.app.core.extensions.editText @@ -33,6 +34,11 @@ import im.vector.app.databinding.FragmentFtueServerSelectionCombinedBinding import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.OnboardingViewEvents import im.vector.app.features.onboarding.OnboardingViewState +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.failure.Failure +import reactivecircus.flowbinding.android.widget.textChanges +import java.net.UnknownHostException import javax.inject.Inject class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFtueAuthFragment() { @@ -61,6 +67,9 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt } views.chooseServerGetInTouch.debouncedClicks { openUrlInExternalBrowser(requireContext(), getString(R.string.ftue_ems_url)) } views.chooseServerSubmit.debouncedClicks { updateServerUrl() } + views.chooseServerInput.editText().textChanges() + .onEach { views.chooseServerInput.error = null } + .launchIn(lifecycleScope) } private fun updateServerUrl() { @@ -78,5 +87,14 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt } } + override fun onError(throwable: Throwable) { + views.chooseServerInput.error = if (throwable is Failure.NetworkConnection && + throwable.ioException is UnknownHostException) { + getString(R.string.login_error_homeserver_not_found) + } else { + errorFormatter.toHumanReadable(throwable) + } + } + private fun String.toReducedUrlKeepingSchemaIfInsecure() = toReducedUrl(keepSchema = this.startsWith("http://")) } diff --git a/vector/src/main/res/layout/fragment_ftue_server_selection_combined.xml b/vector/src/main/res/layout/fragment_ftue_server_selection_combined.xml index 8f4902a577..5a60632e86 100644 --- a/vector/src/main/res/layout/fragment_ftue_server_selection_combined.xml +++ b/vector/src/main/res/layout/fragment_ftue_server_selection_combined.xml @@ -106,7 +106,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:imeOptions="actionDone" - android:inputType="text" + android:inputType="textUri" android:maxLines="1" />