Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/textfield singleline #673

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.dimension.flare.ui.screen.rss
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.input.TextFieldLineLimits
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.CircularProgressIndicator
Expand Down Expand Up @@ -74,11 +75,13 @@ private fun RssSourceEditDialog(
state = state.title,
label = { Text(text = stringResource(id = R.string.rss_sources_title_label)) },
modifier = Modifier.fillMaxWidth(),
lineLimits = TextFieldLineLimits.SingleLine,
)
OutlinedTextField2(
state = state.url,
modifier = Modifier.fillMaxWidth(),
label = { Text(text = stringResource(id = R.string.rss_sources_url_label)) },
lineLimits = TextFieldLineLimits.SingleLine,
trailingIcon = {
state.isValid
.onSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ fun ServiceSelectScreen(
}
},
enabled = !state.loading,
lineLimits = TextFieldLineLimits.SingleLine,
)
AnimatedVisibility(state.canNext && state.detectedPlatformType.isSuccess) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import dev.dimension.flare.ui.model.UiState
import dev.dimension.flare.ui.model.collectAsUiState
import dev.dimension.flare.ui.model.flatMap
import dev.dimension.flare.ui.presenter.PresenterBase
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow

public class CheckRssSourcePresenter : PresenterBase<CheckRssSourcePresenter.State>() {
public interface State {
Expand All @@ -22,25 +24,25 @@ public class CheckRssSourcePresenter : PresenterBase<CheckRssSourcePresenter.Sta
public fun setUrl(value: String)
}

@OptIn(FlowPreview::class)
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
@Composable
override fun body(): State {
var url by remember { mutableStateOf("") }
val isValid =
remember {
snapshotFlow { url }
.debounce(500)
.map {
runCatching {
RssService.fetch(it)
}.fold(
onSuccess = {
UiState.Success(true) as UiState<Boolean>
},
onFailure = {
UiState.Error(it)
},
)
.flatMapLatest {
flow {
runCatching {
emit(UiState.Loading())
RssService.fetch(it)
}.onSuccess {
emit(UiState.Success(true))
}.onFailure {
emit(UiState.Success(false))
}
}
}
}.collectAsUiState().value.flatMap { it }

Expand Down
Loading