|
|
|
@ -1,14 +1,12 @@ |
|
|
|
package net.pokeranalytics.android.util.extensions |
|
|
|
package net.pokeranalytics.android.util.extensions |
|
|
|
|
|
|
|
|
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.* |
|
|
|
import io.realm.RealmModel |
|
|
|
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
|
|
|
import io.realm.Sort |
|
|
|
|
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.kotlin.where |
|
|
|
import net.pokeranalytics.android.model.interfaces.CountableUsage |
|
|
|
import net.pokeranalytics.android.model.interfaces.CountableUsage |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterableType |
|
|
|
|
|
|
|
|
|
|
|
fun <T : Identifiable> Realm.findById(clazz: Class<T>, id: String) : T? { |
|
|
|
fun <T : Identifiable> Realm.findById(clazz: Class<T>, id: String) : T? { |
|
|
|
return this.where(clazz).equalTo("id", id).findFirst() |
|
|
|
return this.where(clazz).equalTo("id", id).findFirst() |
|
|
|
@ -37,15 +35,19 @@ inline fun <reified T: NameManageable> Realm.getOrCreate(name: String) : T { |
|
|
|
* Returns all entities of the [clazz] sorted with their default sorting |
|
|
|
* Returns all entities of the [clazz] sorted with their default sorting |
|
|
|
* Set [editableOnly] to true to only receive entities that can be edited |
|
|
|
* Set [editableOnly] to true to only receive entities that can be edited |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun < T : RealmModel> Realm.sorted(clazz: Class<T>, editableOnly: Boolean = false) : RealmResults<T> { |
|
|
|
fun < T : RealmModel> Realm.sorted(clazz: Class<T>, editableOnly: Boolean = false, filterableTypeOrdinal: Int? = null) : RealmResults<T> { |
|
|
|
val query = this.where(clazz) |
|
|
|
val query = this.where(clazz) |
|
|
|
|
|
|
|
|
|
|
|
if (editableOnly) { |
|
|
|
|
|
|
|
when (clazz.kotlin) { |
|
|
|
when (clazz.kotlin) { |
|
|
|
TransactionType::class -> { |
|
|
|
TransactionType::class -> { |
|
|
|
|
|
|
|
if (editableOnly) { |
|
|
|
query.equalTo("lock", false) |
|
|
|
query.equalTo("lock", false) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Filter::class -> { |
|
|
|
|
|
|
|
filterableTypeOrdinal?.let { |
|
|
|
|
|
|
|
query.equalTo("filterableTypeOrdinal", it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val items = query.findAll() |
|
|
|
val items = query.findAll() |
|
|
|
|