Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ data class CategoryInfo(
val id: Long,
val name: String
)

const val CategoryTechnology = "Technology"
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ abstract class CategoriesDao : BaseDao<Category> {

@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<Category?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
const val NowInAndroid = "https://feeds.libsyn.com/244409/rss"
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Category?>
}

/**
Expand Down Expand Up @@ -119,4 +123,7 @@ class LocalCategoryStore constructor(
PodcastCategoryEntry(podcastUri = podcastUri, categoryId = categoryId)
)
}

override fun getCategory(name: String): Flow<Category?> =
categoriesDao.observeCategory(name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -56,6 +57,8 @@ class TestCategoryStore : CategoryStore {

override suspend fun addPodcastToCategory(podcastUri: String, categoryId: Long) {}

override fun getCategory(name: String): Flow<Category?> = flowOf()

/**
* Test-only API for setting the list of categories backed by this [TestCategoryStore].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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<CategoryInfo?>(null)
private val defaultCategory = categoryStore.getCategory(CategoryTechnology)

// Holds the view state if the UI is refreshing for new data
private val refreshing = MutableStateFlow(false)
Expand All @@ -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(
Expand All @@ -93,9 +95,6 @@ class HomeViewModel @Inject constructor(
podcastCategoryFilterResult,
libraryEpisodes,
queue ->

_selectedCategory.value = filterableCategories.selectedCategory

selectedHomeCategory.value = homeCategory

HomeViewState(
Expand Down