fix issue with filter selection

feature/top10
Razmig Sarkissian 7 years ago
parent ff3e4608d3
commit 3dc8384e4c
  1. 10
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 35
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  5. 14
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -97,7 +97,15 @@ sealed class QueryCondition : FilterElementRow {
interface BetweenLeftExclusive : Between
interface BetweenRightExclusive : Between
val id: String get() { return this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName }
val baseId = this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName
val id: List<String> get() {
return when (this) {
is QueryDataCondition<*> -> this.stringValues.map { "$baseId+$it" }
is StaticDataQueryCondition -> this.intValues.map { "$baseId+$it" }
else -> listOf(baseId)
}
}
override var filterSectionRow: FilterSectionRow = FilterSectionRow.CASH_TOURNAMENT

@ -66,22 +66,26 @@ open class Filter : RealmObject() {
private set
fun createOrUpdateFilterConditions(filterConditionRows: ArrayList<QueryCondition>) {
val casted = arrayListOf<QueryCondition>()
println("list of querys saving: ${filterConditionRows.map { it.id }}")
println("list of querys previous: ${this.filterConditions.map { it.queryCondition.id }}")
filterConditionRows
.map {
it.id
it.filterSectionRow
}
.distinct()
.forEach { filterName->
filterConditionRows
.filter {
it.id == filterName
it.filterSectionRow == filterName
}
.apply {
println("list of querys: ${this.map { it.id }}")
val casted = arrayListOf<QueryCondition>()
casted.addAll(this)
val newFilterCondition = FilterCondition(casted)
val previousCondition = filterConditions.filter {
it.sectionName == newFilterCondition.filterName
it.filterName == newFilterCondition.filterName
}
filterConditions.removeAll(previousCondition)
filterConditions.add(newFilterCondition)
@ -90,20 +94,19 @@ open class Filter : RealmObject() {
}
fun countBy(filterCategoryRow: FilterCategoryRow): Int {
val sections = filterCategoryRow.filterSectionRows
return filterConditions.count {
sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName))
}
val sections = filterCategoryRow.filterSectionRows.map { it.name }
println("list of sections $sections")
val savedSections = filterConditions.filter { sections.contains(it.sectionName) }.flatMap { it.queryCondition.id }
println("list of savedSections $savedSections")
return savedSections.size
}
fun contains(filterElementRow: QueryCondition): Boolean {
val filtered = filterConditions.filter {
it.filterName == filterElementRow.id
}
if (filtered.isEmpty()) {
return false
}
return filterElementRow.contains(filtered)
println("list of saved queries ${filterConditions.map { it.queryCondition.id }}")
println("list of contains ${filterElementRow.id}")
val contained = filterConditions.flatMap{ it.queryCondition.id }.contains(filterElementRow.id.first())
println("list of : $contained")
return contained
}
/**
@ -111,7 +114,7 @@ open class Filter : RealmObject() {
*/
fun loadValueForElement(filterElementRow: QueryCondition) {
val filtered = filterConditions.filter {
it.filterName == filterElementRow.id
it.queryCondition == filterElementRow.id
}
if (filtered.isNotEmpty()) {
return filterElementRow.updateValueMap(filtered.first())

@ -13,7 +13,7 @@ open class FilterCondition() : RealmObject() {
this.sectionName = sectionName
}
constructor(filterElementRows: ArrayList<QueryCondition>) : this(filterElementRows.first().id, filterElementRows.first().filterSectionRow.name) {
constructor(filterElementRows: ArrayList<QueryCondition>) : this(filterElementRows.first().baseId, filterElementRows.first().filterSectionRow.name) {
val row = filterElementRows.first()
this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName

@ -220,6 +220,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresent
}
}
println("list of selected rows : $selectedRows")
// Update UI
rowRepresentableAdapter.refreshRow(row)
}

@ -68,8 +68,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
when (this@FilterSectionRow) {
// General
CASH_TOURNAMENT -> arrayListOf(QueryCondition.CASH, QueryCondition.TOURNAMENT)
LIVE_ONLINE -> arrayListOf(QueryCondition.LIVE, QueryCondition.ONLINE)
CASH_TOURNAMENT -> Criteria.SessionType.queryConditions
LIVE_ONLINE -> Criteria.BankrollType.queryConditions
GAME -> Criteria.Games.queryConditions
LIMIT_TYPE -> Criteria.Limits.queryConditions
TABLE_SIZE -> Criteria.TableSizes.queryConditions
@ -151,7 +151,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
)
// Tournament
TOURNAMENT_TYPE -> arrayListOf()
TOURNAMENT_TYPE -> Criteria.TournamentTypes.queryConditions
COMPLETION_PERCENTAGE -> arrayListOf()
PLACE -> arrayListOf()
PLAYERS_COUNT -> arrayListOf()
@ -159,10 +159,10 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
BUY_IN -> arrayListOf()
TOURNAMENT_NAME -> arrayListOf()
TOURNAMENT_FEATURE -> arrayListOf()
LOCATION -> arrayListOf()
BANKROLL -> arrayListOf()
TOURNAMENT_NAME -> Criteria.TournamentNames.queryConditions
TOURNAMENT_FEATURE -> Criteria.TournamentFeatures.queryConditions
LOCATION -> Criteria.Locations.queryConditions
BANKROLL -> Criteria.Bankrolls.queryConditions
MULTI_TABLING -> arrayListOf()
NUMBER_OF_PLAYERS -> arrayListOf()
MULTI_PLAYER -> arrayListOf()

Loading…
Cancel
Save