From 8332a45028dbd906cb8f27afb0a2878d42173395 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Jan 2020 02:35:45 -0800 Subject: [PATCH] Fixed being able to drag & drop while searching or with filters on Also destroy action mode when leaving library controller or setting a filter --- .../ui/library/LibraryCategoryAdapter.kt | 1 + .../ui/library/LibraryCategoryView.kt | 22 +++++++++++-------- .../tachiyomi/ui/library/LibraryController.kt | 7 ++++++ .../tachiyomi/ui/library/LibraryItem.kt | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 25d2d3cf59..62fe366242 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -64,6 +64,7 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) : if (s == null) { s = "" } + isLongPressDragEnabled = view.canDrag() && s.isNullOrBlank() updateDataSet(mangas.filter { it.filter(s) }) } 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 dd5524ce85..bb5945d385 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 @@ -128,8 +128,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att } else { SelectableAdapter.Mode.SINGLE } - val sortingMode = preferences.librarySortingMode().getOrDefault() - adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP + adapter.isLongPressDragEnabled = canDrag() subscriptions += controller.searchRelay .doOnNext { adapter.setFilter(it) } @@ -174,6 +173,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att } } + fun canDrag(): Boolean { + val sortingMode = preferences.librarySortingMode().getOrDefault() + val filterOff = preferences.filterCompleted().getOrDefault() + + preferences.filterUnread().getOrDefault() + + preferences.filterCompleted().getOrDefault() == 0 + return sortingMode == LibrarySort.DRAG_AND_DROP && filterOff && + adapter.mode != SelectableAdapter.Mode.MULTI + } + fun onRecycle() { adapter.setItems(emptyList()) adapter.clearSelection() @@ -192,10 +200,8 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att */ fun onNextLibraryManga(event: LibraryMangaEvent) { // Get the manga list for this category. - - val sortingMode = preferences.librarySortingMode().getOrDefault() - adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP + adapter.isLongPressDragEnabled = canDrag() var mangaForCategory = event.getMangaForCategory(category).orEmpty() if (sortingMode == LibrarySort.DRAG_AND_DROP) { if (category.name == "Default") @@ -238,16 +244,14 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att if (adapter.indexOf(event.manga) != -1) lastClickPosition = -1 if (controller.selectedMangas.isEmpty()) { adapter.mode = SelectableAdapter.Mode.SINGLE - adapter.isLongPressDragEnabled = preferences.librarySortingMode() - .getOrDefault() == LibrarySort.DRAG_AND_DROP + adapter.isLongPressDragEnabled = canDrag() } } is LibrarySelectionEvent.Cleared -> { adapter.mode = SelectableAdapter.Mode.SINGLE adapter.clearSelection() lastClickPosition = -1 - adapter.isLongPressDragEnabled = preferences.librarySortingMode() - .getOrDefault() == LibrarySort.DRAG_AND_DROP + adapter.isLongPressDragEnabled = canDrag() } } } 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 39bdb0bd52..0756989c51 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 @@ -89,6 +89,8 @@ class LibraryController( */ private var query = "" + private var searchItem:MenuItem? = null + /** * Currently selected mangas. */ @@ -211,6 +213,7 @@ class LibraryController( } override fun onDetach(view: View) { + destroyActionModeIfNeeded() snack?.dismiss() snack = null super.onDetach(view) @@ -322,6 +325,7 @@ class LibraryController( */ private fun onFilterChanged() { presenter.requestFilterUpdate() + destroyActionModeIfNeeded() activity?.invalidateOptionsMenu() } @@ -357,6 +361,7 @@ class LibraryController( fun createActionModeIfNeeded() { if (actionMode == null) { actionMode = (activity as AppCompatActivity).startSupportActionMode(this) + searchItem?.collapseActionView() } } @@ -376,7 +381,9 @@ class LibraryController( val searchItem = menu.findItem(R.id.action_search) val searchView = searchItem.actionView as SearchView searchView.queryHint = resources?.getString(R.string.search_hint) + this.searchItem = searchItem + searchItem.collapseActionView() if (!query.isEmpty()) { searchItem.expandActionView() searchView.setQuery(query, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index d5dff0589a..6b7a355d51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -82,6 +82,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference @SuppressLint("DefaultLocale") private fun containsGenre(tag: String, genres: List?): Boolean { + if (tag.trim().isEmpty()) return true return if (tag.startsWith("-")) genres?.find { it.trim().toLowerCase() == tag.substringAfter("-").toLowerCase()