Mark range of chapters as read/unread + moved to bottom sheet

This commit is contained in:
Jays2Kings 2021-05-08 15:09:49 -04:00
parent 50ca3fa0c7
commit 3ec46f958d
6 changed files with 119 additions and 30 deletions

View File

@ -30,8 +30,6 @@ import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.core.graphics.drawable.DrawableCompat.setTint
import androidx.core.view.iterator
import androidx.palette.graphics.Palette import androidx.palette.graphics.Palette
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -67,6 +65,7 @@ import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet
import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.BaseController
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
@ -167,7 +166,8 @@ class MangaDetailsController :
private var snack: Snackbar? = null private var snack: Snackbar? = null
val fromCatalogue = args.getBoolean(FROM_CATALOGUE_EXTRA, false) val fromCatalogue = args.getBoolean(FROM_CATALOGUE_EXTRA, false)
private var trackingBottomSheet: TrackingBottomSheet? = null private var trackingBottomSheet: TrackingBottomSheet? = null
private var startingDLChapterPos: Int? = null private var startingRangeChapterPos: Int? = null
private var rangeMode: RangeMode? = null
private var editMangaDialog: EditMangaDialog? = null private var editMangaDialog: EditMangaDialog? = null
var refreshTracker: Int? = null var refreshTracker: Int? = null
var chapterPopupMenu: Pair<Int, PopupMenu>? = null var chapterPopupMenu: Pair<Int, PopupMenu>? = null
@ -574,16 +574,16 @@ class MangaDetailsController :
val chapterItem = (adapter?.getItem(position) as? ChapterItem) ?: return false val chapterItem = (adapter?.getItem(position) as? ChapterItem) ?: return false
val chapter = chapterItem.chapter val chapter = chapterItem.chapter
if (actionMode != null) { if (actionMode != null) {
if (startingDLChapterPos == null) { if (startingRangeChapterPos == null) {
adapter?.addSelection(position) adapter?.addSelection(position)
(binding.recycler.findViewHolderForAdapterPosition(position) as? BaseFlexibleViewHolder) (binding.recycler.findViewHolderForAdapterPosition(position) as? BaseFlexibleViewHolder)
?.toggleActivation() ?.toggleActivation()
(binding.recycler.findViewHolderForAdapterPosition(position) as? ChapterHolder) (binding.recycler.findViewHolderForAdapterPosition(position) as? ChapterHolder)
?.notifyStatus(Download.CHECKED, false, 0) ?.notifyStatus(Download.CHECKED, false, 0)
startingDLChapterPos = position startingRangeChapterPos = position
actionMode?.invalidate() actionMode?.invalidate()
} else { } else {
val startingPosition = startingDLChapterPos ?: return false val startingPosition = startingRangeChapterPos ?: return false
var chapterList = listOf<ChapterItem>() var chapterList = listOf<ChapterItem>()
when { when {
startingPosition > position -> startingPosition > position ->
@ -591,12 +591,17 @@ class MangaDetailsController :
startingPosition <= position -> startingPosition <= position ->
chapterList = presenter.chapters.subList(startingPosition - 1, position) chapterList = presenter.chapters.subList(startingPosition - 1, position)
} }
downloadChapters(chapterList) when (rangeMode) {
RangeMode.Download -> downloadChapters(chapterList)
RangeMode.Read -> markAsRead(chapterList)
RangeMode.Unread -> markAsUnread(chapterList)
}
presenter.fetchChapters(false) presenter.fetchChapters(false)
adapter?.removeSelection(startingPosition) adapter?.removeSelection(startingPosition)
(binding.recycler.findViewHolderForAdapterPosition(startingPosition) as? BaseFlexibleViewHolder) (binding.recycler.findViewHolderForAdapterPosition(startingPosition) as? BaseFlexibleViewHolder)
?.toggleActivation() ?.toggleActivation()
startingDLChapterPos = null startingRangeChapterPos = null
rangeMode = null
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
} }
return false return false
@ -609,24 +614,56 @@ class MangaDetailsController :
override fun onItemLongClick(position: Int) { override fun onItemLongClick(position: Int) {
val adapter = adapter ?: return val adapter = adapter ?: return
val item = (adapter.getItem(position) as? ChapterItem) ?: return val item = (adapter.getItem(position) as? ChapterItem) ?: return
val itemView = getHolder(item)?.itemView ?: return // val itemView = getHolder(item)?.itemView ?: return
val popup = PopupMenu(itemView.context, itemView) val items = listOf(
chapterPopupMenu = position to popup MaterialMenuSheet.MenuSheetItem(
0,
// Inflate our menu resource into the PopupMenu's Menu R.drawable.ic_eye_down_24dp,
popup.menuInflater.inflate(R.menu.chapter_single, popup.menu) R.string.mark_previous_as_read
),
popup.setOnMenuItemClickListener { menuItem -> MaterialMenuSheet.MenuSheetItem(
when (menuItem.itemId) { 1,
R.id.action_mark_previous_as_read -> markPreviousAs(item, true) R.drawable.ic_eye_off_down_24dp,
R.id.action_mark_previous_as_unread -> markPreviousAs(item, false) R.string.mark_previous_as_unread
),
MaterialMenuSheet.MenuSheetItem(
2,
R.drawable.ic_eye_range_24dp,
R.string.mark_range_as_read
),
MaterialMenuSheet.MenuSheetItem(
3,
R.drawable.ic_eye_off_range_24dp,
R.string.mark_range_as_unread
)
)
val menuSheet = MaterialMenuSheet(activity!!, items, item.name) { _, itemPos ->
when (itemPos) {
0 -> markPreviousAs(item, true)
1 -> markPreviousAs(item, false)
2 -> startReadRange(position, RangeMode.Read)
3 -> startReadRange(position, RangeMode.Unread)
} }
chapterPopupMenu = null
true true
} }
menuSheet.show()
// Finally show the PopupMenu // val popup = PopupMenu(itemView.context, itemView)
popup.show() // chapterPopupMenu = position to popup
//
// // Inflate our menu resource into the PopupMenu's Menu
// popup.menuInflater.inflate(R.menu.chapter_single, popup.menu)
//
// popup.setOnMenuItemClickListener { menuItem ->
// when (menuItem.itemId) {
// R.id.action_mark_previous_as_read -> markPreviousAs(item, true)
// R.id.action_mark_previous_as_unread -> markPreviousAs(item, false)
// }
// chapterPopupMenu = null
// true
// }
//
// // Finally show the PopupMenu
// popup.show()
} }
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
@ -1018,6 +1055,13 @@ class MangaDetailsController :
override fun startDownloadRange(position: Int) { override fun startDownloadRange(position: Int) {
if (actionMode == null) createActionModeIfNeeded() if (actionMode == null) createActionModeIfNeeded()
rangeMode = RangeMode.Download
onItemClick(null, position)
}
private fun startReadRange(position: Int, mode: RangeMode) {
if (actionMode == null) createActionModeIfNeeded()
rangeMode = mode
onItemClick(null, position) onItemClick(null, position)
} }
@ -1243,7 +1287,7 @@ class MangaDetailsController :
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean { override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
mode?.title = view?.context?.getString( mode?.title = view?.context?.getString(
if (startingDLChapterPos == null) { if (startingRangeChapterPos == null) {
R.string.select_starting_chapter R.string.select_starting_chapter
} else R.string.select_ending_chapter } else R.string.select_ending_chapter
) )
@ -1253,15 +1297,16 @@ class MangaDetailsController :
override fun onDestroyActionMode(mode: ActionMode?) { override fun onDestroyActionMode(mode: ActionMode?) {
actionMode = null actionMode = null
setStatusBarAndToolbar() setStatusBarAndToolbar()
if (startingDLChapterPos != null) { if (startingRangeChapterPos != null && rangeMode == RangeMode.Download) {
val item = adapter?.getItem(startingDLChapterPos!!) as? ChapterItem val item = adapter?.getItem(startingRangeChapterPos!!) as? ChapterItem
(binding.recycler.findViewHolderForAdapterPosition(startingDLChapterPos!!) as? ChapterHolder)?.notifyStatus( (binding.recycler.findViewHolderForAdapterPosition(startingRangeChapterPos!!) as? ChapterHolder)?.notifyStatus(
item?.status ?: Download.NOT_DOWNLOADED, item?.status ?: Download.NOT_DOWNLOADED,
false, false,
0 0
) )
} }
startingDLChapterPos = null rangeMode = null
startingRangeChapterPos = null
adapter?.mode = SelectableAdapter.Mode.IDLE adapter?.mode = SelectableAdapter.Mode.IDLE
adapter?.clearSelection() adapter?.clearSelection()
return return
@ -1473,5 +1518,11 @@ class MangaDetailsController :
const val FROM_CATALOGUE_EXTRA = "from_catalogue" const val FROM_CATALOGUE_EXTRA = "from_catalogue"
const val MANGA_EXTRA = "manga" const val MANGA_EXTRA = "manga"
private enum class RangeMode {
Download,
Read,
Unread
}
} }
} }

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,9c1.7,0 3,1.3 3,3s-1.3,3 -3,3s-3,-1.3 -3,-3S10.3,9 12,9M12,17c0.5,0 1,-0.1 1.4,-0.2C13.1,17.5 13,18.2 13,19v0.5l-1,0c-5,0 -9.3,-3.1 -11,-7.5c1.7,-4.4 6,-7.5 11,-7.5s9.3,3.1 11,7.5c-0.2,0.6 -0.6,1.3 -0.9,1.9c-0.9,-0.5 -2,-0.9 -3.1,-0.9c-0.8,0 -1.5,0.1 -2.2,0.4C16.9,13 17,12.5 17,12c0,-2.8 -2.2,-5 -5,-5s-5,2.2 -5,5S9.2,17 12,17zM17.7,14.2h1.8v4.1l1.6,-1.6l1.1,1.1l-3.6,3.6L15,17.8l1.1,-1.1l1.6,1.6V14.2z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M15,12c0,0 0,0.1 0,0.2L11.8,9c0.1,0 0.1,0 0.2,0C13.7,9 15,10.3 15,12zM12,7c2.8,0 5,2.2 5,5c0,0.5 -0.1,1 -0.2,1.4c0.7,-0.3 1.4,-0.4 2.2,-0.4c1.1,0 2.2,0.3 3.1,0.8c0.4,-0.6 0.7,-1.2 0.9,-1.8c-1.7,-4.4 -6,-7.5 -11,-7.5c-1.4,0 -2.7,0.2 -4,0.7l2.2,2.1C10.7,7.1 11.3,7 12,7zM13,19c0,-0.8 0.2,-1.5 0.4,-2.2C12.9,16.9 12.5,17 12,17c-2.8,0 -5,-2.2 -5,-5c0,-0.8 0.2,-1.5 0.5,-2.2l1.5,1.5C9,11.6 9,11.8 9,12c0,1.7 1.3,3 3,3c0.2,0 0.4,0 0.7,-0.1l1.1,1.1c0.3,-0.5 0.7,-1 1.1,-1.4L3.3,3L2,4.3l2.3,2.3L4.7,7C3.1,8.3 1.8,10 1,12c1.7,4.4 6,7.5 11,7.5c0.3,0 0.7,0 1,0C13,19.3 13,19.2 13,19zM17.7,18.3l-1.6,-1.6L15,17.8l3.6,3.6l3.6,-3.6l-1.1,-1.1l-1.6,1.6v-4.1h-1.8V18.3z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M11.8,9l3.2,3.2c0,-0.1 0,-0.1 0,-0.2c0,-1.7 -1.3,-3 -3,-3C11.9,9 11.9,9 11.8,9M7.5,9.8l1.5,1.6C9,11.6 9,11.8 9,12c0,1.7 1.3,3 3,3c0.2,0 0.4,0 0.6,-0.1l1.6,1.5C13.5,16.8 12.8,17 12,17c-2.8,0 -5,-2.2 -5,-5C7,11.2 7.2,10.5 7.5,9.8M2,4.3l2.3,2.3L4.7,7c-1.7,1.3 -3,3 -3.7,5c1.7,4.4 6,7.5 11,7.5c1.6,0 3,-0.3 4.4,-0.8l0.4,0.4l2.9,2.9l1.3,-1.3L3.3,3M12,7c2.8,0 5,2.2 5,5c0,0.6 -0.1,1.3 -0.4,1.8l2.9,2.9c1.5,-1.2 2.7,-2.9 3.4,-4.8c-1.7,-4.4 -6,-7.5 -11,-7.5c-1.4,0 -2.7,0.2 -4,0.7l2.2,2.2C10.7,7.1 11.4,7 12,7zM7,22h2v2H7V22M11,22h2v2h-2V22M15,22h2v2h-2V22z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,9c-1.7,0 -3,1.3 -3,3s1.3,3 3,3s3,-1.3 3,-3S13.7,9 12,9M12,17c-2.8,0 -5,-2.2 -5,-5s2.2,-5 5,-5s5,2.2 5,5S14.8,17 12,17M12,4.5c-4.9,0 -9.2,3 -11,7.5c2.4,6.1 9.2,9.1 15.3,6.7c3,-1.2 5.5,-3.6 6.7,-6.7C21.2,7.5 16.9,4.5 12,4.5M7,22h2v2H7V22M11,22h2v2h-2V22M15,22h2v2h-2V22z"/>
</vector>

View File

@ -881,8 +881,10 @@
<string name="mark_all_as_unread">Mark all as unread</string> <string name="mark_all_as_unread">Mark all as unread</string>
<string name="mark_as_read">Mark as read</string> <string name="mark_as_read">Mark as read</string>
<string name="mark_as_unread">Mark as unread</string> <string name="mark_as_unread">Mark as unread</string>
<string name="mark_previous_as_read">Mark previous as read</string> <string name="mark_range_as_read">Mark a range of chapters as read</string>
<string name="mark_previous_as_unread">Mark previous as unread</string> <string name="mark_range_as_unread">Mark a range of chapters as unread</string>
<string name="mark_previous_as_read">Mark previous chapters as read</string>
<string name="mark_previous_as_unread">Mark previous chapters as unread</string>
<string name="menu">menu</string> <string name="menu">menu</string>
<string name="more">More</string> <string name="more">More</string>
<string name="move_to_bottom">Move to bottom</string> <string name="move_to_bottom">Move to bottom</string>