Skip to content

Commit

Permalink
Lists: replace favorite with watched next, overlay favorite indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Mar 14, 2024
1 parent 19bcc45 commit 8725d51
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Version 72

* 🔧 Seasons: different indicators if only some or all episodes are skipped or in collection.
* 🔧 Lists: add option to watch next episode, update to shows more options menu.
* 🔧 Lists: replace favorite with set next watched button to match Shows section.

#### 72.0.5 🧪
*2024-03-08*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2012-2024 Uwe Trottmann

package com.battlelancer.seriesguide.lists

Expand Down Expand Up @@ -109,8 +109,8 @@ class SgListFragment : Fragment() {
model.updateQuery()
}

private val onItemClickListener: SgListItemAdapter.OnItemClickListener =
object : SgListItemAdapter.OnItemClickListener {
private val onItemClickListener: SgListItemViewHolder.OnItemClickListener =
object : SgListItemViewHolder.OnItemClickListener {
override fun onItemClick(anchor: View, item: SgListItemWithDetails) {
Utils.startActivityWithAnimation(
requireActivity(),
Expand All @@ -123,13 +123,18 @@ class SgListFragment : Fragment() {
val popupMenu = PopupMenu(anchor.context, anchor)
popupMenu.inflate(R.menu.lists_popup_menu)
val menu = popupMenu.menu
menu.findItem(R.id.menu_action_lists_favorites_add).isVisible = !item.favorite
menu.findItem(R.id.menu_action_lists_favorites_remove).isVisible = item.favorite
// Hide some options that only make sense for shows (for legacy non-show items)
val isShow =
item.type == ListItemTypes.TMDB_SHOW || item.type == ListItemTypes.TVDB_SHOW
menu.findItem(R.id.menu_action_lists_watched_next).isVisible = isShow
menu.findItem(R.id.menu_action_lists_favorites_add).isVisible =
isShow && !item.favorite
menu.findItem(R.id.menu_action_lists_favorites_remove).isVisible =
isShow && item.favorite
popupMenu.setOnMenuItemClickListener(
PopupMenuItemClickListener(
requireContext(), parentFragmentManager,
item.listItemId, item.showId,
item.nextEpisode?.toLongOrNull() ?: 0
item.listItemId, item.showId, item.nextEpisodeId
)
)
// Hide manage lists option for legacy show items, only allow removal.
Expand All @@ -139,10 +144,8 @@ class SgListFragment : Fragment() {
popupMenu.show()
}


override fun onFavoriteClick(showId: Long, isFavorite: Boolean) {
SgApp.getServicesComponent(requireContext()).showTools()
.storeIsFavorite(showId, isFavorite)
override fun onItemSetWatchedClick(item: SgListItemWithDetails) {
EpisodeTools.episodeWatchedIfNotZero(context, item.nextEpisodeId)
}
}

Expand All @@ -162,26 +165,32 @@ class SgListFragment : Fragment() {
EpisodeTools.episodeWatchedIfNotZero(context, nextEpisodeId)
return true
}

R.id.menu_action_lists_favorites_add -> {
showTools.storeIsFavorite(showId, true)
return true
}

R.id.menu_action_lists_favorites_remove -> {
showTools.storeIsFavorite(showId, false)
return true
}

R.id.menu_action_lists_manage -> {
ManageListsDialogFragment.show(fragmentManager, showId)
return true
}

R.id.menu_action_lists_update -> {
ShowSync.triggerDeltaSync(context, showId)
return true
}

R.id.menu_action_lists_remove -> {
ListsTools.removeListItem(context, itemId)
return true
}

else -> return false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021-2024 Uwe Trottmann

package com.battlelancer.seriesguide.lists

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.databinding.ItemShowBinding
import com.battlelancer.seriesguide.databinding.ItemShowListBinding
import com.battlelancer.seriesguide.lists.database.SgListItemWithDetails
import com.battlelancer.seriesguide.provider.SeriesGuideContract.ListItemTypes
import com.battlelancer.seriesguide.provider.SgRoomDatabase
Expand All @@ -28,24 +28,11 @@ import org.threeten.bp.Instant

class SgListItemAdapter(
private val context: Context,
private val onItemClickListener: OnItemClickListener
private val onItemClickListener: SgListItemViewHolder.OnItemClickListener
) : ListAdapter<SgListItemWithDetails, SgListItemViewHolder>(DIFF_CALLBACK) {

private val drawableStar = VectorDrawableCompat
.create(context.resources, R.drawable.ic_star_black_24dp, context.theme)!!
private val drawableStarZero = VectorDrawableCompat
.create(context.resources, R.drawable.ic_star_border_black_24dp, context.theme)!!

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SgListItemViewHolder {
return SgListItemViewHolder(
ItemShowBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
), onItemClickListener,
drawableStar,
drawableStarZero
)
return SgListItemViewHolder.create(onItemClickListener, parent)
}

override fun onBindViewHolder(holder: SgListItemViewHolder, position: Int) {
Expand All @@ -66,35 +53,39 @@ class SgListItemAdapter(
}
}

interface OnItemClickListener {
fun onItemClick(anchor: View, item: SgListItemWithDetails)
fun onMenuClick(anchor: View, item: SgListItemWithDetails)
fun onFavoriteClick(showId: Long, isFavorite: Boolean)
}

}

class SgListItemViewHolder(
private val binding: ItemShowBinding,
onItemClickListener: SgListItemAdapter.OnItemClickListener,
private val drawableStar: Drawable,
private val drawableStarZero: Drawable
private val binding: ItemShowListBinding,
onItemClickListener: OnItemClickListener
) : RecyclerView.ViewHolder(binding.root) {

interface OnItemClickListener {
fun onItemClick(anchor: View, item: SgListItemWithDetails)
fun onMenuClick(anchor: View, item: SgListItemWithDetails)
fun onItemSetWatchedClick(item: SgListItemWithDetails)
}

var item: SgListItemWithDetails? = null

init {
// item
binding.root.setOnClickListener { view ->
item?.let { onItemClickListener.onItemClick(view, it) }
}
// favorite star
binding.favoritedLabel.setOnClickListener {
item?.let { onItemClickListener.onFavoriteClick(it.showId, !it.favorite) }
// set watched button
binding.imageViewShowsSetWatched.apply {
TooltipCompat.setTooltipText(this, this.contentDescription)
setOnClickListener {
item?.let { onItemClickListener.onItemSetWatchedClick(it) }
}
}
// context menu
binding.imageViewShowsContextMenu.setOnClickListener { view ->
item?.let { onItemClickListener.onMenuClick(view, it) }
binding.imageViewShowsContextMenu.apply {
TooltipCompat.setTooltipText(this, this.contentDescription)
setOnClickListener { view ->
item?.let { onItemClickListener.onMenuClick(view, it) }
}
}
}

Expand All @@ -103,26 +94,11 @@ class SgListItemViewHolder(

if (item == null) {
binding.seriesname.text = null
binding.favoritedLabel.setImageDrawable(null)
return
}

// show title
binding.seriesname.text = item.title

// favorite label
binding.favoritedLabel.apply {
setImageDrawable(if (item.favorite) drawableStar else drawableStarZero)
contentDescription = context.getString(
if (item.favorite) {
R.string.context_unfavorite
} else {
R.string.context_favorite
}
)
}

// poster
binding.favoritedLabel.isVisible = item.favorite
ImageTools.loadShowPosterResizeCrop(context, binding.showposter, item.posterSmall)

// network, regular day and time, or type for legacy season/episode
Expand Down Expand Up @@ -235,4 +211,18 @@ class SgListItemViewHolder(
}
}

companion object {
fun create(
onItemClickListener: OnItemClickListener,
parent: ViewGroup
): SgListItemViewHolder = SgListItemViewHolder(
ItemShowListBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
),
onItemClickListener
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ data class SgListItemWithDetails(
get() = customReleaseDayOffset ?: SgShow2.CUSTOM_RELEASE_DAY_OFFSET_NOT_SET
val statusOrUnknown: Int
get() = status ?: ShowStatus.UNKNOWN

val nextEpisodeId: Long
get() = nextEpisode?.toLongOrNull() ?: 0
}

0 comments on commit 8725d51

Please sign in to comment.