Improve filter management (Limit, table size)

feature/top10
Aurelien Hubert 7 years ago
parent f40bc3325c
commit 8f05a9ca9e
  1. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  2. 66
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterElement.kt
  3. 18
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt

@ -19,7 +19,7 @@ import java.util.*
*/ */
open class Filter : RealmObject() { open class Filter : RealmObject() {
private var entityType : Int? = Entity.SESSION.ordinal private var entityType: Int? = Entity.SESSION.ordinal
private enum class Entity { private enum class Entity {
SESSION, SESSION,
@ -29,13 +29,13 @@ open class Filter : RealmObject() {
companion object { companion object {
// Create a new instance // Create a new instance
fun newInstance(realm: Realm) : Filter { fun newInstance(realm: Realm): Filter {
val filter = Filter() val filter = Filter()
return realm.copyToRealm(filter) return realm.copyToRealm(filter)
} }
// Get a filter by its id // Get a filter by its id
fun getFilterBydId(realm: Realm, filterId: String) : Filter? { fun getFilterBydId(realm: Realm, filterId: String): Filter? {
return realm.where<Filter>().equalTo("id", filterId).findFirst() return realm.where<Filter>().equalTo("id", filterId).findFirst()
} }
@ -88,17 +88,18 @@ open class Filter : RealmObject() {
} }
} }
fun countBy(filterCategoryRow: FilterCategoryRow) : Int { fun countBy(filterCategoryRow: FilterCategoryRow): Int {
val sections = filterCategoryRow.filterSectionRows val sections = filterCategoryRow.filterSectionRows
return filterElements.count { return filterElements.count {
sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName)) sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName))
} }
} }
fun contains(filterElementRow:FilterElementRow) : Boolean { fun contains(filterElementRow: FilterElementRow): Boolean {
val filtered = filterElements.filter { val filtered = filterElements.filter {
it.filterName == filterElementRow.filterName it.filterName == filterElementRow.filterName
} }
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
return false return false
} }

@ -7,17 +7,16 @@ import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.util.* import java.util.*
import kotlin.collections.ArrayList
open class FilterElement() : RealmObject() { open class FilterElement() : RealmObject() {
private constructor(filterName:String, sectionName:String) : this() { private constructor(filterName: String, sectionName: String) : this() {
this.filterName = filterName this.filterName = filterName
this.sectionName = sectionName this.sectionName = sectionName
} }
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) {
val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName val filterName: String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName
this.stringValues = when (QueryType.valueOf(filterName)) { this.stringValues = when (QueryType.valueOf(filterName)) {
QueryType.GAME, QueryType.BANKROLL, QueryType.TOURNAMENT_NAME, QueryType.ALL_TOURNAMENT_FEATURES, QueryType.ANY_TOURNAMENT_FEATURES, QueryType.LOCATION -> { QueryType.GAME, QueryType.BANKROLL, QueryType.TOURNAMENT_NAME, QueryType.ALL_TOURNAMENT_FEATURES, QueryType.ANY_TOURNAMENT_FEATURES, QueryType.LOCATION -> {
RealmList<String>().apply { RealmList<String>().apply {
@ -26,6 +25,13 @@ open class FilterElement() : RealmObject() {
}) })
} }
} }
QueryType.LIMIT, QueryType.TABLE_SIZE -> {
RealmList<String>().apply {
this.addAll(filterElementRows.map {
(it as StaticDataFilterElementRow).id
})
}
}
else -> null else -> null
} }
@ -80,31 +86,31 @@ open class FilterElement() : RealmObject() {
} }
} }
constructor(filterElementRow:FilterElementRow) : this(arrayListOf(filterElementRow)) { constructor(filterElementRow: FilterElementRow) : this(arrayListOf(filterElementRow)) {
when (filterElementRow) { when (filterElementRow) {
is From -> dateValue = filterElementRow.date is From -> dateValue = filterElementRow.date
is To -> dateValue= filterElementRow.date is To -> dateValue = filterElementRow.date
} }
} }
var filterName : String? = null var filterName: String? = null
var sectionName : String? = null var sectionName: String? = null
val queryType : QueryType val queryType: QueryType
get() = QueryType.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName) get() = QueryType.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName)
.apply { .apply {
this.updateValueMap(this@FilterElement) this.updateValueMap(this@FilterElement)
} }
private var numericValues: RealmList<Double>? = null private var numericValues: RealmList<Double>? = null
private var dateValue : Date? = null private var dateValue: Date? = null
private var stringValues : RealmList<String>? = null private var stringValues: RealmList<String>? = null
private var blindValues : RealmList<FilterElementBlind>? = null private var blindValues: RealmList<FilterElementBlind>? = null
val ids : Array<String> val ids: Array<String>
get() = stringValues?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = stringValues?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val blinds : RealmList<FilterElementBlind> val blinds: RealmList<FilterElementBlind>
get() { get() {
blindValues?.let { blindValues?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -117,37 +123,37 @@ open class FilterElement() : RealmObject() {
} }
val date : Date val date: Date
get() = dateValue?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = dateValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val values : Array<Int> val values: Array<Int>
get() = numericValues?.map { get() = numericValues?.map {
it.toInt() it.toInt()
}?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing }?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val value : Double val value: Double
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val leftValue : Double val leftValue: Double
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val rightValue : Double val rightValue: Double
get() = numericValues?.last()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.last() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val dayOfWeek : Int val dayOfWeek: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val month : Int val month: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val year : Int val year: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
} }

@ -30,13 +30,10 @@ sealed class FilterElementRow : RowRepresentable {
val name: String = (data as RowRepresentable).getDisplayName() val name: String = (data as RowRepresentable).getDisplayName()
} }
open class StaticDataFilterElementRow(var row: RowRepresentable) : FilterElementRow() { open class StaticDataFilterElementRow(var row: RowRepresentable, var id: String) : FilterElementRow() {
override val resId: Int? = row.resId override val resId: Int? = row.resId
val name: String = row.getDisplayName()
fun getDataDisplayName() : String {
return row.getDisplayName()
}
fun getDataLocalizedTitle(context: Context): String { fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context) return row.localizedTitle(context)
@ -52,8 +49,8 @@ sealed class FilterElementRow : RowRepresentable {
data class Month(val month: Int) : SingleValueFilterElementRow(month) data class Month(val month: Int) : SingleValueFilterElementRow(month)
data class Day(val day: Int) : SingleValueFilterElementRow(day) data class Day(val day: Int) : SingleValueFilterElementRow(day)
data class PastDays(var lastDays: Int = 0) : FilterElementRow() data class PastDays(var lastDays: Int = 0) : FilterElementRow()
data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit) data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize) data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString())
data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll) data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll)
data class Game(val game: Manageable) : DataFilterElementRow(game) data class Game(val game: Manageable) : DataFilterElementRow(game)
data class Location(val location: Manageable) : DataFilterElementRow(location) data class Location(val location: Manageable) : DataFilterElementRow(location)
@ -112,7 +109,10 @@ sealed class FilterElementRow : RowRepresentable {
is DataFilterElementRow -> filterElements.any { is DataFilterElementRow -> filterElements.any {
it.ids.contains(this.id) it.ids.contains(this.id)
} }
else -> return true is StaticDataFilterElementRow ->filterElements.any {
it.ids.contains(this.id)
}
else -> true
} }
} }
@ -148,7 +148,7 @@ sealed class FilterElementRow : RowRepresentable {
override fun getDisplayName(): String { override fun getDisplayName(): String {
return when (this) { return when (this) {
is DataFilterElementRow -> this.name is DataFilterElementRow -> this.name
is StaticDataFilterElementRow -> this.getDataDisplayName() is StaticDataFilterElementRow -> this.name
else -> super.getDisplayName() else -> super.getDisplayName()
} }
} }

Loading…
Cancel
Save