diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt index f24f7979..b1810923 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.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 get() { + + val data = ArrayList() + 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 get() { return when (this) { GENERAL -> arrayListOf( diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt index 5dd5bde3..316ff259 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt @@ -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 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 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) : Boolean { + fun contains(filterElements: List): 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? get() { val excluded = arrayListOf() if (!this.filterSectionRow.allowMultiSelection) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt index d51b7959..b812bf4f 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt @@ -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,86 +52,100 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable { val allowMultiSelection: Boolean get() = (this.selectionType == SelectionType.MULTIPLE) - val filterElements: List by lazy { - arrayListOf(this).apply { - this.addAll( - when (this@FilterSectionRow) { - CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) - LIVE_ONLINE -> arrayListOf(Live, Online) - LIMIT_TYPE -> { - val limits = arrayListOf() - net.pokeranalytics.android.model.Limit.values().forEach { - limits.add(Limit(it)) + val filterElements: List + get() { + + val data = arrayListOf().apply { + this.addAll( + when (this@FilterSectionRow) { + CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) + LIVE_ONLINE -> arrayListOf(Live, Online) + LIMIT_TYPE -> { + val limits = arrayListOf() + net.pokeranalytics.android.model.Limit.values().forEach { + limits.add(Limit(it)) + } + limits } - limits - } - TABLE_SIZE -> { - val tableSizes = arrayListOf() - net.pokeranalytics.android.model.TableSize.all.forEach { - tableSizes.add(TableSize(it)) + TABLE_SIZE -> { + val tableSizes = arrayListOf() + val realm = Realm.getDefaultInstance() + val distinctTableSizes = realm.where().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_FEATURE -> arrayListOf() - DYNAMIC_DATE -> arrayListOf( - Today, - Yesterday, - TodayAndYesterday, - CurrentWeek, - CurrentMonth, - CurrentYear - ) - FIXED_DATE -> arrayListOf(From(), To()) - DURATION -> arrayListOf() - WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend) - DAY_OF_WEEK -> arrayListOf() - MONTH_OF_YEAR -> arrayListOf() - YEAR -> arrayListOf() - - GAME -> { - val games = arrayListOf() - val realm = Realm.getDefaultInstance() - LiveData.GAME.items(realm).forEach { - val game = Game(it as net.pokeranalytics.android.model.realm.Game) - games.add(game) + TOURNAMENT_NAME -> arrayListOf() + TOURNAMENT_FEATURE -> arrayListOf() + DYNAMIC_DATE -> arrayListOf( + Today, + Yesterday, + TodayAndYesterday, + CurrentWeek, + CurrentMonth, + CurrentYear + ) + FIXED_DATE -> arrayListOf(From(), To()) + DURATION -> arrayListOf() + WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend) + DAY_OF_WEEK -> arrayListOf() + MONTH_OF_YEAR -> arrayListOf() + YEAR -> arrayListOf() + + GAME -> { + val games = arrayListOf() + val realm = Realm.getDefaultInstance() + LiveData.GAME.items(realm).forEach { + val game = Game(it as net.pokeranalytics.android.model.realm.Game) + games.add(game) + } + realm.close() + games } - realm.close() - games - } - LOCATION -> arrayListOf() - BANKROLL -> arrayListOf() + LOCATION -> arrayListOf() + BANKROLL -> arrayListOf() - MULTI_TABLING -> arrayListOf() + MULTI_TABLING -> arrayListOf() - BLINDS -> arrayListOf() - CASH_RE_BUY_COUNT -> arrayListOf() - BUY_IN -> arrayListOf() + BLINDS -> arrayListOf() + CASH_RE_BUY_COUNT -> arrayListOf() + BUY_IN -> arrayListOf() - COMPLETION_PERCENTAGE -> arrayListOf() - NUMBER_OF_PLAYERS -> arrayListOf() - TOURNAMENT_TYPE -> arrayListOf() - PLAYERS_COUNT -> arrayListOf() - PLACE -> arrayListOf() - TOURNAMENT_RE_BUY_COUNT -> arrayListOf() + COMPLETION_PERCENTAGE -> arrayListOf() + NUMBER_OF_PLAYERS -> arrayListOf() + TOURNAMENT_TYPE -> arrayListOf() + PLAYERS_COUNT -> arrayListOf() + PLACE -> 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 { - this.forEach { - it.filterSectionRow = this@FilterSectionRow + }.apply { + this.forEach { + 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 get() {