From cbc69fe2f3e6a2798d7d63d56d8336b70a027cc3 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Fri, 15 Dec 2023 11:31:00 +0100 Subject: [PATCH] Shows: do not assume collected all if none collected. Also consider all episodes, not just released ones. This now matches with what episodes the collect all or none buttons change. --- CHANGELOG.md | 4 ++++ .../seriesguide/shows/database/SgEpisode2Helper.kt | 14 ++++++++++---- .../shows/overview/RemainingCountLiveData.kt | 13 ++++++++----- .../seriesguide/shows/overview/SeasonsFragment.kt | 12 ++++++------ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b82bef8293..2bfb9f963c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ Version 71 ---------- *in development* +* 🔨 Shows: do not consider all episodes collected, if there are none collected. Also consider all + episodes, not just released ones. This now matches with what episodes the collect all or none + buttons change. + #### 71.0.1 🧪 *2023-12-07* diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/database/SgEpisode2Helper.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/database/SgEpisode2Helper.kt index 261c9cc6bb..e2ae22a74a 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/database/SgEpisode2Helper.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/database/SgEpisode2Helper.kt @@ -235,11 +235,17 @@ interface SgEpisode2Helper { fun countWatchedEpisodesOfShowWithoutSpecials(showId: Long): Int /** - * Returns how many episodes of a show are left to collect. Only considers regular, released - * episodes (no specials, must have a release date in the past). + * Returns if at least one episode of the show is collected. Excludes specials. */ - @Query("SELECT COUNT(_id) FROM sg_episode WHERE series_id = :showId AND episode_collected = 0 AND episode_season_number != 0 AND episode_firstairedms != ${SgEpisode2.EPISODE_UNKNOWN_RELEASE} AND episode_firstairedms <= :currentTimeToolsTime") - fun countNotCollectedEpisodesOfShow(showId: Long, currentTimeToolsTime: Long): Int + @Query("SELECT COUNT(_id) FROM sg_episode WHERE series_id = :showId AND episode_collected = 1 AND episode_season_number != 0 LIMIT 1") + fun hasCollectedEpisodes(showId: Long): Boolean + + /** + * Returns if at least one episode of a show is left to collect. Excludes specials. + * Should match with what [updateCollectedOfShowExcludeSpecials] changes. + */ + @Query("SELECT COUNT(_id) FROM sg_episode WHERE series_id = :showId AND episode_collected = 0 AND episode_season_number != 0 LIMIT 1") + fun hasEpisodesToCollect(showId: Long): Boolean /** * Returns how many episodes of a show are left to watch (only aired and not watched, exclusive diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/overview/RemainingCountLiveData.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/overview/RemainingCountLiveData.kt index 38996eef2b..a4bbfab029 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/overview/RemainingCountLiveData.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/overview/RemainingCountLiveData.kt @@ -15,7 +15,8 @@ import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext /** - * Calculates the number of unwatched and not collected episodes of a show. + * Calculates the number of unwatched episodes and if all episodes are collected + * (excluding specials) for a show. */ class RemainingCountLiveData( val context: Context, @@ -25,8 +26,8 @@ class RemainingCountLiveData( private val semaphore = Semaphore(1) data class Result( - val unwatchedEpisodes: Int, - val uncollectedEpisodes: Int + val unwatchedEpisodes: Int, + val collectedAllEpisodes: Boolean ) fun load(showRowId: Long) { @@ -45,8 +46,10 @@ class RemainingCountLiveData( val helper = SgRoomDatabase.getInstance(context).sgEpisode2Helper() val currentTime = TimeTools.getCurrentTime(context) val unwatchedEpisodes = helper.countNotWatchedEpisodesOfShow(showRowId, currentTime) - val uncollectedEpisodes = helper.countNotCollectedEpisodesOfShow(showRowId, currentTime) - postValue(Result(unwatchedEpisodes, uncollectedEpisodes)) + // Only consider all collected if there is at least one collected + val collectedAllEpisodes = !helper.hasEpisodesToCollect(showRowId) + && helper.hasCollectedEpisodes(showRowId) + postValue(Result(unwatchedEpisodes, collectedAllEpisodes)) } } \ No newline at end of file diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/overview/SeasonsFragment.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/overview/SeasonsFragment.kt index c76fd80426..2d39788045 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/overview/SeasonsFragment.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/overview/SeasonsFragment.kt @@ -277,12 +277,12 @@ class SeasonsFragment() : Fragment() { val unwatched = result.unwatchedEpisodes binding.textViewSeasonsRemaining.text = TextTools.getRemainingEpisodes(requireContext().resources, unwatched) - setWatchedToggleState(unwatched) - setCollectedToggleState(result.uncollectedEpisodes) + setWatchedToggleState(unwatched == 0) + setCollectedToggleState(result.collectedAllEpisodes) } - private fun setWatchedToggleState(unwatchedEpisodes: Int) { - watchedAllEpisodes = unwatchedEpisodes == 0 + private fun setWatchedToggleState(watchedAllEpisodes: Boolean) { + this.watchedAllEpisodes = watchedAllEpisodes binding?.imageViewSeasonsWatchedToggle?.apply { // using vectors is safe because it will be an AppCompatImageView contentDescription = if (watchedAllEpisodes) { @@ -319,8 +319,8 @@ class SeasonsFragment() : Fragment() { }.show() } - private fun setCollectedToggleState(uncollectedEpisodes: Int) { - collectedAllEpisodes = uncollectedEpisodes == 0 + private fun setCollectedToggleState(collectedAllEpisodes: Boolean) { + this.collectedAllEpisodes = collectedAllEpisodes binding?.imageViewSeasonsCollectedToggle?.apply { // using vectors is safe because it will be an AppCompatImageView contentDescription = if (collectedAllEpisodes) {