|
|
|
@ -7,6 +7,7 @@ import io.realm.RealmQuery |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.Sort |
|
|
|
import io.realm.Sort |
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.kotlin.where |
|
|
|
|
|
|
|
import net.pokeranalytics.android.BuildConfig |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
@ -52,7 +53,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
Location::class.java -> AnyLocation() |
|
|
|
Location::class.java -> AnyLocation() |
|
|
|
TransactionType::class.java -> AnyTransactionType() |
|
|
|
TransactionType::class.java -> AnyTransactionType() |
|
|
|
TournamentName::class.java -> AnyTournamentName() |
|
|
|
TournamentName::class.java -> AnyTournamentName() |
|
|
|
TournamentFeature::class.java -> AnyTournamentFeature() |
|
|
|
TournamentFeature::class.java -> AllTournamentFeature() |
|
|
|
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
|
|
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -116,7 +117,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
abstract fun labelForValue(value:T, context: Context): String |
|
|
|
abstract fun labelForValue(value:T, context: Context): String |
|
|
|
|
|
|
|
|
|
|
|
open fun entityName(context: Context): String { |
|
|
|
open fun entityName(context: Context): String { |
|
|
|
return baseId |
|
|
|
return getDisplayName(context) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
override fun getDisplayName(context: Context): String { |
|
|
|
@ -374,11 +375,11 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
|
|
class NumberOfTable: ListOfInt() { |
|
|
|
class NumberOfTable: ListOfInt() { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
return value.toString() |
|
|
|
return value.toString()+" "+context.getString(R.string.tables) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
override fun entityName(context: Context): String { |
|
|
|
return context.getString(R.string.number_of_tables) |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -401,7 +402,11 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
val nf = RuleBasedNumberFormat(Locale.getDefault(), RuleBasedNumberFormat.ORDINAL) |
|
|
|
val nf = RuleBasedNumberFormat(Locale.getDefault(), RuleBasedNumberFormat.ORDINAL) |
|
|
|
return nf.format(value) |
|
|
|
return nf.format(value)+" "+context.getString(R.string.position) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
|
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -412,11 +417,11 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
|
|
class TournamentNumberOfPlayer: ListOfInt() { |
|
|
|
class TournamentNumberOfPlayer: ListOfInt() { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
return value.toString() |
|
|
|
return value.toString()+" "+context.getString(R.string.number_of_players) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun entityName(context: Context): String { |
|
|
|
override fun entityName(context: Context): String { |
|
|
|
return context.getString(R.string.number_of_players) |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -427,13 +432,13 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
|
|
class AnyDayOfWeek: ListOfInt() { |
|
|
|
class AnyDayOfWeek: ListOfInt() { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[value] |
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[value].capitalize() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class AnyMonthOfYear(): ListOfInt() { |
|
|
|
class AnyMonthOfYear(): ListOfInt() { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).months[value] |
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).months[value].capitalize() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor(month:Int) : this() { |
|
|
|
constructor(month:Int) : this() { |
|
|
|
@ -487,12 +492,19 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
get() { return singleValue } |
|
|
|
get() { return singleValue } |
|
|
|
set(value) { singleValue = value } |
|
|
|
set(value) { singleValue = value } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val netDuration: Long? |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
minutes?.let { |
|
|
|
|
|
|
|
return (it*60*1000).toLong() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal |
|
|
|
override val bottomSheetType: BottomSheetType = BottomSheetType.DOUBLE_EDIT_TEXT |
|
|
|
override val bottomSheetType: BottomSheetType = BottomSheetType.DOUBLE_EDIT_TEXT |
|
|
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
override fun labelForValue(value: Int, context: Context): String { |
|
|
|
val nf = RuleBasedNumberFormat(Locale.getDefault(), RuleBasedNumberFormat.DURATION) |
|
|
|
return value.toMinutes(context) |
|
|
|
return nf.format(value.toDouble()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -600,7 +612,10 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
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) |
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this::class.java) |
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fieldName ?: return realmQuery |
|
|
|
|
|
|
|
|
|
|
|
when (this) { |
|
|
|
when (this) { |
|
|
|
//is Between -> realmQuery.between(fieldName, leftValue, rightValue) |
|
|
|
//is Between -> realmQuery.between(fieldName, leftValue, rightValue) |
|
|
|
@ -666,22 +681,30 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
} |
|
|
|
} |
|
|
|
is StartedFromTime -> { |
|
|
|
is StartedFromTime -> { |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
calendar.time = singleValue |
|
|
|
singleValue?.let { |
|
|
|
|
|
|
|
calendar.time = it |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
if (otherQueryCondition is EndedToTime) { |
|
|
|
if (otherQueryCondition is EndedToTime) { |
|
|
|
calendar.time = otherQueryCondition.singleValue |
|
|
|
otherQueryCondition.singleValue?.let {endTime -> |
|
|
|
|
|
|
|
calendar.time = endTime |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return realmQuery |
|
|
|
return realmQuery |
|
|
|
} |
|
|
|
} |
|
|
|
is EndedToTime -> { |
|
|
|
is EndedToTime -> { |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
|
|
|
singleValue?.let { |
|
|
|
calendar.time = singleValue |
|
|
|
calendar.time = singleValue |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
if (otherQueryCondition is StartedFromTime) { |
|
|
|
if (otherQueryCondition is StartedFromTime) { |
|
|
|
calendar.time = otherQueryCondition.singleValue |
|
|
|
otherQueryCondition.singleValue?.let { startTime -> |
|
|
|
|
|
|
|
calendar.time = startTime |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, calendar.hourMinute()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return realmQuery |
|
|
|
return realmQuery |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -693,7 +716,12 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this is ListOfValues<*>) { |
|
|
|
if (this is ListOfValues<*>) { |
|
|
|
if (this.listOfValues.isEmpty()) return realmQuery |
|
|
|
if (this.listOfValues.isEmpty()) { |
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
|
|
|
|
throw PokerAnalyticsException.FilterElementExpectedValueMissing |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return realmQuery |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return when (operator) { |
|
|
|
return when (operator) { |
|
|
|
@ -710,6 +738,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
Operator.MORE -> { |
|
|
|
Operator.MORE -> { |
|
|
|
when (this) { |
|
|
|
when (this) { |
|
|
|
is SingleDate -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue?.startOfDay()?: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 SingleInt -> realmQuery.greaterThanOrEqualTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
is ListOfInt -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
is ListOfInt -> realmQuery.greaterThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
is NetAmountLost -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first() * -1) |
|
|
|
is NetAmountLost -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first() * -1) |
|
|
|
@ -720,6 +749,7 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
Operator.LESS -> { |
|
|
|
Operator.LESS -> { |
|
|
|
when (this) { |
|
|
|
when (this) { |
|
|
|
is SingleDate -> realmQuery.lessThanOrEqualTo(fieldName, singleValue?.endOfDay()?: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 SingleInt -> realmQuery.lessThanOrEqualTo(fieldName, singleValue?:throw PokerAnalyticsException.FilterElementExpectedValueMissing) |
|
|
|
is ListOfInt -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
is ListOfInt -> realmQuery.lessThanOrEqualTo(fieldName, listOfValues.first()) |
|
|
|
is NetAmountLost -> { |
|
|
|
is NetAmountLost -> { |
|
|
|
@ -808,13 +838,22 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
is DuringThisWeek -> R.string.current_week |
|
|
|
is DuringThisWeek -> R.string.current_week |
|
|
|
is DuringThisMonth -> R.string.current_month |
|
|
|
is DuringThisMonth -> R.string.current_month |
|
|
|
is DuringThisYear -> R.string.current_year |
|
|
|
is DuringThisYear -> R.string.current_year |
|
|
|
is StartedFromTime, is StartedFromDate -> R.string.from |
|
|
|
is StartedFromDate -> R.string.from |
|
|
|
is EndedToDate, is EndedToTime-> R.string.to |
|
|
|
is StartedFromTime -> R.string.from_hour_ |
|
|
|
|
|
|
|
is EndedToDate -> R.string.to |
|
|
|
|
|
|
|
is EndedToTime -> R.string.to_hour_ |
|
|
|
is IsLive -> R.string.live |
|
|
|
is IsLive -> R.string.live |
|
|
|
is IsOnline -> R.string.online |
|
|
|
is IsOnline -> R.string.online |
|
|
|
is IsWeekDay -> R.string.week_days |
|
|
|
is IsWeekDay -> R.string.week_days |
|
|
|
is IsWeekEnd -> R.string.weekend |
|
|
|
is IsWeekEnd -> R.string.weekend |
|
|
|
is PastDay -> R.string.period_in_days |
|
|
|
is PastDay -> R.string.period_in_days |
|
|
|
|
|
|
|
is TournamentNumberOfPlayer -> { |
|
|
|
|
|
|
|
when (this.operator) { |
|
|
|
|
|
|
|
Operator.MORE -> R.string.minimum |
|
|
|
|
|
|
|
Operator.LESS -> R.string.maximum |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
is NetAmountWon -> { |
|
|
|
is NetAmountWon -> { |
|
|
|
when (this.operator) { |
|
|
|
when (this.operator) { |
|
|
|
Operator.MORE -> R.string.won_amount_more_than |
|
|
|
Operator.MORE -> R.string.won_amount_more_than |
|
|
|
@ -829,6 +868,13 @@ sealed class QueryCondition : FilterElementRow { |
|
|
|
else -> null |
|
|
|
else -> null |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
is TournamentFinalPosition -> { |
|
|
|
|
|
|
|
when (this.operator) { |
|
|
|
|
|
|
|
Operator.MORE -> R.string.minimum |
|
|
|
|
|
|
|
Operator.LESS -> R.string.maximum |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
when (this.operator) { |
|
|
|
when (this.operator) { |
|
|
|
Operator.MORE -> R.string.more_than |
|
|
|
Operator.MORE -> R.string.more_than |
|
|
|
|