Catalogue fixes

This commit is contained in:
len 2017-01-21 18:48:27 +01:00
parent 03967b67cf
commit 1e4a01399d

View file

@ -254,8 +254,8 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(),
(layoutManager as GridLayoutManager).spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { (layoutManager as GridLayoutManager).spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int { override fun getSpanSize(position: Int): Int {
return when (adapter.getItemViewType(position)) { return when (adapter?.getItemViewType(position)) {
R.layout.item_catalogue_grid -> 1 R.layout.item_catalogue_grid, null -> 1
else -> spanCount else -> spanCount
} }
} }
@ -495,7 +495,18 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(),
* @return the holder of the manga or null if it's not bound. * @return the holder of the manga or null if it's not bound.
*/ */
private fun getHolder(manga: Manga): CatalogueHolder? { private fun getHolder(manga: Manga): CatalogueHolder? {
return recycler.findViewHolderForItemId(manga.id!!) as? CatalogueHolder val layoutManager = recycler.layoutManager as LinearLayoutManager
val firstVisiblePos = layoutManager.findFirstVisibleItemPosition()
val lastVisiblePos = layoutManager.findLastVisibleItemPosition()
(firstVisiblePos..lastVisiblePos-1).forEach { i ->
val item = adapter.getItem(i) as? CatalogueItem
if (item != null && item.manga.id!! == manga.id!!) {
return recycler.findViewHolderForLayoutPosition(i) as? CatalogueHolder
}
}
return null
} }
/** /**