mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
Fix crashes in task list
This commit is contained in:
parent
d2a3f52ac7
commit
6b26899017
4 changed files with 6 additions and 68 deletions
|
|
@ -150,7 +150,7 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
multiDexEnabled true
|
||||
|
||||
versionCode 2157
|
||||
versionCode 2159
|
||||
versionName "1.10"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,9 @@ import io.reactivex.functions.Action
|
|||
import io.reactivex.subjects.PublishSubject
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.OrderedRealmCollectionChangeListener
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
|
||||
abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(private var unfilteredData: OrderedRealmCollection<Task>?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : androidx.recyclerview.widget.RecyclerView.Adapter<VH>(), TaskRecyclerViewAdapter {
|
||||
abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(private var unfilteredData: OrderedRealmCollection<Task>?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : RealmRecyclerViewAdapter<Task, VH>(null, true), TaskRecyclerViewAdapter {
|
||||
private var updateOnModification: Boolean = false
|
||||
override var ignoreUpdates: Boolean = false
|
||||
private val listener: OrderedRealmCollectionChangeListener<OrderedRealmCollection<Task>> by lazy {
|
||||
|
|
@ -47,8 +46,6 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
}
|
||||
}
|
||||
}
|
||||
var data: OrderedRealmCollection<Task>? = null
|
||||
private set
|
||||
|
||||
private var errorButtonEventsSubject = PublishSubject.create<String>()
|
||||
override val errorButtonEvents: Flowable<String> = errorButtonEventsSubject.toFlowable(BackpressureStrategy.DROP)
|
||||
|
|
@ -66,79 +63,21 @@ abstract class RealmBaseTasksRecyclerViewAdapter<VH : BaseTaskViewHolder>(privat
|
|||
if (unfilteredData != null && unfilteredData?.isManaged == false) {
|
||||
throw IllegalStateException("Only use this adapter with managed RealmCollection, " + "for un-managed lists you can just use the BaseRecyclerViewAdapter")
|
||||
}
|
||||
this.data = unfilteredData
|
||||
this.updateOnModification = true
|
||||
filter()
|
||||
}
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: androidx.recyclerview.widget.RecyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView)
|
||||
if (hasAutoUpdates && isDataValid) {
|
||||
addListener(data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: androidx.recyclerview.widget.RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
if (hasAutoUpdates && isDataValid) {
|
||||
removeListener(data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemId(index: Int): Long = index.toLong()
|
||||
|
||||
override fun getItemCount(): Int = if (isDataValid) data?.size ?: 0 else 0
|
||||
|
||||
fun getItem(index: Int): Task? = if (isDataValid) data?.get(index) else null
|
||||
|
||||
override fun updateData(tasks: OrderedRealmCollection<Task>?) {
|
||||
if (hasAutoUpdates) {
|
||||
if (isDataValid) {
|
||||
|
||||
removeListener(tasks)
|
||||
}
|
||||
if (tasks != null) {
|
||||
addListener(tasks)
|
||||
}
|
||||
}
|
||||
|
||||
this.data = tasks
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun getItem(index: Int): Task? = if (isDataValid) data?.get(index) else null
|
||||
|
||||
override fun updateUnfilteredData(data: OrderedRealmCollection<Task>?) {
|
||||
unfilteredData = data
|
||||
updateData(data)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun addListener(data: OrderedRealmCollection<Task>?) = when (data) {
|
||||
is RealmResults<*> -> {
|
||||
val results = data as RealmResults<Task>
|
||||
results.addChangeListener(listener as OrderedRealmCollectionChangeListener<RealmResults<Task>>)
|
||||
}
|
||||
is RealmList<*> -> {
|
||||
val list = data as RealmList<Task>
|
||||
list.addChangeListener(listener as OrderedRealmCollectionChangeListener<RealmList<Task>>)
|
||||
}
|
||||
else -> throw IllegalArgumentException("RealmCollection not supported: " + data?.javaClass)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun removeListener(data: OrderedRealmCollection<Task>?) {
|
||||
when (data) {
|
||||
is RealmResults<*> -> {
|
||||
val results = data as RealmResults<Task>
|
||||
results.removeChangeListener(listener as OrderedRealmCollectionChangeListener<RealmResults<Task>>)
|
||||
}
|
||||
is RealmList<*> -> {
|
||||
val list = data as RealmList<Task>
|
||||
list.removeChangeListener(listener as OrderedRealmCollectionChangeListener<RealmList<Task>>)
|
||||
}
|
||||
else -> throw IllegalArgumentException("RealmCollection not supported: " + data?.javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
val item = getItem(position)
|
||||
if (item != null) {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ buildscript {
|
|||
maven { url "https://plugins.gradle.org/m2/" }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath 'com.android.tools.build:gradle:3.4.1'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
classpath 'com.google.gms:google-services:4.2.0'
|
||||
classpath "io.realm:realm-gradle-plugin:5.10.0"
|
||||
classpath "io.realm:realm-gradle-plugin:5.11.0"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0.RC4-3"
|
||||
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0"
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ kotlin {
|
|||
}
|
||||
|
||||
iosMain.dependencies {
|
||||
implementation "com.squareup.sqldelight:ios-driver:1.1.3"
|
||||
}
|
||||
|
||||
iosMain.kotlin.srcDirs += 'src/iosMain/kotlin'
|
||||
|
|
|
|||
Loading…
Reference in a new issue