Remove chapter item popup menu

This commit is contained in:
arkon 2020-03-07 23:00:29 -05:00
parent 4061232fe3
commit c275adbb91
10 changed files with 21 additions and 144 deletions

View file

@ -1,29 +1,20 @@
package eu.kanade.tachiyomi.ui.manga.chapter
import android.view.View
import android.widget.PopupMenu
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import java.util.Date
import kotlinx.android.synthetic.main.chapters_item.chapter_description
import kotlinx.android.synthetic.main.chapters_item.chapter_menu
import kotlinx.android.synthetic.main.chapters_item.chapter_title
import kotlinx.android.synthetic.main.chapters_item.download_text
class ChapterHolder(
private val view: View,
view: View,
private val adapter: ChaptersAdapter
) : BaseFlexibleViewHolder(view, adapter) {
init {
// We need to post a Runnable to show the popup to make sure that the PopupMenu is
// correctly positioned. The reason being that the view may change position before the
// PopupMenu is shown.
chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } }
}
fun bind(item: ChapterItem, manga: Manga) {
val chapter = item.chapter
@ -73,45 +64,4 @@ class ChapterHolder(
else -> text = ""
}
}
private fun showPopupMenu(view: View) {
val item = adapter.getItem(adapterPosition) ?: return
// Create a PopupMenu, giving it the clicked view for an anchor
val popup = PopupMenu(view.context, view)
// Inflate our menu resource into the PopupMenu's Menu
popup.menuInflater.inflate(R.menu.chapter_single, popup.menu)
val chapter = item.chapter
// Hide download and show delete if the chapter is downloaded
if (item.isDownloaded) {
popup.menu.findItem(R.id.action_download).isVisible = false
popup.menu.findItem(R.id.action_delete).isVisible = true
}
// Hide bookmark if bookmark
popup.menu.findItem(R.id.action_bookmark).isVisible = !chapter.bookmark
popup.menu.findItem(R.id.action_remove_bookmark).isVisible = chapter.bookmark
// Hide mark as unread when the chapter is unread
if (!chapter.read && chapter.last_page_read == 0) {
popup.menu.findItem(R.id.action_mark_as_unread).isVisible = false
}
// Hide mark as read when the chapter is read
if (chapter.read) {
popup.menu.findItem(R.id.action_mark_as_read).isVisible = false
}
// Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener { menuItem ->
adapter.menuItemListener.onMenuItemClick(adapterPosition, menuItem)
true
}
// Finally show the PopupMenu
popup.show()
}
}

View file

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.manga.chapter
import android.content.Context
import android.view.MenuItem
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
@ -21,8 +20,6 @@ class ChaptersAdapter(
var items: List<ChapterItem> = emptyList()
val menuItemListener: OnMenuItemClickListener = controller
val readColor = context.getResourceColor(android.R.attr.textColorHint)
val unreadColor = context.getResourceColor(android.R.attr.textColorPrimary)
@ -42,8 +39,4 @@ class ChaptersAdapter(
fun indexOf(item: ChapterItem): Int {
return items.indexOf(item)
}
interface OnMenuItemClickListener {
fun onMenuItemClick(position: Int, item: MenuItem)
}
}

View file

@ -42,7 +42,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
ActionMode.Callback,
FlexibleAdapter.OnItemClickListener,
FlexibleAdapter.OnItemLongClickListener,
ChaptersAdapter.OnMenuItemClickListener,
DownloadCustomChaptersDialog.Listener,
DeleteChaptersDialog.Listener {
@ -364,6 +363,15 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
destroyActionModeIfNeeded()
} else {
mode.title = count.toString()
val chapters = getSelectedChapters()
menu.findItem(R.id.action_download).isVisible = chapters.any { !it.isDownloaded }
menu.findItem(R.id.action_delete).isVisible = chapters.any { it.isDownloaded }
menu.findItem(R.id.action_bookmark).isVisible = chapters.any { !it.chapter.bookmark }
menu.findItem(R.id.action_remove_bookmark).isVisible = chapters.any { it.chapter.bookmark }
menu.findItem(R.id.action_mark_as_read).isVisible = chapters.any { !it.chapter.read }
menu.findItem(R.id.action_mark_as_unread).isVisible = chapters.any { it.chapter.read }
menu.findItem(R.id.action_mark_previous_as_read).isVisible = count == 1
}
return false
}
@ -377,6 +385,7 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
R.id.action_select_all -> selectAll()
R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0])
else -> return false
}
return true
@ -394,21 +403,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
super.onDetach(view)
}
override fun onMenuItemClick(position: Int, item: MenuItem) {
val chapter = adapter?.getItem(position) ?: return
val chapters = listOf(chapter)
when (item.itemId) {
R.id.action_download -> downloadChapters(chapters)
R.id.action_delete -> deleteChapters(chapters)
R.id.action_bookmark -> bookmarkChapters(chapters, true)
R.id.action_remove_bookmark -> bookmarkChapters(chapters, false)
R.id.action_mark_as_read -> markAsRead(chapters)
R.id.action_mark_as_unread -> markAsUnread(chapters)
R.id.action_mark_previous_as_read -> markPreviousAsRead(chapter)
}
}
// SELECTION MODE ACTIONS
private fun selectAll() {
@ -431,7 +425,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
private fun downloadChapters(chapters: List<ChapterItem>) {
val view = view
destroyActionModeIfNeeded()
presenter.downloadChapters(chapters)
if (view != null && !presenter.manga.favorite) {
recycler?.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) {
@ -460,12 +453,10 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
}
private fun bookmarkChapters(chapters: List<ChapterItem>, bookmarked: Boolean) {
destroyActionModeIfNeeded()
presenter.bookmarkChapters(chapters, bookmarked)
}
fun deleteChapters(chapters: List<ChapterItem>) {
destroyActionModeIfNeeded()
if (chapters.isEmpty()) return
DeletingChaptersDialog().showDialog(router)

View file

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z"/>
</vector>

View file

@ -15,7 +15,7 @@
android:layout_marginTop="12dp"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintEnd_toStartOf="@+id/chapter_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
@ -34,20 +34,6 @@
app:layout_constraintStart_toStartOf="parent"
tools:text="22/02/2016 • Scanlator • Page: 45" />
<ImageButton
android:id="@+id/chapter_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/action_menu"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/download_text"
app:srcCompat="@drawable/ic_more_vert_black_24dp"
app:tint="?attr/icon_color" />
<TextView
android:id="@+id/download_text"
style="@style/TextAppearance.Regular.Caption.Hint"

View file

@ -17,13 +17,15 @@
<item
android:id="@+id/action_bookmark"
android:icon="@drawable/ic_bookmark_white_24dp"
android:title="@string/action_bookmark"
android:visible="true" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_remove_bookmark"
android:icon="@drawable/ic_bookmark_border_white_24dp"
android:title="@string/action_remove_bookmark"
android:visible="true" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_mark_as_read"
@ -43,4 +45,9 @@
android:title="@string/action_select_all"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_mark_previous_as_read"
android:title="@string/action_mark_previous_as_read"
app:showAsAction="never" />
</menu>

View file

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_download"
android:title="@string/action_download"
android:visible="true" />
<item
android:id="@+id/action_delete"
android:title="@string/action_delete"
android:visible="false" />
<item
android:id="@+id/action_bookmark"
android:title="@string/action_bookmark"
android:visible="true" />
<item
android:id="@+id/action_remove_bookmark"
android:title="@string/action_remove_bookmark"
android:visible="true" />
<item
android:id="@+id/action_mark_as_read"
android:title="@string/action_mark_as_read" />
<item
android:id="@+id/action_mark_as_unread"
android:title="@string/action_mark_as_unread" />
<item
android:id="@+id/action_mark_previous_as_read"
android:title="@string/action_mark_previous_as_read" />
</menu>

View file

@ -25,7 +25,6 @@
<attr name="text_color_primary" format="reference|integer"/>
<attr name="background_card" format="reference|integer"/>
<attr name="colorBackgroundSplash" format="reference|integer"/>
<attr name="icon_color" format="reference|integer"/>
<attr name="tabBarIconColor" format="reference|integer"/>
<attr name="tabBarIconInactive" format="reference|integer"/>

View file

@ -29,7 +29,6 @@
<!-- Actions -->
<string name="action_settings">Settings</string>
<string name="action_menu">Menu</string>
<string name="action_filter">Filter</string>
<string name="action_filter_downloaded">Downloaded</string>
<string name="action_filter_bookmarked">Bookmarked</string>

View file

@ -39,7 +39,6 @@
<item name="selectable_library_drawable">@drawable/library_item_selector_light</item>
<item name="text_color_primary">@color/textColorPrimaryLight</item>
<item name="background_card">@color/dialogLight</item>
<item name="icon_color">@color/iconColorLight</item>
<item name="tabBarIconColor">@android:color/white</item>
<item name="tabBarIconInactive">@color/textColorHintDark</item>
</style>
@ -88,7 +87,6 @@
<item name="selectable_library_drawable">@drawable/library_item_selector_dark</item>
<item name="text_color_primary">@color/textColorPrimaryDark</item>
<item name="background_card">@color/dialogDark</item>
<item name="icon_color">@color/iconColorDark</item>
<item name="tabBarIconColor">@android:color/white</item>
<item name="tabBarIconInactive">@color/textColorHintDark</item>
</style>