From 19bcc45bb14998647f6779ecc55bdc72ea435eb9 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 14 Mar 2024 11:28:07 +0100 Subject: [PATCH] Lists: add watched next, favorite change, update to item menu --- CHANGELOG.md | 1 + .../seriesguide/lists/SgListFragment.kt | 48 +++++++++++++++---- .../lists/database/SgListHelper.kt | 21 +------- .../provider/SeriesGuideDatabase.java | 1 + app/src/main/res/menu/lists_popup_menu.xml | 12 +++++ 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f10ec66b31..d11b6e98b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Version 72 *in development* * ๐Ÿ”ง 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. #### 72.0.5 ๐Ÿงช *2024-03-08* diff --git a/app/src/main/java/com/battlelancer/seriesguide/lists/SgListFragment.kt b/app/src/main/java/com/battlelancer/seriesguide/lists/SgListFragment.kt index 399f862ca5..33df81769f 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/lists/SgListFragment.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/lists/SgListFragment.kt @@ -20,6 +20,8 @@ import com.battlelancer.seriesguide.databinding.FragmentListBinding import com.battlelancer.seriesguide.lists.ListsDistillationSettings.ListsSortOrderChangedEvent import com.battlelancer.seriesguide.lists.database.SgListItemWithDetails import com.battlelancer.seriesguide.provider.SeriesGuideContract.ListItemTypes +import com.battlelancer.seriesguide.shows.episodes.EpisodeTools +import com.battlelancer.seriesguide.shows.tools.ShowSync import com.battlelancer.seriesguide.ui.AutoGridLayoutManager import com.battlelancer.seriesguide.ui.OverviewActivity import com.battlelancer.seriesguide.ui.widgets.SgFastScroller @@ -120,10 +122,14 @@ class SgListFragment : Fragment() { override fun onMenuClick(anchor: View, item: SgListItemWithDetails) { 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 popupMenu.setOnMenuItemClickListener( PopupMenuItemClickListener( requireContext(), parentFragmentManager, - item.listItemId, item.showId + item.listItemId, item.showId, + item.nextEpisode?.toLongOrNull() ?: 0 ) ) // Hide manage lists option for legacy show items, only allow removal. @@ -144,18 +150,40 @@ class SgListFragment : Fragment() { private val context: Context, private val fragmentManager: FragmentManager, private val itemId: String, - private val showId: Long + private val showId: Long, + private val nextEpisodeId: Long ) : PopupMenu.OnMenuItemClickListener { + + private val showTools = SgApp.getServicesComponent(context).showTools() + override fun onMenuItemClick(item: MenuItem): Boolean { - val id = item.itemId - if (id == R.id.menu_action_lists_manage) { - ManageListsDialogFragment.show(fragmentManager, showId) - return true - } else if (id == R.id.menu_action_lists_remove) { - ListsTools.removeListItem(context, itemId) - return true + when (item.itemId) { + R.id.menu_action_lists_watched_next -> { + 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 } - return false } } diff --git a/app/src/main/java/com/battlelancer/seriesguide/lists/database/SgListHelper.kt b/app/src/main/java/com/battlelancer/seriesguide/lists/database/SgListHelper.kt index 22815fe08a..34450ad1e7 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/lists/database/SgListHelper.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/lists/database/SgListHelper.kt @@ -81,6 +81,7 @@ data class SgListItemWithDetails( @ColumnInfo(name = SgShow2Columns.POSTER_SMALL) val posterSmall: String?, @ColumnInfo(name = SgShow2Columns.NETWORK) val network: String?, @ColumnInfo(name = SgShow2Columns.STATUS) val status: Int?, + @ColumnInfo(name = SgShow2Columns.NEXTEPISODE) val nextEpisode: String?, @ColumnInfo(name = SgShow2Columns.FAVORITE) var favorite: Boolean, @ColumnInfo(name = SgShow2Columns.RELEASE_WEEKDAY) val releaseWeekDay: Int?, @ColumnInfo(name = SgShow2Columns.RELEASE_TIMEZONE) val releaseTimeZone: String?, @@ -102,24 +103,4 @@ data class SgListItemWithDetails( get() = customReleaseDayOffset ?: SgShow2.CUSTOM_RELEASE_DAY_OFFSET_NOT_SET val statusOrUnknown: Int get() = status ?: ShowStatus.UNKNOWN - - companion object { - const val SELECT = "SELECT ${ListItems._ID}," + - "${ListItems.LIST_ITEM_ID}," + - "${ListItems.ITEM_REF_ID}," + - "${ListItems.TYPE}," + - "${SgShow2Columns.REF_SHOW_ID}," + - "${SgShow2Columns.TITLE}," + - "${SgShow2Columns.POSTER_SMALL}," + - "${SgShow2Columns.NETWORK}," + - "${SgShow2Columns.RELEASE_TIME}," + - "${SgShow2Columns.RELEASE_WEEKDAY}," + - "${SgShow2Columns.RELEASE_TIMEZONE}," + - "${SgShow2Columns.RELEASE_COUNTRY}," + - "${SgShow2Columns.STATUS}," + - "${SgShow2Columns.NEXTTEXT}," + - "${SgShow2Columns.NEXTAIRDATEMS}," + - "${SgShow2Columns.FAVORITE}," + - SgShow2Columns.UNWATCHED_COUNT - } } diff --git a/app/src/main/java/com/battlelancer/seriesguide/provider/SeriesGuideDatabase.java b/app/src/main/java/com/battlelancer/seriesguide/provider/SeriesGuideDatabase.java index f1b7ee4466..9b61b2182d 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/provider/SeriesGuideDatabase.java +++ b/app/src/main/java/com/battlelancer/seriesguide/provider/SeriesGuideDatabase.java @@ -273,6 +273,7 @@ private interface ItemsQuery { + SgShow2Columns.POSTER_SMALL + "," + SgShow2Columns.NETWORK + "," + SgShow2Columns.STATUS + "," + + SgShow2Columns.NEXTEPISODE + "," + SgShow2Columns.FAVORITE + "," + SgShow2Columns.RELEASE_WEEKDAY + "," + SgShow2Columns.RELEASE_TIMEZONE + "," diff --git a/app/src/main/res/menu/lists_popup_menu.xml b/app/src/main/res/menu/lists_popup_menu.xml index 58fd618180..6c7ef25686 100644 --- a/app/src/main/res/menu/lists_popup_menu.xml +++ b/app/src/main/res/menu/lists_popup_menu.xml @@ -2,6 +2,18 @@ + + + +