From 21d7f342e6e45a99b9db7619b69705d0c547b522 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 17 Feb 2020 23:08:14 -0800 Subject: [PATCH] Fixed long press not working after switching from list to grid --- .../kanade/tachiyomi/ui/library/LibraryController.kt | 9 ++++++++- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 e2009a255b..f53f5847aa 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 @@ -596,6 +596,7 @@ class LibraryController( val position = (recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() if (recycler is AutofitRecyclerView && preferences.libraryLayout().getOrDefault() == 0 || recycler !is AutofitRecyclerView && preferences.libraryLayout().getOrDefault() > 0) { + destroyActionModeIfNeeded() recycler_layout.removeView(recycler) recycler = if (preferences.libraryLayout().getOrDefault() == 0) { (recycler_layout.inflate(R.layout.library_list_recycler) as RecyclerView).apply { @@ -614,10 +615,16 @@ class LibraryController( } } recycler.setHasFixedSize(true) + adapter = LibraryCategoryAdapter(this) + recycler.adapter = adapter recycler.addOnScrollListener(scrollListener) + adapter.isLongPressDragEnabled = canDrag() recycler_layout.addView(recycler) + adapter.setItems(presenter.getList()) + } else { + recycler.adapter = adapter } - recycler.adapter = adapter + (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0) //val adapter = adapter ?: return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 71f11d090e..2666257aeb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -503,6 +503,16 @@ class LibraryPresenter( } } + fun getList(): List { + val list = mutableListOf() + for (element in currentMangaMap!!.toSortedMap(compareBy { entry -> + categories.find { it.id == entry }?.order ?: -1 + })) { + list.addAll(element.value) + } + return list + } + fun updateViewBlocking() { /* val list = withContext(Dispatchers.IO) { val showCategories = !preferences.hideCategories().getOrDefault()