|
|
|
@ -10,7 +10,6 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow |
|
|
|
import org.jetbrains.annotations.TestOnly |
|
|
|
import org.jetbrains.annotations.TestOnly |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -18,44 +17,13 @@ import java.util.* |
|
|
|
* It contains a list of [FilterElement] describing the complete query to launch |
|
|
|
* It contains a list of [FilterElement] describing the complete query to launch |
|
|
|
* The [Filter] is working closely with a [Filterable] interface providing the entity we want the query being launched on |
|
|
|
* The [Filter] is working closely with a [Filterable] interface providing the entity we want the query being launched on |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
open class Filter(entity: Filterable) : RealmObject() { |
|
|
|
open class Filter : RealmObject() { |
|
|
|
|
|
|
|
|
|
|
|
constructor() : this(entity = Session) |
|
|
|
private var entityType : Int? = Entity.SESSION.ordinal |
|
|
|
|
|
|
|
|
|
|
|
private var entityType : Int? = FilterableClass.filterableClass(entity = entity).ordinal |
|
|
|
private enum class Entity { |
|
|
|
private val filterableClass : FilterableClass? |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
entityType?.let { |
|
|
|
|
|
|
|
return FilterableClass.values()[it] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private enum class FilterableClass { |
|
|
|
|
|
|
|
SESSION, |
|
|
|
SESSION, |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
fun filterableClass(entity: Filterable): FilterableClass { |
|
|
|
|
|
|
|
return when (entity) { |
|
|
|
|
|
|
|
is Session.Companion -> SESSION |
|
|
|
|
|
|
|
else -> throw PokerAnalyticsException.FilterUnhandledEntity |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
@TestOnly |
|
|
|
|
|
|
|
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryType>): RealmResults<T> { |
|
|
|
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
|
|
|
queries.forEach { |
|
|
|
|
|
|
|
realmQuery = it.filter<T>(realmQuery) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Timber.d(">>>>> query = ${realmQuery.description}") |
|
|
|
|
|
|
|
return realmQuery.findAll() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
@PrimaryKey |
|
|
|
@ -71,6 +39,17 @@ open class Filter(entity: Filterable) : RealmObject() { |
|
|
|
var filterElements: RealmList<FilterElement> = RealmList() |
|
|
|
var filterElements: RealmList<FilterElement> = RealmList() |
|
|
|
private set |
|
|
|
private set |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
@TestOnly |
|
|
|
|
|
|
|
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryType>): RealmResults<T> { |
|
|
|
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
|
|
|
queries.forEach { |
|
|
|
|
|
|
|
realmQuery = it.filter<T>(realmQuery) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return realmQuery.findAll() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun createOrUpdateFilterElements(filterElementRows: ArrayList<FilterElementRow>) { |
|
|
|
fun createOrUpdateFilterElements(filterElementRows: ArrayList<FilterElementRow>) { |
|
|
|
filterElements.clear() |
|
|
|
filterElements.clear() |
|
|
|
filterElementRows |
|
|
|
filterElementRows |
|
|
|
@ -115,7 +94,7 @@ open class Filter(entity: Filterable) : RealmObject() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline fun <reified T : Filterable> results(): RealmResults<T> { |
|
|
|
inline fun <reified T : Filterable> results(): RealmResults<T> { |
|
|
|
var realmQuery : RealmQuery<T> = realm.where<T>() |
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
this.filterElements.map { |
|
|
|
this.filterElements.map { |
|
|
|
it.queryType |
|
|
|
it.queryType |
|
|
|
}.forEach { |
|
|
|
}.forEach { |
|
|
|
|