Skip to content

Commit

Permalink
Shows: do not assume collected all if none collected.
Browse files Browse the repository at this point in the history
Also consider all episodes, not just released ones. This now matches
with what episodes the collect all or none buttons change.
  • Loading branch information
UweTrottmann committed Dec 15, 2023
1 parent 0a0b8ee commit cbc69fe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cbc69fe

Please sign in to comment.