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.setHasFixedSize(true)
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).
*/
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<LibraryPresenter>(), 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<LibraryPresenter>(), 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<LibraryPresenter>(), 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<LibraryPresenter>(), 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<LibraryPresenter>(), 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<LibraryPresenter>(), 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()
}

View File

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