Fix crashes introduced yesterday

This commit is contained in:
len 2016-07-31 14:07:12 +02:00
parent b6a06189fb
commit 4200409f79
3 changed files with 17 additions and 12 deletions

View File

@ -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.recycledViewPool = libraryFragment.pool
recycler.setHasFixedSize(true) recycler.setHasFixedSize(true)
recycler.adapter = adapter recycler.adapter = adapter

View File

@ -94,7 +94,10 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
/** /**
* A pool to share view holders between all the registered categories (fragments). * 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 private var numColumnsSubscription: Subscription? = null
@ -127,8 +130,8 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState) super.onCreate(savedState)
setHasOptionsMenu(true) setHasOptionsMenu(true)
isFilterDownloaded = presenter.preferences.filterDownloaded().get() as Boolean isFilterDownloaded = preferences.filterDownloaded().get() as Boolean
isFilterUnread = presenter.preferences.filterUnread().get() as Boolean isFilterUnread = preferences.filterUnread().get() as Boolean
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? {
@ -142,7 +145,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
view_pager.adapter = adapter view_pager.adapter = adapter
view_pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { view_pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
presenter.preferences.lastUsedCategory().set(position) preferences.lastUsedCategory().set(position)
} }
}) })
tabs.setupWithViewPager(view_pager) tabs.setupWithViewPager(view_pager)
@ -152,7 +155,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
query = savedState.getString(QUERY_KEY) query = savedState.getString(QUERY_KEY)
presenter.searchSubject.onNext(query) presenter.searchSubject.onNext(query)
} else { } else {
activeCategory = presenter.preferences.lastUsedCategory().getOrDefault() activeCategory = preferences.lastUsedCategory().getOrDefault()
} }
numColumnsSubscription = getColumnsPreferenceForCurrentOrientation().asObservable() numColumnsSubscription = getColumnsPreferenceForCurrentOrientation().asObservable()
@ -218,7 +221,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
// Change unread filter status. // Change unread filter status.
isFilterUnread = !isFilterUnread isFilterUnread = !isFilterUnread
// Update settings. // Update settings.
presenter.preferences.filterUnread().set(isFilterUnread) preferences.filterUnread().set(isFilterUnread)
// Apply filter. // Apply filter.
onFilterCheckboxChanged() onFilterCheckboxChanged()
} }
@ -226,7 +229,7 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
// Change downloaded filter status. // Change downloaded filter status.
isFilterDownloaded = !isFilterDownloaded isFilterDownloaded = !isFilterDownloaded
// Update settings. // Update settings.
presenter.preferences.filterDownloaded().set(isFilterDownloaded) preferences.filterDownloaded().set(isFilterDownloaded)
// Apply filter. // Apply filter.
onFilterCheckboxChanged() onFilterCheckboxChanged()
} }
@ -235,8 +238,8 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
isFilterUnread = false isFilterUnread = false
isFilterDownloaded = false isFilterDownloaded = false
// Update settings. // Update settings.
presenter.preferences.filterUnread().set(isFilterUnread) preferences.filterUnread().set(isFilterUnread)
presenter.preferences.filterDownloaded().set(isFilterDownloaded) preferences.filterDownloaded().set(isFilterDownloaded)
// Apply filter // Apply filter
onFilterCheckboxChanged() onFilterCheckboxChanged()
} }

View File

@ -37,8 +37,8 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
override fun onMeasure(widthSpec: Int, heightSpec: Int) { override fun onMeasure(widthSpec: Int, heightSpec: Int) {
super.onMeasure(widthSpec, heightSpec) super.onMeasure(widthSpec, heightSpec)
if (spanCount == 0 && columnWidth > 0) { if (spanCount == 0 && columnWidth > 0) {
val spanCount = Math.max(1, measuredWidth / columnWidth) val count = Math.max(1, measuredWidth / columnWidth)
manager.spanCount = spanCount spanCount = count
} }
} }