SuperRecyclerView
SuperRecyclerView copied to clipboard
Fixed a crash when the adapter still triggers the update of the previous recycler view
How to reproduce the bug:
- Assign a non-null adapter
adapterto a SuperRecyclerView instancerecyclerView:recyclerView.setAdapter(adapter) - Assign a null adapter to the
recyclerView:recyclerView.setAdapter(null). - Call
adapter.notifyDataSetChanged().
The recyclerView will get notified since the observer is not cancelled. But now, recyclerView.getAdapter() will return null, this will crash when recyclerView.getAdapter().getCount() is called.
This PR fixed this issue by cancelling the observation once the adapter is changed. (Essentially this is how the official RecyclerView handles adapter changing.)