Skip to content

Commit

Permalink
Merge pull request #673 from DimensionDev/bugfix/textfield_singleline
Browse files Browse the repository at this point in the history
Bugfix/textfield singleline
  • Loading branch information
Tlaster authored Jan 26, 2025
2 parents 0c1f61c + af36398 commit f848a6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
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

0 comments on commit f848a6e

Please sign in to comment.