Fix spotless

Change-Id: I7dcd7fa9544c873edeb8270f8d89b3bcb7211428
dt/nav-safe-args-android-dependency
Don Turner 8 months ago
parent 2d45b84031
commit 924391cd22

@ -97,7 +97,7 @@ class NiaAppState(
.currentBackStackEntryAsState().value?.destination .currentBackStackEntryAsState().value?.destination
val currentTopLevelDestination: TopLevelDestination? val currentTopLevelDestination: TopLevelDestination?
@Composable get(){ @Composable get() {
with(currentDestination) { with(currentDestination) {
if (this?.hasRoute<ForYouDestination>() == true) return FOR_YOU if (this?.hasRoute<ForYouDestination>() == true) return FOR_YOU
if (this?.hasRoute<BookmarksDestination>() == true) return BOOKMARKS if (this?.hasRoute<BookmarksDestination>() == true) return BOOKMARKS

@ -41,17 +41,18 @@ import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable object TopicPlaceholderDestination @Serializable object TopicPlaceholderDestination
@Serializable object DetailPaneNavHostDestination @Serializable object DetailPaneNavHostDestination
fun NavGraphBuilder.interestsListDetailScreen() { fun NavGraphBuilder.interestsListDetailScreen() {
composable<InterestsDestination>{ composable<InterestsDestination> {
InterestsListDetailScreen() InterestsListDetailScreen()
} }
} }
@Composable @Composable
internal fun InterestsListDetailScreen() { internal fun InterestsListDetailScreen() {
var selectedTopicId : String? by rememberSaveable { mutableStateOf(null) } var selectedTopicId: String? by rememberSaveable { mutableStateOf(null) }
InterestsListDetailScreen( InterestsListDetailScreen(
selectedTopicId = selectedTopicId, selectedTopicId = selectedTopicId,
onTopicClick = { topicId -> selectedTopicId = topicId }, onTopicClick = { topicId -> selectedTopicId = topicId },
@ -92,8 +93,8 @@ internal fun InterestsListDetailScreen(
NavHost( NavHost(
navController = nestedNavController, navController = nestedNavController,
startDestination = TopicPlaceholderDestination::class, startDestination = TopicPlaceholderDestination::class,
route = DetailPaneNavHostDestination::class route = DetailPaneNavHostDestination::class,
){ ) {
topicScreen( topicScreen(
showBackButton = !listDetailNavigator.isListPaneVisible(), showBackButton = !listDetailNavigator.isListPaneVisible(),
onBackClick = listDetailNavigator::navigateBack, onBackClick = listDetailNavigator::navigateBack,

@ -36,4 +36,3 @@ fun NavGraphBuilder.bookmarksScreen(
BookmarksRoute(onTopicClick, onShowSnackbar) BookmarksRoute(onTopicClick, onShowSnackbar)
} }
} }

@ -27,6 +27,7 @@ import kotlinx.serialization.Serializable
const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId" const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId"
private const val DEEP_LINK_URI_PATTERN = private const val DEEP_LINK_URI_PATTERN =
"https://www.nowinandroid.apps.samples.google.com/foryou/{$LINKED_NEWS_RESOURCE_ID}" "https://www.nowinandroid.apps.samples.google.com/foryou/{$LINKED_NEWS_RESOURCE_ID}"
@Serializable data class ForYouDestination(val linkedNewsResourceId: String? = null) @Serializable data class ForYouDestination(val linkedNewsResourceId: String? = null)
fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(), navOptions) fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(), navOptions)
@ -35,7 +36,7 @@ fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) {
composable<ForYouDestination>( composable<ForYouDestination>(
deepLinks = listOf( deepLinks = listOf(
navDeepLink { uriPattern = DEEP_LINK_URI_PATTERN }, navDeepLink { uriPattern = DEEP_LINK_URI_PATTERN },
) ),
) { ) {
ForYouRoute(onTopicClick) ForYouRoute(onTopicClick)
} }

@ -25,7 +25,6 @@ import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCa
import com.google.samples.apps.nowinandroid.core.domain.TopicSortField import com.google.samples.apps.nowinandroid.core.domain.TopicSortField
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsDestination import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsDestination
import com.google.samples.apps.nowinandroid.feature.interests.navigation.TOPIC_ID_ARG
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -41,7 +40,7 @@ class InterestsViewModel @Inject constructor(
getFollowableTopics: GetFollowableTopicsUseCase, getFollowableTopics: GetFollowableTopicsUseCase,
) : ViewModel() { ) : ViewModel() {
private val interestsDestination : InterestsDestination = savedStateHandle.toRoute() private val interestsDestination: InterestsDestination = savedStateHandle.toRoute()
val uiState: StateFlow<InterestsUiState> = val uiState: StateFlow<InterestsUiState> =
getFollowableTopics(sortBy = TopicSortField.NAME).map { topics -> getFollowableTopics(sortBy = TopicSortField.NAME).map { topics ->

@ -20,11 +20,10 @@ import androidx.navigation.NavController
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
const val TOPIC_ID_ARG = "topicId" const val TOPIC_ID_ARG = "topicId"
@Serializable data class InterestsDestination(val topicId: String?) @Serializable data class InterestsDestination(val topicId: String?)
fun NavController.navigateToInterests(topicId: String? = null, navOptions: NavOptions? = null) { fun NavController.navigateToInterests(topicId: String? = null, navOptions: NavOptions? = null) {
navigate(route = InterestsDestination(topicId), navOptions) navigate(route = InterestsDestination(topicId), navOptions)
} }

@ -25,7 +25,6 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserData
import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule
import com.google.samples.apps.nowinandroid.feature.interests.InterestsUiState import com.google.samples.apps.nowinandroid.feature.interests.InterestsUiState
import com.google.samples.apps.nowinandroid.feature.interests.InterestsViewModel import com.google.samples.apps.nowinandroid.feature.interests.InterestsViewModel
import com.google.samples.apps.nowinandroid.feature.interests.navigation.TOPIC_ID_ARG
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.UnconfinedTestDispatcher
@ -55,7 +54,7 @@ class InterestsViewModelTest {
@Before @Before
fun setup() { fun setup() {
viewModel = InterestsViewModel( viewModel = InterestsViewModel(
//TODO: Figure out how to supply the correct dependency: InterestsDestination(topicId = testInputTopics[0].topic.id) // TODO: Figure out how to supply the correct dependency: InterestsDestination(topicId = testInputTopics[0].topic.id)
savedStateHandle = SavedStateHandle(mapOf("topicId" to testInputTopics[0].topic.id)), savedStateHandle = SavedStateHandle(mapOf("topicId" to testInputTopics[0].topic.id)),
userDataRepository = userDataRepository, userDataRepository = userDataRepository,
getFollowableTopics = getFollowableTopicsUseCase, getFollowableTopics = getFollowableTopicsUseCase,

@ -48,7 +48,7 @@ class TopicViewModel @Inject constructor(
userNewsResourceRepository: UserNewsResourceRepository, userNewsResourceRepository: UserNewsResourceRepository,
) : ViewModel() { ) : ViewModel() {
private val topicDestination : TopicDestination = savedStateHandle.toRoute() private val topicDestination: TopicDestination = savedStateHandle.toRoute()
val topicId = topicDestination.id val topicId = topicDestination.id

@ -59,7 +59,7 @@ class TopicViewModelTest {
@Before @Before
fun setup() { fun setup() {
viewModel = TopicViewModel( viewModel = TopicViewModel(
//TODO: Figure out how to supply the correct dependency TopicDestination(id = testInputTopics[0].topic.id) // TODO: Figure out how to supply the correct dependency TopicDestination(id = testInputTopics[0].topic.id)
savedStateHandle = SavedStateHandle(mapOf("id" to testInputTopics[0].topic.id)), savedStateHandle = SavedStateHandle(mapOf("id" to testInputTopics[0].topic.id)),
userDataRepository = userDataRepository, userDataRepository = userDataRepository,
topicsRepository = topicsRepository, topicsRepository = topicsRepository,

Loading…
Cancel
Save