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. 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.RowViewType
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 {
GENERAL(R.string.general),
@ -20,14 +21,29 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
PLAYERS(R.string.players),
;
val filterElements : List < RowRepresentable >
val filterElements: List<RowRepresentable>
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 {
it.filterElements
}
*/
}
val filterSectionRows : List < FilterSectionRow >
val filterSectionRows: List<FilterSectionRow>
get() {
return when (this) {
GENERAL -> arrayListOf(

@ -1,5 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
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.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import java.util.*
sealed class FilterElementRow : RowRepresentable {
@ -21,16 +21,29 @@ sealed class FilterElementRow : RowRepresentable {
object TodayAndYesterday : FilterElementRow()
object CurrentWeek : FilterElementRow()
object CurrentMonth : FilterElementRow()
object CurrentYear: FilterElementRow()
object Weekday: FilterElementRow()
object CurrentYear : FilterElementRow()
object Weekday : FilterElementRow()
object Weekend : FilterElementRow()
open class DataFilterElementRow(data:Manageable) : FilterElementRow() {
val id : String = data.id
val name : String = (data as RowRepresentable).getDisplayName()
open class DataFilterElementRow(data: Manageable) : FilterElementRow() {
val id: String = data.id
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 From(var date: Date = Date()) : FilterElementRow()
@ -38,23 +51,23 @@ sealed class FilterElementRow : RowRepresentable {
data class Year(val year: Int) : SingleValueFilterElementRow(year)
data class Month(val month: Int) : SingleValueFilterElementRow(month)
data class Day(val day: Int) : SingleValueFilterElementRow(day)
data class PastDays(var lastDays : Int = 0) : FilterElementRow()
data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElementRow()
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElementRow()
data class PastDays(var lastDays: Int = 0) : FilterElementRow()
data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize)
data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll)
data class Game(val game: Manageable) : DataFilterElementRow(game)
data class Location(val location: Manageable) : DataFilterElementRow(location)
data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName)
data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class ResultMoreThan(var value:Double) : FilterElementRow()
data class ResultLessThan(var value:Double) : FilterElementRow()
data class ResultMoreThan(var value: Double) : FilterElementRow()
data class ResultLessThan(var value: Double) : FilterElementRow()
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() {
return when (this) {
is Cash -> QueryType.CASH
@ -68,17 +81,19 @@ sealed class FilterElementRow : RowRepresentable {
is Live -> QueryType.LIVE
is Online -> QueryType.ONLINE
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 TodayAndYesterday -> R.string.yesterday_and_today
is CurrentWeek -> R.string.current_week
is CurrentMonth -> R.string.current_month
is CurrentYear -> R.string.current_year
is PastDays -> R.string.period_in_days
is Limit -> R.string.limit
*/
is Limit -> QueryType.LIMIT
is TableSize -> QueryType.TABLE_SIZE
is Game -> QueryType.GAME
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) {
is DataFilterElementRow -> filterElements.any {
it.ids.contains(this.id)
@ -118,13 +133,11 @@ sealed class FilterElementRow : RowRepresentable {
is Live -> R.string.live
is Online -> R.string.online
is Weekday -> R.string.week_days
is Weekend-> R.string.weekend
is Year-> R.string.year
is Month-> R.string.month_of_the_year
is Weekend -> R.string.weekend
is Year -> R.string.year
is Month -> R.string.month_of_the_year
is Day -> R.string.day_of_the_week
is PastDays -> R.string.period_in_days
is Limit -> R.string.limit
is TableSize -> R.string.table_size
is Blind -> TODO()
is ResultMoreThan -> TODO()
is ResultLessThan -> TODO()
@ -135,13 +148,21 @@ sealed class FilterElementRow : RowRepresentable {
override fun getDisplayName(): String {
return when (this) {
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
val sectionToExclude : List < FilterSectionRow > ?
val sectionToExclude: List<FilterSectionRow>?
get() {
val excluded = arrayListOf<FilterSectionRow>()
if (!this.filterSectionRow.allowMultiSelection) {

@ -1,7 +1,10 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm
import io.realm.Sort
import io.realm.kotlin.where
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.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
@ -49,8 +52,10 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
val allowMultiSelection: Boolean
get() = (this.selectionType == SelectionType.MULTIPLE)
val filterElements: List<RowRepresentable> by lazy {
arrayListOf<RowRepresentable>(this).apply {
val filterElements: List<RowRepresentable>
get() {
val data = arrayListOf<RowRepresentable>().apply {
this.addAll(
when (this@FilterSectionRow) {
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
@ -64,9 +69,14 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
}
TABLE_SIZE -> {
val tableSizes = arrayListOf<FilterElementRow.TableSize>()
net.pokeranalytics.android.model.TableSize.all.forEach {
tableSizes.add(TableSize(it))
val realm = Realm.getDefaultInstance()
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
}
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

Loading…
Cancel
Save