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

Commit 1f04706

Browse files
authored
Use followed only filter on Up Next (#1951)
1 parent 1344218 commit 1f04706

9 files changed

Lines changed: 20 additions & 63 deletions

File tree

core/preferences/src/commonMain/kotlin/app/tivi/settings/TiviPreferences.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface TiviPreferences {
1111
val useLessData: Preference<Boolean>
1212

1313
val libraryFollowedActive: Preference<Boolean>
14-
val libraryWatchedActive: Preference<Boolean>
1514

1615
val upNextFollowedOnly: Preference<Boolean>
1716

core/preferences/src/commonMain/kotlin/app/tivi/settings/TiviPreferencesImpl.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class TiviPreferencesImpl(
4242
override val libraryFollowedActive: Preference<Boolean> by lazy {
4343
BooleanPreference(KEY_LIBRARY_FOLLOWED_ACTIVE)
4444
}
45-
override val libraryWatchedActive: Preference<Boolean> by lazy {
46-
BooleanPreference(KEY_LIBRARY_WATCHED_ACTIVE)
47-
}
4845
override val upNextFollowedOnly: Preference<Boolean> by lazy {
4946
BooleanPreference(KEY_UPNEXT_FOLLOWED_ONLY)
5047
}

data/db-sqldelight/src/commonMain/kotlin/app/tivi/data/daos/SqlDelightLibraryShowsDao.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,22 @@ class SqlDelightLibraryShowsDao(
2323
override fun pagedListLastWatched(
2424
sort: SortOption,
2525
filter: String?,
26-
includeWatched: Boolean,
27-
includeFollowed: Boolean,
26+
onlyFollowed: Boolean,
2827
): PagingSource<Int, LibraryShow> {
2928
val searchQuery = when {
3029
filter.isNullOrEmpty() -> null
3130
else -> "%$filter%"
3231
}
3332
return QueryPagingSource(
3433
countQuery = db.library_showsQueries.count(
35-
includeWatched = includeWatched.sqlValue,
36-
includeFollowed = includeFollowed.sqlValue,
34+
onlyFollowed = onlyFollowed.sqlValue,
3735
filter = searchQuery,
3836
),
3937
transacter = db.library_showsQueries,
4038
context = dispatchers.io,
4139
queryProvider = { limit: Long, offset: Long ->
4240
db.library_showsQueries.entries(
43-
includeWatched = includeWatched.sqlValue,
44-
includeFollowed = includeFollowed.sqlValue,
41+
onlyFollowed = onlyFollowed.sqlValue,
4542
filter = searchQuery,
4643
sort = sort.sqlValue,
4744
limit = limit,
@@ -85,10 +82,10 @@ class SqlDelightLibraryShowsDao(
8582
network_logo_path, runtime, genres, status, airs_day, airs_time, airs_tz,
8683
),
8784
stats = show_id_?.let {
88-
ShowsWatchStats(show_id_, episode_count!!, watched_episode_count!!)
85+
ShowsWatchStats(it, episode_count!!, watched_episode_count!!)
8986
},
9087
watchedEntry = id_?.let {
91-
WatchedShowEntry(id_, show_id!!, last_watched!!, last_updated!!)
88+
WatchedShowEntry(it, show_id!!, last_watched!!, last_updated!!)
9289
},
9390
)
9491
}

data/db-sqldelight/src/commonMain/sqldelight/app/tivi/data/library_shows.sq

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ LEFT JOIN episodes AS eps ON eps.season_id = s.id
88
LEFT JOIN episode_watch_entries AS ew ON ew.episode_id = eps.id
99
WHERE
1010
(s.number IS NULL OR s.number != 0)
11-
AND (
12-
(:includeWatched = 1 AND watched_entries.id IS NOT NULL) OR
13-
(:includeFollowed = 1 AND myshows_entries.id IS NOT NULL)
14-
)
11+
AND (:onlyFollowed = 0 OR myshows_entries.id IS NOT NULL)
1512
AND (:filter IS NULL OR shows.title LIKE :filter)
1613
GROUP BY shows.id
1714
ORDER BY CASE
@@ -28,8 +25,6 @@ count:
2825
SELECT COUNT(DISTINCT shows.id) FROM shows
2926
LEFT JOIN myshows_entries ON shows.id = myshows_entries.show_id
3027
LEFT JOIN watched_entries ON shows.id = watched_entries.show_id
31-
WHERE (
32-
(:includeWatched = 1 AND watched_entries.id IS NOT NULL) OR
33-
(:includeFollowed = 1 AND myshows_entries.id IS NOT NULL)
34-
)
35-
AND (:filter IS NULL OR shows.title LIKE :filter);
28+
WHERE
29+
(:onlyFollowed = 0 OR myshows_entries.id IS NOT NULL)
30+
AND (:filter IS NULL OR shows.title LIKE :filter);

data/db/src/commonMain/kotlin/app/tivi/data/daos/LibraryShowsDao.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface LibraryShowsDao {
1111
fun pagedListLastWatched(
1212
sort: SortOption,
1313
filter: String?,
14-
includeWatched: Boolean,
15-
includeFollowed: Boolean,
14+
onlyFollowed: Boolean,
1615
): PagingSource<Int, LibraryShow>
1716
}

domain/src/commonMain/kotlin/app/tivi/domain/observers/ObservePagedLibraryShows.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ class ObservePagedLibraryShows(
2424
libraryShowsDao.pagedListLastWatched(
2525
sort = params.sort,
2626
filter = if (params.filter.isNullOrEmpty()) null else params.filter,
27-
includeWatched = params.includeWatched,
28-
includeFollowed = params.includeFollowed,
27+
onlyFollowed = params.onlyFollowed,
2928
)
3029
}.flow
3130

3231
data class Parameters(
3332
val sort: SortOption,
3433
val filter: String? = null,
35-
val includeWatched: Boolean = true,
36-
val includeFollowed: Boolean = true,
34+
val onlyFollowed: Boolean = true,
3735
override val pagingConfig: PagingConfig,
3836
) : PagingInteractor.Parameters<LibraryShow>
3937
}

ui/library/src/commonMain/kotlin/app/tivi/home/library/Library.kt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ internal fun Library(
125125
openShowDetails = { eventSink(LibraryUiEvent.OpenShowDetails(it)) },
126126
onMessageShown = { eventSink(LibraryUiEvent.ClearMessage(it)) },
127127
onToggleIncludeFollowedShows = { eventSink(LibraryUiEvent.ToggleFollowedShowsIncluded) },
128-
onToggleIncludeWatchedShows = { eventSink(LibraryUiEvent.ToggleWatchedShowsIncluded) },
129128
openUser = {
130129
scope.launch {
131130
overlayHost.showInDialog(AccountScreen, navigator::goTo)
@@ -145,7 +144,6 @@ internal fun Library(
145144
openShowDetails: (showId: Long) -> Unit,
146145
onMessageShown: (id: Long) -> Unit,
147146
onToggleIncludeFollowedShows: () -> Unit,
148-
onToggleIncludeWatchedShows: () -> Unit,
149147
refresh: () -> Unit,
150148
openUser: () -> Unit,
151149
onFilterChanged: (String) -> Unit,
@@ -217,7 +215,6 @@ internal fun Library(
217215
paddingValues = paddingValues,
218216
onFilterChanged = onFilterChanged,
219217
onToggleIncludeFollowedShows = onToggleIncludeFollowedShows,
220-
onToggleIncludeWatchedShows = onToggleIncludeWatchedShows,
221218
onSortSelected = onSortSelected,
222219
openShowDetails = openShowDetails,
223220
modifier = Modifier
@@ -246,7 +243,6 @@ private fun LibraryGrid(
246243
paddingValues: PaddingValues,
247244
onFilterChanged: (String) -> Unit,
248245
onToggleIncludeFollowedShows: () -> Unit,
249-
onToggleIncludeWatchedShows: () -> Unit,
250246
onSortSelected: (SortOption) -> Unit,
251247
openShowDetails: (showId: Long) -> Unit,
252248
modifier: Modifier = Modifier,
@@ -306,9 +302,9 @@ private fun LibraryGrid(
306302
modifier = Modifier.padding(vertical = 8.dp),
307303
) {
308304
FilterChip(
309-
selected = state.followedShowsIncluded,
305+
selected = state.onlyFollowedShows,
310306
leadingIcon = {
311-
AnimatedVisibility(visible = state.followedShowsIncluded) {
307+
AnimatedVisibility(visible = state.onlyFollowedShows) {
312308
Icon(
313309
imageVector = Icons.Default.Done,
314310
contentDescription = null,
@@ -317,23 +313,7 @@ private fun LibraryGrid(
317313
},
318314
onClick = onToggleIncludeFollowedShows,
319315
label = {
320-
Text(text = LocalStrings.current.followingShowsTitle)
321-
},
322-
)
323-
324-
FilterChip(
325-
selected = state.watchedShowsIncluded,
326-
leadingIcon = {
327-
AnimatedVisibility(visible = state.watchedShowsIncluded) {
328-
Icon(
329-
imageVector = Icons.Default.Done,
330-
contentDescription = null,
331-
)
332-
}
333-
},
334-
onClick = onToggleIncludeWatchedShows,
335-
label = {
336-
Text(text = LocalStrings.current.watchedShowsTitle)
316+
Text(text = LocalStrings.current.upnextFilterFollowedShowsOnlyTitle)
337317
},
338318
)
339319

ui/library/src/commonMain/kotlin/app/tivi/home/library/LibraryPresenter.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class LibraryPresenter(
9191
val user by observeUserDetails.value.flow.collectAsRetainedState(null)
9292
val authState by observeTraktAuthState.value.flow.collectAsRetainedState(TraktAuthState.LOGGED_OUT)
9393

94-
val includeWatchedShows by preferences.value.libraryWatchedActive.collectAsState()
95-
val includeFollowedShows by preferences.value.libraryFollowedActive.collectAsState()
94+
val onlyFollowed by preferences.value.libraryFollowedActive.collectAsState()
9695

9796
val coroutineScope = rememberCoroutineScope()
9897

@@ -120,9 +119,6 @@ class LibraryPresenter(
120119
LibraryUiEvent.ToggleFollowedShowsIncluded -> {
121120
coroutineScope.launch { preferences.value.libraryFollowedActive.toggle() }
122121
}
123-
LibraryUiEvent.ToggleWatchedShowsIncluded -> {
124-
coroutineScope.launch { preferences.value.libraryWatchedActive.toggle() }
125-
}
126122
LibraryUiEvent.OpenAccount -> navigator.goTo(AccountScreen)
127123
is LibraryUiEvent.OpenShowDetails -> {
128124
navigator.goTo(ShowDetailsScreen(event.showId))
@@ -143,14 +139,13 @@ class LibraryPresenter(
143139
}
144140
}
145141

146-
LaunchedEffect(filter, sort, includeFollowedShows, includeWatchedShows) {
142+
LaunchedEffect(filter, sort, onlyFollowed) {
147143
// When the filter and sort options change, update the data source
148144
retainedObservePagedLibraryShows(
149145
ObservePagedLibraryShows.Parameters(
150146
sort = sort,
151147
filter = filter,
152-
includeFollowed = includeFollowedShows,
153-
includeWatched = includeWatchedShows,
148+
onlyFollowed = onlyFollowed,
154149
pagingConfig = PAGING_CONFIG,
155150
),
156151
)
@@ -166,8 +161,7 @@ class LibraryPresenter(
166161
availableSorts = AVAILABLE_SORT_OPTIONS,
167162
sort = sort,
168163
message = message,
169-
watchedShowsIncluded = includeWatchedShows,
170-
followedShowsIncluded = includeFollowedShows,
164+
onlyFollowedShows = onlyFollowed,
171165
eventSink = ::eventSink,
172166
)
173167
}

ui/library/src/commonMain/kotlin/app/tivi/home/library/LibraryUiState.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ data class LibraryUiState(
2424
val availableSorts: List<SortOption> = emptyList(),
2525
val sort: SortOption = SortOption.LAST_WATCHED,
2626
val message: UiMessage? = null,
27-
val followedShowsIncluded: Boolean = false,
28-
val watchedShowsIncluded: Boolean = false,
27+
val onlyFollowedShows: Boolean = false,
2928
val eventSink: (LibraryUiEvent) -> Unit,
3029
) : CircuitUiState
3130

@@ -35,7 +34,6 @@ sealed interface LibraryUiEvent : CircuitUiEvent {
3534
data class ChangeFilter(val filter: String?) : LibraryUiEvent
3635
data class ChangeSort(val sort: SortOption) : LibraryUiEvent
3736
data object ToggleFollowedShowsIncluded : LibraryUiEvent
38-
data object ToggleWatchedShowsIncluded : LibraryUiEvent
3937
data object OpenAccount : LibraryUiEvent
4038
data class OpenShowDetails(val showId: Long) : LibraryUiEvent
4139
}

0 commit comments

Comments
 (0)