commit
55cc805e3b
@ -0,0 +1,64 @@ |
|||||||
|
package net.pokeranalytics.android.filter |
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
||||||
|
import net.pokeranalytics.android.model.filter.QueryType |
||||||
|
import net.pokeranalytics.android.model.realm.Filter |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow |
||||||
|
import org.junit.Assert |
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
class RealmFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() { |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testSaveLoadCashFilter() { |
||||||
|
|
||||||
|
val realm = this.mockRealm |
||||||
|
realm.beginTransaction() |
||||||
|
val filter = Filter() |
||||||
|
filter.name = "testSaveLoadCashFilter" |
||||||
|
|
||||||
|
val filterElement = FilterElementRow.Cash |
||||||
|
filterElement.filterSectionRow = FilterSectionRow.CASH_TOURNAMENT |
||||||
|
filter.createOrUpdateFilterElements(arrayListOf(filterElement)) |
||||||
|
|
||||||
|
val useCount = filter.countBy(FilterCategoryRow.GENERAL) |
||||||
|
Assert.assertEquals(1, useCount) |
||||||
|
|
||||||
|
val isCash = filter.contains(filterElement) |
||||||
|
Assert.assertEquals(true, isCash) |
||||||
|
|
||||||
|
val filterComponent = filter.filterElements.first() |
||||||
|
|
||||||
|
filterComponent?.let { |
||||||
|
Assert.assertEquals(QueryType.CASH, QueryType.valueOf(it.filterName)) |
||||||
|
} ?: run { |
||||||
|
Assert.fail() |
||||||
|
} |
||||||
|
|
||||||
|
Session.testInstance(100.0, false, Date(), 1) |
||||||
|
Session.testInstance(100.0, true, Date(), 1) |
||||||
|
|
||||||
|
realm.copyToRealm(filter) |
||||||
|
realm.commitTransaction() |
||||||
|
|
||||||
|
val newRealm = this.mockRealm |
||||||
|
newRealm.where(Filter::class.java).equalTo("name", "testSaveLoadCashFilter").findFirst()?.let { foundFilter -> |
||||||
|
val sessions = foundFilter.queryOn(Session) |
||||||
|
|
||||||
|
Assert.assertEquals(1, sessions.size) |
||||||
|
sessions[0]?.run { |
||||||
|
Assert.assertEquals(Session.Type.CASH_GAME.ordinal, (this as Session).type) |
||||||
|
} ?: run { |
||||||
|
Assert.fail() |
||||||
|
} |
||||||
|
} ?: run { |
||||||
|
Assert.fail() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,77 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.filter |
|
||||||
|
|
||||||
import io.realm.RealmObject |
|
||||||
import io.realm.RealmQuery |
|
||||||
import net.pokeranalytics.android.model.filter.interfaces.Filterable |
|
||||||
import java.util.* |
|
||||||
|
|
||||||
enum class DateFilterable : Filterable { |
|
||||||
STARTED_FROM_DATE, |
|
||||||
STARTED_TO_DATE, |
|
||||||
ENDED_FROM_DATE, |
|
||||||
ENDED_TO_DATE, |
|
||||||
DAY_OF_WEEK, |
|
||||||
MONTH, |
|
||||||
YEAR, |
|
||||||
WEEK_DAY, |
|
||||||
WEEK_END, |
|
||||||
; |
|
||||||
|
|
||||||
private enum class Field(var fieldName:String) { |
|
||||||
START_DATE("startDate"), |
|
||||||
END_DATE("endDate"), |
|
||||||
DAY("dayOfWeek"), |
|
||||||
MONTH("month"), |
|
||||||
YEAR("year"), |
|
||||||
} |
|
||||||
|
|
||||||
override var valueMap : Map<String, Any?>? = null |
|
||||||
|
|
||||||
override val filterValuesExpectedKeys : Array<String>? |
|
||||||
get() { |
|
||||||
return when (this) { |
|
||||||
STARTED_FROM_DATE, STARTED_TO_DATE, ENDED_FROM_DATE, ENDED_TO_DATE -> arrayOf("date") |
|
||||||
DAY_OF_WEEK -> arrayOf("dayOfWeek") |
|
||||||
MONTH -> arrayOf("month") |
|
||||||
YEAR -> arrayOf("year") |
|
||||||
else -> null |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override fun filter(realmQuery: RealmQuery<out RealmObject>): RealmQuery<out RealmObject> { |
|
||||||
return when (this) { |
|
||||||
STARTED_FROM_DATE -> { |
|
||||||
val date : Date by filterValues |
|
||||||
realmQuery.greaterThanOrEqualTo(Field.START_DATE.fieldName, date) |
|
||||||
} |
|
||||||
STARTED_TO_DATE -> { |
|
||||||
val date : Date by filterValues |
|
||||||
realmQuery.lessThanOrEqualTo(Field.START_DATE.fieldName, date) |
|
||||||
} |
|
||||||
ENDED_FROM_DATE -> { |
|
||||||
val date : Date by filterValues |
|
||||||
realmQuery.greaterThanOrEqualTo(Field.END_DATE.fieldName, date) |
|
||||||
} |
|
||||||
ENDED_TO_DATE -> { |
|
||||||
val date : Date by filterValues |
|
||||||
realmQuery.lessThanOrEqualTo(Field.END_DATE.fieldName, date) |
|
||||||
} |
|
||||||
DAY_OF_WEEK -> { |
|
||||||
val dayOfWeek : Int by filterValues |
|
||||||
realmQuery.equalTo(Field.DAY.fieldName, dayOfWeek) |
|
||||||
} |
|
||||||
MONTH -> { |
|
||||||
val month: Int by filterValues |
|
||||||
realmQuery.equalTo(Field.MONTH.fieldName, month) |
|
||||||
} |
|
||||||
YEAR -> { |
|
||||||
val year: Int by filterValues |
|
||||||
realmQuery.equalTo(Field.YEAR.fieldName, year) |
|
||||||
} |
|
||||||
WEEK_END -> { |
|
||||||
realmQuery.`in`(Field.DAY.fieldName, arrayOf(Calendar.SATURDAY,Calendar.SUNDAY)) |
|
||||||
} |
|
||||||
WEEK_DAY -> WEEK_END.filter(realmQuery.not()) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,5 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.filter |
|
||||||
|
|
||||||
enum class FilterComponent { |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,292 @@ |
|||||||
|
package net.pokeranalytics.android.model.filter |
||||||
|
|
||||||
|
import io.realm.RealmList |
||||||
|
import io.realm.RealmObject |
||||||
|
import io.realm.RealmQuery |
||||||
|
import net.pokeranalytics.android.exceptions.FilterValueMapException |
||||||
|
import net.pokeranalytics.android.model.realm.FilterElementBlind |
||||||
|
import net.pokeranalytics.android.model.realm.FilterElement |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Enum describing the way a query should be handled |
||||||
|
* Some queries requires a value to be checked upon through equals, in, more, less, between |
||||||
|
* To handle that, the enum has a public [valueMap] variable |
||||||
|
* A new type should also set the expected numericValues required in the [filterValuesExpectedKeys] |
||||||
|
*/ |
||||||
|
enum class QueryType(private var subType:SubType? = null) { |
||||||
|
LIVE, |
||||||
|
CASH, |
||||||
|
ONLINE, |
||||||
|
TOURNAMENT, |
||||||
|
BANKROLL, |
||||||
|
GAME, |
||||||
|
TOURNAMENT_NAME, |
||||||
|
ANY_TOURNAMENT_FEATURES, |
||||||
|
ALL_TOURNAMENT_FEATURES, |
||||||
|
LOCATION, |
||||||
|
LIMIT, |
||||||
|
TABLE_SIZE, |
||||||
|
TOURNAMENT_TYPE, |
||||||
|
BLINDS, |
||||||
|
MORE_NUMBER_OF_TABLE(SubType.MORE), |
||||||
|
LESS_NUMBER_OF_TABLE(SubType.LESS), |
||||||
|
BETWEEN_NUMBER_OF_TABLE(SubType.BETWEEN), |
||||||
|
MORE_THAN_NET_RESULT(SubType.MORE), |
||||||
|
LESS_THAN_NET_RESULT(SubType.LESS), |
||||||
|
MORE_THAN_BUY_IN(SubType.MORE), |
||||||
|
LESS_THAN_BUY_IN(SubType.LESS), |
||||||
|
MORE_THAN_CASH_OUT(SubType.MORE), |
||||||
|
LESS_THAN_CASH_OUT(SubType.LESS), |
||||||
|
MORE_THAN_TIPS(SubType.MORE), |
||||||
|
LESS_THAN_TIPS(SubType.LESS), |
||||||
|
MORE_THAN_NUMBER_OF_PLAYER(SubType.MORE), |
||||||
|
LESS_THAN_NUMBER_OF_PLAYER(SubType.LESS), |
||||||
|
BETWEEN_NUMBER_OF_PLAYER(SubType.BETWEEN), |
||||||
|
MORE_THAN_TOURNAMENT_FEE(SubType.MORE), |
||||||
|
LESS_THAN_TOURNAMENT_FEE(SubType.LESS), |
||||||
|
BETWEEN_TOURNAMENT_FEE(SubType.BETWEEN), |
||||||
|
|
||||||
|
// Dates |
||||||
|
STARTED_FROM_DATE, |
||||||
|
STARTED_TO_DATE, |
||||||
|
ENDED_FROM_DATE, |
||||||
|
ENDED_TO_DATE, |
||||||
|
DAY_OF_WEEK, |
||||||
|
MONTH, |
||||||
|
YEAR, |
||||||
|
WEEK_DAY, |
||||||
|
WEEK_END, |
||||||
|
|
||||||
|
CURRENCY, |
||||||
|
CURRENCY_CODE, |
||||||
|
BIG_BLIND, |
||||||
|
SMALL_BLIND, |
||||||
|
COMMENT, |
||||||
|
|
||||||
|
; |
||||||
|
|
||||||
|
private enum class SubType { |
||||||
|
BETWEEN, |
||||||
|
MORE, |
||||||
|
LESS; |
||||||
|
} |
||||||
|
|
||||||
|
private val filterValuesExpectedKeys : Array<String>? |
||||||
|
get() { |
||||||
|
this.subType?.let { |
||||||
|
return when (it) { |
||||||
|
SubType.BETWEEN -> arrayOf("leftValue", "rightValue") |
||||||
|
else -> arrayOf("value") |
||||||
|
} |
||||||
|
} |
||||||
|
return when (this) { |
||||||
|
BANKROLL, GAME, LOCATION, ANY_TOURNAMENT_FEATURES, ALL_TOURNAMENT_FEATURES, TOURNAMENT_NAME -> arrayOf("ids") |
||||||
|
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> arrayOf("values") |
||||||
|
BLINDS -> arrayOf("blinds") |
||||||
|
STARTED_FROM_DATE, STARTED_TO_DATE, ENDED_FROM_DATE, ENDED_TO_DATE -> arrayOf("date") |
||||||
|
DAY_OF_WEEK -> arrayOf("dayOfWeek") |
||||||
|
MONTH -> arrayOf("month") |
||||||
|
YEAR -> arrayOf("year") |
||||||
|
else -> null |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 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] |
||||||
|
*/ |
||||||
|
fun filter(realmQuery: RealmQuery<out RealmObject>, filterable: Filterable): RealmQuery<out RealmObject> { |
||||||
|
when { |
||||||
|
this == BLINDS -> { |
||||||
|
val smallBlindFieldName = filterable.fieldNameForQueryType(SMALL_BLIND) |
||||||
|
val bigBlindFieldName = filterable.fieldNameForQueryType(BIG_BLIND) |
||||||
|
val currencyCodeFieldName = filterable.fieldNameForQueryType(CURRENCY_CODE) |
||||||
|
smallBlindFieldName ?: throw FilterValueMapException("fieldName is missing") |
||||||
|
bigBlindFieldName ?: throw FilterValueMapException("fieldName is missing") |
||||||
|
currencyCodeFieldName ?: throw FilterValueMapException("fieldName is missing") |
||||||
|
|
||||||
|
val blinds: RealmList<FilterElementBlind> by valueMap |
||||||
|
blinds.forEachIndexed {index, blind -> |
||||||
|
realmQuery |
||||||
|
.beginGroup() |
||||||
|
|
||||||
|
blind.sb?.let { |
||||||
|
realmQuery |
||||||
|
.equalTo(smallBlindFieldName, it) |
||||||
|
.and() |
||||||
|
} |
||||||
|
|
||||||
|
realmQuery |
||||||
|
.equalTo(bigBlindFieldName, blind.bb) |
||||||
|
.and() |
||||||
|
|
||||||
|
blind.code?.let { |
||||||
|
realmQuery.equalTo(currencyCodeFieldName, it) |
||||||
|
} ?: run { |
||||||
|
realmQuery.isNull(currencyCodeFieldName) |
||||||
|
} |
||||||
|
|
||||||
|
realmQuery.endGroup() |
||||||
|
|
||||||
|
if (index < blinds.size - 1) { |
||||||
|
realmQuery.or() |
||||||
|
} |
||||||
|
} |
||||||
|
return realmQuery |
||||||
|
} |
||||||
|
this == ONLINE -> return LIVE.filter(realmQuery.not(), filterable) |
||||||
|
this == TOURNAMENT -> return CASH.filter(realmQuery.not(), filterable) |
||||||
|
this == WEEK_DAY -> return WEEK_END.filter(realmQuery.not(), filterable) |
||||||
|
else -> { |
||||||
|
val fieldName = filterable.fieldNameForQueryType(this) |
||||||
|
fieldName ?: throw FilterValueMapException("fieldName is missing") |
||||||
|
|
||||||
|
this.subType?.let { subType -> |
||||||
|
return when (subType) { |
||||||
|
SubType.LESS -> { |
||||||
|
val value: Double by valueMap |
||||||
|
realmQuery.lessThanOrEqualTo(fieldName, value) |
||||||
|
} |
||||||
|
SubType.MORE -> { |
||||||
|
val value: Double by valueMap |
||||||
|
realmQuery.greaterThanOrEqualTo(fieldName, value) |
||||||
|
} |
||||||
|
SubType.BETWEEN -> { |
||||||
|
val leftValue: Double by valueMap |
||||||
|
val rightValue: Double by valueMap |
||||||
|
realmQuery.between(fieldName, leftValue, rightValue) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return when (this) { |
||||||
|
LIVE -> realmQuery.equalTo(fieldName, true) |
||||||
|
CASH -> realmQuery.equalTo(fieldName, Session.Type.CASH_GAME.ordinal) |
||||||
|
ALL_TOURNAMENT_FEATURES -> { |
||||||
|
val ids: Array<String> by valueMap |
||||||
|
ids.forEach { |
||||||
|
realmQuery.equalTo(fieldName, it) |
||||||
|
} |
||||||
|
realmQuery |
||||||
|
} |
||||||
|
ANY_TOURNAMENT_FEATURES -> { |
||||||
|
val ids: Array<String> by valueMap |
||||||
|
realmQuery.`in`(fieldName, ids) |
||||||
|
} |
||||||
|
BANKROLL, GAME, LOCATION, TOURNAMENT_NAME -> { |
||||||
|
val ids: Array<String> by valueMap |
||||||
|
realmQuery.`in`(fieldName, ids) |
||||||
|
} |
||||||
|
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> { |
||||||
|
val values: Array<Int?>? by valueMap |
||||||
|
realmQuery.`in`(fieldName, values) |
||||||
|
} |
||||||
|
STARTED_FROM_DATE -> { |
||||||
|
val date: Date by valueMap |
||||||
|
realmQuery.greaterThanOrEqualTo(fieldName, date) |
||||||
|
} |
||||||
|
STARTED_TO_DATE -> { |
||||||
|
val date: Date by valueMap |
||||||
|
realmQuery.lessThanOrEqualTo(fieldName, date) |
||||||
|
} |
||||||
|
ENDED_FROM_DATE -> { |
||||||
|
val date: Date by valueMap |
||||||
|
realmQuery.greaterThanOrEqualTo(fieldName, date) |
||||||
|
} |
||||||
|
ENDED_TO_DATE -> { |
||||||
|
val date: Date by valueMap |
||||||
|
realmQuery.lessThanOrEqualTo(fieldName, date) |
||||||
|
} |
||||||
|
DAY_OF_WEEK -> { |
||||||
|
val dayOfWeek: Int by valueMap |
||||||
|
realmQuery.equalTo(fieldName, dayOfWeek) |
||||||
|
} |
||||||
|
MONTH -> { |
||||||
|
val month: Int by valueMap |
||||||
|
realmQuery.equalTo(fieldName, month) |
||||||
|
} |
||||||
|
YEAR -> { |
||||||
|
val year: Int by valueMap |
||||||
|
realmQuery.equalTo(fieldName, year) |
||||||
|
} |
||||||
|
WEEK_END -> { |
||||||
|
realmQuery.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY)) |
||||||
|
} |
||||||
|
else -> { |
||||||
|
throw FilterValueMapException("filter type not handled") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
fun updateValueMap(filterElement: FilterElement) { |
||||||
|
if (filterValuesExpectedKeys == null) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
this.subType?.let { subType -> |
||||||
|
valueMap = when (subType) { |
||||||
|
SubType.LESS, SubType.MORE -> { |
||||||
|
mapOf("value" to filterElement.value) |
||||||
|
} |
||||||
|
SubType.BETWEEN -> { |
||||||
|
mapOf( |
||||||
|
"leftValue" to filterElement.leftValue, |
||||||
|
"rightValue" to filterElement.rightValue |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
when (this) { |
||||||
|
ALL_TOURNAMENT_FEATURES, ANY_TOURNAMENT_FEATURES, BANKROLL, GAME, LOCATION, TOURNAMENT_NAME -> { |
||||||
|
valueMap = mapOf("ids" to filterElement.ids) |
||||||
|
} |
||||||
|
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> { |
||||||
|
valueMap = mapOf("values" to filterElement.values) |
||||||
|
} |
||||||
|
BLINDS -> { |
||||||
|
valueMap = mapOf("blinds" to filterElement.blinds) |
||||||
|
} |
||||||
|
STARTED_FROM_DATE, STARTED_TO_DATE, ENDED_FROM_DATE, ENDED_TO_DATE -> { |
||||||
|
valueMap = mapOf("date" to filterElement.date) |
||||||
|
} |
||||||
|
DAY_OF_WEEK -> { |
||||||
|
valueMap = mapOf("dayOfWeek" to filterElement.dayOfWeek) |
||||||
|
} |
||||||
|
MONTH -> { |
||||||
|
valueMap = mapOf("month" to filterElement.month) |
||||||
|
} |
||||||
|
YEAR -> { |
||||||
|
valueMap = mapOf("year" to filterElement.year) |
||||||
|
} |
||||||
|
else -> { |
||||||
|
throw FilterValueMapException("filter type not handled") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var valueMap : Map<String, Any?>? = null |
||||||
|
get() { |
||||||
|
this.filterValuesExpectedKeys?.let { valueMapExceptedKeys -> |
||||||
|
field?.let { map -> |
||||||
|
val missingKeys = map.keys.filter { !valueMapExceptedKeys.contains(it) } |
||||||
|
if (map.keys.size == valueMapExceptedKeys.size && missingKeys.isNotEmpty()) { |
||||||
|
throw FilterValueMapException("valueMap does not contain $missingKeys") |
||||||
|
} |
||||||
|
} ?: run { |
||||||
|
throw FilterValueMapException("valueMap null not expected") |
||||||
|
} |
||||||
|
} |
||||||
|
return field |
||||||
|
} |
||||||
|
private set |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -1,189 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.filter |
|
||||||
|
|
||||||
import io.realm.RealmObject |
|
||||||
import io.realm.RealmQuery |
|
||||||
import net.pokeranalytics.android.exceptions.FilterValueMapException |
|
||||||
import net.pokeranalytics.android.model.filter.interfaces.Filterable |
|
||||||
import net.pokeranalytics.android.model.realm.Session |
|
||||||
|
|
||||||
enum class SessionFilterable(private var fieldName:String? = null, private var subType:SubType? = null): Filterable { |
|
||||||
LIVE, |
|
||||||
CASH, |
|
||||||
ONLINE, |
|
||||||
TOURNAMENT, |
|
||||||
BANKROLL("bankroll.id"), |
|
||||||
GAME("game.id"), |
|
||||||
TOURNAMENT_NAME("tournamentName.id"), |
|
||||||
ANY_TOURNAMENT_FEATURES, |
|
||||||
ALL_TOURNAMENT_FEATURES, |
|
||||||
LOCATION("location.id"), |
|
||||||
LIMIT("limit"), |
|
||||||
TABLE_SIZE("tableSize"), |
|
||||||
TOURNAMENT_TYPE("tournamentType"), |
|
||||||
BLINDS, |
|
||||||
MORE_NUMBER_OF_TABLE(Field.NUMBER_OF_TABLE.fieldName, SubType.MORE), |
|
||||||
LESS_NUMBER_OF_TABLE(Field.NUMBER_OF_TABLE.fieldName, SubType.LESS), |
|
||||||
BETWEEN_NUMBER_OF_TABLE(Field.NUMBER_OF_TABLE.fieldName, SubType.BETWEEN), |
|
||||||
MORE_THAN_NET_RESULT(Field.NET_RESULT.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_NET_RESULT(Field.NET_RESULT.fieldName, SubType.LESS), |
|
||||||
MORE_THAN_BUY_IN(Field.BUY_IN.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_BUY_IN(Field.BUY_IN.fieldName, SubType.LESS), |
|
||||||
MORE_THAN_CASH_OUT(Field.CASH_OUT.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_CASH_OUT(Field.CASH_OUT.fieldName, SubType.LESS), |
|
||||||
MORE_THAN_TIPS(Field.TIPS.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_TIPS(Field.TIPS.fieldName, SubType.LESS), |
|
||||||
MORE_THAN_NUMBER_OF_PLAYER(Field.NUMBER_OF_PLAYER.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_NUMBER_OF_PLAYER(Field.NUMBER_OF_PLAYER.fieldName, SubType.LESS), |
|
||||||
BETWEEN_NUMBER_OF_PLAYER(Field.NUMBER_OF_PLAYER.fieldName, SubType.BETWEEN), |
|
||||||
MORE_THAN_TOURNAMENT_FEE(Field.NET_RESULT.fieldName, SubType.MORE), |
|
||||||
LESS_THAN_TOURNAMENT_FEE(Field.NET_RESULT.fieldName, SubType.LESS), |
|
||||||
BETWEEN_TOURNAMENT_FEE(Field.TOURNAMENT_FEE.fieldName, SubType.BETWEEN), |
|
||||||
; |
|
||||||
|
|
||||||
enum class SubType { |
|
||||||
BETWEEN, |
|
||||||
MORE, |
|
||||||
LESS; |
|
||||||
} |
|
||||||
|
|
||||||
private enum class Field(var fieldName:String) { |
|
||||||
LIVE("bankroll.live"), |
|
||||||
CASH("type"), |
|
||||||
CURRENCY("bankroll.currency"), |
|
||||||
CURRENCY_CODE("bankroll.currency.code"), |
|
||||||
BIG_BLIND("cgBigBlind"), |
|
||||||
SMALL_BLIND("cgSmallBlind"), |
|
||||||
COMMENT("comment"), |
|
||||||
TOURNAMENT_FEATURES("tournamentFeatures.id"), |
|
||||||
NET_RESULT("computableResults.ratedNet"), |
|
||||||
BUY_IN("result.buyin"), |
|
||||||
CASH_OUT("result.cashout"), |
|
||||||
TIPS("result.tips"), |
|
||||||
NUMBER_OF_TABLE("numberOfTable"), |
|
||||||
NUMBER_OF_PLAYER("tournamentNumberOfPlayers"), |
|
||||||
TOURNAMENT_FEE("tournamentEntryFee"), |
|
||||||
; |
|
||||||
} |
|
||||||
|
|
||||||
override var valueMap : Map<String, Any?>? = null |
|
||||||
|
|
||||||
override val filterValuesExpectedKeys : Array<String>? |
|
||||||
get() { |
|
||||||
this.subType?.let { |
|
||||||
return when (it) { |
|
||||||
SubType.BETWEEN -> arrayOf("leftValue", "rightValue") |
|
||||||
else -> arrayOf("value") |
|
||||||
} |
|
||||||
} |
|
||||||
return when (this) { |
|
||||||
BANKROLL, GAME, LOCATION, ANY_TOURNAMENT_FEATURES, ALL_TOURNAMENT_FEATURES -> arrayOf("ids") |
|
||||||
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> arrayOf("values") |
|
||||||
BLINDS -> arrayOf("map") |
|
||||||
else -> null |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override fun filter(realmQuery: RealmQuery<out RealmObject>): RealmQuery<out RealmObject> { |
|
||||||
|
|
||||||
this.subType?.let {subType -> |
|
||||||
this.fieldName?.let { |
|
||||||
return when (subType) { |
|
||||||
SubType.LESS -> { |
|
||||||
val value: Double by filterValues |
|
||||||
println("filter test less") |
|
||||||
realmQuery.lessThanOrEqualTo(it, value) |
|
||||||
} |
|
||||||
SubType.MORE -> { |
|
||||||
println("filter test more") |
|
||||||
val value: Double by filterValues |
|
||||||
realmQuery.greaterThanOrEqualTo(it, value) |
|
||||||
} |
|
||||||
SubType.BETWEEN -> { |
|
||||||
val leftValue: Double by filterValues |
|
||||||
val rightValue: Double by filterValues |
|
||||||
realmQuery.between(it, leftValue, rightValue) |
|
||||||
} |
|
||||||
} |
|
||||||
} ?: run { |
|
||||||
throw FilterValueMapException("fieldName is missing") |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return when (this) { |
|
||||||
LIVE -> realmQuery.equalTo(Field.LIVE.fieldName, true) |
|
||||||
CASH -> realmQuery.equalTo(Field.CASH.fieldName, Session.Type.CASH_GAME.ordinal) |
|
||||||
ONLINE -> LIVE.filter(realmQuery.not()) |
|
||||||
TOURNAMENT -> CASH.filter(realmQuery.not()) |
|
||||||
ALL_TOURNAMENT_FEATURES -> { |
|
||||||
val ids : Array<String> by filterValues |
|
||||||
ids.forEach { |
|
||||||
realmQuery.equalTo(Field.TOURNAMENT_FEATURES.fieldName, it) |
|
||||||
} |
|
||||||
realmQuery |
|
||||||
} |
|
||||||
ANY_TOURNAMENT_FEATURES -> { |
|
||||||
val ids : Array<String> by filterValues |
|
||||||
realmQuery.`in`(Field.TOURNAMENT_FEATURES.fieldName, ids) |
|
||||||
} |
|
||||||
BANKROLL, GAME, LOCATION, TOURNAMENT_NAME -> { |
|
||||||
val ids : Array<String> by filterValues |
|
||||||
this.fieldName?.let { |
|
||||||
realmQuery.`in`(it, ids) |
|
||||||
} ?: run { |
|
||||||
throw FilterValueMapException("fieldName is missing") |
|
||||||
} |
|
||||||
} |
|
||||||
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> { |
|
||||||
val values : Array<Int?>? by filterValues |
|
||||||
this.fieldName?.let { |
|
||||||
realmQuery.`in`(it, values) |
|
||||||
} ?: run { |
|
||||||
throw FilterValueMapException("fieldName is missing") |
|
||||||
} |
|
||||||
} |
|
||||||
BLINDS -> { |
|
||||||
val map : Array<Map<String,Any?>> by filterValues |
|
||||||
val expectedSubKeys = arrayOf("sb", "bb", "code") |
|
||||||
map.forEachIndexed { index, subMap -> |
|
||||||
val missingKeys = subMap.keys.filter { !expectedSubKeys.contains(it) } |
|
||||||
if (subMap.keys.size == expectedSubKeys.size && missingKeys.isNotEmpty()) { |
|
||||||
throw FilterValueMapException("subValueMap does not contain $missingKeys") |
|
||||||
} |
|
||||||
|
|
||||||
val sb : Double? by subMap |
|
||||||
val bb : Double? by subMap |
|
||||||
val code : String? by subMap |
|
||||||
|
|
||||||
realmQuery |
|
||||||
.beginGroup() |
|
||||||
|
|
||||||
sb?.let { |
|
||||||
realmQuery |
|
||||||
.equalTo(Field.SMALL_BLIND.fieldName, sb) |
|
||||||
.and() |
|
||||||
} |
|
||||||
|
|
||||||
realmQuery |
|
||||||
.equalTo(Field.BIG_BLIND.fieldName, bb) |
|
||||||
.and() |
|
||||||
|
|
||||||
code?.let { |
|
||||||
realmQuery.equalTo(Field.CURRENCY_CODE.fieldName, code) |
|
||||||
} ?: run { |
|
||||||
realmQuery.isNull(Field.CURRENCY_CODE.fieldName) |
|
||||||
} |
|
||||||
|
|
||||||
realmQuery.endGroup() |
|
||||||
|
|
||||||
if (index < map.size - 1) { |
|
||||||
realmQuery.or() |
|
||||||
} |
|
||||||
} |
|
||||||
realmQuery |
|
||||||
} |
|
||||||
else -> { |
|
||||||
realmQuery |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,8 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.filter.interfaces |
|
||||||
|
|
||||||
import io.realm.RealmObject |
|
||||||
import io.realm.RealmQuery |
|
||||||
|
|
||||||
interface Filterable : ValueFilterable { |
|
||||||
fun filter(realmQuery: RealmQuery<out RealmObject>): RealmQuery<out RealmObject> |
|
||||||
} |
|
||||||
@ -1,28 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.filter.interfaces |
|
||||||
|
|
||||||
import net.pokeranalytics.android.exceptions.FilterValueMapException |
|
||||||
|
|
||||||
interface ValueFilterable { |
|
||||||
|
|
||||||
var valueMap: Map<String, Any?>? |
|
||||||
|
|
||||||
var filterValues : Map<String, Any?>? |
|
||||||
get() { |
|
||||||
this.filterValuesExpectedKeys?.let { valueMapExceptedKeys -> |
|
||||||
valueMap?.let { map -> |
|
||||||
var missingKeys = map.keys.filter { !valueMapExceptedKeys.contains(it) } |
|
||||||
if (map.keys.size == valueMapExceptedKeys.size && missingKeys.isNotEmpty()) { |
|
||||||
throw FilterValueMapException("valueMap does not contain ${missingKeys}") |
|
||||||
} |
|
||||||
} ?: run { |
|
||||||
throw FilterValueMapException("valueMap null not expected") |
|
||||||
} |
|
||||||
} |
|
||||||
return this.valueMap |
|
||||||
} |
|
||||||
set(value) { |
|
||||||
valueMap = value |
|
||||||
} |
|
||||||
|
|
||||||
val filterValuesExpectedKeys : Array<String>? |
|
||||||
} |
|
||||||
@ -0,0 +1,144 @@ |
|||||||
|
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import io.realm.RealmList |
||||||
|
import io.realm.RealmObject |
||||||
|
import net.pokeranalytics.android.exceptions.FilterValueMapException |
||||||
|
import net.pokeranalytics.android.model.filter.QueryType |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* |
||||||
|
import java.util.* |
||||||
|
import kotlin.collections.ArrayList |
||||||
|
|
||||||
|
open class FilterElement(var filterName : String = "", var sectionName: String = "") : RealmObject() { |
||||||
|
|
||||||
|
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { |
||||||
|
this.stringValues = when (QueryType.valueOf(this.filterName)) { |
||||||
|
QueryType.GAME, QueryType.BANKROLL, QueryType.TOURNAMENT_NAME, QueryType.ALL_TOURNAMENT_FEATURES, QueryType.ANY_TOURNAMENT_FEATURES, QueryType.LOCATION -> { |
||||||
|
RealmList<String>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as DataFilterElementRow).id |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
else -> null |
||||||
|
} |
||||||
|
|
||||||
|
this.numericValues = when (QueryType.valueOf(filterName)) { |
||||||
|
QueryType.LIMIT -> { |
||||||
|
RealmList<Double>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as FilterElementRow.Limit).limit.ordinal.toDouble() |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
QueryType.TABLE_SIZE -> { |
||||||
|
RealmList<Double>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as FilterElementRow.TableSize).tableSize.numberOfPlayer.toDouble() |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
QueryType.YEAR, QueryType.MONTH, QueryType.DAY_OF_WEEK -> { |
||||||
|
RealmList<Double>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as SingleValueFilterElementRow).value.toDouble() |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
QueryType.LESS_THAN_NET_RESULT -> { |
||||||
|
RealmList<Double>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as ResultLessThan).value |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
QueryType.MORE_THAN_NET_RESULT -> { |
||||||
|
RealmList<Double>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
(it as ResultMoreThan).value |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
else -> null |
||||||
|
} |
||||||
|
|
||||||
|
this.blindValues = when (QueryType.valueOf(filterName)) { |
||||||
|
QueryType.BLINDS -> { |
||||||
|
RealmList<FilterElementBlind>().apply { |
||||||
|
this.addAll(filterElementRows.map { |
||||||
|
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 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
val queryType : QueryType |
||||||
|
get() = QueryType.valueOf(filterName) |
||||||
|
.apply { |
||||||
|
this.updateValueMap(this@FilterElement) |
||||||
|
} |
||||||
|
|
||||||
|
private var numericValues: RealmList<Double>? = null |
||||||
|
private var dateValue : Date? = null |
||||||
|
private var stringValues : RealmList<String>? = null |
||||||
|
private var blindValues : RealmList<FilterElementBlind>? = null |
||||||
|
|
||||||
|
val ids : Array<String> |
||||||
|
get() = stringValues?.toTypedArray()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
val blinds : RealmList<FilterElementBlind> |
||||||
|
get() { |
||||||
|
blindValues?.let { |
||||||
|
if (it.isNotEmpty()) { |
||||||
|
return it |
||||||
|
} else { |
||||||
|
throw FilterValueMapException("filter is empty or null") |
||||||
|
} |
||||||
|
} |
||||||
|
throw FilterValueMapException("filter is empty or null") |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
val date : Date |
||||||
|
get() = dateValue?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val values : Array<Int> |
||||||
|
get() = numericValues?.map { |
||||||
|
it.toInt() |
||||||
|
}?.toTypedArray()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val value : Double |
||||||
|
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val leftValue : Double |
||||||
|
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val rightValue : Double |
||||||
|
get() = numericValues?.last()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val dayOfWeek : Int |
||||||
|
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val month : Int |
||||||
|
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
|
||||||
|
val year : Int |
||||||
|
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
package net.pokeranalytics.android.model.realm |
||||||
|
|
||||||
|
import io.realm.RealmObject |
||||||
|
|
||||||
|
open class FilterElementBlind(var sb : Double? = null, |
||||||
|
var bb : Double? = null, |
||||||
|
var code : String? = null |
||||||
|
) : RealmObject() |
||||||
@ -1,33 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
|
||||||
|
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
import net.pokeranalytics.android.ui.view.RowViewType |
|
||||||
|
|
||||||
enum class FilterCategory(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable { |
|
||||||
GENERAL(R.string.general), |
|
||||||
DATE(R.string.date), |
|
||||||
TIME_FRAME(R.string.duration), |
|
||||||
SESSION(R.string.session), |
|
||||||
CASH(R.string.cash), |
|
||||||
TOURNAMENT(R.string.tournament), |
|
||||||
ONLINE(R.string.online), |
|
||||||
RESULT(R.string.result), |
|
||||||
TRANSACTION_TYPES(R.string.operation_types), |
|
||||||
LOCATIONS(R.string.locations), |
|
||||||
BANKROLLS(R.string.bankrolls), |
|
||||||
PLAYERS(R.string.players), |
|
||||||
; |
|
||||||
|
|
||||||
val filterElements : List < RowRepresentable > |
|
||||||
get() { |
|
||||||
return filterSections.flatMap { |
|
||||||
it.filterElements |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private val filterSections : List < FilterSectionDataSource > |
|
||||||
get() { |
|
||||||
return FilterSection.filterSectionsFor(this) |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,82 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow.* |
||||||
|
|
||||||
|
enum class FilterCategoryRow(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable { |
||||||
|
GENERAL(R.string.general), |
||||||
|
DATE(R.string.date), |
||||||
|
TIME_FRAME(R.string.duration), |
||||||
|
SESSION(R.string.session), |
||||||
|
CASH(R.string.cash), |
||||||
|
TOURNAMENT(R.string.tournament), |
||||||
|
ONLINE(R.string.online), |
||||||
|
RESULT(R.string.result), |
||||||
|
TRANSACTION_TYPES(R.string.operation_types), |
||||||
|
LOCATIONS(R.string.locations), |
||||||
|
BANKROLLS(R.string.bankrolls), |
||||||
|
PLAYERS(R.string.players), |
||||||
|
; |
||||||
|
|
||||||
|
val filterElements : List < RowRepresentable > |
||||||
|
get() { |
||||||
|
return filterSectionRows.flatMap { |
||||||
|
it.filterElements |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
val filterSectionRows : List < FilterSectionRow > |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
GENERAL -> arrayListOf( |
||||||
|
CASH_TOURNAMENT, |
||||||
|
LIVE_ONLINE, |
||||||
|
GAME, LIMIT_TYPE, |
||||||
|
TABLE_SIZE |
||||||
|
) |
||||||
|
DATE -> arrayListOf( |
||||||
|
DYNAMIC_DATE, |
||||||
|
FIXED_DATE, |
||||||
|
DURATION, |
||||||
|
YEAR, |
||||||
|
WEEKDAYS_OR_WEEKEND, |
||||||
|
DAY_OF_WEEK, |
||||||
|
MONTH_OF_YEAR |
||||||
|
) |
||||||
|
BANKROLLS -> arrayListOf( |
||||||
|
BANKROLL |
||||||
|
) |
||||||
|
CASH -> arrayListOf( |
||||||
|
BLINDS, |
||||||
|
CASH_RE_BUY_COUNT |
||||||
|
) |
||||||
|
TOURNAMENT -> arrayListOf( |
||||||
|
TOURNAMENT_TYPE, |
||||||
|
COMPLETION_PERCENTAGE, |
||||||
|
PLACE, |
||||||
|
PLAYERS_COUNT, |
||||||
|
TOURNAMENT_RE_BUY_COUNT, |
||||||
|
BUY_IN |
||||||
|
) |
||||||
|
ONLINE -> arrayListOf( |
||||||
|
MULTI_TABLING |
||||||
|
) |
||||||
|
LOCATIONS -> arrayListOf( |
||||||
|
LOCATION |
||||||
|
) |
||||||
|
PLAYERS -> arrayListOf( |
||||||
|
NUMBER_OF_PLAYERS, |
||||||
|
MULTI_PLAYER |
||||||
|
) |
||||||
|
RESULT -> arrayListOf( |
||||||
|
VALUE |
||||||
|
) |
||||||
|
|
||||||
|
TIME_FRAME -> arrayListOf() |
||||||
|
SESSION -> arrayListOf() |
||||||
|
TRANSACTION_TYPES -> arrayListOf() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,178 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.rowrepresentable |
||||||
|
|
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.exceptions.FilterValueMapException |
||||||
|
import net.pokeranalytics.android.model.filter.QueryType |
||||||
|
import net.pokeranalytics.android.model.interfaces.Manageable |
||||||
|
import net.pokeranalytics.android.model.realm.FilterElement |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import net.pokeranalytics.android.ui.view.RowViewType |
||||||
|
|
||||||
|
import java.util.* |
||||||
|
|
||||||
|
sealed class FilterElementRow : RowRepresentable { |
||||||
|
|
||||||
|
object Cash : FilterElementRow() |
||||||
|
object Tournament : FilterElementRow() |
||||||
|
object Live : FilterElementRow() |
||||||
|
object Online : FilterElementRow() |
||||||
|
object Today : FilterElementRow() |
||||||
|
object Yesterday : FilterElementRow() |
||||||
|
object TodayAndYesterday : FilterElementRow() |
||||||
|
object CurrentWeek : FilterElementRow() |
||||||
|
object CurrentMonth : FilterElementRow() |
||||||
|
object CurrentYear: FilterElementRow() |
||||||
|
object Weekday: FilterElementRow() |
||||||
|
object Weekend : FilterElementRow() |
||||||
|
|
||||||
|
open class DataFilterElementRow(data:Manageable) : FilterElementRow() { |
||||||
|
val id : String = data.id |
||||||
|
val name : String = (data as RowRepresentable).getDisplayName() |
||||||
|
} |
||||||
|
|
||||||
|
open class SingleValueFilterElementRow(val value:Int) : 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() |
||||||
|
data class To(var date: Date = Date()) : FilterElementRow() |
||||||
|
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 PastDays(var lastDays : Int = 0) : FilterElementRow() |
||||||
|
data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElementRow() |
||||||
|
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElementRow() |
||||||
|
data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll) |
||||||
|
data class Game(val game: Manageable) : DataFilterElementRow(game) |
||||||
|
data class Location(val location: Manageable) : DataFilterElementRow(location) |
||||||
|
data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName) |
||||||
|
data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) |
||||||
|
data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) |
||||||
|
data class ResultMoreThan(var value:Double) : FilterElementRow() |
||||||
|
data class ResultLessThan(var value:Double) : FilterElementRow() |
||||||
|
|
||||||
|
lateinit var filterSectionRow: FilterSectionRow |
||||||
|
|
||||||
|
val filterName : String = this.queryType.name |
||||||
|
|
||||||
|
private val queryType : QueryType |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
is Cash -> QueryType.CASH |
||||||
|
is Tournament -> QueryType.TOURNAMENT |
||||||
|
is Blind -> QueryType.BLINDS |
||||||
|
is From -> QueryType.STARTED_FROM_DATE |
||||||
|
is To -> QueryType.ENDED_TO_DATE |
||||||
|
is Month -> QueryType.MONTH |
||||||
|
is Day -> QueryType.DAY_OF_WEEK |
||||||
|
is Year -> QueryType.YEAR |
||||||
|
is Live -> QueryType.LIVE |
||||||
|
is Online -> QueryType.ONLINE |
||||||
|
is Weekday -> QueryType.WEEK_DAY |
||||||
|
is Weekend-> QueryType.WEEK_END |
||||||
|
|
||||||
|
/* is Today -> QueryType. |
||||||
|
is Yesterday -> R.string.yesterday |
||||||
|
is TodayAndYesterday -> R.string.yesterday_and_today |
||||||
|
is CurrentWeek -> R.string.current_week |
||||||
|
is CurrentMonth -> R.string.current_month |
||||||
|
is CurrentYear -> R.string.current_year |
||||||
|
is PastDays -> R.string.period_in_days |
||||||
|
is Limit -> R.string.limit |
||||||
|
*/ |
||||||
|
is TableSize -> QueryType.TABLE_SIZE |
||||||
|
is Game -> QueryType.GAME |
||||||
|
is Bankroll -> QueryType.BANKROLL |
||||||
|
is Location -> QueryType.LOCATION |
||||||
|
is TournamentName -> QueryType.TOURNAMENT_NAME |
||||||
|
is AnyTournamentFeature -> QueryType.ANY_TOURNAMENT_FEATURES |
||||||
|
is AllTournamentFeature -> QueryType.ALL_TOURNAMENT_FEATURES |
||||||
|
is ResultMoreThan -> QueryType.MORE_THAN_NET_RESULT |
||||||
|
is ResultLessThan -> QueryType.LESS_THAN_NET_RESULT |
||||||
|
else -> throw FilterValueMapException("no filter type for $this") //TODO create exception |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun contains(filterElements: List<FilterElement>) : Boolean { |
||||||
|
return when (this) { |
||||||
|
is DataFilterElementRow -> filterElements.any { |
||||||
|
it.ids.contains(this.id) |
||||||
|
} |
||||||
|
else -> return true |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override val resId: Int? |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
is Cash -> R.string.cash_game |
||||||
|
is Tournament -> R.string.tournament |
||||||
|
is Today -> R.string.today |
||||||
|
is Yesterday -> R.string.yesterday |
||||||
|
is TodayAndYesterday -> R.string.yesterday_and_today |
||||||
|
is CurrentWeek -> R.string.current_week |
||||||
|
is CurrentMonth -> R.string.current_month |
||||||
|
is CurrentYear -> R.string.current_year |
||||||
|
is From -> R.string.from |
||||||
|
is To -> R.string.to |
||||||
|
is Live -> R.string.live |
||||||
|
is Online -> R.string.online |
||||||
|
is Weekday -> R.string.week_days |
||||||
|
is Weekend-> R.string.weekend |
||||||
|
is Year-> R.string.year |
||||||
|
is Month-> R.string.month_of_the_year |
||||||
|
is Day -> R.string.day_of_the_week |
||||||
|
is PastDays -> R.string.period_in_days |
||||||
|
is Limit -> R.string.limit |
||||||
|
is TableSize -> R.string.table_size |
||||||
|
is Blind -> TODO() |
||||||
|
is ResultMoreThan -> TODO() |
||||||
|
is ResultLessThan -> TODO() |
||||||
|
else -> null |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getDisplayName(): String { |
||||||
|
return when (this) { |
||||||
|
is DataFilterElementRow -> this.name |
||||||
|
else -> return super.getDisplayName() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal |
||||||
|
|
||||||
|
val sectionToExclude : List < FilterSectionRow > ? |
||||||
|
get() { |
||||||
|
val excluded = arrayListOf<FilterSectionRow>() |
||||||
|
if (!this.filterSectionRow.allowMultiSelection) { |
||||||
|
excluded.add(this.filterSectionRow) |
||||||
|
} |
||||||
|
this.filterSectionRow.exclusiveWith?.let { exclusives -> |
||||||
|
excluded.addAll(exclusives) |
||||||
|
} |
||||||
|
|
||||||
|
if (excluded.size > 0) { |
||||||
|
return excluded |
||||||
|
} |
||||||
|
return null |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { |
||||||
|
when (this) { |
||||||
|
PAST_DAYS -> { |
||||||
|
val defaultValue: String? by map |
||||||
|
val data = arrayListOf<RowRepresentableEditDescriptor>() |
||||||
|
data.add( |
||||||
|
RowRepresentableEditDescriptor( |
||||||
|
defaultValue, |
||||||
|
inputType = InputType.TYPE_CLASS_NUMBER |
||||||
|
) |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return super.editingDescriptors(map) |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
@ -1,189 +0,0 @@ |
|||||||
package net.pokeranalytics.android.ui.view.rowrepresentable |
|
||||||
|
|
||||||
import io.realm.Realm |
|
||||||
import net.pokeranalytics.android.R |
|
||||||
import net.pokeranalytics.android.model.LiveData |
|
||||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
||||||
import net.pokeranalytics.android.ui.view.RowViewType |
|
||||||
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection.* |
|
||||||
import java.lang.Exception |
|
||||||
import java.util.* |
|
||||||
|
|
||||||
sealed class FilterElement : RowRepresentable { |
|
||||||
|
|
||||||
companion object { |
|
||||||
fun filterElementsFor(filterSection: FilterSectionDataSource) : List<FilterElement> { |
|
||||||
return when (filterSection) { |
|
||||||
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) |
|
||||||
LIVE_ONLINE -> arrayListOf(Live, Online) |
|
||||||
LIMIT_TYPE -> { |
|
||||||
val limits = arrayListOf<Limit>() |
|
||||||
net.pokeranalytics.android.model.Limit.values().forEach { |
|
||||||
limits.add(FilterElement.Limit(it)) |
|
||||||
} |
|
||||||
limits |
|
||||||
} |
|
||||||
TABLE_SIZE -> { |
|
||||||
val tableSizes = arrayListOf<TableSize>() |
|
||||||
net.pokeranalytics.android.model.TableSize.all.forEach { |
|
||||||
tableSizes.add(FilterElement.TableSize(it)) |
|
||||||
} |
|
||||||
tableSizes |
|
||||||
} |
|
||||||
|
|
||||||
DYNAMIC_DATE -> arrayListOf(Today, Yesterday, TodayAndYesterday, CurrentWeek, CurrentMonth, CurrentYear) |
|
||||||
FIXED_DATE -> arrayListOf(From(), To()) |
|
||||||
DURATION -> arrayListOf() |
|
||||||
WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend) |
|
||||||
DAY_OF_WEEK -> arrayListOf() |
|
||||||
MONTH_OF_YEAR -> arrayListOf() |
|
||||||
YEAR -> arrayListOf() |
|
||||||
|
|
||||||
GAME -> { |
|
||||||
val games = arrayListOf<Game>() |
|
||||||
val realm = Realm.getDefaultInstance() |
|
||||||
LiveData.GAME.items(realm).forEach { |
|
||||||
val game = FilterElement.Game(it as net.pokeranalytics.android.model.realm.Game) |
|
||||||
games.add(game) |
|
||||||
} |
|
||||||
realm.close() |
|
||||||
games |
|
||||||
} |
|
||||||
|
|
||||||
LOCATION -> arrayListOf() |
|
||||||
BANKROLL -> arrayListOf() |
|
||||||
|
|
||||||
MULTI_TABLING -> arrayListOf() |
|
||||||
|
|
||||||
BLINDS -> arrayListOf() |
|
||||||
CASH_RE_BUY_COUNT -> arrayListOf() |
|
||||||
BUY_IN -> arrayListOf() |
|
||||||
|
|
||||||
COMPLETION_PERCENTAGE -> arrayListOf() |
|
||||||
NUMBER_OF_PLAYERS -> arrayListOf() |
|
||||||
TOURNAMENT_TYPE -> arrayListOf() |
|
||||||
PLAYERS_COUNT -> arrayListOf() |
|
||||||
PLACE -> arrayListOf() |
|
||||||
TOURNAMENT_RE_BUY_COUNT -> arrayListOf() |
|
||||||
|
|
||||||
MULTI_PLAYER -> arrayListOf() |
|
||||||
|
|
||||||
RANGE -> arrayListOf() |
|
||||||
|
|
||||||
SESSION_DURATION -> arrayListOf() |
|
||||||
|
|
||||||
VALUE -> arrayListOf() |
|
||||||
|
|
||||||
else -> throw Exception("unknown filtersection") //TODO create exception |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
object Cash : FilterElement() |
|
||||||
object Tournament : FilterElement() |
|
||||||
object Live : FilterElement() |
|
||||||
object Online : FilterElement() |
|
||||||
object Today : FilterElement() |
|
||||||
object Yesterday : FilterElement() |
|
||||||
object TodayAndYesterday : FilterElement() |
|
||||||
object CurrentWeek : FilterElement() |
|
||||||
object CurrentMonth : FilterElement() |
|
||||||
object CurrentYear: FilterElement() |
|
||||||
data class From(var date: Date = Date()) : FilterElement() |
|
||||||
data class To(var date: Date = Date()) : FilterElement() |
|
||||||
object Weekday: FilterElement() |
|
||||||
object Weekend : FilterElement() |
|
||||||
data class Year(val day: Int) : FilterElement() |
|
||||||
data class Month(val day: Int) : FilterElement() |
|
||||||
data class Day(val day: Int) : FilterElement() |
|
||||||
data class PastDays(var lastDays : Int = 0) : FilterElement() |
|
||||||
data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElement() |
|
||||||
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElement() |
|
||||||
data class Bankroll(val bankroll: net.pokeranalytics.android.model.realm.Bankroll) : FilterElement() |
|
||||||
data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElement() |
|
||||||
data class Location(val location: net.pokeranalytics.android.model.realm.Location) : FilterElement() |
|
||||||
data class TournamentName(val tournamentName: net.pokeranalytics.android.model.realm.TournamentName) : FilterElement() |
|
||||||
data class TournamentFeature(val tournamentFeature: net.pokeranalytics.android.model.realm.TournamentFeature) : FilterElement() |
|
||||||
|
|
||||||
var filterSection: FilterSectionDataSource? = null |
|
||||||
|
|
||||||
override val resId: Int? |
|
||||||
get() { |
|
||||||
return when (this) { |
|
||||||
is Cash -> R.string.cash_game |
|
||||||
is Tournament -> R.string.tournament |
|
||||||
is Today -> R.string.today |
|
||||||
is Yesterday -> R.string.yesterday |
|
||||||
is TodayAndYesterday -> R.string.yesterday_and_today |
|
||||||
is CurrentWeek -> R.string.current_week |
|
||||||
is CurrentMonth -> R.string.current_month |
|
||||||
is CurrentYear -> R.string.current_year |
|
||||||
is From -> R.string.from |
|
||||||
is To -> R.string.to |
|
||||||
is Live -> R.string.live |
|
||||||
is Online -> R.string.online |
|
||||||
is Weekday -> R.string.week_days |
|
||||||
is Weekend-> R.string.weekend |
|
||||||
is Year-> R.string.year |
|
||||||
is Month-> R.string.month_of_the_year |
|
||||||
is Day -> R.string.day_of_the_week |
|
||||||
is PastDays -> R.string.period_in_days |
|
||||||
is Limit -> R.string.limit |
|
||||||
is TableSize -> R.string.table_size |
|
||||||
is Bankroll -> R.string.bankroll |
|
||||||
is Game -> R.string.game |
|
||||||
is Location -> R.string.location |
|
||||||
is TournamentName -> R.string.tournament_name |
|
||||||
is TournamentFeature -> R.string.tournament_feature |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override fun getDisplayName(): String { |
|
||||||
return when (this) { |
|
||||||
is Game -> game.getDisplayName() |
|
||||||
else -> return super.getDisplayName() |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal |
|
||||||
|
|
||||||
val sectionToExclude : List < FilterSectionDataSource > ? |
|
||||||
get() { |
|
||||||
val excluded = arrayListOf<FilterSectionDataSource>() |
|
||||||
this.filterSection?.let { |
|
||||||
if (!it.allowMultiSelection) { |
|
||||||
excluded.add(it) |
|
||||||
} |
|
||||||
it.exclusiveWith?.let { exclusives -> |
|
||||||
excluded.addAll(exclusives) |
|
||||||
} |
|
||||||
|
|
||||||
if (excluded.size > 0) { |
|
||||||
return excluded |
|
||||||
} |
|
||||||
} ?: run { |
|
||||||
return null |
|
||||||
} |
|
||||||
|
|
||||||
return null |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { |
|
||||||
when (this) { |
|
||||||
PAST_DAYS -> { |
|
||||||
val defaultValue: String? by map |
|
||||||
val data = arrayListOf<RowRepresentableEditDescriptor>() |
|
||||||
data.add( |
|
||||||
RowRepresentableEditDescriptor( |
|
||||||
defaultValue, |
|
||||||
inputType = InputType.TYPE_CLASS_NUMBER |
|
||||||
) |
|
||||||
) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return super.editingDescriptors(map) |
|
||||||
} |
|
||||||
*/ |
|
||||||
} |
|
||||||
Loading…
Reference in new issue