Improve Filter Element management

feature/top10
Aurelien Hubert 7 years ago
parent 6cef9636fc
commit 9e4f108a59
  1. 16
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  2. 37
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  3. 25
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -4,6 +4,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow.*
import timber.log.Timber
enum class FilterCategoryRow(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable { enum class FilterCategoryRow(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable {
GENERAL(R.string.general), GENERAL(R.string.general),
@ -22,9 +23,24 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
val filterElements: List<RowRepresentable> val filterElements: List<RowRepresentable>
get() { get() {
val data = ArrayList<RowRepresentable>()
for (section in filterSectionRows) {
if (section.filterElements.isNotEmpty()) {
//data.add(section)
section.filterElements.forEach {
Timber.d("filterElements: $it")
}
data.addAll(section.filterElements)
}
}
return data
/*
return filterSectionRows.flatMap { return filterSectionRows.flatMap {
it.filterElements it.filterElements
} }
*/
} }
val filterSectionRows: List<FilterSectionRow> val filterSectionRows: List<FilterSectionRow>

@ -1,5 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryType import net.pokeranalytics.android.model.filter.QueryType
@ -7,7 +8,6 @@ import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.realm.FilterElement import net.pokeranalytics.android.model.realm.FilterElement
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import java.util.* import java.util.*
sealed class FilterElementRow : RowRepresentable { sealed class FilterElementRow : RowRepresentable {
@ -30,6 +30,19 @@ 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() {
override val resId: Int? = row.resId
fun getDataDisplayName() : String {
return row.getDisplayName()
}
fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context)
}
}
open class SingleValueFilterElementRow(val value: Int) : FilterElementRow() open class SingleValueFilterElementRow(val value: Int) : FilterElementRow()
data class Blind(var sb: Double? = null, var bb: Double? = null, var code: String? = null) : FilterElementRow() data class Blind(var sb: Double? = null, var bb: Double? = null, var code: String? = null) : FilterElementRow()
@ -39,8 +52,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) : FilterElementRow() data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit)
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElementRow() data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize)
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)
@ -70,15 +83,17 @@ sealed class FilterElementRow : RowRepresentable {
is Weekday -> QueryType.WEEK_DAY is Weekday -> QueryType.WEEK_DAY
is Weekend -> QueryType.WEEK_END is Weekend -> QueryType.WEEK_END
/* is Today -> QueryType. /*
is Today -> QueryType.
is Yesterday -> R.string.yesterday is Yesterday -> R.string.yesterday
is TodayAndYesterday -> R.string.yesterday_and_today is TodayAndYesterday -> R.string.yesterday_and_today
is CurrentWeek -> R.string.current_week is CurrentWeek -> R.string.current_week
is CurrentMonth -> R.string.current_month is CurrentMonth -> R.string.current_month
is CurrentYear -> R.string.current_year is CurrentYear -> R.string.current_year
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Limit -> R.string.limit
*/ */
is Limit -> QueryType.LIMIT
is TableSize -> QueryType.TABLE_SIZE is TableSize -> QueryType.TABLE_SIZE
is Game -> QueryType.GAME is Game -> QueryType.GAME
is Bankroll -> QueryType.BANKROLL is Bankroll -> QueryType.BANKROLL
@ -123,8 +138,6 @@ sealed class FilterElementRow : RowRepresentable {
is Month -> R.string.month_of_the_year is Month -> R.string.month_of_the_year
is Day -> R.string.day_of_the_week is Day -> R.string.day_of_the_week
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Limit -> R.string.limit
is TableSize -> R.string.table_size
is Blind -> TODO() is Blind -> TODO()
is ResultMoreThan -> TODO() is ResultMoreThan -> TODO()
is ResultLessThan -> TODO() is ResultLessThan -> TODO()
@ -135,7 +148,15 @@ 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
else -> return super.getDisplayName() is StaticDataFilterElementRow -> this.getDataDisplayName()
else -> super.getDisplayName()
}
}
override fun localizedTitle(context: Context): String {
return when (this) {
is StaticDataFilterElementRow -> this.getDataLocalizedTitle(context)
else -> super.localizedTitle(context)
} }
} }

@ -1,7 +1,10 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm import io.realm.Realm
import io.realm.Sort
import io.realm.kotlin.where
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
@ -49,8 +52,10 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
val allowMultiSelection: Boolean val allowMultiSelection: Boolean
get() = (this.selectionType == SelectionType.MULTIPLE) get() = (this.selectionType == SelectionType.MULTIPLE)
val filterElements: List<RowRepresentable> by lazy { val filterElements: List<RowRepresentable>
arrayListOf<RowRepresentable>(this).apply { get() {
val data = arrayListOf<RowRepresentable>().apply {
this.addAll( this.addAll(
when (this@FilterSectionRow) { when (this@FilterSectionRow) {
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
@ -64,9 +69,14 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
} }
TABLE_SIZE -> { TABLE_SIZE -> {
val tableSizes = arrayListOf<FilterElementRow.TableSize>() val tableSizes = arrayListOf<FilterElementRow.TableSize>()
net.pokeranalytics.android.model.TableSize.all.forEach { val realm = Realm.getDefaultInstance()
tableSizes.add(TableSize(it)) val distinctTableSizes = realm.where<Session>().distinct("tableSize").findAll().sort("tableSize", Sort.ASCENDING)
distinctTableSizes.forEach { session ->
session.tableSize?.let { tableSize ->
tableSizes.add(TableSize(net.pokeranalytics.android.model.TableSize(tableSize)))
}
} }
realm.close()
tableSizes tableSizes
} }
TOURNAMENT_NAME -> arrayListOf() TOURNAMENT_NAME -> arrayListOf()
@ -128,6 +138,13 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
} }
) )
} }
// Add the section row only if we have data for this section
if (data.isNotEmpty()) {
data.add(0, this@FilterSectionRow)
}
return data
} }
private val selectionType: SelectionType private val selectionType: SelectionType

Loading…
Cancel
Save