Fix crash when ViewHolder's adapterPosition is -1

This should address #1340
This commit is contained in:
moezbhatti
2019-04-01 02:30:13 -04:00
parent 408eca5b2b
commit 0f7714138e
8 changed files with 27 additions and 17 deletions
@@ -28,6 +28,7 @@ import io.realm.RealmList
import io.realm.RealmModel
import io.realm.RealmRecyclerViewAdapter
import io.realm.RealmResults
import timber.log.Timber
abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkViewHolder>(null, true) {
@@ -79,6 +80,15 @@ abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkVi
notifyDataSetChanged()
}
override fun getItem(index: Int): T? {
if (index < 0) {
Timber.w("Only indexes >= 0 are allowed. Input was: $index")
return null
}
return super.getItem(index)
}
override fun updateData(data: OrderedRealmCollection<T>?) {
if (getData() === data) return