diff --git a/Habitica/build.gradle b/Habitica/build.gradle index e0b5dbebe..0009846a6 100644 --- a/Habitica/build.gradle +++ b/Habitica/build.gradle @@ -150,7 +150,7 @@ android { buildConfigField "String", "TESTING_LEVEL", "\"production\"" multiDexEnabled true - versionCode 2157 + versionCode 2159 versionName "1.10" } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/tasks/RealmBaseTasksRecyclerViewAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/tasks/RealmBaseTasksRecyclerViewAdapter.kt index 426b49843..54eeedd1d 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/tasks/RealmBaseTasksRecyclerViewAdapter.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/tasks/RealmBaseTasksRecyclerViewAdapter.kt @@ -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(private var unfilteredData: OrderedRealmCollection?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : androidx.recyclerview.widget.RecyclerView.Adapter(), TaskRecyclerViewAdapter { +abstract class RealmBaseTasksRecyclerViewAdapter(private var unfilteredData: OrderedRealmCollection?, private val hasAutoUpdates: Boolean, private val layoutResource: Int, private val taskFilterHelper: TaskFilterHelper?) : RealmRecyclerViewAdapter(null, true), TaskRecyclerViewAdapter { private var updateOnModification: Boolean = false override var ignoreUpdates: Boolean = false private val listener: OrderedRealmCollectionChangeListener> by lazy { @@ -47,8 +46,6 @@ abstract class RealmBaseTasksRecyclerViewAdapter(privat } } } - var data: OrderedRealmCollection? = null - private set private var errorButtonEventsSubject = PublishSubject.create() override val errorButtonEvents: Flowable = errorButtonEventsSubject.toFlowable(BackpressureStrategy.DROP) @@ -66,79 +63,21 @@ abstract class RealmBaseTasksRecyclerViewAdapter(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?) { - 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?) { unfilteredData = data updateData(data) } - @Suppress("UNCHECKED_CAST") - private fun addListener(data: OrderedRealmCollection?) = when (data) { - is RealmResults<*> -> { - val results = data as RealmResults - results.addChangeListener(listener as OrderedRealmCollectionChangeListener>) - } - is RealmList<*> -> { - val list = data as RealmList - list.addChangeListener(listener as OrderedRealmCollectionChangeListener>) - } - else -> throw IllegalArgumentException("RealmCollection not supported: " + data?.javaClass) - } - - @Suppress("UNCHECKED_CAST") - private fun removeListener(data: OrderedRealmCollection?) { - when (data) { - is RealmResults<*> -> { - val results = data as RealmResults - results.removeChangeListener(listener as OrderedRealmCollectionChangeListener>) - } - is RealmList<*> -> { - val list = data as RealmList - list.removeChangeListener(listener as OrderedRealmCollectionChangeListener>) - } - else -> throw IllegalArgumentException("RealmCollection not supported: " + data?.javaClass) - } - } - override fun onBindViewHolder(holder: VH, position: Int) { val item = getItem(position) if (item != null) { diff --git a/build.gradle b/build.gradle index 02ba3ea24..40ec1019b 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/shared/build.gradle b/shared/build.gradle index 8fdad12ed..8d01d504e 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -50,7 +50,6 @@ kotlin { } iosMain.dependencies { - implementation "com.squareup.sqldelight:ios-driver:1.1.3" } iosMain.kotlin.srcDirs += 'src/iosMain/kotlin'