Improve cash filters

feature/top10
Aurelien Hubert 7 years ago
parent 0bba7c966d
commit 3d78ae4605
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  3. 188
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -51,6 +51,8 @@ enum class QueryCondition(var operator: Operator? = null) {
MORE_THAN_TOURNAMENT_FEE(Operator.MORE),
LESS_THAN_TOURNAMENT_FEE(Operator.LESS),
BETWEEN_TOURNAMENT_FEE(Operator.BETWEEN),
MIN_RE_BUY(Operator.MORE),
MAX_RE_BUY(Operator.LESS),
// Dates
STARTED_FROM_DATE,

@ -91,6 +91,11 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is FilterElementRow.AmountFilterElement -> {
val amount = if (row.amount > 0) row.amount.toString() else ""
val data = row.editingDescriptors(mapOf("amount" to amount))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
else -> {
updateRowsSelection(row)
}
@ -103,12 +108,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
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.DateFilterElementRow -> row.dateValue.shortDate()
is FilterElementRow.AmountFilterElement -> if (row.amount > 0) row.amount.toString() else NULL_TEXT
is FilterElementRow.DurationFilterElement -> row.minutes.toMinutes(requireContext())
// TODO: Refactor that
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)
}
}
@ -126,11 +127,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
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.LastSessions -> row.lastSessions = if (value != null && value is String) value.toInt() else 0
// TODO: Refactor that
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.AmountFilterElement -> row.amount = if (value != null && value is String) value.toDouble() else 0.0
is FilterElementRow.DurationFilterElement -> {
if (value is ArrayList<*>) {
val hours = try {

@ -11,62 +11,65 @@ import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheet
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.formatted
import net.pokeranalytics.android.util.extensions.round
import java.text.DateFormatSymbols
import java.util.*
sealed class FilterElementRow : RowRepresentable {
interface Duration {
var minutes : Int
}
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()
// Subclasses
open class SingleValueFilterElementRow(open val intValue: Int) : NumericFilterElementRow() {
override val doubleValue : Double
get() {
return intValue.toDouble()
}
}
open class DataFilterElementRow(data: Manageable) : StringFilterElementRow(data.id) {
val id: String = data.id
val name: String = (data as RowRepresentable).getDisplayName()
}
open class StaticDataFilterElementRow(var row: RowRepresentable, var id: Int) : NumericFilterElementRow(id.toDouble()) {
override val resId: Int? = row.resId
val name: String = row.getDisplayName()
fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context)
}
}
open class DurationFilterElement : NumericFilterElementRow(), Duration {
override var minutes: Int = 0
override val doubleValue : Double
get() {
return minutes.toDouble()
}
}
open class AmountFilterElement : NumericFilterElementRow() {
var amount: Double = 0.0
override val doubleValue : Double
get() {
return amount
}
}
interface Duration {
var minutes: Int
}
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()
// Subclasses
open class SingleValueFilterElementRow(open val intValue: Int) : NumericFilterElementRow() {
override val doubleValue: Double
get() {
return intValue.toDouble()
}
}
open class DataFilterElementRow(data: Manageable) : StringFilterElementRow(data.id) {
val id: String = data.id
val name: String = (data as RowRepresentable).getDisplayName()
}
open class StaticDataFilterElementRow(val row: RowRepresentable, val id: Int) : NumericFilterElementRow(id.toDouble()) {
override val resId: Int? = row.resId
val name: String = row.getDisplayName()
fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context)
}
}
open class DurationFilterElement : NumericFilterElementRow(), Duration {
override var minutes: Int = 0
override val doubleValue: Double
get() {
return minutes.toDouble()
}
}
open class AmountFilterElement : NumericFilterElementRow() {
var amount: Double = 0.0
override val doubleValue: Double
get() {
return amount
}
}
object Cash : BoolFilterElementRow()
object Tournament : BoolFilterElementRow()
@ -80,43 +83,53 @@ sealed class FilterElementRow : RowRepresentable {
object CurrentYear : BoolFilterElementRow()
object Weekday : BoolFilterElementRow()
object Weekend : BoolFilterElementRow()
object From : DateFilterElementRow()
object To : DateFilterElementRow()
// 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 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()
object From : DateFilterElementRow()
object To : DateFilterElementRow()
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 Blind(var sb: Double? = null, var bb: Double? = null, var code: String? = null) : FilterElementRow() {
val name: String
get() {
val currencyCode = code ?: Currency.getInstance(Locale.getDefault()).currencyCode
val currencySymbol = Currency.getInstance(currencyCode).symbol
return if (sb == null) NULL_TEXT else "$currencySymbol ${sb?.formatted()}/${bb?.round()}"
}
}
//TODO: Refactor?
data class PastDays(var lastDays: Int = 0) : SingleValueFilterElementRow(lastDays) {
override val intValue: Int
get() {
return lastDays
}
}
override val intValue: Int
get() {
return lastDays
}
}
data class LastGames(var lastGames: Int) : SingleValueFilterElementRow(lastGames) {
override val intValue: Int
get() {
return lastGames
}
}
override val intValue: Int
get() {
return lastGames
}
}
data class LastSessions(var lastSessions: Int) : SingleValueFilterElementRow(lastSessions) {
override val intValue: Int
get() {
return 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)
@ -167,9 +180,12 @@ sealed class FilterElementRow : RowRepresentable {
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
//TODO: Check the conditions
is LastGames -> QueryCondition.LAST_GAMES
is LastSessions -> QueryCondition.LAST_SESSIONS
is ReBuyMoreThan -> QueryCondition.MIN_RE_BUY
is ReBuyLessThan -> QueryCondition.MAX_RE_BUY
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
}
@ -206,9 +222,10 @@ sealed class FilterElementRow : RowRepresentable {
is Weekday -> R.string.week_days
is Weekend -> R.string.weekend
is PastDays -> R.string.period_in_days
is Blind -> R.string.blinds
is LastGames -> R.string.last_records
is LastSessions -> R.string.last_sessions
is ReBuyMoreThan -> R.string.minimum
is ReBuyLessThan -> R.string.maximum
is MoreOperator -> R.string.more_than
is LessOperator -> R.string.less_than
else -> null
@ -254,20 +271,16 @@ sealed class FilterElementRow : RowRepresentable {
)
}
is ReBuyMoreThan -> {
val reBuyMore: String? by map
arrayListOf(
RowRepresentableEditDescriptor(reBuyMore, R.string.maximum, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is ReBuyLessThan -> {
val reBuyLess: String? by map
//TODO: Refactor that
is AmountFilterElement -> {
val amount: String? by map
arrayListOf(
RowRepresentableEditDescriptor(reBuyLess, R.string.minimum, inputType = InputType.TYPE_CLASS_NUMBER)
RowRepresentableEditDescriptor(amount, R.string.amount, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is DurationFilterElement -> { val hours: String? by map
is DurationFilterElement -> {
val hours: String? by map
val minutes: String? by map
arrayListOf(
RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER),
@ -289,6 +302,7 @@ sealed class FilterElementRow : RowRepresentable {
}
is DataFilterElementRow -> this.name
is StaticDataFilterElementRow -> this.name
is Blind -> this.name
else -> super.getDisplayName()
}
}

@ -162,7 +162,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
blinds
}
CASH_RE_BUY_COUNT -> arrayListOf()
CASH_RE_BUY_COUNT -> arrayListOf(ReBuyMoreThan as FilterElementRow, ReBuyLessThan as FilterElementRow)
LOCATION -> arrayListOf()
BANKROLL -> arrayListOf()

Loading…
Cancel
Save