Fixed long press not working after switching from list to grid

This commit is contained in:
Jay 2020-02-17 23:08:14 -08:00
parent 715507be2a
commit 21d7f342e6
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -503,6 +503,16 @@ class LibraryPresenter(
}
}
fun getList(): List<LibraryItem> {
val list = mutableListOf<LibraryItem>()
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()