Skip to content

Commit

Permalink
ManualSyncMenu: add to lists
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 11, 2024
1 parent 6ce5623 commit 4c7ff64
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 82 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Releases marked with 🧪 (or previously with the "beta" suffix) were released o
* 🔧 Display more options of list items on touch and hold and right click (for example in Samsung
Dex) as well.
* 🔧 Where touch and hold copies text, support right click to copy as well.
* 🔧 Add manual sync action back to show Upcoming, Recent tabs, new to movie Watchlist, Collection,
Watched tabs.
* 🔧 Add manual sync action back to show Upcoming, Recent tabs, new to lists and movie Watchlist,
Collection, Watched tabs.
* 🔧 Seasons: move skipped and collection indicators to the right to work better with multi-line
status text.
* 🔨 Show overview: do not display no spoiler warning if there is no image.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2012-2024 Uwe Trottmann

package com.battlelancer.seriesguide.lists

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels
Expand All @@ -17,6 +18,7 @@ import com.battlelancer.seriesguide.databinding.ActivityListsBinding
import com.battlelancer.seriesguide.settings.DisplaySettings
import com.battlelancer.seriesguide.ui.BaseTopActivity
import com.battlelancer.seriesguide.ui.SearchActivity
import com.battlelancer.seriesguide.ui.menus.ManualSyncMenu
import com.battlelancer.seriesguide.util.ThemeUtils
import com.battlelancer.seriesguide.util.ThemeUtils.setDefaultStyle
import com.battlelancer.seriesguide.util.ViewTools
Expand All @@ -43,6 +45,7 @@ open class ListsActivityImpl : BaseTopActivity() {

setupViews()
setupSyncProgressBar(R.id.sgProgressBar)
addMenuProvider(optionsMenuProvider, this)

viewModel.listsLiveData.observe(this) { items ->
listsAdapter.updateItems(items)
Expand Down Expand Up @@ -93,88 +96,99 @@ open class ListsActivityImpl : BaseTopActivity() {
.apply()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.lists_menu, menu)

// set current sort order and check box states
val sortOrderId = ListsDistillationSettings.getSortOrderId(this)
val sortTitleItem = menu.findItem(R.id.menu_action_lists_sort_title)
sortTitleItem.setTitle(R.string.action_shows_sort_title)
val sortLatestItem = menu.findItem(R.id.menu_action_lists_sort_latest_episode)
sortLatestItem.setTitle(R.string.action_shows_sort_latest_episode)
val sortOldestItem = menu.findItem(R.id.menu_action_lists_sort_oldest_episode)
sortOldestItem.setTitle(R.string.action_shows_sort_oldest_episode)
val lastWatchedItem = menu.findItem(R.id.menu_action_lists_sort_last_watched)
lastWatchedItem.setTitle(R.string.action_shows_sort_last_watched)
val remainingItem = menu.findItem(R.id.menu_action_lists_sort_remaining)
remainingItem.setTitle(R.string.action_shows_sort_remaining)
when (sortOrderId) {
ListsDistillationSettings.ListsSortOrder.TITLE_ALPHABETICAL_ID -> {
ViewTools.setMenuItemActiveString(sortTitleItem)
private val optionsMenuProvider by lazy {
object : ManualSyncMenu(this@ListsActivityImpl, R.menu.lists_menu) {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
super.onCreateMenu(menu, menuInflater)

// set current sort order and check box states
val sortOrderId = ListsDistillationSettings.getSortOrderId(this@ListsActivityImpl)
val sortTitleItem = menu.findItem(R.id.menu_action_lists_sort_title)
sortTitleItem.setTitle(R.string.action_shows_sort_title)
val sortLatestItem = menu.findItem(R.id.menu_action_lists_sort_latest_episode)
sortLatestItem.setTitle(R.string.action_shows_sort_latest_episode)
val sortOldestItem = menu.findItem(R.id.menu_action_lists_sort_oldest_episode)
sortOldestItem.setTitle(R.string.action_shows_sort_oldest_episode)
val lastWatchedItem = menu.findItem(R.id.menu_action_lists_sort_last_watched)
lastWatchedItem.setTitle(R.string.action_shows_sort_last_watched)
val remainingItem = menu.findItem(R.id.menu_action_lists_sort_remaining)
remainingItem.setTitle(R.string.action_shows_sort_remaining)
when (sortOrderId) {
ListsDistillationSettings.ListsSortOrder.TITLE_ALPHABETICAL_ID -> {
ViewTools.setMenuItemActiveString(sortTitleItem)
}

ListsDistillationSettings.ListsSortOrder.LATEST_EPISODE_ID -> {
ViewTools.setMenuItemActiveString(sortLatestItem)
}

ListsDistillationSettings.ListsSortOrder.OLDEST_EPISODE_ID -> {
ViewTools.setMenuItemActiveString(sortOldestItem)
}

ListsDistillationSettings.ListsSortOrder.LAST_WATCHED_ID -> {
ViewTools.setMenuItemActiveString(lastWatchedItem)
}

ListsDistillationSettings.ListsSortOrder.LEAST_REMAINING_EPISODES_ID -> {
ViewTools.setMenuItemActiveString(remainingItem)
}
}
menu.findItem(R.id.menu_action_lists_sort_ignore_articles).isChecked =
DisplaySettings.isSortOrderIgnoringArticles(this@ListsActivityImpl)
}
ListsDistillationSettings.ListsSortOrder.LATEST_EPISODE_ID -> {
ViewTools.setMenuItemActiveString(sortLatestItem)
}
ListsDistillationSettings.ListsSortOrder.OLDEST_EPISODE_ID -> {
ViewTools.setMenuItemActiveString(sortOldestItem)
}
ListsDistillationSettings.ListsSortOrder.LAST_WATCHED_ID -> {
ViewTools.setMenuItemActiveString(lastWatchedItem)
}
ListsDistillationSettings.ListsSortOrder.LEAST_REMAINING_EPISODES_ID -> {
ViewTools.setMenuItemActiveString(remainingItem)
}
}
menu.findItem(R.id.menu_action_lists_sort_ignore_articles).isChecked =
DisplaySettings.isSortOrderIgnoringArticles(this)

return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val itemId = item.itemId
if (itemId == R.id.menu_action_lists_add) {
AddListDialogFragment.show(supportFragmentManager)
return true
}
if (itemId == R.id.menu_action_lists_search) {
startActivity(Intent(this, SearchActivity::class.java))
return true
}
if (itemId == R.id.menu_action_lists_edit) {
val selectedListIndex = binding.viewPagerLists.currentItem
showListManageDialog(selectedListIndex)
return true
}
if (itemId == R.id.menu_action_lists_sort_title) {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.TITLE_ALPHABETICAL_ID)
return true
}
if (itemId == R.id.menu_action_lists_sort_latest_episode) {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LATEST_EPISODE_ID)
return true
}
if (itemId == R.id.menu_action_lists_sort_oldest_episode) {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.OLDEST_EPISODE_ID)
return true
}
if (itemId == R.id.menu_action_lists_sort_last_watched) {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LAST_WATCHED_ID)
return true
}
if (itemId == R.id.menu_action_lists_sort_remaining) {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LEAST_REMAINING_EPISODES_ID)
return true
}
if (itemId == R.id.menu_action_lists_sort_ignore_articles) {
toggleSortIgnoreArticles()
return true
}
if (itemId == R.id.menu_action_lists_reorder) {
ListsReorderDialogFragment().safeShow(supportFragmentManager, "listsReorderDialog")
return true
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.menu_action_lists_add -> {
AddListDialogFragment.show(supportFragmentManager)
return true
}
R.id.menu_action_lists_search -> {
startActivity(Intent(this@ListsActivityImpl, SearchActivity::class.java))
return true
}
R.id.menu_action_lists_edit -> {
val selectedListIndex = binding.viewPagerLists.currentItem
showListManageDialog(selectedListIndex)
return true
}
R.id.menu_action_lists_sort_title -> {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.TITLE_ALPHABETICAL_ID)
return true
}
R.id.menu_action_lists_sort_latest_episode -> {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LATEST_EPISODE_ID)
return true
}
R.id.menu_action_lists_sort_oldest_episode -> {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.OLDEST_EPISODE_ID)
return true
}
R.id.menu_action_lists_sort_last_watched -> {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LAST_WATCHED_ID)
return true
}
R.id.menu_action_lists_sort_remaining -> {
changeSortOrder(ListsDistillationSettings.ListsSortOrder.LEAST_REMAINING_EPISODES_ID)
return true
}
R.id.menu_action_lists_sort_ignore_articles -> {
toggleSortIgnoreArticles()
return true
}
R.id.menu_action_lists_reorder -> {
ListsReorderDialogFragment().safeShow(
supportFragmentManager,
"listsReorderDialog"
)
return true
}
else -> return super.onMenuItemSelected(menuItem)
}
}
}
return super.onOptionsItemSelected(item)
}

private fun showListManageDialog(selectedListIndex: Int) {
Expand Down

0 comments on commit 4c7ff64

Please sign in to comment.