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

# Conflicts:
#	app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
#	app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
feature/top10
Aurelien Hubert 7 years ago
commit 0bba7c966d
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  3. 84
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt
  4. 35
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  5. 178
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  6. 8
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -297,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,22 +68,18 @@ 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) { val casted = arrayListOf<FilterElementRow>()
filterConditions.add(FilterCondition(this.first())) casted.addAll(this)
} else { filterConditions.add(FilterCondition(casted))
val casted = arrayListOf<FilterElementRow>()
casted.addAll(this)
filterConditions.add(FilterCondition(casted))
}
} }
} }
} }
@ -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,95 +16,37 @@ 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 -> {
RealmList<Double>().apply {
this.addAll(filterElementRows.map {
(it as FilterElementRow.TableSize).tableSize.numberOfPlayer.toDouble()
})
}
} }
QueryCondition.YEAR, QueryCondition.MONTH, QueryCondition.DAY_OF_WEEK -> { is StringFilterElementRow -> {
RealmList<Double>().apply { this.stringValues = RealmList<String>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
(it as SingleValueFilterElementRow).value.toDouble() (it as StringFilterElementRow).stringValue
}) })
} }
} }
QueryCondition.LESS_THAN_NET_RESULT -> { is NumericFilterElementRow -> {
RealmList<Double>().apply { this.numericValues = RealmList<Double>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
(it as ResultLessThan).value (it as NumericFilterElementRow).doubleValue
}) })
} }
} }
QueryCondition.MORE_THAN_NET_RESULT -> { is FilterElementBlind -> {
RealmList<Double>().apply { this.blindValues = RealmList<FilterElementBlind>().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
}
}
var filterName: String? = null var filterName: String? = null
var sectionName: String? = null var sectionName: String? = null

@ -69,8 +69,7 @@ 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))
@ -86,13 +85,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
val data = row.editingDescriptors(mapOf("lastSessions" to lastSessions)) val data = row.editingDescriptors(mapOf("lastSessions" to lastSessions))
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
is FilterElementRow.DurationMoreThan -> { is FilterElementRow.DurationFilterElement -> {
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 data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is FilterElementRow.DurationLessThan -> {
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))
@ -109,11 +102,13 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
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.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT is FilterElementRow.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT
is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT
is FilterElementRow.ReBuyLessThan -> if (row.value > 0) row.value.toString() else NULL_TEXT is FilterElementRow.DateFilterElementRow -> row.dateValue.shortDate()
is FilterElementRow.ReBuyMoreThan -> if (row.value > 0) row.value.toString() else NULL_TEXT is FilterElementRow.DurationFilterElement -> row.minutes.toMinutes(requireContext())
is FilterElementRow.From -> row.date.shortDate()
is FilterElementRow.To -> row.date.shortDate() // TODO: Refactor that
is FilterElementRow.TimeFilterElementRow -> row.minutes.toMinutes(requireContext()) is FilterElementRow.ReBuyLessThan -> if (row.amount > 0) row.amount.toString() else NULL_TEXT
is FilterElementRow.ReBuyMoreThan -> if (row.amount > 0) row.amount.toString() else NULL_TEXT
else -> super.stringForRow(row) else -> super.stringForRow(row)
} }
} }
@ -127,14 +122,16 @@ 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.LastGames -> row.lastGames = if (value != null && value is String) value.toInt() else 0 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.LastSessions -> row.lastSessions = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.ReBuyLessThan -> row.value = if (value != null && value is String) value.toDouble() else 0.0
is FilterElementRow.ReBuyMoreThan -> row.value = if (value != null && value is String) value.toDouble() else 0.0 // TODO: Refactor that
is FilterElementRow.TimeFilterElementRow -> { is FilterElementRow.ReBuyLessThan -> row.amount = if (value != null && value is String) value.toDouble() else 0.0
is FilterElementRow.ReBuyMoreThan -> row.amount = if (value != null && value is String) value.toDouble() else 0.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()

@ -16,73 +16,111 @@ 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() interface Operator
object Online : FilterElementRow() interface MoreOperator : Operator
object Today : FilterElementRow() interface LessOperator : Operator
object Yesterday : FilterElementRow()
object TodayAndYesterday : FilterElementRow() open class BoolFilterElementRow : FilterElementRow()
object CurrentWeek : FilterElementRow() open class DateFilterElementRow(var dateValue: Date = Date()) : FilterElementRow()
object CurrentMonth : FilterElementRow() open class NumericFilterElementRow(open val doubleValue : Double = 0.0 ) : FilterElementRow()
object CurrentYear : FilterElementRow() open class StringFilterElementRow(val stringValue : String = "") : FilterElementRow()
object Weekday : FilterElementRow()
object Weekend : FilterElementRow() // Subclasses
open class SingleValueFilterElementRow(open val intValue: Int) : NumericFilterElementRow() {
object ResultMoreThan : MoreFilterElementRow() override val doubleValue : Double
object ResultLessThan : LessFilterElementRow() get() {
object ReBuyMoreThan: MoreFilterElementRow() return intValue.toDouble()
object ReBuyLessThan: LessFilterElementRow() }
object DurationMoreThan : MoreTimeFilterElementRow() }
object DurationLessThan : LessTimeFilterElementRow()
open class DataFilterElementRow(data: Manageable) : StringFilterElementRow(data.id) {
// Subclasses val id: String = data.id
val name: String = (data as RowRepresentable).getDisplayName()
open class SingleValueFilterElementRow(val value: Int) : FilterElementRow() }
open class DataFilterElementRow(data: Manageable) : FilterElementRow() { open class StaticDataFilterElementRow(var row: RowRepresentable, var id: Int) : NumericFilterElementRow(id.toDouble()) {
val id: String = data.id
val name: String = (data as RowRepresentable).getDisplayName() override val resId: Int? = row.resId
} val name: String = row.getDisplayName()
open class StaticDataFilterElementRow(var row: RowRepresentable, var id: String) : FilterElementRow() { fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context)
override val resId: Int? = row.resId }
val name: String = row.getDisplayName() }
fun getDataLocalizedTitle(context: Context): String { open class DurationFilterElement : NumericFilterElementRow(), Duration {
return row.localizedTitle(context) override var minutes: Int = 0
} override val doubleValue : Double
} get() {
return minutes.toDouble()
open class QuantityFilterElementRow(var value: Double = 0.0) : FilterElementRow() }
open class TimeFilterElementRow : QuantityFilterElementRow() { }
var minutes = value.toInt()
} open class AmountFilterElement : NumericFilterElementRow() {
var amount: Double = 0.0
open class MoreFilterElementRow : QuantityFilterElementRow() override val doubleValue : Double
open class LessFilterElementRow : QuantityFilterElementRow() get() {
open class MoreTimeFilterElementRow : TimeFilterElementRow() return amount
open class LessTimeFilterElementRow : TimeFilterElementRow() }
}
// Data classes
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 - holding value
object ResultMoreThan : AmountFilterElement(), MoreOperator
object ResultLessThan : AmountFilterElement(), LessOperator
object DurationMoreThan : DurationFilterElement(), MoreOperator
object DurationLessThan : DurationFilterElement(), LessOperator
object ReBuyMoreThan: AmountFilterElement(), MoreOperator
object ReBuyLessThan: AmountFilterElement(), 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)
//TODO: Refactor? //TODO: Refactor?
data class PastDays(var lastDays: Int = 0) : FilterElementRow() data class PastDays(var lastDays: Int = 0) : SingleValueFilterElementRow(lastDays) {
data class LastGames(var lastGames: Int) : FilterElementRow() override val intValue: Int
data class LastSessions(var lastSessions: Int) : FilterElementRow() 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 Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString())
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)
@ -140,14 +178,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
} }
} }
@ -174,10 +209,8 @@ sealed class FilterElementRow : RowRepresentable {
is Blind -> R.string.blinds is Blind -> R.string.blinds
is LastGames -> R.string.last_records is LastGames -> R.string.last_records
is LastSessions -> R.string.last_sessions is LastSessions -> R.string.last_sessions
is ReBuyMoreThan -> R.string.maximum is MoreOperator -> R.string.more_than
is ReBuyLessThan -> R.string.minimum is LessOperator -> R.string.less_than
is MoreFilterElementRow, is MoreTimeFilterElementRow -> R.string.more_than
is LessFilterElementRow, is LessTimeFilterElementRow -> R.string.less_than
else -> null else -> null
} }
} }
@ -220,6 +253,7 @@ sealed class FilterElementRow : RowRepresentable {
RowRepresentableEditDescriptor(lastSessions, R.string.last_sessions, inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(lastSessions, R.string.last_sessions, inputType = InputType.TYPE_CLASS_NUMBER)
) )
} }
is ReBuyMoreThan -> { is ReBuyMoreThan -> {
val reBuyMore: String? by map val reBuyMore: String? by map
arrayListOf( arrayListOf(
@ -232,8 +266,8 @@ sealed class FilterElementRow : RowRepresentable {
RowRepresentableEditDescriptor(reBuyLess, R.string.minimum, inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(reBuyLess, R.string.minimum, inputType = InputType.TYPE_CLASS_NUMBER)
) )
} }
is DurationMoreThan, is DurationLessThan -> {
val hours: String? by map is DurationFilterElement -> { val hours: String? by map
val minutes: String? by map val minutes: String? by map
arrayListOf( arrayListOf(
RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER), RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER),
@ -248,9 +282,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

@ -93,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()
@ -180,8 +180,8 @@ 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)) SESSIONS -> arrayListOf(LastGames(0), LastSessions(0))

Loading…
Cancel
Save