Merge branch 'dev' of gitlab.com:stax-river/poker-analytics into dev

feature/top10
Laurent 7 years ago
commit fdb28449fa
  1. BIN
      app/src/androidTest/assets/schema_2.realm
  2. 5
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  3. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  4. 84
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt
  5. 108
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  7. 154
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  8. 14
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -8,7 +8,6 @@ import net.pokeranalytics.android.model.realm.FilterElementBlind
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.extensions.endOfDay import net.pokeranalytics.android.util.extensions.endOfDay
import net.pokeranalytics.android.util.extensions.startOfDay import net.pokeranalytics.android.util.extensions.startOfDay
import java.time.*
import java.util.* import java.util.*
@ -33,6 +32,8 @@ enum class QueryCondition(var operator: Operator? = null) {
TABLE_SIZE, TABLE_SIZE,
TOURNAMENT_TYPE, TOURNAMENT_TYPE,
BLINDS, BLINDS,
LAST_GAMES,
LAST_SESSIONS,
MORE_NUMBER_OF_TABLE(Operator.MORE), MORE_NUMBER_OF_TABLE(Operator.MORE),
LESS_NUMBER_OF_TABLE(Operator.LESS), LESS_NUMBER_OF_TABLE(Operator.LESS),
BETWEEN_NUMBER_OF_TABLE(Operator.BETWEEN), BETWEEN_NUMBER_OF_TABLE(Operator.BETWEEN),
@ -296,7 +297,7 @@ enum class QueryCondition(var operator: Operator? = null) {
return return
} }
this.operator?.let { subType -> this.operator?.let {
valueMap = mapOf("value" to filterCondition.value) valueMap = mapOf("value" to filterCondition.value)
return return
} }

@ -68,25 +68,21 @@ open class Filter : RealmObject() {
filterConditions.clear() filterConditions.clear()
filterConditionRows filterConditionRows
.map { .map {
it.filterSectionRow it.filterName
} }
.distinct() .distinct()
.forEach { section -> .forEach { filterName->
filterConditionRows filterConditionRows
.filter { .filter {
it.filterSectionRow == section it.filterName == filterName
} }
.apply { .apply {
if (this.size == 1) {
filterConditions.add(FilterCondition(this.first()))
} else {
val casted = arrayListOf<FilterElementRow>() val casted = arrayListOf<FilterElementRow>()
casted.addAll(this) casted.addAll(this)
filterConditions.add(FilterCondition(casted)) filterConditions.add(FilterCondition(casted))
} }
} }
} }
}
fun countBy(filterCategoryRow: FilterCategoryRow): Int { fun countBy(filterCategoryRow: FilterCategoryRow): Int {
val sections = filterCategoryRow.filterSectionRows val sections = filterCategoryRow.filterSectionRows
@ -116,8 +112,7 @@ open class Filter : RealmObject() {
filterElementRow.lastDays = values.first() as Int filterElementRow.lastDays = values.first() as Int
} }
} }
is FilterElementRow.From -> filterElementRow.date = getSavedValueForElement(filterElementRow) as Date? ?: Date() is FilterElementRow.DateFilterElementRow -> filterElementRow.dateValue = getSavedValueForElement(filterElementRow) as Date? ?: Date()
is FilterElementRow.To -> filterElementRow.date = getSavedValueForElement(filterElementRow) as Date? ?: Date()
} }
} }

@ -16,92 +16,34 @@ open class FilterCondition() : RealmObject() {
} }
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) {
val row = filterElementRows.first()
this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName
when (row) {
is DateFilterElementRow -> {
this.dateValue = row.dateValue
val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName
this.stringValues = when (QueryCondition.valueOf(filterName)) {
QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> {
RealmList<String>().apply {
this.addAll(filterElementRows.map {
(it as DataFilterElementRow).id
})
}
}
QueryCondition.LIMIT, QueryCondition.TABLE_SIZE -> {
RealmList<String>().apply {
this.addAll(filterElementRows.map {
(it as StaticDataFilterElementRow).id
})
}
}
else -> null
}
this.numericValues = when (QueryCondition.valueOf(filterName)) {
QueryCondition.LIMIT -> {
RealmList<Double>().apply {
this.addAll(filterElementRows.map {
(it as FilterElementRow.Limit).limit.ordinal.toDouble()
})
}
} }
QueryCondition.TABLE_SIZE -> { is StringFilterElementRow -> {
RealmList<Double>().apply { this.stringValues = RealmList<String>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
(it as FilterElementRow.TableSize).tableSize.numberOfPlayer.toDouble() (it as StringFilterElementRow).stringValue
}) })
} }
} }
QueryCondition.YEAR, QueryCondition.MONTH, QueryCondition.DAY_OF_WEEK -> { is NumericFilterElementRow -> {
RealmList<Double>().apply { this.numericValues = RealmList<Double>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
(it as SingleValueFilterElementRow).value.toDouble() (it as NumericFilterElementRow).doubleValue
}) })
} }
} }
QueryCondition.LESS_THAN_NET_RESULT -> { is FilterElementBlind -> {
RealmList<Double>().apply { this.blindValues = RealmList<FilterElementBlind>().apply {
this.addAll(filterElementRows.map {
(it as ResultLessThan).value
})
}
}
QueryCondition.MORE_THAN_NET_RESULT -> {
RealmList<Double>().apply {
this.addAll(filterElementRows.map {
(it as ResultMoreThan).value
})
}
}
QueryCondition.PAST_DAYS -> {
RealmList<Double>().apply {
this.addAll(filterElementRows.map {
(it as FilterElementRow.PastDays).lastDays.toDouble()
})
}
}
else -> null
}
this.blindValues = when (QueryCondition.valueOf(filterName)) {
QueryCondition.BLINDS -> {
RealmList<FilterElementBlind>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
FilterElementBlind((it as FilterElementRow.Blind).sb, it.bb, it.code) FilterElementBlind((it as FilterElementRow.Blind).sb, it.bb, it.code)
}) })
} }
} }
else -> null
}
}
constructor(filterElementRow: FilterElementRow) : this(arrayListOf(filterElementRow)) {
when (filterElementRow) {
is From -> dateValue = filterElementRow.date
is To -> dateValue = filterElementRow.date
} }
} }

@ -69,73 +69,41 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
is FilterElementRow.From -> DateTimePickerManager.create(requireContext(), row, this, row.date, onlyDate = true) is FilterElementRow.DateFilterElementRow -> DateTimePickerManager.create(requireContext(), row, this, row.dateValue, onlyDate = true)
is FilterElementRow.To -> DateTimePickerManager.create(requireContext(), row, this, row.date, onlyDate = true)
is FilterElementRow.PastDays -> { is FilterElementRow.PastDays -> {
val pastDays = if (row.lastDays > 0) row.lastDays.toString() else "" val pastDays = if (row.lastDays > 0) row.lastDays.toString() else ""
val data = row.editingDescriptors(mapOf("pastDays" to pastDays)) val data = row.editingDescriptors(mapOf("pastDays" to pastDays))
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
is FilterElementRow.DurationMoreThan -> { is FilterElementRow.LastGames -> {
val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else "" val lastGames = if (row.lastGames > 0) row.lastGames.toString() else ""
val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else "" val data = row.editingDescriptors(mapOf("lastGames" to lastGames))
val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes)) BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is FilterElementRow.LastSessions -> {
val lastSessions = if (row.lastSessions > 0) row.lastSessions.toString() else ""
val data = row.editingDescriptors(mapOf("lastSessions" to lastSessions))
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
is FilterElementRow.DurationLessThan -> { is FilterElementRow.DurationFilterElement -> {
val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else "" val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else ""
val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else "" val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else ""
val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes)) val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes))
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
else -> { else -> {
updateRowsSelection(row)
val oldRows = ArrayList<RowRepresentable>()
oldRows.addAll(rows)
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSectionRow)
}
excludedFilters.forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
}
}
selectedRows.add(row)
}
} }
} }
} }
/*
Timber.d("Row: $row")
when (row) {
FilterRow.FROM -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true)
FilterRow.TO -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true)
FilterRow.PAST_DAYS -> {
val data = row.editingDescriptors(mapOf("defaultValue" to ""))
BottomSheetFragment.create(fragmentManager, row, this, data, null)
}
else -> {
selectedRows.add(row)
}
}
}
*/
rowRepresentableAdapter.refreshRow(row)
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT
is FilterElementRow.From -> row.date.shortDate() is FilterElementRow.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT
is FilterElementRow.To -> row.date.shortDate() is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT
is FilterElementRow.TimeFilterElementRow -> row.minutes.toMinutes(requireContext()) is FilterElementRow.DateFilterElementRow -> row.dateValue.shortDate()
is FilterElementRow.DurationFilterElement -> row.minutes.toMinutes(requireContext())
else -> super.stringForRow(row) else -> super.stringForRow(row)
} }
} }
@ -149,10 +117,11 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("onRowValueChanged: $row $value") Timber.d("onRowValueChanged: $row $value")
when (row) { when (row) {
is FilterElementRow.From -> row.date = if (value != null && value is Date) value else Date() is FilterElementRow.DateFilterElementRow -> row.dateValue = if (value != null && value is Date) value else Date()
is FilterElementRow.To -> row.date = if (value != null && value is Date) value else Date()
is FilterElementRow.PastDays -> row.lastDays = if (value != null && value is String) value.toInt() else 0 is FilterElementRow.PastDays -> row.lastDays = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.TimeFilterElementRow -> { is FilterElementRow.LastGames -> row.lastGames = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.LastSessions -> row.lastSessions = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.DurationFilterElement -> {
if (value is ArrayList<*>) { if (value is ArrayList<*>) {
val hours = try { val hours = try {
(value[0] as String? ?: "0").toInt() (value[0] as String? ?: "0").toInt()
@ -172,16 +141,10 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
} }
} }
//TODO: Update management like in onRowSelected // Remove the row before updating the selected rows list
if (value != null) {
if (!selectedRows.contains(row)) {
selectedRows.add(row as FilterElementRow)
}
} else {
selectedRows.remove(row as FilterElementRow) selectedRows.remove(row as FilterElementRow)
} updateRowsSelection(row, value == null)
rowRepresentableAdapter.refreshRow(row)
} }
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {
@ -229,10 +192,6 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
this.rowsForFilterSubcategoryRow.clear() this.rowsForFilterSubcategoryRow.clear()
this.rows.addAll(it.filterElements) this.rows.addAll(it.filterElements)
currentFilter?.filterConditions?.forEach {
Timber.d(it.toString())
}
this.rows.forEach { element -> this.rows.forEach { element ->
if (element is FilterElementRow && currentFilter?.contains(element) == true) { if (element is FilterElementRow && currentFilter?.contains(element) == true) {
currentFilter?.setSavedValueForElement(element) currentFilter?.setSavedValueForElement(element)
@ -245,6 +204,31 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
} }
} }
/**
* Update rows selection
*/
private fun updateRowsSelection(row: RowRepresentable, forceDeselection: Boolean = false) {
if (selectedRows.contains(row) || forceDeselection) {
selectedRows.remove(row)
} else {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSectionRow)
}
excludedFilters.forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
}
}
selectedRows.add(row)
}
}
// Update UI
rowRepresentableAdapter.refreshRow(row)
}
/** /**
* Save data * Save data

@ -9,7 +9,7 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
GENERAL(R.string.general), GENERAL(R.string.general),
DATE(R.string.date), DATE(R.string.date),
TIME_FRAME(R.string.duration), TIME_FRAME(R.string.duration),
SESSION(R.string.session), SESSIONS(R.string.sessions),
CASH(R.string.cash), CASH(R.string.cash),
TOURNAMENT(R.string.tournament), TOURNAMENT(R.string.tournament),
ONLINE(R.string.online), ONLINE(R.string.online),
@ -49,6 +49,7 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
SESSION_DURATION, SESSION_DURATION,
RANGE RANGE
) )
SESSIONS -> arrayListOf(FilterSectionRow.SESSIONS)
BANKROLLS -> arrayListOf( BANKROLLS -> arrayListOf(
BANKROLL BANKROLL
) )
@ -78,7 +79,6 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
VALUE VALUE
) )
SESSION -> arrayListOf()
TRANSACTION_TYPES -> arrayListOf() TRANSACTION_TYPES -> arrayListOf()
} }
} }

@ -16,36 +16,33 @@ import java.util.*
sealed class FilterElementRow : RowRepresentable { sealed class FilterElementRow : RowRepresentable {
// Objects interface Duration {
var minutes : Int
object Cash : FilterElementRow() }
object Tournament : FilterElementRow()
object Live : FilterElementRow()
object Online : FilterElementRow()
object Today : FilterElementRow()
object Yesterday : FilterElementRow()
object TodayAndYesterday : FilterElementRow()
object CurrentWeek : FilterElementRow()
object CurrentMonth : FilterElementRow()
object CurrentYear : FilterElementRow()
object Weekday : FilterElementRow()
object Weekend : FilterElementRow()
object ResultMoreThan : MoreFilterElementRow()
object ResultLessThan : LessFilterElementRow()
object DurationMoreThan : MoreTimeFilterElementRow()
object DurationLessThan : LessTimeFilterElementRow()
// Subclasses interface Operator
interface MoreOperator : Operator
interface LessOperator : Operator
open class BoolFilterElementRow : FilterElementRow()
open class DateFilterElementRow(var dateValue: Date = Date()) : FilterElementRow()
open class NumericFilterElementRow(open val doubleValue : Double = 0.0 ) : FilterElementRow()
open class StringFilterElementRow(val stringValue : String = "") : FilterElementRow()
open class SingleValueFilterElementRow(val value: Int) : FilterElementRow() // Subclasses
open class SingleValueFilterElementRow(open val intValue: Int) : NumericFilterElementRow() {
override val doubleValue : Double
get() {
return intValue.toDouble()
}
}
open class DataFilterElementRow(data: Manageable) : FilterElementRow() { open class DataFilterElementRow(data: Manageable) : StringFilterElementRow(data.id) {
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 StaticDataFilterElementRow(var row: RowRepresentable, var id: String) : FilterElementRow() { open class StaticDataFilterElementRow(var row: RowRepresentable, var id: Int) : NumericFilterElementRow(id.toDouble()) {
override val resId: Int? = row.resId override val resId: Int? = row.resId
val name: String = row.getDisplayName() val name: String = row.getDisplayName()
@ -55,27 +52,73 @@ sealed class FilterElementRow : RowRepresentable {
} }
} }
open class QuantityFilterElementRow(var value: Double = 0.0) : FilterElementRow() open class DurationFilterElement : NumericFilterElementRow(), Duration {
open class TimeFilterElementRow : QuantityFilterElementRow() { override var minutes: Int = 0
var minutes = value.toInt() override val doubleValue : Double
get() {
return minutes.toDouble()
}
} }
open class MoreFilterElementRow : QuantityFilterElementRow() open class AmountFilterElement : NumericFilterElementRow() {
open class LessFilterElementRow : QuantityFilterElementRow() var amount: Double = 0.0
open class MoreTimeFilterElementRow : TimeFilterElementRow() override val doubleValue : Double
open class LessTimeFilterElementRow : TimeFilterElementRow() get() {
return amount
}
}
object Cash : BoolFilterElementRow()
object Tournament : BoolFilterElementRow()
object Live : BoolFilterElementRow()
object Online : BoolFilterElementRow()
object Today : BoolFilterElementRow()
object Yesterday : BoolFilterElementRow()
object TodayAndYesterday : BoolFilterElementRow()
object CurrentWeek : BoolFilterElementRow()
object CurrentMonth : BoolFilterElementRow()
object CurrentYear : BoolFilterElementRow()
object Weekday : BoolFilterElementRow()
object Weekend : BoolFilterElementRow()
// Data classes // Data classes - holding value
object ResultMoreThan : AmountFilterElement(), MoreOperator
object ResultLessThan : AmountFilterElement(), LessOperator
object DurationMoreThan : DurationFilterElement(), MoreOperator
object DurationLessThan : DurationFilterElement(), LessOperator
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() object From : DateFilterElementRow()
data class To(var date: Date = Date()) : FilterElementRow() object To : DateFilterElementRow()
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 Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName) //TODO: Refactor?
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString()) data class PastDays(var lastDays: Int = 0) : SingleValueFilterElementRow(lastDays) {
override val intValue: Int
get() {
return lastDays
}
}
data class LastGames(var lastGames: Int) : SingleValueFilterElementRow(lastGames) {
override val intValue: Int
get() {
return lastGames
}
}
data class LastSessions(var lastSessions: Int) : SingleValueFilterElementRow(lastSessions) {
override val intValue: Int
get() {
return lastSessions
}
}
data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.ordinal)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer)
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)
@ -83,7 +126,6 @@ sealed class FilterElementRow : RowRepresentable {
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)
lateinit var filterSectionRow: FilterSectionRow lateinit var filterSectionRow: FilterSectionRow
val filterName: String = this.queryCondition.name val filterName: String = this.queryCondition.name
@ -123,6 +165,10 @@ sealed class FilterElementRow : RowRepresentable {
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
//TODO: Check the conditions
is LastGames -> QueryCondition.LAST_GAMES
is LastSessions -> QueryCondition.LAST_SESSIONS
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this) else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
} }
} }
@ -130,14 +176,11 @@ sealed class FilterElementRow : RowRepresentable {
fun contains(filterConditions: List<FilterCondition>): Boolean { fun contains(filterConditions: List<FilterCondition>): Boolean {
return when (this) { return when (this) {
is SingleValueFilterElementRow -> filterConditions.any { is SingleValueFilterElementRow -> filterConditions.any {
it.values.contains(this.value) it.values.contains(this.intValue)
} }
is DataFilterElementRow -> filterConditions.any { is DataFilterElementRow -> filterConditions.any {
it.ids.contains(this.id) it.ids.contains(this.id)
} }
is StaticDataFilterElementRow -> filterConditions.any {
it.ids.contains(this.id)
}
else -> true else -> true
} }
} }
@ -162,8 +205,10 @@ sealed class FilterElementRow : RowRepresentable {
is Weekend -> R.string.weekend is Weekend -> R.string.weekend
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Blind -> R.string.blinds is Blind -> R.string.blinds
is MoreFilterElementRow, is MoreTimeFilterElementRow -> R.string.more_than is LastGames -> R.string.last_records
is LessFilterElementRow, is LessTimeFilterElementRow -> R.string.less_than is LastSessions -> R.string.last_sessions
is MoreOperator -> R.string.more_than
is LessOperator -> R.string.less_than
else -> null else -> null
} }
} }
@ -173,6 +218,7 @@ sealed class FilterElementRow : RowRepresentable {
return when (this) { return when (this) {
is PastDays, is PastDays,
is From, is To, is From, is To,
is LastGames, is LastSessions,
is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal
else -> RowViewType.TITLE_CHECK.ordinal else -> RowViewType.TITLE_CHECK.ordinal
} }
@ -181,7 +227,7 @@ sealed class FilterElementRow : RowRepresentable {
override val bottomSheetType: BottomSheetType override val bottomSheetType: BottomSheetType
get() { get() {
return when (this) { return when (this) {
is PastDays -> BottomSheetType.EDIT_TEXT is PastDays, is LastGames, is LastSessions -> BottomSheetType.EDIT_TEXT
is DurationMoreThan, is DurationLessThan -> BottomSheetType.DOUBLE_EDIT_TEXT is DurationMoreThan, is DurationLessThan -> BottomSheetType.DOUBLE_EDIT_TEXT
else -> BottomSheetType.NONE else -> BottomSheetType.NONE
} }
@ -195,7 +241,19 @@ sealed class FilterElementRow : RowRepresentable {
RowRepresentableEditDescriptor(pastDays, R.string.period_in_days, inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(pastDays, R.string.period_in_days, inputType = InputType.TYPE_CLASS_NUMBER)
) )
} }
is DurationMoreThan, is DurationLessThan -> { is LastGames -> {
val lastGames: String? by map
arrayListOf(
RowRepresentableEditDescriptor(lastGames, R.string.last_records, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is LastSessions -> {
val lastSessions: String? by map
arrayListOf(
RowRepresentableEditDescriptor(lastSessions, R.string.last_sessions, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is DurationFilterElement -> {
val hours: String? by map val hours: String? by map
val minutes: String? by map val minutes: String? by map
arrayListOf( arrayListOf(
@ -211,9 +269,9 @@ sealed class FilterElementRow : RowRepresentable {
return when (this) { return when (this) {
is SingleValueFilterElementRow -> { is SingleValueFilterElementRow -> {
when (this) { when (this) {
is Day -> DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[this.value] is Day -> DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[this.intValue]
is Month -> DateFormatSymbols.getInstance(Locale.getDefault()).months[this.value] is Month -> DateFormatSymbols.getInstance(Locale.getDefault()).months[this.intValue]
else -> "${this.value}" else -> "${this.intValue}"
} }
} }
is DataFilterElementRow -> this.name is DataFilterElementRow -> this.name

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm import io.realm.Realm
import io.realm.Sort import io.realm.Sort
import io.realm.kotlin.where import io.realm.kotlin.where
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
@ -26,6 +27,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
MONTH_OF_YEAR(net.pokeranalytics.android.R.string.month_of_the_year), MONTH_OF_YEAR(net.pokeranalytics.android.R.string.month_of_the_year),
SESSION_DURATION(net.pokeranalytics.android.R.string.session_duration), SESSION_DURATION(net.pokeranalytics.android.R.string.session_duration),
RANGE(net.pokeranalytics.android.R.string.hour_slot), RANGE(net.pokeranalytics.android.R.string.hour_slot),
SESSIONS(R.string.sessions),
BLINDS(net.pokeranalytics.android.R.string.blinds), BLINDS(net.pokeranalytics.android.R.string.blinds),
CASH_RE_BUY_COUNT(net.pokeranalytics.android.R.string.cash_game), CASH_RE_BUY_COUNT(net.pokeranalytics.android.R.string.cash_game),
TOURNAMENT_TYPE(net.pokeranalytics.android.R.string.tournament_types), TOURNAMENT_TYPE(net.pokeranalytics.android.R.string.tournament_types),
@ -91,8 +93,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
CurrentMonth, CurrentMonth,
CurrentYear CurrentYear
) )
FIXED_DATE -> arrayListOf(From(), To()) FIXED_DATE -> arrayListOf(From, To)
DURATION -> arrayListOf(PastDays()) DURATION -> arrayListOf(PastDays(0))
YEAR -> { YEAR -> {
val years = arrayListOf<FilterElementRow.Year>() val years = arrayListOf<FilterElementRow.Year>()
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
@ -154,8 +156,10 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
MULTI_PLAYER -> arrayListOf() MULTI_PLAYER -> arrayListOf()
SESSION_DURATION -> arrayListOf(DurationMoreThan, DurationLessThan) SESSION_DURATION -> arrayListOf(DurationMoreThan as FilterElementRow, DurationLessThan as FilterElementRow)
RANGE -> arrayListOf(From(Date()), To(Date())) RANGE -> arrayListOf(From, To)
SESSIONS -> arrayListOf(LastGames(0), LastSessions(0))
VALUE -> arrayListOf() VALUE -> arrayListOf()
@ -178,7 +182,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
private val selectionType: SelectionType private val selectionType: SelectionType
get() { get() {
return when (this) { return when (this) {
CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> SelectionType.SINGLE CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE, SESSIONS -> SelectionType.SINGLE
else -> SelectionType.MULTIPLE else -> SelectionType.MULTIPLE
} }
} }

Loading…
Cancel
Save