diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/calendar/CalendarItemViewHolder.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/calendar/CalendarItemViewHolder.kt index 30a8ef83a3..06333884a4 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/calendar/CalendarItemViewHolder.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/calendar/CalendarItemViewHolder.kt @@ -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 diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/EpisodesAdapter.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/EpisodesAdapter.kt index 04f96f5f13..258654ee5d 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/EpisodesAdapter.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/EpisodesAdapter.kt @@ -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 @@ -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 diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/WatchedBox.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/WatchedBox.kt index 6f25f07397..8b1098c88c 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/WatchedBox.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/episodes/WatchedBox.kt @@ -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) { @@ -21,6 +24,7 @@ class WatchedBox(context: Context, attrs: AttributeSet?) : AppCompatImageView(co EpisodeTools.validateFlags(value) field = value updateStateImage() + updateContentDescription() } init { @@ -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) + } }