-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
1 parent
d1f776c
commit 2311fad
Showing
7 changed files
with
117 additions
and
44 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
core/ui/src/androidMain/kotlin/org/michaelbel/movies/ui/ktx/LifecycleKtx.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 org.michaelbel.movies.ui.ktx | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
@Composable | ||
actual fun <T> StateFlow<T>.collectAsStateCommon( | ||
lifecycleOwner: LifecycleOwner, | ||
minActiveState: Lifecycle.State, | ||
context: CoroutineContext | ||
): State<T> = collectAsStateWithLifecycle() |
17 changes: 17 additions & 0 deletions
17
core/ui/src/commonMain/kotlin/org/michaelbel/movies/ui/ktx/LifecycleKtx.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 org.michaelbel.movies.ui.ktx | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
@Composable | ||
expect fun <T> StateFlow<T>.collectAsStateCommon( | ||
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, | ||
minActiveState: Lifecycle.State = Lifecycle.State.STARTED, | ||
context: CoroutineContext = EmptyCoroutineContext | ||
): State<T> |
16 changes: 16 additions & 0 deletions
16
core/ui/src/desktopMain/kotlin/org/michaelbel/movies/ui/ktx/LifecycleKtx.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 org.michaelbel.movies.ui.ktx | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
@Composable | ||
actual fun <T> StateFlow<T>.collectAsStateCommon( | ||
lifecycleOwner: LifecycleOwner, | ||
minActiveState: Lifecycle.State, | ||
context: CoroutineContext | ||
): State<T> = collectAsState() |
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
14 changes: 13 additions & 1 deletion
14
feature/feed-impl/src/desktopMain/kotlin/org/michaelbel/movies/feed/FeedViewModel.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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
package org.michaelbel.movies.feed | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.stateIn | ||
import kotlinx.coroutines.runBlocking | ||
import org.michaelbel.movies.common.list.MovieList | ||
import org.michaelbel.movies.common.viewmodel.BaseViewModel | ||
import org.michaelbel.movies.interactor.Interactor | ||
|
||
class FeedViewModel( | ||
private val interactor: Interactor | ||
): BaseViewModel() { | ||
|
||
|
||
val currentMovieList: StateFlow<MovieList> = interactor.currentMovieList | ||
.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.Lazily, | ||
initialValue = runBlocking { interactor.currentMovieList.first() } | ||
) | ||
} |
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
44 changes: 44 additions & 0 deletions
44
feature/feed-impl/src/desktopMain/kotlin/org/michaelbel/movies/feed/ui/FeedScreenContent.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,44 @@ | ||
@file:OptIn(ExperimentalMaterial3Api::class) | ||
|
||
package org.michaelbel.movies.feed.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import org.michaelbel.movies.common.list.MovieList | ||
import org.michaelbel.movies.feed.ktx.titleText | ||
import org.michaelbel.movies.persistence.database.entity.pojo.AccountPojo | ||
|
||
@Composable | ||
internal fun FeedScreenContent( | ||
currentMovieList: MovieList, | ||
onNavigateToSearch: () -> Unit, | ||
onNavigateToAuth: () -> Unit, | ||
onNavigateToAccount: () -> Unit, | ||
onNavigateToSettings: () -> Unit, | ||
onNavigateToDetails: (String, Int) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
Scaffold( | ||
modifier = modifier.fillMaxSize(), | ||
topBar = { | ||
FeedToolbar( | ||
title = currentMovieList.titleText, | ||
account = AccountPojo.Empty, | ||
isTmdbApiKeyEmpty = false, | ||
topAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(), | ||
onSearchIconClick = onNavigateToSearch, | ||
onAuthIconClick = onNavigateToAuth, | ||
onAccountIconClick = onNavigateToAccount, | ||
onSettingsIconClick = onNavigateToSettings | ||
) | ||
}, | ||
containerColor = MaterialTheme.colorScheme.background | ||
) { innerPadding -> | ||
|
||
} | ||
} |