Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 12 additions & 5 deletions Jetcaster/app/src/main/java/com/example/jetcaster/ui/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalSavedStateRegistryOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
Expand All @@ -99,6 +101,7 @@ import com.example.jetcaster.core.data.model.LibraryInfo
import com.example.jetcaster.core.data.model.PlayerEpisode
import com.example.jetcaster.core.data.model.PodcastCategoryFilterResult
import com.example.jetcaster.core.data.model.PodcastInfo
import com.example.jetcaster.ui.Screen
import com.example.jetcaster.ui.home.discover.discoverItems
import com.example.jetcaster.ui.home.library.libraryItems
import com.example.jetcaster.ui.podcast.PodcastDetailsScreen
Expand All @@ -123,9 +126,7 @@ fun MainScreen(
viewModel: HomeViewModel = viewModel()
) {
val viewState by viewModel.state.collectAsStateWithLifecycle()
val navigator = rememberSupportingPaneScaffoldNavigator<String>(
isDestinationHistoryAware = false
)
val navigator = rememberSupportingPaneScaffoldNavigator<String>()
BackHandler(enabled = navigator.canNavigateBack()) {
navigator.navigateBack()
}
Expand All @@ -137,8 +138,14 @@ fun MainScreen(
val podcastUri = navigator.currentDestination?.content
?: viewState.featuredPodcasts.firstOrNull()?.uri
if (!podcastUri.isNullOrEmpty()) {
val podcastDetailsViewModel = PodcastDetailsViewModel(
podcastUri = podcastUri
val podcastDetailsViewModel: PodcastDetailsViewModel = viewModel(
key = podcastUri,
factory = PodcastDetailsViewModel.provideFactory(
owner = LocalSavedStateRegistryOwner.current,
defaultArgs = bundleOf(
Screen.ARG_PODCAST_URI to podcastUri
)
)
)
PodcastDetailsScreen(
viewModel = podcastDetailsViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.example.jetcaster.ui.podcast

import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.AbstractSavedStateViewModelFactory
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -53,20 +54,14 @@ class PodcastDetailsViewModel(
private val episodeStore: EpisodeStore = Graph.episodeStore,
private val episodePlayer: EpisodePlayer = Graph.episodePlayer,
private val podcastStore: PodcastStore = Graph.podcastStore,
private val podcastUri: String
savedStateHandle: SavedStateHandle
) : ViewModel() {

constructor(
episodeStore: EpisodeStore = Graph.episodeStore,
episodePlayer: EpisodePlayer = Graph.episodePlayer,
podcastStore: PodcastStore = Graph.podcastStore,
savedStateHandle: SavedStateHandle
) : this(
episodeStore = episodeStore,
episodePlayer = episodePlayer,
podcastStore = podcastStore,
podcastUri = Uri.decode(savedStateHandle.get<String>(Screen.ARG_PODCAST_URI)!!)
)
private val podcastUri = Uri.decode(savedStateHandle.get<String>(Screen.ARG_PODCAST_URI)!!)

init {
Log.d("JetcasterVM", "PodcatURI: $podcastUri")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podcat 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for the next Compose sample 😸

}

val state: StateFlow<PodcastUiState> =
combine(
Expand Down