diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt index 7b4916a8de..57c100dc0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt @@ -91,7 +91,9 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli } } - (recycler.layoutManager as LinearLayoutManager).recycleChildrenOnDetach = true + // This crashes when opening a manga after changing categories, but then viewholders aren't + // recycled between pages. It may be fixed if this fragment is replaced with a custom view. + //(recycler.layoutManager as LinearLayoutManager).recycleChildrenOnDetach = true recycler.recycledViewPool = libraryFragment.pool recycler.setHasFixedSize(true) recycler.adapter = adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index 0c3f997f78..fe78be102d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -94,7 +94,10 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback /** * A pool to share view holders between all the registered categories (fragments). */ - var pool = RecyclerView.RecycledViewPool() + var pool = RecyclerView.RecycledViewPool().apply { setMaxRecycledViews(0, 20) } + private set(value) { + field = value.apply { setMaxRecycledViews(0, 20) } + } private var numColumnsSubscription: Subscription? = null @@ -127,8 +130,8 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) setHasOptionsMenu(true) - isFilterDownloaded = presenter.preferences.filterDownloaded().get() as Boolean - isFilterUnread = presenter.preferences.filterUnread().get() as Boolean + isFilterDownloaded = preferences.filterDownloaded().get() as Boolean + isFilterUnread = preferences.filterUnread().get() as Boolean } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? { @@ -142,7 +145,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback view_pager.adapter = adapter view_pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { override fun onPageSelected(position: Int) { - presenter.preferences.lastUsedCategory().set(position) + preferences.lastUsedCategory().set(position) } }) tabs.setupWithViewPager(view_pager) @@ -152,7 +155,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback query = savedState.getString(QUERY_KEY) presenter.searchSubject.onNext(query) } else { - activeCategory = presenter.preferences.lastUsedCategory().getOrDefault() + activeCategory = preferences.lastUsedCategory().getOrDefault() } numColumnsSubscription = getColumnsPreferenceForCurrentOrientation().asObservable() @@ -218,7 +221,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback // Change unread filter status. isFilterUnread = !isFilterUnread // Update settings. - presenter.preferences.filterUnread().set(isFilterUnread) + preferences.filterUnread().set(isFilterUnread) // Apply filter. onFilterCheckboxChanged() } @@ -226,7 +229,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback // Change downloaded filter status. isFilterDownloaded = !isFilterDownloaded // Update settings. - presenter.preferences.filterDownloaded().set(isFilterDownloaded) + preferences.filterDownloaded().set(isFilterDownloaded) // Apply filter. onFilterCheckboxChanged() } @@ -235,8 +238,8 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback isFilterUnread = false isFilterDownloaded = false // Update settings. - presenter.preferences.filterUnread().set(isFilterUnread) - presenter.preferences.filterDownloaded().set(isFilterDownloaded) + preferences.filterUnread().set(isFilterUnread) + preferences.filterDownloaded().set(isFilterDownloaded) // Apply filter onFilterCheckboxChanged() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt index 11a8e11405..62cc4b04c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt @@ -37,8 +37,8 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att override fun onMeasure(widthSpec: Int, heightSpec: Int) { super.onMeasure(widthSpec, heightSpec) if (spanCount == 0 && columnWidth > 0) { - val spanCount = Math.max(1, measuredWidth / columnWidth) - manager.spanCount = spanCount + val count = Math.max(1, measuredWidth / columnWidth) + spanCount = count } }