mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 22:41:48 +01:00
Remove chapter item popup menu
This commit is contained in:
parent
4061232fe3
commit
c275adbb91
@ -1,29 +1,20 @@
|
|||||||
package eu.kanade.tachiyomi.ui.manga.chapter
|
package eu.kanade.tachiyomi.ui.manga.chapter
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.PopupMenu
|
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import kotlinx.android.synthetic.main.chapters_item.chapter_description
|
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.chapter_title
|
||||||
import kotlinx.android.synthetic.main.chapters_item.download_text
|
import kotlinx.android.synthetic.main.chapters_item.download_text
|
||||||
|
|
||||||
class ChapterHolder(
|
class ChapterHolder(
|
||||||
private val view: View,
|
view: View,
|
||||||
private val adapter: ChaptersAdapter
|
private val adapter: ChaptersAdapter
|
||||||
) : BaseFlexibleViewHolder(view, adapter) {
|
) : 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) {
|
fun bind(item: ChapterItem, manga: Manga) {
|
||||||
val chapter = item.chapter
|
val chapter = item.chapter
|
||||||
|
|
||||||
@ -73,45 +64,4 @@ class ChapterHolder(
|
|||||||
else -> text = ""
|
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.manga.chapter
|
package eu.kanade.tachiyomi.ui.manga.chapter
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.MenuItem
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
@ -21,8 +20,6 @@ class ChaptersAdapter(
|
|||||||
|
|
||||||
var items: List<ChapterItem> = emptyList()
|
var items: List<ChapterItem> = emptyList()
|
||||||
|
|
||||||
val menuItemListener: OnMenuItemClickListener = controller
|
|
||||||
|
|
||||||
val readColor = context.getResourceColor(android.R.attr.textColorHint)
|
val readColor = context.getResourceColor(android.R.attr.textColorHint)
|
||||||
|
|
||||||
val unreadColor = context.getResourceColor(android.R.attr.textColorPrimary)
|
val unreadColor = context.getResourceColor(android.R.attr.textColorPrimary)
|
||||||
@ -42,8 +39,4 @@ class ChaptersAdapter(
|
|||||||
fun indexOf(item: ChapterItem): Int {
|
fun indexOf(item: ChapterItem): Int {
|
||||||
return items.indexOf(item)
|
return items.indexOf(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnMenuItemClickListener {
|
|
||||||
fun onMenuItemClick(position: Int, item: MenuItem)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
FlexibleAdapter.OnItemLongClickListener,
|
FlexibleAdapter.OnItemLongClickListener,
|
||||||
ChaptersAdapter.OnMenuItemClickListener,
|
|
||||||
DownloadCustomChaptersDialog.Listener,
|
DownloadCustomChaptersDialog.Listener,
|
||||||
DeleteChaptersDialog.Listener {
|
DeleteChaptersDialog.Listener {
|
||||||
|
|
||||||
@ -364,6 +363,15 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
destroyActionModeIfNeeded()
|
destroyActionModeIfNeeded()
|
||||||
} else {
|
} else {
|
||||||
mode.title = count.toString()
|
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
|
return false
|
||||||
}
|
}
|
||||||
@ -377,6 +385,7 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
||||||
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
|
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
|
||||||
R.id.action_select_all -> selectAll()
|
R.id.action_select_all -> selectAll()
|
||||||
|
R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0])
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -394,21 +403,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
super.onDetach(view)
|
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
|
// SELECTION MODE ACTIONS
|
||||||
|
|
||||||
private fun selectAll() {
|
private fun selectAll() {
|
||||||
@ -431,7 +425,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
|
|
||||||
private fun downloadChapters(chapters: List<ChapterItem>) {
|
private fun downloadChapters(chapters: List<ChapterItem>) {
|
||||||
val view = view
|
val view = view
|
||||||
destroyActionModeIfNeeded()
|
|
||||||
presenter.downloadChapters(chapters)
|
presenter.downloadChapters(chapters)
|
||||||
if (view != null && !presenter.manga.favorite) {
|
if (view != null && !presenter.manga.favorite) {
|
||||||
recycler?.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) {
|
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) {
|
private fun bookmarkChapters(chapters: List<ChapterItem>, bookmarked: Boolean) {
|
||||||
destroyActionModeIfNeeded()
|
|
||||||
presenter.bookmarkChapters(chapters, bookmarked)
|
presenter.bookmarkChapters(chapters, bookmarked)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteChapters(chapters: List<ChapterItem>) {
|
fun deleteChapters(chapters: List<ChapterItem>) {
|
||||||
destroyActionModeIfNeeded()
|
|
||||||
if (chapters.isEmpty()) return
|
if (chapters.isEmpty()) return
|
||||||
|
|
||||||
DeletingChaptersDialog().showDialog(router)
|
DeletingChaptersDialog().showDialog(router)
|
||||||
|
@ -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>
|
|
@ -15,7 +15,7 @@
|
|||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/chapter_menu"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:text="Title" />
|
tools:text="Title" />
|
||||||
@ -34,20 +34,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
tools:text="22/02/2016 • Scanlator • Page: 45" />
|
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
|
<TextView
|
||||||
android:id="@+id/download_text"
|
android:id="@+id/download_text"
|
||||||
style="@style/TextAppearance.Regular.Caption.Hint"
|
style="@style/TextAppearance.Regular.Caption.Hint"
|
||||||
|
@ -17,13 +17,15 @@
|
|||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_bookmark"
|
android:id="@+id/action_bookmark"
|
||||||
|
android:icon="@drawable/ic_bookmark_white_24dp"
|
||||||
android:title="@string/action_bookmark"
|
android:title="@string/action_bookmark"
|
||||||
android:visible="true" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_remove_bookmark"
|
android:id="@+id/action_remove_bookmark"
|
||||||
|
android:icon="@drawable/ic_bookmark_border_white_24dp"
|
||||||
android:title="@string/action_remove_bookmark"
|
android:title="@string/action_remove_bookmark"
|
||||||
android:visible="true" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_mark_as_read"
|
android:id="@+id/action_mark_as_read"
|
||||||
@ -43,4 +45,9 @@
|
|||||||
android:title="@string/action_select_all"
|
android:title="@string/action_select_all"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_mark_previous_as_read"
|
||||||
|
android:title="@string/action_mark_previous_as_read"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -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>
|
|
@ -25,7 +25,6 @@
|
|||||||
<attr name="text_color_primary" format="reference|integer"/>
|
<attr name="text_color_primary" format="reference|integer"/>
|
||||||
<attr name="background_card" format="reference|integer"/>
|
<attr name="background_card" format="reference|integer"/>
|
||||||
<attr name="colorBackgroundSplash" format="reference|integer"/>
|
<attr name="colorBackgroundSplash" format="reference|integer"/>
|
||||||
<attr name="icon_color" format="reference|integer"/>
|
|
||||||
<attr name="tabBarIconColor" format="reference|integer"/>
|
<attr name="tabBarIconColor" format="reference|integer"/>
|
||||||
<attr name="tabBarIconInactive" format="reference|integer"/>
|
<attr name="tabBarIconInactive" format="reference|integer"/>
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="action_menu">Menu</string>
|
|
||||||
<string name="action_filter">Filter</string>
|
<string name="action_filter">Filter</string>
|
||||||
<string name="action_filter_downloaded">Downloaded</string>
|
<string name="action_filter_downloaded">Downloaded</string>
|
||||||
<string name="action_filter_bookmarked">Bookmarked</string>
|
<string name="action_filter_bookmarked">Bookmarked</string>
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
<item name="selectable_library_drawable">@drawable/library_item_selector_light</item>
|
<item name="selectable_library_drawable">@drawable/library_item_selector_light</item>
|
||||||
<item name="text_color_primary">@color/textColorPrimaryLight</item>
|
<item name="text_color_primary">@color/textColorPrimaryLight</item>
|
||||||
<item name="background_card">@color/dialogLight</item>
|
<item name="background_card">@color/dialogLight</item>
|
||||||
<item name="icon_color">@color/iconColorLight</item>
|
|
||||||
<item name="tabBarIconColor">@android:color/white</item>
|
<item name="tabBarIconColor">@android:color/white</item>
|
||||||
<item name="tabBarIconInactive">@color/textColorHintDark</item>
|
<item name="tabBarIconInactive">@color/textColorHintDark</item>
|
||||||
</style>
|
</style>
|
||||||
@ -88,7 +87,6 @@
|
|||||||
<item name="selectable_library_drawable">@drawable/library_item_selector_dark</item>
|
<item name="selectable_library_drawable">@drawable/library_item_selector_dark</item>
|
||||||
<item name="text_color_primary">@color/textColorPrimaryDark</item>
|
<item name="text_color_primary">@color/textColorPrimaryDark</item>
|
||||||
<item name="background_card">@color/dialogDark</item>
|
<item name="background_card">@color/dialogDark</item>
|
||||||
<item name="icon_color">@color/iconColorDark</item>
|
|
||||||
<item name="tabBarIconColor">@android:color/white</item>
|
<item name="tabBarIconColor">@android:color/white</item>
|
||||||
<item name="tabBarIconInactive">@color/textColorHintDark</item>
|
<item name="tabBarIconInactive">@color/textColorHintDark</item>
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user