Skip to content

Commit

Permalink
bugfix: null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kroegerama committed Oct 6, 2018
1 parent 7b347a1 commit 8e00d17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class StateRecyclerView @JvmOverloads constructor(
override fun onSaveInstanceState(): Parcelable? {
val bundle = Bundle()
bundle.putParcelable(STATE_SUPER, super.onSaveInstanceState())
bundle.putParcelable(STATE_LAYOUT, layoutManager.onSaveInstanceState())
bundle.putParcelable(STATE_LAYOUT, layoutManager?.onSaveInstanceState())
return bundle
}

override fun onRestoreInstanceState(state: Parcelable) {
var superstate: Parcelable = state
var superstate: Parcelable? = state
if (state is Bundle) {
layoutManagerState = state.getParcelable(STATE_LAYOUT)
superstate = state.getParcelable(STATE_SUPER)
Expand All @@ -31,12 +31,12 @@ class StateRecyclerView @JvmOverloads constructor(

private fun restorePosition() {
if (layoutManagerState != null) {
layoutManager.onRestoreInstanceState(layoutManagerState)
layoutManager?.onRestoreInstanceState(layoutManagerState)
layoutManagerState = null
}
}

override fun setAdapter(adapter: RecyclerView.Adapter<*>) {
override fun setAdapter(adapter: RecyclerView.Adapter<*>?) {
super.setAdapter(adapter)
restorePosition()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StaggeredGridLayoutSpaceItemDecoration(

val lp = view.layoutParams as StaggeredGridLayoutManager.LayoutParams

val count = parent.adapter.itemCount
val count = parent.adapter?.itemCount ?: 0
val pos = lp.viewLayoutPosition

val spanCount = layoutManager.spanCount
Expand Down

0 comments on commit 8e00d17

Please sign in to comment.