Improve Filter Element management

feature/top10
Aurelien Hubert 7 years ago
parent 6cef9636fc
commit 9e4f108a59
  1. 20
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  2. 71
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  3. 149
      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),
@ -20,14 +21,29 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
PLAYERS(R.string.players), PLAYERS(R.string.players),
; ;
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>
get() { get() {
return when (this) { return when (this) {
GENERAL -> arrayListOf( GENERAL -> arrayListOf(

@ -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 {
@ -21,16 +21,29 @@ sealed class FilterElementRow : RowRepresentable {
object TodayAndYesterday : FilterElementRow() object TodayAndYesterday : FilterElementRow()
object CurrentWeek : FilterElementRow() object CurrentWeek : FilterElementRow()
object CurrentMonth : FilterElementRow() object CurrentMonth : FilterElementRow()
object CurrentYear: FilterElementRow() object CurrentYear : FilterElementRow()
object Weekday: FilterElementRow() object Weekday : FilterElementRow()
object Weekend : FilterElementRow() object Weekend : FilterElementRow()
open class DataFilterElementRow(data:Manageable) : FilterElementRow() { open class DataFilterElementRow(data: Manageable) : FilterElementRow() {
val id : String = data.id val id: String = data.id
val name : String = (data as RowRepresentable).getDisplayName() val name: String = (data as RowRepresentable).getDisplayName()
} }
open class SingleValueFilterElementRow(val value:Int) : FilterElementRow() 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()
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()
data class From(var date: Date = Date()) : FilterElementRow() data class From(var date: Date = Date()) : FilterElementRow()
@ -38,23 +51,23 @@ sealed class FilterElementRow : RowRepresentable {
data class Year(val year: Int) : SingleValueFilterElementRow(year) data class Year(val year: Int) : SingleValueFilterElementRow(year)
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)
data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName) data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName)
data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class ResultMoreThan(var value:Double) : FilterElementRow() data class ResultMoreThan(var value: Double) : FilterElementRow()
data class ResultLessThan(var value:Double) : FilterElementRow() data class ResultLessThan(var value: Double) : FilterElementRow()
lateinit var filterSectionRow: FilterSectionRow lateinit var filterSectionRow: FilterSectionRow
val filterName : String = this.queryType.name val filterName: String = this.queryType.name
private val queryType : QueryType private val queryType: QueryType
get() { get() {
return when (this) { return when (this) {
is Cash -> QueryType.CASH is Cash -> QueryType.CASH
@ -68,17 +81,19 @@ sealed class FilterElementRow : RowRepresentable {
is Live -> QueryType.LIVE is Live -> QueryType.LIVE
is Online -> QueryType.ONLINE is Online -> QueryType.ONLINE
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
@ -92,7 +107,7 @@ sealed class FilterElementRow : RowRepresentable {
} }
} }
fun contains(filterElements: List<FilterElement>) : Boolean { fun contains(filterElements: List<FilterElement>): Boolean {
return when (this) { return when (this) {
is DataFilterElementRow -> filterElements.any { is DataFilterElementRow -> filterElements.any {
it.ids.contains(this.id) it.ids.contains(this.id)
@ -118,13 +133,11 @@ sealed class FilterElementRow : RowRepresentable {
is Live -> R.string.live is Live -> R.string.live
is Online -> R.string.online is Online -> R.string.online
is Weekday -> R.string.week_days is Weekday -> R.string.week_days
is Weekend-> R.string.weekend is Weekend -> R.string.weekend
is Year-> R.string.year is Year -> R.string.year
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,13 +148,21 @@ 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)
} }
} }
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
val sectionToExclude : List < FilterSectionRow > ? val sectionToExclude: List<FilterSectionRow>?
get() { get() {
val excluded = arrayListOf<FilterSectionRow>() val excluded = arrayListOf<FilterSectionRow>()
if (!this.filterSectionRow.allowMultiSelection) { if (!this.filterSectionRow.allowMultiSelection) {

@ -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,86 +52,100 @@ 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() {
this.addAll(
when (this@FilterSectionRow) { val data = arrayListOf<RowRepresentable>().apply {
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) this.addAll(
LIVE_ONLINE -> arrayListOf(Live, Online) when (this@FilterSectionRow) {
LIMIT_TYPE -> { CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
val limits = arrayListOf<FilterElementRow.Limit>() LIVE_ONLINE -> arrayListOf(Live, Online)
net.pokeranalytics.android.model.Limit.values().forEach { LIMIT_TYPE -> {
limits.add(Limit(it)) val limits = arrayListOf<FilterElementRow.Limit>()
net.pokeranalytics.android.model.Limit.values().forEach {
limits.add(Limit(it))
}
limits
} }
limits TABLE_SIZE -> {
} val tableSizes = arrayListOf<FilterElementRow.TableSize>()
TABLE_SIZE -> { val realm = Realm.getDefaultInstance()
val tableSizes = arrayListOf<FilterElementRow.TableSize>() val distinctTableSizes = realm.where<Session>().distinct("tableSize").findAll().sort("tableSize", Sort.ASCENDING)
net.pokeranalytics.android.model.TableSize.all.forEach { distinctTableSizes.forEach { session ->
tableSizes.add(TableSize(it)) session.tableSize?.let { tableSize ->
tableSizes.add(TableSize(net.pokeranalytics.android.model.TableSize(tableSize)))
}
}
realm.close()
tableSizes
} }
tableSizes TOURNAMENT_NAME -> arrayListOf()
} TOURNAMENT_FEATURE -> arrayListOf()
TOURNAMENT_NAME -> arrayListOf() DYNAMIC_DATE -> arrayListOf(
TOURNAMENT_FEATURE -> arrayListOf() Today,
DYNAMIC_DATE -> arrayListOf( Yesterday,
Today, TodayAndYesterday,
Yesterday, CurrentWeek,
TodayAndYesterday, CurrentMonth,
CurrentWeek, CurrentYear
CurrentMonth, )
CurrentYear FIXED_DATE -> arrayListOf(From(), To())
) DURATION -> arrayListOf()
FIXED_DATE -> arrayListOf(From(), To()) WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend)
DURATION -> arrayListOf() DAY_OF_WEEK -> arrayListOf()
WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend) MONTH_OF_YEAR -> arrayListOf()
DAY_OF_WEEK -> arrayListOf() YEAR -> arrayListOf()
MONTH_OF_YEAR -> arrayListOf()
YEAR -> arrayListOf() GAME -> {
val games = arrayListOf<FilterElementRow.Game>()
GAME -> { val realm = Realm.getDefaultInstance()
val games = arrayListOf<FilterElementRow.Game>() LiveData.GAME.items(realm).forEach {
val realm = Realm.getDefaultInstance() val game = Game(it as net.pokeranalytics.android.model.realm.Game)
LiveData.GAME.items(realm).forEach { games.add(game)
val game = Game(it as net.pokeranalytics.android.model.realm.Game) }
games.add(game) realm.close()
games
} }
realm.close()
games
}
LOCATION -> arrayListOf() LOCATION -> arrayListOf()
BANKROLL -> arrayListOf() BANKROLL -> arrayListOf()
MULTI_TABLING -> arrayListOf() MULTI_TABLING -> arrayListOf()
BLINDS -> arrayListOf() BLINDS -> arrayListOf()
CASH_RE_BUY_COUNT -> arrayListOf() CASH_RE_BUY_COUNT -> arrayListOf()
BUY_IN -> arrayListOf() BUY_IN -> arrayListOf()
COMPLETION_PERCENTAGE -> arrayListOf() COMPLETION_PERCENTAGE -> arrayListOf()
NUMBER_OF_PLAYERS -> arrayListOf() NUMBER_OF_PLAYERS -> arrayListOf()
TOURNAMENT_TYPE -> arrayListOf() TOURNAMENT_TYPE -> arrayListOf()
PLAYERS_COUNT -> arrayListOf() PLAYERS_COUNT -> arrayListOf()
PLACE -> arrayListOf() PLACE -> arrayListOf()
TOURNAMENT_RE_BUY_COUNT -> arrayListOf() TOURNAMENT_RE_BUY_COUNT -> arrayListOf()
MULTI_PLAYER -> arrayListOf() MULTI_PLAYER -> arrayListOf()
RANGE -> arrayListOf() RANGE -> arrayListOf()
SESSION_DURATION -> arrayListOf() SESSION_DURATION -> arrayListOf()
VALUE -> arrayListOf() VALUE -> arrayListOf()
}.apply { }.apply {
this.forEach { this.forEach {
it.filterSectionRow = this@FilterSectionRow it.filterSectionRow = this@FilterSectionRow
}
} }
} )
) }
// 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
get() { get() {

Loading…
Cancel
Save