diff --git a/Jetcaster/core/model/src/main/java/com/example/jetcaster/core/model/CategoryInfo.kt b/Jetcaster/core/model/src/main/java/com/example/jetcaster/core/model/CategoryInfo.kt index 9ebf1a9577..cb75a308af 100644 --- a/Jetcaster/core/model/src/main/java/com/example/jetcaster/core/model/CategoryInfo.kt +++ b/Jetcaster/core/model/src/main/java/com/example/jetcaster/core/model/CategoryInfo.kt @@ -20,3 +20,5 @@ data class CategoryInfo( val id: Long, val name: String ) + +const val CategoryTechnology = "Technology" diff --git a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/database/dao/CategoriesDao.kt b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/database/dao/CategoriesDao.kt index f9b36601cb..baf958f139 100644 --- a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/database/dao/CategoriesDao.kt +++ b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/database/dao/CategoriesDao.kt @@ -43,4 +43,7 @@ abstract class CategoriesDao : BaseDao { @Query("SELECT * FROM categories WHERE name = :name") abstract suspend fun getCategoryWithName(name: String): Category? + + @Query("SELECT * FROM categories WHERE name = :name") + abstract fun observeCategory(name: String): Flow } diff --git a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/network/Feeds.kt b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/network/Feeds.kt index ead4bbb3e4..216cce6b9d 100644 --- a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/network/Feeds.kt +++ b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/network/Feeds.kt @@ -20,14 +20,18 @@ package com.example.jetcaster.core.data.network * A hand selected list of feeds URLs used for the purposes of displaying real information * in this sample app. */ +private const val NowInAndroid = "https://feeds.libsyn.com/244409/rss" +private const val AndroidDevelopersBackstage = + "https://feeds.feedburner.com/blogspot/AndroidDevelopersBackstage" + val SampleFeeds = listOf( + NowInAndroid, + AndroidDevelopersBackstage, "https://www.omnycontent.com/d/playlist/aaea4e69-af51-495e-afc9-a9760146922b/" + "dc5b55ca-5f00-4063-b47f-ab870163d2b7/ca63aa52-ef7b-43ee-8ba5-ab8701645231/podcast.rss", "https://audioboom.com/channels/2399216.rss", - "http://nowinandroid.googledevelopers.libsynpro.com/rss", "https://fragmentedpodcast.com/feed/", "https://feeds.megaphone.fm/replyall", - "http://feeds.feedburner.com/blogspot/AndroidDevelopersBackstage", "https://feeds.thisamericanlife.org/talpodcast", "https://feeds.npr.org/510289/podcast.xml", "https://feeds.99percentinvisible.org/99percentinvisible", diff --git a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/repository/CategoryStore.kt b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/repository/CategoryStore.kt index a69d082652..0c29188054 100644 --- a/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/repository/CategoryStore.kt +++ b/Jetcaster/core/src/main/java/com/example/jetcaster/core/data/repository/CategoryStore.kt @@ -25,7 +25,6 @@ import com.example.jetcaster.core.data.database.model.EpisodeToPodcast import com.example.jetcaster.core.data.database.model.PodcastCategoryEntry import com.example.jetcaster.core.data.database.model.PodcastWithExtraInfo import kotlinx.coroutines.flow.Flow - interface CategoryStore { /** * Returns a flow containing a list of categories which is sorted by the number @@ -61,6 +60,11 @@ interface CategoryStore { suspend fun addCategory(category: Category): Long suspend fun addPodcastToCategory(podcastUri: String, categoryId: Long) + + /** + * @return gets the category with [name], if it exists, otherwise, null + */ + fun getCategory(name: String): Flow } /** @@ -119,4 +123,7 @@ class LocalCategoryStore constructor( PodcastCategoryEntry(podcastUri = podcastUri, categoryId = categoryId) ) } + + override fun getCategory(name: String): Flow = + categoriesDao.observeCategory(name) } diff --git a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt index 9b867f0f9e..5aa0f4ef08 100644 --- a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt +++ b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt @@ -21,6 +21,7 @@ import com.example.jetcaster.core.data.database.model.EpisodeToPodcast import com.example.jetcaster.core.data.database.model.PodcastWithExtraInfo import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update @@ -56,6 +57,8 @@ class TestCategoryStore : CategoryStore { override suspend fun addPodcastToCategory(podcastUri: String, categoryId: Long) {} + override fun getCategory(name: String): Flow = flowOf() + /** * Test-only API for setting the list of categories backed by this [TestCategoryStore]. */ diff --git a/Jetcaster/wear/src/main/java/com/example/jetcaster/ui/home/HomeViewModel.kt b/Jetcaster/wear/src/main/java/com/example/jetcaster/ui/home/HomeViewModel.kt index 5169258265..f50fd9f31e 100644 --- a/Jetcaster/wear/src/main/java/com/example/jetcaster/ui/home/HomeViewModel.kt +++ b/Jetcaster/wear/src/main/java/com/example/jetcaster/ui/home/HomeViewModel.kt @@ -21,12 +21,14 @@ import androidx.lifecycle.viewModelScope import com.example.jetcaster.core.data.database.model.EpisodeToPodcast import com.example.jetcaster.core.data.database.model.Podcast import com.example.jetcaster.core.data.database.model.PodcastWithExtraInfo +import com.example.jetcaster.core.data.database.model.asExternalModel import com.example.jetcaster.core.data.domain.FilterableCategoriesUseCase import com.example.jetcaster.core.data.domain.PodcastCategoryFilterUseCase +import com.example.jetcaster.core.data.repository.CategoryStore import com.example.jetcaster.core.data.repository.EpisodeStore import com.example.jetcaster.core.data.repository.PodcastStore import com.example.jetcaster.core.data.repository.PodcastsRepository -import com.example.jetcaster.core.model.CategoryInfo +import com.example.jetcaster.core.model.CategoryTechnology import com.example.jetcaster.core.model.FilterableCategoriesModel import com.example.jetcaster.core.model.PlayerEpisode import com.example.jetcaster.core.model.PodcastCategoryFilterResult @@ -38,7 +40,6 @@ import kotlinx.collections.immutable.toPersistentList import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn @@ -50,6 +51,7 @@ class HomeViewModel @Inject constructor( private val podcastsRepository: PodcastsRepository, private val podcastStore: PodcastStore, private val episodeStore: EpisodeStore, + private val categoryStore: CategoryStore, private val podcastCategoryFilterUseCase: PodcastCategoryFilterUseCase, private val filterableCategoriesUseCase: FilterableCategoriesUseCase, private val episodePlayer: EpisodePlayer, @@ -59,7 +61,7 @@ class HomeViewModel @Inject constructor( // Holds our currently selected home category private val selectedHomeCategory = MutableStateFlow(HomeCategory.Library) // Holds our currently selected category - private val _selectedCategory = MutableStateFlow(null) + private val defaultCategory = categoryStore.getCategory(CategoryTechnology) // Holds the view state if the UI is refreshing for new data private val refreshing = MutableStateFlow(false) @@ -70,11 +72,11 @@ class HomeViewModel @Inject constructor( selectedHomeCategory, podcastStore.followedPodcastsSortedByLastEpisode(limit = 10), refreshing, - _selectedCategory.flatMapLatest { selectedCategory -> - filterableCategoriesUseCase(selectedCategory) + defaultCategory.flatMapLatest { + filterableCategoriesUseCase(it?.asExternalModel()) }, - _selectedCategory.flatMapLatest { - podcastCategoryFilterUseCase(it) + defaultCategory.flatMapLatest { + podcastCategoryFilterUseCase(it?.asExternalModel()) }, selectedLibraryPodcast.flatMapLatest { episodeStore.episodesInPodcast( @@ -93,9 +95,6 @@ class HomeViewModel @Inject constructor( podcastCategoryFilterResult, libraryEpisodes, queue -> - - _selectedCategory.value = filterableCategories.selectedCategory - selectedHomeCategory.value = homeCategory HomeViewState(