Skip to content

Commit

Permalink
Merge branch 'consistent-tooltips' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 11, 2024
2 parents 4c7ff64 + fac7c3a commit 9bf5937
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 90 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Releases marked with 🧪 (or previously with the "beta" suffix) were released o
* 🔨 Show overview: do not display no spoiler warning if there is no image.
* 🔨 Consistently style more options menus.
* 🔨 Episodes: can use watched button also after dismissing the popup menu.
* 🔨 Consistently show tooltips for actions.

### 2024.4.3 - 2024-09-13 🧪

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.widget.TooltipCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.battlelancer.seriesguide.R
Expand Down Expand Up @@ -37,8 +38,11 @@ class MovieViewHolder(
itemView.setContextAndLongClickListener {
onMoreOptionsClick()
}
moreOptions.setOnClickListener {
onMoreOptionsClick()
moreOptions.also {
TooltipCompat.setTooltipText(it, it.contentDescription)
it.setOnClickListener {
onMoreOptionsClick()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PlainTooltip
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.rememberTooltipState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -91,14 +95,22 @@ fun WatchProviderList(
) {
Text(stringResource(id = R.string.action_reset))
}
IconButton(
modifier = Modifier.padding(top = 2.dp, start = 4.dp, end = 4.dp),
onClick = onSelectRegion
val descriptionStreamSettingsButton =
stringResource(id = R.string.action_stream_info)
TooltipBox(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
tooltip = { PlainTooltip { Text(descriptionStreamSettingsButton) } },
state = rememberTooltipState()
) {
Icon(
imageVector = Icons.Outlined.Settings,
contentDescription = stringResource(id = R.string.action_stream_info)
)
IconButton(
modifier = Modifier.padding(top = 2.dp, start = 4.dp, end = 4.dp),
onClick = onSelectRegion
) {
Icon(
imageVector = Icons.Outlined.Settings,
contentDescription = descriptionStreamSettingsButton
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CalendarItemViewHolder(
private val episodeTextView: TextView = itemView.findViewById(R.id.textViewActivityEpisode)
private val collected: View = itemView.findViewById(R.id.imageViewActivityCollected)
private val watchedBox: WatchedBox = itemView.findViewById(R.id.watchedBoxActivity)
private val contextMenu: ImageView = itemView.findViewById(R.id.imageViewActivityMoreOptions)
private val moreOptionsButton: ImageView = itemView.findViewById(R.id.imageViewActivityMoreOptions)
private val info: TextView = itemView.findViewById(R.id.textViewActivityInfo)
private val timestamp: TextView = itemView.findViewById(R.id.textViewActivityTimestamp)
private val poster: ImageView = itemView.findViewById(R.id.imageViewActivityPoster)
Expand All @@ -57,8 +57,11 @@ class CalendarItemViewHolder(
itemContainer.setContextAndLongClickListener {
onMoreOptionsClick()
}
contextMenu.setOnClickListener {
onMoreOptionsClick()
moreOptionsButton.also {
TooltipCompat.setTooltipText(it, it.contentDescription)
it.setOnClickListener {
onMoreOptionsClick()
}
}
watchedBox.setOnClickListener {
item?.episode?.let {
Expand All @@ -74,7 +77,7 @@ class CalendarItemViewHolder(

private fun onMoreOptionsClick() {
item?.episode?.let {
itemClickListener.onMoreOptionsClick(contextMenu, it)
itemClickListener.onMoreOptionsClick(moreOptionsButton, it)
}
}

Expand Down Expand Up @@ -152,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.apply {
isEnabled = true
episodeFlag = episode.watched
}

// collected indicator
collected.isGone = !episode.episode_collected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ class EpisodeViewHolder(
binding.root.setContextAndLongClickListener {
onMoreOptionsClick()
}
binding.imageViewItemEpisodeMoreOptions.setOnClickListener {
onMoreOptionsClick()
binding.imageViewItemEpisodeMoreOptions.also {
TooltipCompat.setTooltipText(it, it.contentDescription)
it.setOnClickListener {
onMoreOptionsClick()
}
}
}

Expand Down Expand Up @@ -159,18 +162,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 @@ -12,6 +12,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -341,17 +342,18 @@ class EpisodesFragment : Fragment() {

private fun setWatchedToggleState(unwatchedEpisodes: Int) {
watchedAllEpisodes = unwatchedEpisodes == 0
binding?.imageViewEpisodesWatched?.apply {
binding?.imageViewEpisodesWatched?.also {
// using vectors is safe because it will be an AppCompatImageView
contentDescription = if (watchedAllEpisodes) {
setImageResource(R.drawable.ic_watched_all_24dp)
getString(R.string.unmark_all)
if (watchedAllEpisodes) {
it.setImageResource(R.drawable.ic_watched_all_24dp)
it.contentDescription = getString(R.string.unmark_all)
} else {
setImageResource(R.drawable.ic_watch_all_black_24dp)
getString(R.string.mark_all)
it.setImageResource(R.drawable.ic_watch_all_black_24dp)
it.contentDescription = getString(R.string.mark_all)
}
TooltipCompat.setTooltipText(it, it.contentDescription)
// set onClick listener not before here to avoid unexpected actions
setOnClickListener(watchedAllClickListener)
it.setOnClickListener(watchedAllClickListener)
}
}

Expand Down Expand Up @@ -389,17 +391,18 @@ class EpisodesFragment : Fragment() {

private fun setCollectedToggleState(uncollectedEpisodes: Int) {
collectedAllEpisodes = uncollectedEpisodes == 0
binding?.imageViewEpisodesCollected?.apply {
binding?.imageViewEpisodesCollected?.also {
// using vectors is safe because it will be an AppCompatImageView
contentDescription = if (collectedAllEpisodes) {
setImageResource(R.drawable.ic_collected_all_24dp)
getString(R.string.uncollect_all)
if (collectedAllEpisodes) {
it.setImageResource(R.drawable.ic_collected_all_24dp)
it.contentDescription = getString(R.string.uncollect_all)
} else {
setImageResource(R.drawable.ic_collect_all_black_24dp)
getString(R.string.collect_all)
it.setImageResource(R.drawable.ic_collect_all_black_24dp)
it.contentDescription = getString(R.string.collect_all)
}
TooltipCompat.setTooltipText(it, it.contentDescription)
// set onClick listener not before here to avoid unexpected actions
setOnClickListener(collectedAllClickListener)
it.setOnClickListener(collectedAllClickListener)
}
}

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.isVisible
import androidx.core.widget.TextViewCompat
import androidx.recyclerview.widget.DiffUtil
Expand Down Expand Up @@ -50,8 +51,11 @@ class SeasonsAdapter(
itemView.setContextAndLongClickListener {
onMoreOptionsClick()
}
binding.imageViewSeasonMoreOptions.setOnClickListener {
onMoreOptionsClick()
binding.imageViewSeasonMoreOptions.also {
TooltipCompat.setTooltipText(it, it.contentDescription)
it.setOnClickListener {
onMoreOptionsClick()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.TooltipCompat
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityOptionsCompat
import androidx.core.os.bundleOf
Expand Down Expand Up @@ -296,17 +297,18 @@ class SeasonsFragment() : Fragment() {

private fun setWatchedToggleState(watchedAllEpisodes: Boolean) {
this.watchedAllEpisodes = watchedAllEpisodes
binding?.imageViewSeasonsWatchedToggle?.apply {
binding?.imageViewSeasonsWatchedToggle?.also {
// using vectors is safe because it will be an AppCompatImageView
contentDescription = if (watchedAllEpisodes) {
setImageResource(R.drawable.ic_watched_all_24dp)
getString(R.string.unmark_all)
if (watchedAllEpisodes) {
it.setImageResource(R.drawable.ic_watched_all_24dp)
it.contentDescription = getString(R.string.unmark_all)
} else {
setImageResource(R.drawable.ic_watch_all_black_24dp)
getString(R.string.mark_all)
it.setImageResource(R.drawable.ic_watch_all_black_24dp)
it.contentDescription = getString(R.string.mark_all)
}
TooltipCompat.setTooltipText(it, it.contentDescription)
// set onClick listener not before here to avoid unexpected actions
setOnClickListener(watchedAllClickListener)
it.setOnClickListener(watchedAllClickListener)
}
}

Expand Down Expand Up @@ -336,17 +338,18 @@ class SeasonsFragment() : Fragment() {

private fun setCollectedToggleState(collectedAllEpisodes: Boolean) {
this.collectedAllEpisodes = collectedAllEpisodes
binding?.imageViewSeasonsCollectedToggle?.apply {
binding?.imageViewSeasonsCollectedToggle?.also {
// using vectors is safe because it will be an AppCompatImageView
contentDescription = if (collectedAllEpisodes) {
setImageResource(R.drawable.ic_collected_all_24dp)
getString(R.string.uncollect_all)
if (collectedAllEpisodes) {
it.setImageResource(R.drawable.ic_collected_all_24dp)
it.contentDescription = getString(R.string.uncollect_all)
} else {
setImageResource(R.drawable.ic_collect_all_black_24dp)
getString(R.string.collect_all)
it.setImageResource(R.drawable.ic_collect_all_black_24dp)
it.contentDescription = getString(R.string.collect_all)
}
TooltipCompat.setTooltipText(it, it.contentDescription)
// set onClick listener not before here to avoid unexpected actions
setOnClickListener(collectedAllClickListener)
it.setOnClickListener(collectedAllClickListener)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import android.view.ViewGroup
import android.view.animation.AnimationUtils
import android.widget.ArrayAdapter
import android.widget.GridView
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.ViewCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.databinding.ItemAddshowBinding
import com.battlelancer.seriesguide.enums.NetworkResult
import com.battlelancer.seriesguide.shows.tools.AddShowTask.OnShowAddedEvent
Expand Down Expand Up @@ -224,6 +226,9 @@ abstract class AddFragment : Fragment() {
binding.addIndicatorAddShow.setOnAddClickListener {
item?.let { itemClickListener.onAddClick(it) }
}
binding.buttonItemAddMoreOptions.also {
TooltipCompat.setTooltipText(it, it.contentDescription)
}
}

private fun onMoreOptionsClick() {
Expand Down Expand Up @@ -254,18 +259,18 @@ abstract class AddFragment : Fragment() {
if (enableMoreOptions) View.VISIBLE else View.GONE

if (item == null) {
binding.addIndicatorAddShow.setState(SearchResult.STATE_ADD)
binding.addIndicatorAddShow.setContentDescriptionAdded(null)
binding.addIndicatorAddShow.isGone = true
binding.textViewAddTitle.text = null
binding.textViewAddDescription.text = null
binding.imageViewAddPoster.setImageDrawable(null)
} else {
// display added indicator instead of add button if already added that show
binding.addIndicatorAddShow.setState(item.state)
// add indicator
val showTitle = item.title
binding.addIndicatorAddShow.setContentDescriptionAdded(
context.getString(R.string.add_already_exists, showTitle)
)
binding.addIndicatorAddShow.apply {
setState(item.state)
setNameOfAssociatedItem(showTitle)
isVisible = true
}

// set text properties immediately
binding.textViewAddTitle.text = showTitle
Expand Down
Loading

0 comments on commit 9bf5937

Please sign in to comment.