|
|
|
|
@ -49,6 +49,10 @@ inline fun <reified T : Filterable> List<QueryCondition>.queryWith(query: RealmQ |
|
|
|
|
|
|
|
|
|
sealed class QueryCondition : FilterElementRow { |
|
|
|
|
companion object { |
|
|
|
|
inline fun < reified T:QueryCondition> more():T { return T::class.java.newInstance().apply { this.operator = Operator.MORE } } |
|
|
|
|
inline fun < reified T:QueryCondition> less():T { return T::class.java.newInstance().apply { this.operator = Operator.LESS } } |
|
|
|
|
inline fun < reified T:QueryCondition> moreOrLess():ArrayList<T> { return arrayListOf(more(), less()) } |
|
|
|
|
|
|
|
|
|
fun <T:QueryCondition> valueOf(name:String) : T { |
|
|
|
|
val kClass = Class.forName("${QueryCondition::class.qualifiedName}$$name").kotlin |
|
|
|
|
val instance = kClass.objectInstance ?: kClass.java.newInstance() |
|
|
|
|
@ -57,7 +61,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
inline fun <reified T:Identifiable>getInstance(): QueryCondition { |
|
|
|
|
return when (T::class.java) { |
|
|
|
|
AnyBankroll::class.java -> AnyBankroll() |
|
|
|
|
Bankroll::class.java -> AnyBankroll() |
|
|
|
|
Game::class.java -> AnyGame() |
|
|
|
|
Location::class.java -> AnyLocation() |
|
|
|
|
TournamentName::class.java -> AnyTournamentName() |
|
|
|
|
@ -97,7 +101,12 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
val baseId = this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName |
|
|
|
|
|
|
|
|
|
val id: List<String> get() { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE, Operator.LESS -> return listOf("$baseId+${this.operator.name}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return when (this) { |
|
|
|
|
is SingleValue<*> -> listOf(baseId) |
|
|
|
|
is ListOfValues<*> -> { |
|
|
|
|
if (listOfValues.isEmpty()) { return listOf(baseId) } |
|
|
|
|
this.listOfValues.map{ "$baseId+$it" } |
|
|
|
|
@ -131,7 +140,9 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class ListOfDouble: ListOfValues<Double>() { |
|
|
|
|
override var listOfValues = ArrayList<Double>() |
|
|
|
|
open var sign: Int = 1 |
|
|
|
|
|
|
|
|
|
override var listOfValues = arrayListOf(0.0) |
|
|
|
|
override fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueMap(filterCondition) |
|
|
|
|
listOfValues = filterCondition.getValues() |
|
|
|
|
@ -142,9 +153,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class ListOfInt: ListOfValues<Int>() { |
|
|
|
|
override var listOfValues = ArrayList<Int>() |
|
|
|
|
override var listOfValues = arrayListOf(0) |
|
|
|
|
override fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueMap(filterCondition) |
|
|
|
|
println("<<<< updateValueMap ${filterCondition.intValues}") |
|
|
|
|
listOfValues = filterCondition.getValues() |
|
|
|
|
} |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
@ -176,20 +188,6 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class SingleDouble: SingleValue<Double>() { |
|
|
|
|
override fun labelForValue(value: Double): String { |
|
|
|
|
return value.toCurrency(UserDefaults.currency) |
|
|
|
|
} |
|
|
|
|
override var singleValue: Double |
|
|
|
|
get() { return listOfValues.firstOrNull() ?: 0.0 } |
|
|
|
|
set(value) { listOfValues.add(value) } |
|
|
|
|
|
|
|
|
|
override fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueMap(filterCondition) |
|
|
|
|
singleValue = filterCondition.getValue() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class SingleInt: SingleValue<Int>() { |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
return value.toString() |
|
|
|
|
@ -242,9 +240,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
abstract class DateQuery: SingleDate(), DateTime { |
|
|
|
|
override val showTime: Boolean = false |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class TimeQuery: SingleDate(), DateTime { |
|
|
|
|
abstract class TimeQuery: DateQuery() { |
|
|
|
|
override val showTime: Boolean = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -327,30 +326,15 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
class AnyBlind: ListOfString() |
|
|
|
|
|
|
|
|
|
class LastGame: SingleInt() |
|
|
|
|
class LastSession: SingleDate() |
|
|
|
|
class LastSession: SingleInt() |
|
|
|
|
|
|
|
|
|
class NumberOfTable: ListOfInt() |
|
|
|
|
|
|
|
|
|
class NetResult(): ListOfDouble() { |
|
|
|
|
constructor(operator:Operator): this() { |
|
|
|
|
this.operator = operator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class BuyIn: ListOfDouble() |
|
|
|
|
|
|
|
|
|
class CashOut: ListOfDouble() |
|
|
|
|
|
|
|
|
|
class Tips: ListOfDouble() |
|
|
|
|
open class NetAmountWon: ListOfDouble() |
|
|
|
|
class NetAmountLost: NetAmountWon() { override var sign: Int = -1 } |
|
|
|
|
|
|
|
|
|
class NumberOfPlayer: ListOfInt() |
|
|
|
|
|
|
|
|
|
class Rebuy(): ListOfDouble() { |
|
|
|
|
constructor(operator:Operator): this() { |
|
|
|
|
this.operator = operator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StartedFromDate: DateQuery() { override var operator = Operator.MORE } |
|
|
|
|
class StartedToDate: DateQuery() { override var operator = Operator.LESS } |
|
|
|
|
class EndedFromDate: DateQuery() { override var operator = Operator.MORE } |
|
|
|
|
@ -389,21 +373,32 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class PastDay: SingleInt() |
|
|
|
|
class Duration(): SingleInt() { |
|
|
|
|
constructor(operator:Operator): this() { |
|
|
|
|
this.operator = operator |
|
|
|
|
} |
|
|
|
|
class PastDay: SingleInt() { |
|
|
|
|
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class Duration: SingleInt() { |
|
|
|
|
var minutes:Int |
|
|
|
|
get() { return singleValue } |
|
|
|
|
set(value) { singleValue = value } |
|
|
|
|
|
|
|
|
|
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
override val bottomSheetType: BottomSheetType = BottomSheetType.DOUBLE_EDIT_TEXT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StartedFromTime: TimeQuery() { override var operator = Operator.MORE } |
|
|
|
|
class EndedToTime: TimeQuery() { override var operator = Operator.LESS } |
|
|
|
|
class StartedFromTime: TimeQuery() { |
|
|
|
|
override var operator = Operator.MORE |
|
|
|
|
init { |
|
|
|
|
this.singleValue = Date().startOfDay() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class HasComment: QueryCondition() |
|
|
|
|
class EndedToTime: TimeQuery() { |
|
|
|
|
override var operator = Operator.LESS |
|
|
|
|
init { |
|
|
|
|
this.singleValue = Date().endOfDay() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* main method of the enum |
|
|
|
|
@ -472,9 +467,8 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.equalTo(fieldName, singleValue) |
|
|
|
|
is SingleInt -> realmQuery.equalTo(fieldName, singleValue) |
|
|
|
|
is SingleDouble -> realmQuery.equalTo(fieldName, singleValue) |
|
|
|
|
is ListOfInt -> realmQuery.equalTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.equalTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.equalTo(fieldName, listOfValues.first() * sign) |
|
|
|
|
is ListOfString -> realmQuery.equalTo(fieldName, listOfValues.first()) |
|
|
|
|
else -> realmQuery |
|
|
|
|
} |
|
|
|
|
@ -483,9 +477,8 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is SingleInt -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is SingleDouble -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is ListOfInt -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first() * sign) |
|
|
|
|
else -> realmQuery |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -493,9 +486,8 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.lessThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is SingleInt -> realmQuery.lessThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is SingleDouble -> realmQuery.lessThanOrEqualTo(fieldName, singleValue) |
|
|
|
|
is ListOfInt -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first() * sign) |
|
|
|
|
else -> realmQuery |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -506,7 +498,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
realmQuery |
|
|
|
|
} |
|
|
|
|
is ListOfDouble -> { |
|
|
|
|
listOfValues.forEach { realmQuery.equalTo(fieldName, it) } |
|
|
|
|
listOfValues.forEach { realmQuery.equalTo(fieldName, it * sign) } |
|
|
|
|
realmQuery |
|
|
|
|
} |
|
|
|
|
is ListOfString -> { |
|
|
|
|
@ -537,10 +529,13 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
override val viewType: Int |
|
|
|
|
get() { |
|
|
|
|
return when (this) { |
|
|
|
|
is PastDay, is StartedFromDate, is EndedToDate, is StartedFromTime, is EndedToTime, is LastGame, is LastSession, is Duration -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
is PastDay -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
is LastGame -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
is LastSession -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
else -> { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE, Operator.LESS -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
Operator.MORE -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
Operator.LESS -> RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
else -> RowViewType.TITLE_CHECK.ordinal |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -550,11 +545,13 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
override val bottomSheetType: BottomSheetType |
|
|
|
|
get() { |
|
|
|
|
return when (this) { |
|
|
|
|
is PastDay, is LastGame, is LastSession -> BottomSheetType.EDIT_TEXT |
|
|
|
|
is Duration -> BottomSheetType.DOUBLE_EDIT_TEXT |
|
|
|
|
is PastDay -> BottomSheetType.EDIT_TEXT |
|
|
|
|
is LastGame -> BottomSheetType.EDIT_TEXT |
|
|
|
|
is LastSession -> BottomSheetType.EDIT_TEXT |
|
|
|
|
else -> { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE, Operator.LESS -> BottomSheetType.EDIT_TEXT |
|
|
|
|
Operator.MORE -> BottomSheetType.EDIT_TEXT |
|
|
|
|
Operator.LESS -> BottomSheetType.EDIT_TEXT |
|
|
|
|
else -> BottomSheetType.NONE |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -581,6 +578,20 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
is PastDay -> R.string.period_in_days |
|
|
|
|
is LastGame -> R.string.last_records |
|
|
|
|
is LastSession -> R.string.last_sessions |
|
|
|
|
is NetAmountWon -> { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE -> R.string.won_amount_more_than |
|
|
|
|
Operator.LESS -> R.string.won_amount_less_than |
|
|
|
|
else -> null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
is NetAmountLost -> { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE -> R.string.lost_amount_more_than |
|
|
|
|
Operator.LESS -> R.string.lost_amount_less_than |
|
|
|
|
else -> null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE -> R.string.more_than |
|
|
|
|
|