-
-
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
15 changed files
with
201 additions
and
3 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
6 changes: 6 additions & 0 deletions
6
...ommonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/favorite/FavoriteComponent.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,6 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.favorite | ||
|
||
import dev.datlag.burningseries.ui.navigation.Component | ||
|
||
interface FavoriteComponent : Component { | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/commonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/favorite/FavoriteScreen.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,8 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.favorite | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun FavoriteScreen(component: FavoriteComponent) { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ain/kotlin/dev/datlag/burningseries/ui/screen/initial/favorite/FavoriteScreenComponent.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,16 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.favorite | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.arkivanov.decompose.ComponentContext | ||
import org.kodein.di.DI | ||
|
||
class FavoriteScreenComponent( | ||
componentContext: ComponentContext, | ||
override val di: DI | ||
) : FavoriteComponent, ComponentContext by componentContext { | ||
|
||
@Composable | ||
override fun render() { | ||
FavoriteScreen(this) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rc/commonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/search/SearchComponent.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,10 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.search | ||
|
||
import dev.datlag.burningseries.model.state.SearchState | ||
import dev.datlag.burningseries.ui.navigation.Component | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
interface SearchComponent : Component { | ||
|
||
val searchState: StateFlow<SearchState> | ||
} |
8 changes: 8 additions & 0 deletions
8
...d/src/commonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/search/SearchScreen.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,8 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.search | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun SearchScreen(component: SearchComponent) { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...monMain/kotlin/dev/datlag/burningseries/ui/screen/initial/search/SearchScreenComponent.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,28 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.search | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.arkivanov.decompose.ComponentContext | ||
import dev.datlag.burningseries.common.ioDispatcher | ||
import dev.datlag.burningseries.common.ioScope | ||
import dev.datlag.burningseries.model.state.SearchState | ||
import dev.datlag.burningseries.network.state.SearchStateMachine | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.stateIn | ||
import org.kodein.di.DI | ||
import org.kodein.di.instance | ||
|
||
class SearchScreenComponent( | ||
componentContext: ComponentContext, | ||
override val di: DI | ||
) : SearchComponent, ComponentContext by componentContext { | ||
|
||
private val homeStateMachine: SearchStateMachine by di.instance() | ||
override val searchState: StateFlow<SearchState> = homeStateMachine.state.flowOn(ioDispatcher()).stateIn(ioScope(), SharingStarted.Lazily, SearchState.Loading) | ||
|
||
@Composable | ||
override fun render() { | ||
SearchScreen(this) | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
model/src/commonMain/kotlin/dev/datlag/burningseries/model/Genre.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,17 @@ | ||
package dev.datlag.burningseries.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Genre( | ||
@SerialName("title") val title: String, | ||
@SerialName("items") val items: List<Item> | ||
) { | ||
|
||
@Serializable | ||
data class Item( | ||
@SerialName("title") val title: String, | ||
@SerialName("href") val href: String | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
model/src/commonMain/kotlin/dev/datlag/burningseries/model/state/SearchState.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,13 @@ | ||
package dev.datlag.burningseries.model.state | ||
|
||
import dev.datlag.burningseries.model.Genre | ||
|
||
sealed interface SearchState { | ||
data object Loading : SearchState | ||
data class Success(val genres: List<Genre>) : SearchState | ||
data class Error(val msg: String) : SearchState | ||
} | ||
|
||
sealed interface SearchAction { | ||
data object Retry : SearchAction | ||
} |
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
38 changes: 38 additions & 0 deletions
38
network/src/commonMain/kotlin/dev/datlag/burningseries/network/state/SearchStateMachine.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,38 @@ | ||
package dev.datlag.burningseries.network.state | ||
|
||
import com.freeletics.flowredux.dsl.FlowReduxStateMachine | ||
import dev.datlag.burningseries.model.state.SearchAction | ||
import dev.datlag.burningseries.model.state.SearchState | ||
import dev.datlag.burningseries.network.scraper.BurningSeries | ||
import io.ktor.client.* | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class SearchStateMachine( | ||
private val client: HttpClient | ||
) : FlowReduxStateMachine<SearchState, SearchAction>(initialState = SearchState.Loading) { | ||
init { | ||
spec { | ||
inState<SearchState.Loading> { | ||
onEnter { state -> | ||
try { | ||
val loadedGenres = BurningSeries.getSearch(client) | ||
if (loadedGenres.isEmpty()) { | ||
state.override { SearchState.Error(String()) } | ||
} else { | ||
state.override { SearchState.Success(loadedGenres) } | ||
} | ||
} catch (t: Throwable) { | ||
state.override { SearchState.Error(t.message ?: String()) } | ||
} | ||
} | ||
} | ||
|
||
inState<SearchState.Error> { | ||
on<SearchAction.Retry> { _, state -> | ||
state.override { SearchState.Loading } | ||
} | ||
} | ||
} | ||
} | ||
} |