-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
87 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...rc/commonMain/kotlin/dev/dimension/flare/ui/presenter/home/rss/CheckRssSourcePresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.dimension.flare.ui.presenter.home.rss | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.snapshotFlow | ||
import dev.dimension.flare.data.network.rss.Rss | ||
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.flow.map | ||
|
||
public class CheckRssSourcePresenter : PresenterBase<CheckRssSourcePresenter.State>() { | ||
public interface State { | ||
public val isValid: UiState<Boolean> | ||
|
||
public fun setUrl(value: String) | ||
} | ||
|
||
@Composable | ||
override fun body(): State { | ||
var url by remember { mutableStateOf("") } | ||
val isValid = | ||
remember { | ||
snapshotFlow { url } | ||
.map { | ||
runCatching { | ||
Rss.fetch(it) | ||
}.fold( | ||
onSuccess = { | ||
UiState.Success(true) as UiState<Boolean> | ||
}, | ||
onFailure = { | ||
UiState.Error(it) | ||
}, | ||
) | ||
} | ||
}.collectAsUiState().value.flatMap { it } | ||
|
||
return object : State { | ||
override val isValid = isValid | ||
|
||
override fun setUrl(value: String) { | ||
url = value | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters