mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 17:41:50 +01:00
Disabling drag and drop in library unless selected as the sort option
So the option for DnD now appears in sort list, otherwise categories not in DnD mode are locked
This commit is contained in:
parent
a0dba53128
commit
d4a754b92d
@ -34,7 +34,7 @@ interface Category : Serializable {
|
||||
return ((mangaSort?.minus('a') ?: 0) % 2) != 1
|
||||
}
|
||||
|
||||
fun sortingMode(): Int? = when (mangaSort) {
|
||||
fun sortingMode(nullAsDND: Boolean = false): Int? = when (mangaSort) {
|
||||
ALPHA_ASC, ALPHA_DSC -> LibrarySort.ALPHA
|
||||
UPDATED_ASC, UPDATED_DSC -> LibrarySort.LATEST_CHAPTER
|
||||
UNREAD_ASC, UNREAD_DSC -> LibrarySort.UNREAD
|
||||
@ -42,9 +42,12 @@ interface Category : Serializable {
|
||||
TOTAL_ASC, TOTAL_DSC -> LibrarySort.TOTAL
|
||||
DRAG_AND_DROP -> LibrarySort.DRAG_AND_DROP
|
||||
DATE_ADDED_ASC, DATE_ADDED_DSC -> LibrarySort.DATE_ADDED
|
||||
else -> null
|
||||
else -> if (nullAsDND && !isDynamic) LibrarySort.DRAG_AND_DROP else null
|
||||
}
|
||||
|
||||
val isDragAndDrop
|
||||
get() = (mangaSort == null || mangaSort == DRAG_AND_DROP) && !isDynamic
|
||||
|
||||
fun sortRes(): Int = when (mangaSort) {
|
||||
ALPHA_ASC, ALPHA_DSC -> R.string.title
|
||||
UPDATED_ASC, UPDATED_DSC -> R.string.latest_chapter
|
||||
|
@ -30,6 +30,7 @@ interface Manga : SManga {
|
||||
var hide_title: Boolean
|
||||
|
||||
fun isBlank() = id == Long.MIN_VALUE
|
||||
fun isHidden() = status == -1
|
||||
|
||||
fun setChapterOrder(order: Int) {
|
||||
setFlags(order, SORT_MASK)
|
||||
|
@ -64,6 +64,17 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position in the adapter for the given manga.
|
||||
*
|
||||
* @param manga the manga to find.
|
||||
*/
|
||||
fun findCategoryHeader(catId: Int): LibraryHeaderItem? {
|
||||
return currentItems.find {
|
||||
(it is LibraryHeaderItem) && it.category.id == catId
|
||||
} as LibraryHeaderItem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position in the adapter for the given manga.
|
||||
*
|
||||
|
@ -1402,8 +1402,17 @@ class LibraryController(
|
||||
}
|
||||
|
||||
override fun sortCategory(catId: Int, sortBy: Int) {
|
||||
val category = presenter.categories.find { it.id == catId }
|
||||
if (category?.isDynamic == false && ('a' + (sortBy - 1)) == Category.DRAG_AND_DROP) {
|
||||
val item = adapter.findCategoryHeader(catId) ?: return
|
||||
val libraryItems = adapter.getSectionItems(item)
|
||||
.filterIsInstance<LibraryItem>()
|
||||
val mangaIds = libraryItems.mapNotNull { (it as? LibraryItem)?.manga?.id }
|
||||
presenter.rearrangeCategory(catId, mangaIds)
|
||||
} else {
|
||||
presenter.sortCategory(catId, sortBy)
|
||||
}
|
||||
}
|
||||
|
||||
override fun selectAll(position: Int) {
|
||||
val header = adapter.getSectionHeader(position) ?: return
|
||||
|
@ -184,8 +184,16 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
R.string.category
|
||||
)
|
||||
)
|
||||
} else {
|
||||
items.add(
|
||||
MaterialMenuSheet.MenuSheetItem(
|
||||
LibrarySort.DRAG_AND_DROP,
|
||||
R.drawable.ic_swap_vert_24dp,
|
||||
R.string.drag_and_drop
|
||||
)
|
||||
)
|
||||
}
|
||||
val sortingMode = category.sortingMode()
|
||||
val sortingMode = category.sortingMode(true)
|
||||
val sheet = MaterialMenuSheet(
|
||||
activity,
|
||||
items,
|
||||
|
@ -61,8 +61,17 @@ abstract class LibraryHolder(
|
||||
|
||||
override fun onLongClick(view: View?): Boolean {
|
||||
return if (adapter.isLongPressDragEnabled) {
|
||||
val manga = (adapter.getItem(flexibleAdapterPosition) as LibraryItem).manga
|
||||
if (!isDraggable && !manga.isBlank() && !manga.isHidden()) {
|
||||
adapter.mItemLongClickListener.onItemLongClick(flexibleAdapterPosition)
|
||||
toggleActivation()
|
||||
true
|
||||
} else {
|
||||
super.onLongClick(view)
|
||||
false
|
||||
} else super.onLongClick(view)
|
||||
}
|
||||
} else {
|
||||
super.onLongClick(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class LibraryItem(
|
||||
* Returns true if this item is draggable.
|
||||
*/
|
||||
override fun isDraggable(): Boolean {
|
||||
return !manga.isBlank()
|
||||
return !manga.isBlank() && header.category.isDragAndDrop
|
||||
}
|
||||
|
||||
override fun isEnabled(): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user