Skip to content

Commit af65265

Browse files
committed
Fix empty screen.
1 parent ec7cca7 commit af65265

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Jetcaster/app/src/main/java/com/example/jetcaster/ui/home/HomeViewModel.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.jetcaster.ui.home
1818

19+
import android.util.Log
1920
import androidx.lifecycle.ViewModel
2021
import androidx.lifecycle.viewModelScope
2122
import com.example.jetcaster.Graph
@@ -60,14 +61,19 @@ class HomeViewModel(
6061
private val refreshing = MutableStateFlow(false)
6162

6263
@OptIn(ExperimentalCoroutinesApi::class)
63-
private val libraryEpisodes = podcastStore.followedPodcastsSortedByLastEpisode()
64+
private val libraryEpisodes =
65+
podcastStore.followedPodcastsSortedByLastEpisode()
6466
.flatMapLatest { followedPodcasts ->
65-
combine(
66-
followedPodcasts.map { p ->
67-
episodeStore.episodesInPodcast(p.podcast.uri, 5)
67+
if (followedPodcasts.isEmpty()) {
68+
flowOf(emptyList())
69+
} else {
70+
combine(
71+
followedPodcasts.map { p ->
72+
episodeStore.episodesInPodcast(p.podcast.uri, 5)
73+
}
74+
) { allEpisodes ->
75+
allEpisodes.toList().flatten().sortedByDescending { it.episode.published }
6876
}
69-
) { allEpisodes ->
70-
allEpisodes.toList().flatten().sortedByDescending { it.episode.published }
7177
}
7278
}
7379

0 commit comments

Comments
 (0)