mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 16:11:51 +01:00
Reordering Drag & Drop via menu keeps the sort order when adding new manga
This commit is contained in:
parent
f5ffbd4eb4
commit
ab75f44d9c
@ -41,8 +41,12 @@ class CategoryPutResolver : DefaultPutResolver<Category>() {
|
|||||||
put(COL_NAME, obj.name)
|
put(COL_NAME, obj.name)
|
||||||
put(COL_ORDER, obj.order)
|
put(COL_ORDER, obj.order)
|
||||||
put(COL_FLAGS, obj.flags)
|
put(COL_FLAGS, obj.flags)
|
||||||
|
if (obj.mangaSort != null)
|
||||||
|
put(COL_MANGA_ORDER, obj.mangaSort.toString())
|
||||||
|
else {
|
||||||
val orderString = obj.mangaOrder.joinToString("/")
|
val orderString = obj.mangaOrder.joinToString("/")
|
||||||
put(COL_MANGA_ORDER, orderString)
|
put(COL_MANGA_ORDER, orderString)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,6 +60,11 @@ class CategoryGetResolver : DefaultGetResolver<Category>() {
|
|||||||
flags = cursor.getInt(cursor.getColumnIndex(COL_FLAGS))
|
flags = cursor.getInt(cursor.getColumnIndex(COL_FLAGS))
|
||||||
|
|
||||||
val orderString = cursor.getString(cursor.getColumnIndex(COL_MANGA_ORDER))
|
val orderString = cursor.getString(cursor.getColumnIndex(COL_MANGA_ORDER))
|
||||||
|
if (orderString.firstOrNull()?.isLetter() == true) {
|
||||||
|
mangaSort = orderString.first()
|
||||||
|
mangaOrder = emptyList()
|
||||||
|
}
|
||||||
|
else
|
||||||
mangaOrder = orderString?.split("/")?.mapNotNull { it.toLongOrNull() } ?: emptyList()
|
mangaOrder = orderString?.split("/")?.mapNotNull { it.toLongOrNull() } ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ interface Category : Serializable {
|
|||||||
|
|
||||||
var mangaOrder:List<Long>
|
var mangaOrder:List<Long>
|
||||||
|
|
||||||
|
var mangaSort:Char?
|
||||||
|
|
||||||
val nameLower: String
|
val nameLower: String
|
||||||
get() = name.toLowerCase()
|
get() = name.toLowerCase()
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ class CategoryImpl : Category {
|
|||||||
|
|
||||||
override var mangaOrder: List<Long> = emptyList()
|
override var mangaOrder: List<Long> = emptyList()
|
||||||
|
|
||||||
|
override var mangaSort: Char? = null
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other == null || javaClass != other.javaClass) return false
|
if (other == null || javaClass != other.javaClass) return false
|
||||||
|
@ -13,6 +13,7 @@ import eu.davidea.flexibleadapter.SelectableAdapter
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
|
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
@ -45,6 +46,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
*/
|
*/
|
||||||
private lateinit var controller: LibraryController
|
private lateinit var controller: LibraryController
|
||||||
|
|
||||||
|
private val db: DatabaseHelper by injectLazy()
|
||||||
/**
|
/**
|
||||||
* Category for this view.
|
* Category for this view.
|
||||||
*/
|
*/
|
||||||
@ -162,6 +164,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
items.removeAll(selectedManga)
|
items.removeAll(selectedManga)
|
||||||
if (it.second == 5) items.addAll(0, selectedManga)
|
if (it.second == 5) items.addAll(0, selectedManga)
|
||||||
else items.addAll(selectedManga)
|
else items.addAll(selectedManga)
|
||||||
|
adapter.setItems(items)
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
saveDragSort()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
items = when (it.second) {
|
items = when (it.second) {
|
||||||
@ -173,10 +178,14 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
else -> adapter.currentItems.sortedBy { it.manga.title }
|
else -> adapter.currentItems.sortedBy { it.manga.title }
|
||||||
}
|
}
|
||||||
if (it.second % 2 == 0) items = items.reversed()
|
if (it.second % 2 == 0) items = items.reversed()
|
||||||
}
|
|
||||||
adapter.setItems(items)
|
adapter.setItems(items)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
saveDragSort()
|
category.mangaSort = ('a' + (it.second - 1))
|
||||||
|
if (category.name == "Default")
|
||||||
|
preferences.defaultMangaOrder().set(category.mangaSort.toString())
|
||||||
|
else
|
||||||
|
db.insertCategory(category).asRxObservable().subscribe()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,13 +221,9 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
val sortingMode = preferences.librarySortingMode().getOrDefault()
|
val sortingMode = preferences.librarySortingMode().getOrDefault()
|
||||||
adapter.isLongPressDragEnabled = canDrag()
|
adapter.isLongPressDragEnabled = canDrag()
|
||||||
var mangaForCategory = event.getMangaForCategory(category).orEmpty()
|
var mangaForCategory = event.getMangaForCategory(category).orEmpty()
|
||||||
if (sortingMode == LibrarySort.DRAG_AND_DROP) {
|
if (sortingMode == LibrarySort.DRAG_AND_DROP)
|
||||||
if (category.name == "Default")
|
mangaForCategory = sortMangaInDragAnDrop(mangaForCategory)
|
||||||
category.mangaOrder = preferences.defaultMangaOrder().getOrDefault().split("/")
|
|
||||||
.mapNotNull { it.toLongOrNull() }
|
|
||||||
mangaForCategory = mangaForCategory.sortedBy { category.mangaOrder.indexOf(it.manga
|
|
||||||
.id) }
|
|
||||||
}
|
|
||||||
// Update the category with its manga.
|
// Update the category with its manga.
|
||||||
adapter.setItems(mangaForCategory)
|
adapter.setItems(mangaForCategory)
|
||||||
|
|
||||||
@ -233,6 +238,32 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sortMangaInDragAnDrop(mangaForCategory: List<LibraryItem>): List<LibraryItem> {
|
||||||
|
if (category.name == "Default") {
|
||||||
|
val defOrder = preferences.defaultMangaOrder().getOrDefault()
|
||||||
|
if (defOrder.first().isLetter()) category.mangaSort = defOrder.first()
|
||||||
|
else category.mangaOrder = defOrder.split("/").mapNotNull { it.toLongOrNull() }
|
||||||
|
}
|
||||||
|
return if (category.mangaSort != null) {
|
||||||
|
var mangas = when (category.mangaSort) {
|
||||||
|
'a', 'b' -> mangaForCategory.sortedBy {
|
||||||
|
if (preferences.removeArticles().getOrDefault()) it.manga.title.removeArticles()
|
||||||
|
else it.manga.title
|
||||||
|
}
|
||||||
|
'c', 'd' -> mangaForCategory.sortedBy { it.manga.last_update }
|
||||||
|
else -> mangaForCategory.sortedBy { it.manga.title }
|
||||||
|
}
|
||||||
|
if (category.mangaSort == 'b' || category.mangaSort == 'd')
|
||||||
|
mangas = mangas.asReversed()
|
||||||
|
mangas
|
||||||
|
|
||||||
|
} else mangaForCategory.sortedBy {
|
||||||
|
category.mangaOrder.indexOf(
|
||||||
|
it.manga.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to [LibrarySelectionEvent]. When an event is received, it updates the selection
|
* Subscribe to [LibrarySelectionEvent]. When an event is received, it updates the selection
|
||||||
* depending on the type of event received.
|
* depending on the type of event received.
|
||||||
@ -336,8 +367,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
|
|
||||||
private fun saveDragSort() {
|
private fun saveDragSort() {
|
||||||
val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
|
val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
|
||||||
|
category.mangaSort = null
|
||||||
category.mangaOrder = mangaIds
|
category.mangaOrder = mangaIds
|
||||||
val db: DatabaseHelper by injectLazy()
|
|
||||||
if (category.name == "Default")
|
if (category.name == "Default")
|
||||||
preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
|
preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user