From 36b893efe1f7aa55514a3dc2f0f70b79fd3df8bc Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Jan 2020 18:33:38 -0800 Subject: [PATCH] Added option to move selected manga in drag & drop mode --- .../ui/library/LibraryCategoryView.kt | 43 ++++++++++++------- .../tachiyomi/ui/library/LibraryController.kt | 20 +++++++-- app/src/main/res/menu/library_selection.xml | 18 +++++++- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 994ca425ed..ddfc3cf9e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -154,21 +154,29 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att subscriptions += controller.reorganizeRelay .subscribe { if (it.first == category.id) { - var items = when (it.second) { + var items:List + if (it.second in 5..6) { + items = adapter.currentItems.toMutableList() + val mangas = controller.selectedMangas + val selectedManga = items.filter { item -> item.manga in mangas } + items.removeAll(selectedManga) + if (it.second == 5) items.addAll(0, selectedManga) + else items.addAll(selectedManga) + } + else { + items = when (it.second) { 1, 2 -> adapter.currentItems.sortedBy { - if (preferences.removeArticles().getOrDefault()) - it.manga.title.removeArticles() - else - it.manga.title + if (preferences.removeArticles().getOrDefault()) it.manga.title.removeArticles() + else it.manga.title } 3, 4 -> adapter.currentItems.sortedBy { it.manga.last_update } - 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.notifyDataSetChanged() - onItemReleased(0) + saveDragSort() } } } @@ -321,16 +329,19 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att override fun onItemReleased(position: Int) { if (adapter.selectedItemCount == 0) { - val mangaIds = adapter.currentItems.mapNotNull { it.manga.id } - category.mangaOrder = mangaIds - val db: DatabaseHelper by injectLazy() - if (category.name == "Default") - preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) - else - db.insertCategory(category).asRxObservable().subscribe() + saveDragSort() } } + private fun saveDragSort() { + val mangaIds = adapter.currentItems.mapNotNull { it.manga.id } + category.mangaOrder = mangaIds + val db: DatabaseHelper by injectLazy() + if (category.name == "Default") + preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) + else + db.insertCategory(category).asRxObservable().subscribe() + } override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean { if (adapter.selectedItemCount > 1) return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 0756989c51..366277a4a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -147,7 +147,7 @@ class LibraryController( /** * Drawer listener to allow swipe only for closing the drawer. */ - private var drawerListener: androidx.drawerlayout.widget.DrawerLayout.DrawerListener? = null + private var drawerListener: DrawerLayout.DrawerListener? = null private var tabsVisibilityRelay: BehaviorRelay = BehaviorRelay.create(false) @@ -247,7 +247,7 @@ class LibraryController( return view } - override fun cleanupSecondaryDrawer(drawer: androidx.drawerlayout.widget.DrawerLayout) { + override fun cleanupSecondaryDrawer(drawer: DrawerLayout) { navView = null } @@ -473,12 +473,18 @@ class LibraryController( menu.findItem(R.id.action_hide_title)?.isVisible = !preferences.libraryAsList().getOrDefault() if (!preferences.libraryAsList().getOrDefault()) { - val showAll = - (selectedMangas.filter { (it as? LibraryManga)?.hide_title == true }).size == selectedMangas.size + val showAll = (selectedMangas.all { (it as? LibraryManga)?.hide_title == true }) menu.findItem(R.id.action_hide_title)?.title = activity?.getString( if (showAll) R.string.action_show_title else R.string.action_hide_title ) } + if (preferences.librarySortingMode().getOrDefault() == LibrarySort.DRAG_AND_DROP) { + val catId = (selectedMangas.first() as? LibraryManga)?.category + val sameCat = (adapter?.categories?.getOrNull(library_pager.currentItem)?.id + == catId) && selectedMangas.all { (it as? LibraryManga)?.category == catId } + menu.findItem(R.id.action_move_manga).isVisible = sameCat + } + else menu.findItem(R.id.action_move_manga).isVisible = false } return false } @@ -516,6 +522,12 @@ class LibraryController( presenter.hideShowTitle(selectedMangas.toList(), !showAll) destroyActionModeIfNeeded() } + R.id.action_to_top, R.id.action_to_bottom -> { + adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let { + reorganizeRelay.call(it to if (item.itemId == R.id.action_to_top) 5 else 6) + } + destroyActionModeIfNeeded() + } else -> return false } return true diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index 05ffadb0f3..183128c8fe 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -25,14 +25,28 @@ + + + + + + + + \ No newline at end of file