Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Simplify ObserveNextShowEpisodeToWatch #1561

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class SqlDelightWatchedShowsDao(
).executeAsList()
}

override fun observeUpNextShow(): Flow<UpNextEntry?> {
return provideUpNextShowsQuery(
followedOnly = false,
sort = SortOption.LAST_WATCHED,
limit = 1,
offset = 0,
).asFlow().mapToOneOrNull(dispatchers.io)
}

override fun entryShowViewStats(showId: Long): Flow<ShowsWatchStats?> {
return db.shows_view_watch_statsQueries.watchStatsForShowId(showId, ::ShowsWatchStats)
.asFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface WatchedShowDao : EntryDao<WatchedShowEntry, WatchedShowEntryWithShow>

fun getUpNextShows(): List<UpNextEntry>

fun observeUpNextShow(): Flow<UpNextEntry?>

fun entryShowViewStats(showId: Long): Flow<ShowsWatchStats?>

fun observeNextShowToWatch(): Flow<TiviShow?>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@

package app.tivi.domain.observers

import app.tivi.data.compoundmodels.EpisodeWithSeasonWithShow
import app.tivi.data.compoundmodels.UpNextEntry
import app.tivi.data.daos.WatchedShowDao
import app.tivi.data.episodes.SeasonsEpisodesRepository
import app.tivi.domain.SubjectInteractor
import app.tivi.extensions.flatMapLatestNullable
import app.tivi.extensions.mapNullable
import kotlinx.coroutines.flow.Flow
import me.tatarka.inject.annotations.Inject

@Inject
class ObserveNextShowEpisodeToWatch(
private val watchedShowDao: WatchedShowDao,
private val seasonsEpisodesRepository: SeasonsEpisodesRepository,
) : SubjectInteractor<Unit, EpisodeWithSeasonWithShow?>() {

override fun createObservable(params: Unit): Flow<EpisodeWithSeasonWithShow?> {
return watchedShowDao.observeNextShowToWatch().flatMapLatestNullable { nextShow ->
seasonsEpisodesRepository.observeNextEpisodeToWatch(nextShow.id).mapNullable {
EpisodeWithSeasonWithShow(it.episode, it.season, nextShow)
}
}
) : SubjectInteractor<Unit, UpNextEntry?>() {
override fun createObservable(params: Unit): Flow<UpNextEntry?> {
return watchedShowDao.observeUpNextShow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package app.tivi.home.discover

import androidx.compose.runtime.Immutable
import app.tivi.common.compose.UiMessage
import app.tivi.data.compoundmodels.EpisodeWithSeasonWithShow
import app.tivi.data.compoundmodels.PopularEntryWithShow
import app.tivi.data.compoundmodels.RecommendedEntryWithShow
import app.tivi.data.compoundmodels.TrendingEntryWithShow
import app.tivi.data.compoundmodels.UpNextEntry
import app.tivi.data.models.TraktUser
import app.tivi.data.traktauth.TraktAuthState
import com.slack.circuit.runtime.CircuitUiEvent
Expand All @@ -24,7 +24,7 @@ data class DiscoverUiState(
val popularRefreshing: Boolean = false,
val recommendedItems: List<RecommendedEntryWithShow> = emptyList(),
val recommendedRefreshing: Boolean = false,
val nextEpisodeWithShowToWatch: EpisodeWithSeasonWithShow? = null,
val nextEpisodeWithShowToWatch: UpNextEntry? = null,
val message: UiMessage? = null,
val eventSink: (DiscoverUiEvent) -> Unit,
) : CircuitUiState {
Expand Down