|
|
|
|
@ -36,17 +36,25 @@ import kotlin.collections.ArrayList |
|
|
|
|
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()) } |
|
|
|
|
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 } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun <T:QueryCondition> valueOf(name:String) : T { |
|
|
|
|
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() |
|
|
|
|
return instance as T |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline fun <reified T:Identifiable>getInstance(): QueryCondition { |
|
|
|
|
inline fun <reified T : Identifiable> getInstance(): QueryCondition { |
|
|
|
|
return when (T::class.java) { |
|
|
|
|
Bankroll::class.java -> AnyBankroll() |
|
|
|
|
Game::class.java -> AnyGame() |
|
|
|
|
@ -58,7 +66,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline fun < reified T: Filterable, reified S: QueryCondition, reified U:Comparable<U>>distinct(): RealmResults<T>? { |
|
|
|
|
inline fun <reified T : Filterable, reified S : QueryCondition, reified U : Comparable<U>> distinct(): RealmResults<T>? { |
|
|
|
|
FilterHelper.fieldNameForQueryType<T>(S::class.java)?.let { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
@ -94,7 +102,8 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
return baseId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val id: List<String> get() { |
|
|
|
|
val id: List<String> |
|
|
|
|
get() { |
|
|
|
|
when (this.operator) { |
|
|
|
|
Operator.MORE, Operator.LESS -> return listOf("$baseId+${this.operator.name}") |
|
|
|
|
} |
|
|
|
|
@ -102,8 +111,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
return when (this) { |
|
|
|
|
is SingleValue<*> -> listOf(baseId) |
|
|
|
|
is ListOfValues<*> -> { |
|
|
|
|
if (listOfValues.isEmpty()) { return listOf(baseId) } |
|
|
|
|
this.listOfValues.map{ "$baseId+$it" } |
|
|
|
|
if (listOfValues.isEmpty()) { |
|
|
|
|
return listOf(baseId) |
|
|
|
|
} |
|
|
|
|
this.listOfValues.map { "$baseId+$it" } |
|
|
|
|
} |
|
|
|
|
else -> listOf(baseId) |
|
|
|
|
} |
|
|
|
|
@ -111,10 +122,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
abstract var operator: Operator |
|
|
|
|
|
|
|
|
|
abstract class ListOfValues<T>: QueryCondition(), Comparable<ListOfValues<T>> where T:Comparable<T> { |
|
|
|
|
abstract class ListOfValues<T> : QueryCondition(), Comparable<ListOfValues<T>> where T : Comparable<T> { |
|
|
|
|
|
|
|
|
|
abstract var listOfValues: ArrayList<T> |
|
|
|
|
abstract fun labelForValue(value:T, context: Context): String |
|
|
|
|
abstract fun labelForValue(value: T, context: Context): String |
|
|
|
|
|
|
|
|
|
open fun entityName(context: Context): String { |
|
|
|
|
return getDisplayName(context) |
|
|
|
|
@ -122,12 +133,12 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
|
val prefix = this.resId?.let { |
|
|
|
|
context.getString(it)+" " |
|
|
|
|
context.getString(it) + " " |
|
|
|
|
} ?: "" |
|
|
|
|
|
|
|
|
|
return when (listOfValues.size) { |
|
|
|
|
0 -> return NULL_TEXT |
|
|
|
|
1,2 -> prefix+ listOfValues.map { labelForValue(it, context) }.joinToString(", ") |
|
|
|
|
1, 2 -> prefix + listOfValues.map { labelForValue(it, context) }.joinToString(", ") |
|
|
|
|
else -> "${listOfValues.size} $prefix ${entityName(context)}" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -136,52 +147,57 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
return listOfValues.sorted().first().compareTo(other.listOfValues.sorted().first()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun firstValue(context:Context): String? { |
|
|
|
|
fun firstValue(context: Context): String? { |
|
|
|
|
return this.listOfValues.firstOrNull()?.let { this.labelForValue(it, context) } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class SingleValue<T>: ListOfValues<T>() where T:Comparable<T> { |
|
|
|
|
abstract class SingleValue<T> : ListOfValues<T>() where T : Comparable<T> { |
|
|
|
|
override var listOfValues = ArrayList<T>() |
|
|
|
|
abstract var singleValue : T? |
|
|
|
|
abstract var singleValue: T? |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class ListOfDouble: ListOfValues<Double>() { |
|
|
|
|
abstract class ListOfDouble : ListOfValues<Double>() { |
|
|
|
|
open var sign: Int = 1 |
|
|
|
|
override var operator: Operator = Operator.ANY |
|
|
|
|
override var listOfValues : ArrayList<Double> = arrayListOf() |
|
|
|
|
override var listOfValues: ArrayList<Double> = arrayListOf() |
|
|
|
|
override fun updateValueBy(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueBy(filterCondition) |
|
|
|
|
listOfValues = filterCondition.getValues() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Double, context: Context): String { |
|
|
|
|
return value.toCurrency(UserDefaults.currency) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class ListOfInt: ListOfValues<Int>() { |
|
|
|
|
abstract class ListOfInt : ListOfValues<Int>() { |
|
|
|
|
override var operator: Operator = Operator.ANY |
|
|
|
|
override var listOfValues : ArrayList<Int> = arrayListOf() |
|
|
|
|
override var listOfValues: ArrayList<Int> = arrayListOf() |
|
|
|
|
override fun updateValueBy(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueBy(filterCondition) |
|
|
|
|
listOfValues = filterCondition.getValues() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return value.toString() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class ListOfString: ListOfValues<String>() { |
|
|
|
|
abstract class ListOfString : ListOfValues<String>() { |
|
|
|
|
override var operator: Operator = Operator.ANY |
|
|
|
|
override var listOfValues = ArrayList<String>() |
|
|
|
|
override fun labelForValue(value: String, context: Context): String { return value } |
|
|
|
|
override fun labelForValue(value: String, context: Context): String { |
|
|
|
|
return value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun updateValueBy(filterCondition: FilterCondition) { |
|
|
|
|
super.updateValueBy(filterCondition) |
|
|
|
|
listOfValues = filterCondition.getValues() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class SingleDate: SingleValue<Date>() { |
|
|
|
|
abstract class SingleDate : SingleValue<Date>() { |
|
|
|
|
override fun labelForValue(value: Date, context: Context): String { |
|
|
|
|
return value.shortDate() |
|
|
|
|
} |
|
|
|
|
@ -189,7 +205,9 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
override var listOfValues = ArrayList<Date>() |
|
|
|
|
|
|
|
|
|
override var singleValue: Date? |
|
|
|
|
get() { return listOfValues.firstOrNull() } |
|
|
|
|
get() { |
|
|
|
|
return listOfValues.firstOrNull() |
|
|
|
|
} |
|
|
|
|
set(value) { |
|
|
|
|
listOfValues.removeAll(this.listOfValues) |
|
|
|
|
value?.let { listOfValues.add(it) } |
|
|
|
|
@ -201,13 +219,15 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class SingleInt: SingleValue<Int>() { |
|
|
|
|
abstract class SingleInt : SingleValue<Int>() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return value.toString() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override var singleValue: Int? |
|
|
|
|
get() { return listOfValues.firstOrNull() } |
|
|
|
|
get() { |
|
|
|
|
return listOfValues.firstOrNull() |
|
|
|
|
} |
|
|
|
|
set(value) { |
|
|
|
|
listOfValues.removeAll(this.listOfValues) |
|
|
|
|
value?.let { listOfValues.add(it) } |
|
|
|
|
@ -228,20 +248,20 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
override var filterSectionRow: FilterSectionRow = FilterSectionRow.CashOrTournament |
|
|
|
|
|
|
|
|
|
abstract class QueryDataCondition < T: NameManageable > : ListOfString() { |
|
|
|
|
abstract class QueryDataCondition<T : NameManageable> : ListOfString() { |
|
|
|
|
fun setObject(dataObject: T) { |
|
|
|
|
this.listOfValues.removeAll(this.listOfValues) |
|
|
|
|
this.listOfValues.add(dataObject.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract val entity : Class<T> |
|
|
|
|
abstract val entity: Class<T> |
|
|
|
|
|
|
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val entityName = entityName(realm) |
|
|
|
|
val completeLabel = when (listOfValues.size) { |
|
|
|
|
0 -> NULL_TEXT |
|
|
|
|
1,2 -> { |
|
|
|
|
1, 2 -> { |
|
|
|
|
listOfValues.map { labelForValue(realm, it) }.joinToString(", ") |
|
|
|
|
} |
|
|
|
|
else -> "${listOfValues.size} $entityName" |
|
|
|
|
@ -254,7 +274,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
return baseId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun labelForValue(realm:Realm, value:String): String { |
|
|
|
|
private fun labelForValue(realm: Realm, value: String): String { |
|
|
|
|
val query = realm.where(entity) |
|
|
|
|
return query.equalTo("id", value).findFirst()?.name ?: NULL_TEXT |
|
|
|
|
} |
|
|
|
|
@ -265,7 +285,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
val showTime: Boolean |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class DateQuery: SingleDate(), DateTime { |
|
|
|
|
abstract class DateQuery : SingleDate(), DateTime { |
|
|
|
|
override val showTime: Boolean = false |
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Date, context: Context): String { |
|
|
|
|
@ -279,11 +299,11 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class TimeQuery: DateQuery() { |
|
|
|
|
abstract class TimeQuery : DateQuery() { |
|
|
|
|
override val showTime: Boolean = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class TrueQueryCondition: QueryCondition() { |
|
|
|
|
abstract class TrueQueryCondition : QueryCondition() { |
|
|
|
|
override var operator: Operator = Operator.TRUE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -295,77 +315,84 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
object IsTournament : TrueQueryCondition() |
|
|
|
|
|
|
|
|
|
class AnyBankroll(): QueryDataCondition<Bankroll>() { |
|
|
|
|
class AnyBankroll() : QueryDataCondition<Bankroll>() { |
|
|
|
|
override var entity: Class<Bankroll> = Bankroll::class.java |
|
|
|
|
constructor(bankroll: Bankroll): this() { |
|
|
|
|
|
|
|
|
|
constructor(bankroll: Bankroll) : this() { |
|
|
|
|
this.setObject(bankroll) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyGame(): QueryDataCondition<Game>() { |
|
|
|
|
class AnyGame() : QueryDataCondition<Game>() { |
|
|
|
|
override val entity: Class<Game> = Game::class.java |
|
|
|
|
constructor(game: Game): this() { |
|
|
|
|
|
|
|
|
|
constructor(game: Game) : this() { |
|
|
|
|
this.setObject(game) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyTournamentName(): QueryDataCondition<TournamentName>() { |
|
|
|
|
class AnyTournamentName() : QueryDataCondition<TournamentName>() { |
|
|
|
|
override val entity: Class<TournamentName> = TournamentName::class.java |
|
|
|
|
constructor(tournamentName: TournamentName): this() { |
|
|
|
|
|
|
|
|
|
constructor(tournamentName: TournamentName) : this() { |
|
|
|
|
this.setObject(tournamentName) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyTournamentFeature(): QueryDataCondition<TournamentFeature>() { |
|
|
|
|
class AnyTournamentFeature() : QueryDataCondition<TournamentFeature>() { |
|
|
|
|
override val entity: Class<TournamentFeature> = TournamentFeature::class.java |
|
|
|
|
constructor(tournamentFeature: TournamentFeature): this() { |
|
|
|
|
|
|
|
|
|
constructor(tournamentFeature: TournamentFeature) : this() { |
|
|
|
|
this.setObject(tournamentFeature) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AllTournamentFeature(): QueryDataCondition<TournamentFeature>() { |
|
|
|
|
class AllTournamentFeature() : QueryDataCondition<TournamentFeature>() { |
|
|
|
|
override var operator = Operator.ALL |
|
|
|
|
override val entity: Class<TournamentFeature> = TournamentFeature::class.java |
|
|
|
|
constructor(tournamentFeature: TournamentFeature): this() { |
|
|
|
|
|
|
|
|
|
constructor(tournamentFeature: TournamentFeature) : this() { |
|
|
|
|
this.setObject(tournamentFeature) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyLocation(): QueryDataCondition<Location>() { |
|
|
|
|
class AnyLocation() : QueryDataCondition<Location>() { |
|
|
|
|
override val entity: Class<Location> = Location::class.java |
|
|
|
|
constructor(location: Location): this() { |
|
|
|
|
|
|
|
|
|
constructor(location: Location) : this() { |
|
|
|
|
this.setObject(location) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyTransactionType(): QueryDataCondition<TransactionType>() { |
|
|
|
|
class AnyTransactionType() : QueryDataCondition<TransactionType>() { |
|
|
|
|
override val entity: Class<TransactionType> = TransactionType::class.java |
|
|
|
|
constructor(transactionType: TransactionType): this() { |
|
|
|
|
|
|
|
|
|
constructor(transactionType: TransactionType) : this() { |
|
|
|
|
this.setObject(transactionType) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyLimit: ListOfInt() { |
|
|
|
|
class AnyLimit : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return Limit.values()[value].getDisplayName(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyTableSize: ListOfInt() { |
|
|
|
|
class AnyTableSize : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return TableSize(value).getDisplayName(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyTournamentType: ListOfInt() { |
|
|
|
|
class AnyTournamentType : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return TournamentType.values()[value].getDisplayName(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyBlind: ListOfString() |
|
|
|
|
class AnyBlind : ListOfString() |
|
|
|
|
|
|
|
|
|
object Last: SingleInt() { |
|
|
|
|
object Last : SingleInt() { |
|
|
|
|
override var operator = Operator.EQUALS |
|
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
|
//TODO update string "last %i" |
|
|
|
|
@ -373,9 +400,9 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class NumberOfTable: ListOfInt() { |
|
|
|
|
class NumberOfTable : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return value.toString()+" "+context.getString(R.string.tables) |
|
|
|
|
return value.toString() + " " + context.getString(R.string.tables) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
|
@ -383,7 +410,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class NumberOfRebuy(): ListOfDouble() { |
|
|
|
|
class NumberOfRebuy() : ListOfDouble() { |
|
|
|
|
constructor(operator: Operator, numberOfRebuy: Double) : this() { |
|
|
|
|
this.operator = operator |
|
|
|
|
this.listOfValues = arrayListOf(numberOfRebuy) |
|
|
|
|
@ -394,7 +421,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TournamentFinalPosition(): ListOfInt() { |
|
|
|
|
class TournamentFinalPosition() : ListOfInt() { |
|
|
|
|
constructor(operator: Operator, finalPosition: Int) : this() { |
|
|
|
|
this.operator = operator |
|
|
|
|
this.listOfValues = arrayListOf(finalPosition) |
|
|
|
|
@ -402,7 +429,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
val nf = RuleBasedNumberFormat(Locale.getDefault(), RuleBasedNumberFormat.ORDINAL) |
|
|
|
|
return nf.format(value)+" "+context.getString(R.string.position) |
|
|
|
|
return nf.format(value) + " " + context.getString(R.string.position) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
|
@ -410,14 +437,16 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
open class NetAmount: ListOfDouble() |
|
|
|
|
open class NetAmount : ListOfDouble() |
|
|
|
|
|
|
|
|
|
class NetAmountWon: NetAmount() |
|
|
|
|
class NetAmountLost: NetAmount() { override var sign: Int = -1 } |
|
|
|
|
class NetAmountWon : NetAmount() |
|
|
|
|
class NetAmountLost : NetAmount() { |
|
|
|
|
override var sign: Int = -1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TournamentNumberOfPlayer: ListOfInt() { |
|
|
|
|
class TournamentNumberOfPlayer : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return value.toString()+" "+context.getString(R.string.number_of_players) |
|
|
|
|
return value.toString() + " " + context.getString(R.string.number_of_players) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
|
@ -425,53 +454,64 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StartedFromDate: DateQuery() { override var operator = Operator.MORE } |
|
|
|
|
class StartedToDate: DateQuery() { override var operator = Operator.LESS } |
|
|
|
|
class EndedFromDate: DateQuery() { override var operator = Operator.MORE } |
|
|
|
|
class EndedToDate: DateQuery() { override var operator = Operator.LESS } |
|
|
|
|
class StartedFromDate : DateQuery() { |
|
|
|
|
override var operator = Operator.MORE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StartedToDate : DateQuery() { |
|
|
|
|
override var operator = Operator.LESS |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EndedFromDate : DateQuery() { |
|
|
|
|
override var operator = Operator.MORE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EndedToDate : DateQuery() { |
|
|
|
|
override var operator = Operator.LESS |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyDayOfWeek: ListOfInt() { |
|
|
|
|
class AnyDayOfWeek : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[value].capitalize() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyMonthOfYear(): ListOfInt() { |
|
|
|
|
class AnyMonthOfYear() : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).months[value].capitalize() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constructor(month:Int) : this() { |
|
|
|
|
constructor(month: Int) : this() { |
|
|
|
|
listOfValues = arrayListOf(month) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class AnyYear(): ListOfInt() { |
|
|
|
|
class AnyYear() : ListOfInt() { |
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
|
return "$value" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constructor(year:Int) : this() { |
|
|
|
|
constructor(year: Int) : this() { |
|
|
|
|
listOfValues = arrayListOf(year) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
object IsWeekDay: TrueQueryCondition() |
|
|
|
|
object IsWeekEnd: TrueQueryCondition() |
|
|
|
|
object IsToday: TrueQueryCondition() |
|
|
|
|
object WasYesterday: TrueQueryCondition() |
|
|
|
|
object WasTodayAndYesterday: TrueQueryCondition() |
|
|
|
|
object DuringThisWeek: TrueQueryCondition() |
|
|
|
|
object DuringThisMonth: TrueQueryCondition() |
|
|
|
|
object DuringThisYear: TrueQueryCondition() |
|
|
|
|
object IsWeekDay : TrueQueryCondition() |
|
|
|
|
object IsWeekEnd : TrueQueryCondition() |
|
|
|
|
object IsToday : TrueQueryCondition() |
|
|
|
|
object WasYesterday : TrueQueryCondition() |
|
|
|
|
object WasTodayAndYesterday : TrueQueryCondition() |
|
|
|
|
object DuringThisWeek : TrueQueryCondition() |
|
|
|
|
object DuringThisMonth : TrueQueryCondition() |
|
|
|
|
object DuringThisYear : TrueQueryCondition() |
|
|
|
|
|
|
|
|
|
class TournamentFee: ListOfDouble() { |
|
|
|
|
class TournamentFee : ListOfDouble() { |
|
|
|
|
override fun labelForValue(value: Double, context: Context): String { |
|
|
|
|
return value.toCurrency(UserDefaults.currency) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class PastDay: SingleInt() { |
|
|
|
|
class PastDay : SingleInt() { |
|
|
|
|
override var operator = Operator.EQUALS |
|
|
|
|
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
|
|
|
|
|
|
@ -481,21 +521,25 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
|
return this.resId?.let { |
|
|
|
|
" "+context.getString(it) |
|
|
|
|
" " + context.getString(it) |
|
|
|
|
} ?: "" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class Duration: SingleInt() { |
|
|
|
|
class Duration : SingleInt() { |
|
|
|
|
override var operator = Operator.EQUALS |
|
|
|
|
var minutes:Int? |
|
|
|
|
get() { return singleValue } |
|
|
|
|
set(value) { singleValue = value } |
|
|
|
|
var minutes: Int? |
|
|
|
|
get() { |
|
|
|
|
return singleValue |
|
|
|
|
} |
|
|
|
|
set(value) { |
|
|
|
|
singleValue = value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val netDuration: Long? |
|
|
|
|
get() { |
|
|
|
|
minutes?.let { |
|
|
|
|
return (it*60*1000).toLong() |
|
|
|
|
return (it * 60 * 1000).toLong() |
|
|
|
|
} |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
@ -508,25 +552,27 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StartedFromTime(): TimeQuery() { |
|
|
|
|
class StartedFromTime() : TimeQuery() { |
|
|
|
|
override var operator = Operator.MORE |
|
|
|
|
constructor(date:Date): this() { |
|
|
|
|
|
|
|
|
|
constructor(date: Date) : this() { |
|
|
|
|
singleValue = date |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EndedToTime(): TimeQuery() { |
|
|
|
|
class EndedToTime() : TimeQuery() { |
|
|
|
|
override var operator = Operator.LESS |
|
|
|
|
constructor(date:Date): this() { |
|
|
|
|
|
|
|
|
|
constructor(date: Date) : this() { |
|
|
|
|
singleValue = date |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface CustomFieldRelated { |
|
|
|
|
var customFieldId : String |
|
|
|
|
var customFieldId: String |
|
|
|
|
|
|
|
|
|
fun customFieldName(realm: Realm): String { |
|
|
|
|
val query = realm.where(CustomField::class.java) |
|
|
|
|
@ -539,15 +585,18 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
class CustomFieldQuery() : QueryDataCondition<CustomField>() { |
|
|
|
|
override var entity: Class<CustomField> = CustomField::class.java |
|
|
|
|
constructor(customField: CustomField): this() { |
|
|
|
|
|
|
|
|
|
constructor(customField: CustomField) : this() { |
|
|
|
|
this.setObject(customField) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
open class CustomFieldNumberQuery() : ListOfDouble(), CustomFieldRelated { |
|
|
|
|
override var customFieldId : String = "" |
|
|
|
|
|
|
|
|
|
override var customFieldId: String = "" |
|
|
|
|
override var operator: Operator = Operator.EQUALS |
|
|
|
|
constructor(customFieldId: String, value: Double): this() { |
|
|
|
|
|
|
|
|
|
constructor(customFieldId: String, value: Double) : this() { |
|
|
|
|
this.listOfValues = arrayListOf(value) |
|
|
|
|
this.customFieldId = customFieldId |
|
|
|
|
} |
|
|
|
|
@ -556,13 +605,13 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val name = customFieldName(realm) |
|
|
|
|
val prefix = this.resId?.let { |
|
|
|
|
context.getString(it)+" " |
|
|
|
|
context.getString(it) + " " |
|
|
|
|
} ?: "" |
|
|
|
|
|
|
|
|
|
val completeLabel = when (listOfValues.size) { |
|
|
|
|
0 -> return NULL_TEXT |
|
|
|
|
1,2 -> { |
|
|
|
|
return name+prefix+listOfValues.map { labelForValue(it, context) }.joinToString(", ") |
|
|
|
|
1, 2 -> { |
|
|
|
|
return name + prefix + listOfValues.map { labelForValue(it, context) }.joinToString(", ") |
|
|
|
|
} |
|
|
|
|
else -> "${listOfValues.size} $prefix $name" |
|
|
|
|
} |
|
|
|
|
@ -589,10 +638,12 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
class CustomFieldListQuery() : QueryDataCondition<CustomFieldEntry>(), CustomFieldRelated { |
|
|
|
|
override var entity: Class<CustomFieldEntry> = CustomFieldEntry::class.java |
|
|
|
|
override var customFieldId : String = "" |
|
|
|
|
constructor(customFieldEntry: CustomFieldEntry): this() { |
|
|
|
|
override var customFieldId: String = "" |
|
|
|
|
|
|
|
|
|
constructor(customFieldEntry: CustomFieldEntry) : this() { |
|
|
|
|
this.setObject(customFieldEntry) |
|
|
|
|
this.customFieldId = customFieldEntry.customField?.id ?: throw PokerAnalyticsException.QueryValueMapUnexpectedValue |
|
|
|
|
this.customFieldId = |
|
|
|
|
customFieldEntry.customField?.id ?: throw PokerAnalyticsException.QueryValueMapUnexpectedValue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun entityName(realm: Realm): String { |
|
|
|
|
@ -610,7 +661,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
* main method of the enum |
|
|
|
|
* providing a base RealmQuery [realmQuery], the method is able to attached the corresponding query and returns the newly formed [RealmQuery] |
|
|
|
|
*/ |
|
|
|
|
inline fun <reified T : Filterable> queryWith(realmQuery: RealmQuery<T>, otherQueryCondition:QueryCondition? = null): RealmQuery<T> { |
|
|
|
|
inline fun <reified T : Filterable> queryWith( |
|
|
|
|
realmQuery: RealmQuery<T>, |
|
|
|
|
otherQueryCondition: QueryCondition? = null |
|
|
|
|
): RealmQuery<T> { |
|
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this::class.java) |
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
@ -633,20 +687,23 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
is IsToday -> { |
|
|
|
|
val startDate = Date() |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, startDate.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, startDate.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is WasTodayAndYesterday -> { |
|
|
|
|
val startDate = Date() |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = startDate |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, -24) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is WasYesterday -> { |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = Date() |
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, -24) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, calendar.time.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, calendar.time.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is PastDay -> { |
|
|
|
|
singleValue?.let { |
|
|
|
|
@ -654,7 +711,8 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = startDate |
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, -it) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
return realmQuery |
|
|
|
|
} |
|
|
|
|
@ -663,21 +721,24 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = startDate |
|
|
|
|
calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, Calendar.SUNDAY) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is DuringThisMonth -> { |
|
|
|
|
val startDate = Date() |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = startDate |
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is DuringThisYear -> { |
|
|
|
|
val startDate = Date() |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
calendar.time = startDate |
|
|
|
|
calendar.set(Calendar.DAY_OF_YEAR, 1) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and().lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, calendar.time.startOfDay()).and() |
|
|
|
|
.lessThanOrEqualTo(fieldName, startDate.endOfDay()) |
|
|
|
|
} |
|
|
|
|
is StartedFromTime -> { |
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
@ -685,7 +746,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
calendar.time = it |
|
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
|
if (otherQueryCondition is EndedToTime) { |
|
|
|
|
otherQueryCondition.singleValue?.let {endTime -> |
|
|
|
|
otherQueryCondition.singleValue?.let { endTime -> |
|
|
|
|
calendar.time = endTime |
|
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
|
} |
|
|
|
|
@ -727,8 +788,14 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
return when (operator) { |
|
|
|
|
Operator.EQUALS -> { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.equalTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleInt -> realmQuery.equalTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleDate -> realmQuery.equalTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is SingleInt -> realmQuery.equalTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is ListOfInt -> realmQuery.equalTo(fieldName, listOfValues.first()) |
|
|
|
|
is ListOfDouble -> realmQuery.equalTo(fieldName, listOfValues.first() * sign) |
|
|
|
|
is ListOfString -> realmQuery.equalTo(fieldName, listOfValues.first()) |
|
|
|
|
@ -737,9 +804,18 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
Operator.MORE -> { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue?.startOfDay()?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is Duration -> realmQuery.greaterThanOrEqualTo(fieldName, netDuration?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleInt -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleDate -> realmQuery.greaterThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue?.startOfDay() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is Duration -> realmQuery.greaterThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
netDuration ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is SingleInt -> realmQuery.greaterThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is ListOfInt -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is NetAmountLost -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first() * -1) |
|
|
|
|
is ListOfDouble -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first() * sign) |
|
|
|
|
@ -748,9 +824,18 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
} |
|
|
|
|
Operator.LESS -> { |
|
|
|
|
when (this) { |
|
|
|
|
is SingleDate -> realmQuery.lessThanOrEqualTo(fieldName, singleValue?.endOfDay()?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is Duration -> realmQuery.lessThanOrEqualTo(fieldName, netDuration?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleInt -> realmQuery.lessThanOrEqualTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
|
is SingleDate -> realmQuery.lessThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue?.endOfDay() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is Duration -> realmQuery.lessThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
netDuration ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is SingleInt -> realmQuery.lessThanOrEqualTo( |
|
|
|
|
fieldName, |
|
|
|
|
singleValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
) |
|
|
|
|
is ListOfInt -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
|
is NetAmountLost -> { |
|
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first() * -1) |
|
|
|
|
|