Skip to content

Commit

Permalink
WatchedBox: let it itself update content description and tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 10, 2024
1 parent 1ed601c commit 8792317
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ class CalendarItemViewHolder(
info.text = TextTools.dotSeparate(episode.network, time)

// watched box
watchedBox.isEnabled = true
val episodeFlag = episode.watched
watchedBox.episodeFlag = episodeFlag
val watched = EpisodeTools.isWatched(episodeFlag)
watchedBox.contentDescription =
context.getString(if (watched) R.string.action_unwatched else R.string.action_watched)
watchedBox.also {
it.isEnabled = true
it.episodeFlag = episode.watched
}

// collected indicator
collected.isGone = !episode.episode_collected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.TooltipCompat
import androidx.core.widget.TextViewCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
Expand Down Expand Up @@ -162,18 +161,6 @@ class EpisodeViewHolder(
// watched box
binding.watchedBoxEpisode.episodeFlag = watchedFlag
binding.watchedBoxEpisode.isEnabled = true
val watched =
EpisodeTools.isWatched(
watchedFlag
)
binding.watchedBoxEpisode.contentDescription =
context.getString(if (watched) R.string.action_unwatched else R.string.action_watched)
TooltipCompat.setTooltipText(
binding.watchedBoxEpisode,
binding.watchedBoxEpisode.context.getString(
if (watched) R.string.action_unwatched else R.string.action_watched
)
)

// collected tag
val isCollected = episode.collected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package com.battlelancer.seriesguide.shows.episodes
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.TooltipCompat
import com.battlelancer.seriesguide.R

/**
* Image view that displays a watched, skipped or watch icon depending on the given episode flag.
*
* Provides a content description and tooltip out of the box.
*/
class WatchedBox(context: Context, attrs: AttributeSet?) : AppCompatImageView(context, attrs) {

Expand All @@ -21,6 +24,7 @@ class WatchedBox(context: Context, attrs: AttributeSet?) : AppCompatImageView(co
EpisodeTools.validateFlags(value)
field = value
updateStateImage()
updateContentDescription()
}

init {
Expand Down Expand Up @@ -48,4 +52,12 @@ class WatchedBox(context: Context, attrs: AttributeSet?) : AppCompatImageView(co
}
}
}

private fun updateContentDescription() {
val watched = EpisodeTools.isWatched(episodeFlag)
contentDescription =
context.getString(if (watched) R.string.action_unwatched else R.string.action_watched)
// Re-set tooltip text after updating
TooltipCompat.setTooltipText(this, contentDescription)
}
}

0 comments on commit 8792317

Please sign in to comment.