Experiment: Stabilize FollowableTopic + lambda

Change-Id: Ib13bcf58f34da618db4145c8357b97577003e59e
tm/experiment-select-topic
Tomáš Mlynarič 1 year ago
parent 2ab010c211
commit 3e6f946f10

@ -15,9 +15,16 @@
*/ */
plugins { plugins {
id("nowinandroid.jvm.library") id("nowinandroid.android.library")
}
android {
namespace = "com.google.samples.apps.nowinandroid.model"
} }
dependencies { dependencies {
implementation(libs.kotlinx.datetime) implementation(libs.kotlinx.datetime)
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
implementation(libs.androidx.compose.runtime)
} }

@ -16,9 +16,12 @@
package com.google.samples.apps.nowinandroid.core.model.data package com.google.samples.apps.nowinandroid.core.model.data
import androidx.compose.runtime.Stable
/** /**
* A [topic] with the additional information for whether or not it is followed. * A [topic] with the additional information for whether or not it is followed.
*/ */
@Stable
data class FollowableTopic( // TODO consider changing to UserTopic and flattening data class FollowableTopic( // TODO consider changing to UserTopic and flattening
val topic: Topic, val topic: Topic,
val isFollowed: Boolean, val isFollowed: Boolean,

@ -62,6 +62,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
@ -109,12 +110,15 @@ internal fun ForYouRoute(
val isSyncing by viewModel.isSyncing.collectAsStateWithLifecycle() val isSyncing by viewModel.isSyncing.collectAsStateWithLifecycle()
val deepLinkedUserNewsResource by viewModel.deepLinkedNewsResource.collectAsStateWithLifecycle() val deepLinkedUserNewsResource by viewModel.deepLinkedNewsResource.collectAsStateWithLifecycle()
val onTopicCheckedChangedRem: (String, Boolean) -> Unit =
remember { viewModel::updateTopicSelection }
ForYouScreen( ForYouScreen(
isSyncing = isSyncing, isSyncing = isSyncing,
onboardingUiState = onboardingUiState, onboardingUiState = onboardingUiState,
feedState = feedState, feedState = feedState,
deepLinkedUserNewsResource = deepLinkedUserNewsResource, deepLinkedUserNewsResource = deepLinkedUserNewsResource,
onTopicCheckedChanged = viewModel::updateTopicSelection, onTopicCheckedChanged = onTopicCheckedChangedRem,
onDeepLinkOpened = viewModel::onDeepLinkOpened, onDeepLinkOpened = viewModel::onDeepLinkOpened,
onTopicClick = onTopicClick, onTopicClick = onTopicClick,
saveFollowedTopics = viewModel::dismissOnboarding, saveFollowedTopics = viewModel::dismissOnboarding,
@ -259,9 +263,9 @@ private fun LazyGridScope.onboarding(
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
) )
TopicSelection( TopicSelection(
onboardingUiState, onboardingUiState = onboardingUiState,
onTopicCheckedChanged, onTopicCheckedChanged = onTopicCheckedChanged,
Modifier.padding(bottom = 8.dp), modifier = Modifier.padding(bottom = 8.dp),
) )
// Done button // Done button
Row( Row(

@ -16,11 +16,13 @@
package com.google.samples.apps.nowinandroid.feature.foryou package com.google.samples.apps.nowinandroid.feature.foryou
import androidx.compose.runtime.Stable
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
/** /**
* A sealed hierarchy describing the onboarding state for the for you screen. * A sealed hierarchy describing the onboarding state for the for you screen.
*/ */
@Stable
sealed interface OnboardingUiState { sealed interface OnboardingUiState {
/** /**
* The onboarding state is loading. * The onboarding state is loading.
@ -40,6 +42,7 @@ sealed interface OnboardingUiState {
/** /**
* There is a onboarding state, with the given lists of topics. * There is a onboarding state, with the given lists of topics.
*/ */
@Stable
data class Shown( data class Shown(
val topics: List<FollowableTopic>, val topics: List<FollowableTopic>,
) : OnboardingUiState { ) : OnboardingUiState {

Loading…
Cancel
Save