mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 18:47:51 +02:00
Remove chapter updates popup menu
This commit is contained in:
@ -296,7 +296,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||
* @param menu menu object of ActionMode
|
||||
*/
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.chapter_recent_selection, menu)
|
||||
mode.menuInflater.inflate(R.menu.updates_chapter_selection, menu)
|
||||
adapter?.mode = SelectableAdapter.Mode.MULTI
|
||||
return true
|
||||
}
|
||||
@ -308,7 +308,14 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||
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_mark_as_read).isVisible = chapters.any { !it.chapter.read }
|
||||
menu.findItem(R.id.action_mark_as_unread).isVisible = chapters.any { it.chapter.read }
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -319,11 +326,11 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||
*/
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
||||
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
|
||||
R.id.action_download -> downloadChapters(getSelectedChapters())
|
||||
R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters())
|
||||
.showDialog(router)
|
||||
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
||||
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
|
@ -1,14 +1,12 @@
|
||||
package eu.kanade.tachiyomi.ui.recent.updates
|
||||
|
||||
import android.view.View
|
||||
import android.widget.PopupMenu
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import kotlinx.android.synthetic.main.updates_item.chapter_menu
|
||||
import kotlinx.android.synthetic.main.updates_item.chapter_title
|
||||
import kotlinx.android.synthetic.main.updates_item.download_text
|
||||
import kotlinx.android.synthetic.main.updates_item.manga_cover
|
||||
@ -43,10 +41,6 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
||||
private var item: UpdatesItem? = null
|
||||
|
||||
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) } }
|
||||
manga_cover.setOnClickListener {
|
||||
adapter.coverClickListener.onCoverClick(adapterPosition)
|
||||
}
|
||||
@ -103,50 +97,4 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
||||
else -> text = ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show pop up menu
|
||||
*
|
||||
* @param view view containing popup menu.
|
||||
*/
|
||||
private fun showPopupMenu(view: View) = item?.let { item ->
|
||||
// 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_recent, popup.menu)
|
||||
|
||||
// Hide download and show delete if the chapter is downloaded and
|
||||
if (item.isDownloaded) {
|
||||
popup.menu.findItem(R.id.action_download).isVisible = false
|
||||
popup.menu.findItem(R.id.action_delete).isVisible = true
|
||||
}
|
||||
|
||||
// Hide mark as unread when the chapter is unread
|
||||
if (!item.chapter.read /*&& mangaChapter.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 (item.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 ->
|
||||
with(adapter.controller) {
|
||||
when (menuItem.itemId) {
|
||||
R.id.action_download -> downloadChapter(item)
|
||||
R.id.action_delete -> deleteChapter(item)
|
||||
R.id.action_mark_as_read -> markAsRead(listOf(item))
|
||||
R.id.action_mark_as_unread -> markAsUnread(listOf(item))
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
// Finally show the PopupMenu
|
||||
popup.show()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user