|
|
|
|
@ -8,10 +8,7 @@ import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.CountableUsage |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.model.realm.TournamentFeature |
|
|
|
|
import net.pokeranalytics.android.model.realm.Transaction |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
|
|
|
|
|
fun <T : Identifiable> Realm.findById(clazz: Class<T>, id: String) : T? { |
|
|
|
|
return this.where(clazz).equalTo("id", id).findFirst() |
|
|
|
|
@ -38,9 +35,20 @@ inline fun <reified T: NameManageable> Realm.getOrCreate(name: String) : T { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns all entities of the [clazz] sorted with their default sorting |
|
|
|
|
* Set [editableOnly] to true to only receive entities that can be edited |
|
|
|
|
*/ |
|
|
|
|
fun < T : RealmModel> Realm.sorted(clazz: Class<T>) : RealmResults<T> { |
|
|
|
|
val items = this.where(clazz).findAll() |
|
|
|
|
fun < T : RealmModel> Realm.sorted(clazz: Class<T>, editableOnly: Boolean = false) : RealmResults<T> { |
|
|
|
|
val query = this.where(clazz) |
|
|
|
|
|
|
|
|
|
if (editableOnly) { |
|
|
|
|
when (clazz.kotlin) { |
|
|
|
|
TransactionType::class -> { |
|
|
|
|
query.equalTo("lock", false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val items = query.findAll() |
|
|
|
|
var sortField = arrayOf("name") |
|
|
|
|
var resultSort = arrayOf(Sort.ASCENDING) |
|
|
|
|
|
|
|
|
|
@ -65,8 +73,8 @@ fun < T : RealmModel> Realm.sorted(clazz: Class<T>) : RealmResults<T> { |
|
|
|
|
/** |
|
|
|
|
* Returns all entities of the [C] class sorted with their default sorting |
|
|
|
|
*/ |
|
|
|
|
inline fun <reified C : RealmModel> Realm.sorted() : RealmResults<C> { |
|
|
|
|
return this.sorted(C::class.java) |
|
|
|
|
inline fun <reified C : RealmModel> Realm.sorted(editableOnly: Boolean = false) : RealmResults<C> { |
|
|
|
|
return this.sorted(C::class.java, editableOnly) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|