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()