From 2a95f0ac86acfda2e7e5d0aaf99bd9c01f52d265 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Tue, 18 Jun 2019 16:08:45 +0200 Subject: [PATCH] fix issue with localisation of query condition --- .../android/model/filter/QueryCondition.kt | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt b/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt index 06e34c97..c3ec3331 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt @@ -89,7 +89,7 @@ sealed class QueryCondition : FilterElementRow { EQUALS, TRUE, ; - } + } val baseId = this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName @@ -257,7 +257,7 @@ sealed class QueryCondition : FilterElementRow { override fun getDisplayName(context: Context): String { val realm = Realm.getDefaultInstance() - val entityName = entityName(realm) + val entityName = entityName(realm, context) val completeLabel = when (listOfValues.size) { 0 -> NULL_TEXT 1, 2 -> { @@ -269,9 +269,9 @@ sealed class QueryCondition : FilterElementRow { return completeLabel } - open fun entityName(realm: Realm): String { - return baseId - } + open fun entityName(realm: Realm, context: Context): String { + return entityName(context) + } private fun labelForValue(realm: Realm, value: String): String { val query = realm.where(entity) @@ -320,7 +320,11 @@ sealed class QueryCondition : FilterElementRow { constructor(bankroll: Bankroll) : this() { this.setObject(bankroll) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.bankrolls) + } + } class AnyGame() : QueryDataCondition() { override val entity: Class = Game::class.java @@ -328,7 +332,11 @@ sealed class QueryCondition : FilterElementRow { constructor(game: Game) : this() { this.setObject(game) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.games) + } + } class AnyTournamentName() : QueryDataCondition() { override val entity: Class = TournamentName::class.java @@ -336,7 +344,11 @@ sealed class QueryCondition : FilterElementRow { constructor(tournamentName: TournamentName) : this() { this.setObject(tournamentName) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.tournament_names) + } + } class AnyTournamentFeature() : QueryDataCondition() { override val entity: Class = TournamentFeature::class.java @@ -344,7 +356,11 @@ sealed class QueryCondition : FilterElementRow { constructor(tournamentFeature: TournamentFeature) : this() { this.setObject(tournamentFeature) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.tournament_features) + } + } class AllTournamentFeature() : QueryDataCondition() { override var operator = Operator.ALL @@ -353,7 +369,11 @@ sealed class QueryCondition : FilterElementRow { constructor(tournamentFeature: TournamentFeature) : this() { this.setObject(tournamentFeature) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.tournament_features) + } + } class AnyLocation() : QueryDataCondition() { override val entity: Class = Location::class.java @@ -361,7 +381,11 @@ sealed class QueryCondition : FilterElementRow { constructor(location: Location) : this() { this.setObject(location) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.locations) + } + } class AnyTransactionType() : QueryDataCondition() { override val entity: Class = TransactionType::class.java @@ -369,27 +393,47 @@ sealed class QueryCondition : FilterElementRow { constructor(transactionType: TransactionType) : this() { this.setObject(transactionType) } - } + + override fun entityName(context: Context): String { + return context.getString(R.string.operation_types) + } + } class AnyLimit : ListOfInt() { override fun labelForValue(value: Int, context: Context): String { return Limit.values()[value].getDisplayName(context) } + + override fun entityName(context: Context): String { + return context.getString(R.string.limits) + } } class AnyTableSize : ListOfInt() { override fun labelForValue(value: Int, context: Context): String { return TableSize(value).getDisplayName(context) } + + override fun entityName(context: Context): String { + return context.getString(R.string.table_sizes) + } } class AnyTournamentType : ListOfInt() { override fun labelForValue(value: Int, context: Context): String { return TournamentType.values()[value].getDisplayName(context) } + + override fun entityName(context: Context): String { + return context.getString(R.string.tournament_types) + } } - class AnyBlind : ListOfString() + class AnyBlind : ListOfString() { + override fun entityName(context: Context): String { + return context.getString(R.string.blinds) + } + } object Last : SingleInt() { override var operator = Operator.EQUALS @@ -649,7 +693,7 @@ sealed class QueryCondition : FilterElementRow { ?: throw PokerAnalyticsException.QueryValueMapUnexpectedValue } - override fun entityName(realm: Realm): String { + override fun entityName(realm: Realm, context: Context): String { return customFieldName(realm) } @@ -940,7 +984,7 @@ sealed class QueryCondition : FilterElementRow { is IsWeekDay -> R.string.week_days is IsWeekEnd -> R.string.weekend is PastDay -> R.string.period_in_days - is TournamentNumberOfPlayer -> { + is TournamentNumberOfPlayer -> { when (this.operator) { Operator.MORE -> R.string.minimum Operator.LESS -> R.string.maximum