Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Use Circuit's Retained state for back stack support #1551

Merged
merged 3 commits into from
Sep 21, 2023
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
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ chucker-library = { module = "com.github.chuckerteam.chucker:library", version.r
circuit-foundation = { module = "com.slack.circuit:circuit-foundation", version.ref = "circuit" }
circuit-gestureNavigation = { module = "com.slack.circuit:circuitx-gesture-navigation", version.ref = "circuit" }
circuit-overlay = { module = "com.slack.circuit:circuit-overlay", version.ref = "circuit" }
circuit-retained = { module = "com.slack.circuit:circuit-retained", version.ref = "circuit" }
circuit-runtime = { module = "com.slack.circuit:circuit-runtime", version.ref = "circuit" }

compose-material3-windowsizeclass = "dev.chrisbanes.material3:material3-window-size-class-multiplatform:0.3.1"
Expand Down
1 change: 1 addition & 0 deletions ui/account/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kotlin {
api(projects.common.ui.screens)
api(projects.common.ui.circuitOverlay) // Only for LocalNavigator
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package app.tivi.account

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import app.tivi.common.compose.rememberCoroutineScope
import app.tivi.data.traktauth.TraktAuthState
Expand All @@ -16,6 +15,7 @@ import app.tivi.domain.observers.ObserveTraktAuthState
import app.tivi.domain.observers.ObserveUserDetails
import app.tivi.screens.AccountScreen
import app.tivi.screens.SettingsScreen
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -47,8 +47,8 @@ class AccountPresenter(

@Composable
override fun present(): AccountUiState {
val user by observeUserDetails.flow.collectAsState(null)
val authState by observeTraktAuthState.flow.collectAsState(TraktAuthState.LOGGED_OUT)
val user by observeUserDetails.flow.collectAsRetainedState(null)
val authState by observeTraktAuthState.flow.collectAsRetainedState(TraktAuthState.LOGGED_OUT)
val scope = rememberCoroutineScope()

LaunchedEffect(Unit) {
Expand Down
1 change: 1 addition & 0 deletions ui/developer/log/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.material3)
implementation(compose.animation)
Expand Down
1 change: 1 addition & 0 deletions ui/developer/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.material3)
implementation(compose.animation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package app.tivi.settings.developer

import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import app.tivi.screens.DevLogScreen
import app.tivi.screens.DevSettingsScreen
import app.tivi.settings.TiviPreferences
import app.tivi.settings.toggle
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -39,7 +40,8 @@ class DevSettingsPresenter(

@Composable
override fun present(): DevSettingsUiState {
val hideArtwork by preferences.observeDeveloperHideArtwork().collectAsState(false)
val hideArtwork by remember { preferences.observeDeveloperHideArtwork() }
.collectAsRetainedState(false)

fun eventSink(event: DevSettingsUiEvent) {
when (event) {
Expand Down
1 change: 1 addition & 0 deletions ui/discover/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {
api(projects.common.ui.screens)
api(projects.common.ui.circuitOverlay)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import app.tivi.screens.ShowSeasonsScreen
import app.tivi.screens.TrendingShowsScreen
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -76,18 +77,18 @@ class DiscoverPresenter(
val scope = rememberCoroutineScope()
val uiMessageManager = remember { UiMessageManager() }

val trendingItems by observeTrendingShows.flow.collectAsRetainedState(emptyList())
val trendingLoading by updateTrendingShows.inProgress.collectAsState(false)
val trendingItems by observeTrendingShows.flow.collectAsState(emptyList())

val popularItems by observePopularShows.flow.collectAsState(emptyList())
val popularItems by observePopularShows.flow.collectAsRetainedState(emptyList())
val popularLoading by updatePopularShows.inProgress.collectAsState(false)

val recommendedItems by observeRecommendedShows.flow.collectAsState(emptyList())
val recommendedItems by observeRecommendedShows.flow.collectAsRetainedState(emptyList())
val recommendedLoading by updateRecommendedShows.inProgress.collectAsState(false)

val nextShow by observeNextShowEpisodeToWatch.flow.collectAsState(null)
val authState by observeTraktAuthState.flow.collectAsState(TraktAuthState.LOGGED_OUT)
val user by observeUserDetails.flow.collectAsState(null)
val nextShow by observeNextShowEpisodeToWatch.flow.collectAsRetainedState(null)
val authState by observeTraktAuthState.flow.collectAsRetainedState(TraktAuthState.LOGGED_OUT)
val user by observeUserDetails.flow.collectAsRetainedState(null)

val message by uiMessageManager.message.collectAsState(null)

Expand Down
1 change: 1 addition & 0 deletions ui/episode/details/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {
api(projects.common.ui.screens)
api(projects.common.ui.circuitOverlay)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.tivi.screens.EpisodeDetailsScreen
import app.tivi.screens.EpisodeTrackScreen
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -61,8 +62,8 @@ class EpisodeDetailsPresenter(
val refreshing by updateEpisodeDetails.inProgress.collectAsState(false)
val message by uiMessageManager.message.collectAsState(null)

val episodeDetails by observeEpisodeDetails.flow.collectAsState(null)
val episodeWatches by observeEpisodeWatches.flow.collectAsState(emptyList())
val episodeDetails by observeEpisodeDetails.flow.collectAsRetainedState(null)
val episodeWatches by observeEpisodeWatches.flow.collectAsRetainedState(emptyList())

fun eventSink(event: EpisodeDetailsUiEvent) {
when (event) {
Expand Down
1 change: 1 addition & 0 deletions ui/episode/track/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.tivi.domain.observers.ObserveEpisodeDetails
import app.tivi.screens.EpisodeTrackScreen
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -65,7 +66,7 @@ class EpisodeTrackPresenter(
var selectedDate by remember { mutableStateOf(now.date) }
var selectedTime by remember { mutableStateOf(now.time) }

val episodeDetails by observeEpisodeDetails.flow.collectAsState(initial = null)
val episodeDetails by observeEpisodeDetails.flow.collectAsRetainedState(initial = null)

val refreshing by updateEpisodeDetails.inProgress.collectAsState(initial = false)
val submitting by addEpisodeWatch.inProgress.collectAsState(initial = false)
Expand Down
1 change: 1 addition & 0 deletions ui/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {
api(projects.common.ui.screens)
api(projects.common.ui.circuitOverlay)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(libs.paging.compose)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import app.cash.paging.PagingConfig
Expand All @@ -31,6 +30,7 @@ import app.tivi.screens.ShowDetailsScreen
import app.tivi.settings.TiviPreferences
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -81,15 +81,13 @@ class LibraryPresenter(
val loading by updateLibraryShows.inProgress.collectAsState(false)
val message by uiMessageManager.message.collectAsState(null)

val user by observeUserDetails.flow.collectAsState(null)
val authState by observeTraktAuthState.flow.collectAsState(TraktAuthState.LOGGED_OUT)
val user by observeUserDetails.flow.collectAsRetainedState(null)
val authState by observeTraktAuthState.flow.collectAsRetainedState(TraktAuthState.LOGGED_OUT)

val includeWatchedShows by produceState(false, preferences) {
preferences.observeLibraryWatchedActive().collect { value = it }
}
val includeFollowedShows by produceState(false, preferences) {
preferences.observeLibraryFollowedActive().collect { value = it }
}
val includeWatchedShows by remember { preferences.observeLibraryWatchedActive() }
.collectAsRetainedState(false)
val includeFollowedShows by remember { preferences.observeLibraryFollowedActive() }
.collectAsRetainedState(false)

fun eventSink(event: LibraryUiEvent) {
when (event) {
Expand Down
2 changes: 2 additions & 0 deletions ui/licenses/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ kotlin {
implementation(projects.common.ui.compose)
implementation(projects.data.licenses) // This should really be used through an interactor
api(projects.common.ui.screens)

api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.material3)
implementation(compose.animation)
Expand Down
1 change: 1 addition & 0 deletions ui/popular/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(libs.paging.compose)

Expand Down
1 change: 1 addition & 0 deletions ui/recommended/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(libs.paging.compose)

Expand Down
1 change: 1 addition & 0 deletions ui/root/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kotlin {

implementation(projects.common.ui.screens)
implementation(libs.circuit.foundation)
implementation(libs.circuit.retained)
implementation(libs.circuit.gestureNavigation)
implementation(libs.circuit.overlay)
implementation(projects.common.ui.circuitOverlay)
Expand Down
3 changes: 3 additions & 0 deletions ui/root/src/commonMain/kotlin/app/tivi/home/TiviContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.seiko.imageloader.LocalImageLoader
import com.slack.circuit.backstack.SaveableBackStack
import com.slack.circuit.foundation.Circuit
import com.slack.circuit.foundation.CircuitCompositionLocals
import com.slack.circuit.retained.LocalRetainedStateRegistry
import com.slack.circuit.retained.continuityRetainedStateRegistry
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.screen.Screen
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -85,6 +87,7 @@ fun TiviContent(
LocalTiviDateFormatter provides tiviDateFormatter,
LocalTiviTextCreator provides tiviTextCreator,
LocalWindowSizeClass provides calculateWindowSizeClass(),
LocalRetainedStateRegistry provides continuityRetainedStateRegistry(),
) {
CircuitCompositionLocals(circuit) {
TiviTheme(
Expand Down
1 change: 1 addition & 0 deletions ui/search/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
1 change: 1 addition & 0 deletions ui/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.materialIconsExtended)
implementation(compose.material3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package app.tivi.settings

import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import app.tivi.app.ApplicationInfo
Expand All @@ -13,6 +12,7 @@ import app.tivi.screens.DevSettingsScreen
import app.tivi.screens.LicensesScreen
import app.tivi.screens.SettingsScreen
import app.tivi.screens.UrlScreen
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -44,16 +44,16 @@ class SettingsPresenter(
@Composable
override fun present(): SettingsUiState {
val theme by remember { preferences.observeTheme() }
.collectAsState(TiviPreferences.Theme.SYSTEM)
.collectAsRetainedState(TiviPreferences.Theme.SYSTEM)

val useDynamicColors by remember { preferences.observeUseDynamicColors() }
.collectAsState(false)
.collectAsRetainedState(false)

val useLessData by remember { preferences.observeUseLessData() }
.collectAsState(false)
.collectAsRetainedState(false)

val ignoreSpecials by remember { preferences.observeIgnoreSpecials() }
.collectAsState(true)
.collectAsRetainedState(true)

fun eventSink(event: SettingsUiEvent) {
when (event) {
Expand Down
1 change: 1 addition & 0 deletions ui/show/details/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import app.tivi.screens.ShowDetailsScreen
import app.tivi.screens.ShowSeasonsScreen
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -82,8 +83,8 @@ class ShowDetailsPresenter(

val uiMessageManager = remember { UiMessageManager() }

val isFollowed by observeShowFollowStatus.flow.collectAsState(false)
val show by observeShowDetails.flow.collectAsState(TiviShow.EMPTY_SHOW)
val isFollowed by observeShowFollowStatus.flow.collectAsRetainedState(false)
val show by observeShowDetails.flow.collectAsRetainedState(TiviShow.EMPTY_SHOW)
val refreshing by produceState(false) {
combine(
updateShowDetails.inProgress,
Expand All @@ -92,10 +93,10 @@ class ShowDetailsPresenter(
transform = { values -> values.any { it } },
).collect { value = it }
}
val relatedShows by observeRelatedShows.flow.collectAsState(emptyList())
val nextEpisode by observeNextEpisodeToWatch.flow.collectAsState(null)
val seasons by observeShowSeasons.flow.collectAsState(emptyList())
val stats by observeShowViewStats.flow.collectAsState(null)
val relatedShows by observeRelatedShows.flow.collectAsRetainedState(emptyList())
val nextEpisode by observeNextEpisodeToWatch.flow.collectAsRetainedState(null)
val seasons by observeShowSeasons.flow.collectAsRetainedState(emptyList())
val stats by observeShowViewStats.flow.collectAsRetainedState(null)
val message by uiMessageManager.message.collectAsState(null)

fun eventSink(event: ShowDetailsUiEvent) {
Expand Down
1 change: 1 addition & 0 deletions ui/show/seasons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

api(projects.common.ui.screens)
api(libs.circuit.foundation)
implementation(libs.circuit.retained)

implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import app.tivi.screens.EpisodeDetailsScreen
import app.tivi.screens.ShowSeasonsScreen
import app.tivi.util.Logger
import app.tivi.util.onException
import com.slack.circuit.retained.collectAsRetainedState
import com.slack.circuit.runtime.CircuitContext
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
Expand Down Expand Up @@ -56,8 +57,9 @@ class ShowSeasonsPresenter(

val uiMessageManager = remember { UiMessageManager() }

val seasons by observeShowSeasons.flow.collectAsState(emptyList())
val show by observeShowDetails.flow.collectAsState(TiviShow.EMPTY_SHOW)
val seasons by observeShowSeasons.flow.collectAsRetainedState(emptyList())
val show by observeShowDetails.flow.collectAsRetainedState(TiviShow.EMPTY_SHOW)

val refreshing by updateShowSeasons.inProgress.collectAsState(false)
val message by uiMessageManager.message.collectAsState(null)

Expand Down
Loading