|
|
|
|
@ -5,16 +5,20 @@ import io.realm.* |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import io.realm.RealmQuery |
|
|
|
|
import io.realm.internal.Table |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
|
import net.pokeranalytics.android.model.TableSize |
|
|
|
|
import net.pokeranalytics.android.model.TournamentType |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Manageable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.NameManageable |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
|
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
import net.pokeranalytics.android.util.extensions.endOfDay |
|
|
|
|
import net.pokeranalytics.android.util.extensions.startOfDay |
|
|
|
|
import java.text.DateFormatSymbols |
|
|
|
|
@ -22,7 +26,7 @@ import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
fun List<QueryCondition>.name() : String { |
|
|
|
|
return this.map { it.label() }.joinToString(" / ") |
|
|
|
|
return this.map { it.getDisplayName() }.joinToString(" / ") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//inline fun <reified T : Filterable> List<QueryCondition>.query(realm: Realm): RealmQuery<T> { |
|
|
|
|
@ -44,11 +48,7 @@ inline fun <reified T : Filterable> List<QueryCondition>.queryWith(query: RealmQ |
|
|
|
|
* A new type should also set the expected numericValues required in the [filterValuesExpectedKeys] |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
interface Labelable { |
|
|
|
|
fun label() : String |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class QueryCondition : FilterElementRow, Labelable { |
|
|
|
|
sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
interface Valuable <T : ArrayList<T>> { |
|
|
|
|
var values: ArrayList<T>? |
|
|
|
|
@ -112,10 +112,11 @@ sealed class QueryCondition : FilterElementRow, Labelable { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun label(): String { |
|
|
|
|
override fun getDisplayName(): String { |
|
|
|
|
return when (this) { |
|
|
|
|
is YEAR -> "$intValue" |
|
|
|
|
is MONTH -> DateFormatSymbols.getInstance(Locale.getDefault()).months[intValue] |
|
|
|
|
is StaticDataQueryCondition -> label() |
|
|
|
|
is QueryDataCondition<*> -> label() |
|
|
|
|
is BLIND -> this.blind!! |
|
|
|
|
else -> baseId |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -130,22 +131,33 @@ sealed class QueryCondition : FilterElementRow, Labelable { |
|
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract class QueryDataCondition < T: Identifiable> : QueryCondition(), asListOfString { |
|
|
|
|
abstract class QueryDataCondition < T: NameManageable > : QueryCondition(), asListOfString { |
|
|
|
|
fun setObject(dataObject: T) { |
|
|
|
|
this.dataObject = dataObject |
|
|
|
|
this.stringValues.add(dataObject.id) |
|
|
|
|
} |
|
|
|
|
var dataObject: Identifiable? = null |
|
|
|
|
|
|
|
|
|
var dataObject: NameManageable? = null |
|
|
|
|
override var stringValues = ArrayList<String>() |
|
|
|
|
|
|
|
|
|
val name: String |
|
|
|
|
get() { |
|
|
|
|
if (stringValues.size > 1) { |
|
|
|
|
return "multiple" |
|
|
|
|
} else { |
|
|
|
|
return (dataObject as RowRepresentable).getDisplayName() |
|
|
|
|
abstract val entity : Class<T> |
|
|
|
|
|
|
|
|
|
fun label(): String { |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val completeLabel = when (stringValues.size) { |
|
|
|
|
0 -> return NULL_TEXT |
|
|
|
|
1,2 -> { |
|
|
|
|
return stringValues.map { labelForValue(realm, it) }.joinToString(", ") |
|
|
|
|
} |
|
|
|
|
else -> "${stringValues.size} $baseId" |
|
|
|
|
} |
|
|
|
|
return "todo" |
|
|
|
|
realm.close() |
|
|
|
|
return completeLabel |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun labelForValue(realm:Realm, value:String): String { |
|
|
|
|
val query = realm.where(entity) |
|
|
|
|
return query.equalTo("id", value).findFirst()?.name ?: NULL_TEXT |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -189,50 +201,51 @@ sealed class QueryCondition : FilterElementRow, Labelable { |
|
|
|
|
abstract class StaticDataQueryCondition : QueryCondition(), asListOfInt { |
|
|
|
|
var data : RowRepresentable? = null |
|
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
|
abstract fun labelForValue(value:Int): String? |
|
|
|
|
|
|
|
|
|
fun label(): String { |
|
|
|
|
return when (intValues.size) { |
|
|
|
|
0 -> return NULL_TEXT |
|
|
|
|
1,2 -> intValues.map { labelForValue(it) }.joinToString(", ") |
|
|
|
|
else -> "${intValues.size} $baseId" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
object LIVE : QueryCondition() |
|
|
|
|
object CASH : QueryCondition() |
|
|
|
|
object ONLINE : QueryCondition() |
|
|
|
|
object TOURNAMENT: QueryCondition() |
|
|
|
|
class BANKROLL: QueryDataCondition<Bankroll>() |
|
|
|
|
class GAME: QueryDataCondition<Game>() |
|
|
|
|
class TOURNAMENT_NAME: QueryDataCondition<TournamentName>() |
|
|
|
|
class ANY_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
|
class ALL_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
|
class LOCATION: QueryDataCondition<Location>() |
|
|
|
|
class BANKROLL: QueryDataCondition<Bankroll>() { override val entity: Class<Bankroll> = Bankroll::class.java } |
|
|
|
|
class GAME: QueryDataCondition<Game>() { override val entity: Class<Game> = Game::class.java } |
|
|
|
|
class TOURNAMENT_NAME: QueryDataCondition<TournamentName>() { override val entity: Class<TournamentName> = TournamentName::class.java } |
|
|
|
|
class ANY_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() { override val entity: Class<TournamentFeature> = TournamentFeature::class.java } |
|
|
|
|
class ALL_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() { override val entity: Class<TournamentFeature> = TournamentFeature::class.java } |
|
|
|
|
class LOCATION: QueryDataCondition<Location>() { override val entity: Class<Location> = Location::class.java } |
|
|
|
|
|
|
|
|
|
class LIMIT: StaticDataQueryCondition() { |
|
|
|
|
val limit : Limit get() { return Limit.values()[intValues.first()] } |
|
|
|
|
val name: String |
|
|
|
|
get() { |
|
|
|
|
if (intValues.size > 1) { |
|
|
|
|
return "multiple" |
|
|
|
|
} else if (intValues.size > 0) { |
|
|
|
|
return Limit.values()[intValues.first()].longName |
|
|
|
|
} |
|
|
|
|
return "todo" |
|
|
|
|
override fun labelForValue(value: Int): String? { |
|
|
|
|
return Limit.values()[value].longName |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TABLE_SIZE: StaticDataQueryCondition() { |
|
|
|
|
val tableSize: TableSize get() { return TableSize.all[intValues.first()] } |
|
|
|
|
val tableSize: TableSize get() { return TableSize(intValues.first()) } |
|
|
|
|
//TODO dynamize this |
|
|
|
|
override val resId: Int? = R.string.max |
|
|
|
|
|
|
|
|
|
override fun localizedTitle(context: Context): String { |
|
|
|
|
return this.tableSize.localizedTitle(context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun labelForValue(value: Int): String? { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TOURNAMENT_TYPE: StaticDataQueryCondition() { |
|
|
|
|
val name: String |
|
|
|
|
get() { |
|
|
|
|
if (intValues.size > 1) { |
|
|
|
|
return "multiple" |
|
|
|
|
} else { |
|
|
|
|
return TournamentType.values()[intValues.first()].getDisplayName() |
|
|
|
|
} |
|
|
|
|
return "todo" |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
return TournamentType.values()[value].getDisplayName() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -291,9 +304,25 @@ sealed class QueryCondition : FilterElementRow, Labelable { |
|
|
|
|
class STARTED_TO_DATE: DateQuery(), Less |
|
|
|
|
class ENDED_FROM_DATE: DateQuery() |
|
|
|
|
class ENDED_TO_DATE: DateQuery(), Less |
|
|
|
|
class DAY_OF_WEEK: SingleValueQueryCondition() |
|
|
|
|
class MONTH: SingleValueQueryCondition() |
|
|
|
|
class YEAR: SingleValueQueryCondition() |
|
|
|
|
|
|
|
|
|
class DAY_OF_WEEK: StaticDataQueryCondition() { |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[value] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MONTH: StaticDataQueryCondition() { |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
return DateFormatSymbols.getInstance(Locale.getDefault()).months[value] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class YEAR: StaticDataQueryCondition() { |
|
|
|
|
override fun labelForValue(value: Int): String { |
|
|
|
|
return "$value" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
object WEEK_DAY: QueryCondition() |
|
|
|
|
object WEEK_END: QueryCondition() |
|
|
|
|
object TODAY: QueryCondition() |
|
|
|
|
|