Move the QueryCondition item wrapping from QueryCondition to the FilterSectionRow

kmm
Laurent 5 years ago
parent 77888e1501
commit b2b36dfdcc
  1. 55
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 24
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -18,7 +18,6 @@ import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.*
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.UserDefaults import net.pokeranalytics.android.util.UserDefaults
import net.pokeranalytics.android.util.extensions.* import net.pokeranalytics.android.util.extensions.*
@ -222,12 +221,6 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
abstract class UserInputListOfInt : ListOfInt() {
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return IntValueListFilterItemRow(this, filterSectionRow)
}
}
abstract class ListOfString : ListOfValues<String>() { abstract class ListOfString : ListOfValues<String>() {
override var operator: Operator = Operator.ANY override var operator: Operator = Operator.ANY
override var listOfValues = mutableListOf<String>() override var listOfValues = mutableListOf<String>()
@ -253,9 +246,6 @@ sealed class QueryCondition : RowRepresentable {
singleValue = filterCondition.getValue() singleValue = filterCondition.getValue()
} }
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return DateFilterItemRow(this, filterSectionRow)
}
} }
abstract class SingleInt(value: Int) : SingleValue<Int>(value) { abstract class SingleInt(value: Int) : SingleValue<Int>(value) {
@ -270,12 +260,6 @@ sealed class QueryCondition : RowRepresentable {
} }
abstract class UserInputSingleInt(value: Int) : SingleInt(value) {
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return IntFilterItemRow(this, filterSectionRow)
}
}
override fun getDisplayName(context: Context): String { override fun getDisplayName(context: Context): String {
this.resId?.let { this.resId?.let {
return context.getString(it) return context.getString(it)
@ -321,7 +305,7 @@ sealed class QueryCondition : RowRepresentable {
val showTime: Boolean val showTime: Boolean
} }
abstract class DateQuery(date: Date) : UserInputSingleDate(date), DateTime { abstract class DateQuery(date: Date) : SingleDate(date), DateTime {
override val showTime: Boolean = false override val showTime: Boolean = false
override fun labelForValue(value: Date, context: Context): String { override fun labelForValue(value: Date, context: Context): String {
@ -333,12 +317,6 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
abstract class UserInputSingleDate(date: Date) : SingleDate(date) {
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return DateFilterItemRow(this, filterSectionRow)
}
}
abstract class TimeQuery(date: Date) : DateQuery(date) { abstract class TimeQuery(date: Date) : DateQuery(date) {
override val showTime: Boolean = true override val showTime: Boolean = true
} }
@ -461,11 +439,6 @@ sealed class QueryCondition : RowRepresentable {
override fun entityName(context: Context): String { override fun entityName(context: Context): String {
return context.getString(R.string.blinds) return context.getString(R.string.blinds)
} }
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return FixedValueFilterItemRow(this, filterSectionRow)
}
} }
class NumberOfTable : ListOfInt() { class NumberOfTable : ListOfInt() {
@ -478,13 +451,7 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
open class UserInputListOfDouble : ListOfDouble() { class NumberOfRebuy() : ListOfDouble() {
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return DoubleValueListFilterItemRow(this, filterSectionRow)
}
}
class NumberOfRebuy() : UserInputListOfDouble() {
constructor(operator: Operator, numberOfRebuy: Double) : this() { constructor(operator: Operator, numberOfRebuy: Double) : this() {
this.operator = operator this.operator = operator
this.listOfValues = arrayListOf(numberOfRebuy) this.listOfValues = arrayListOf(numberOfRebuy)
@ -495,7 +462,7 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
class TournamentFinalPosition() : UserInputListOfInt() { class TournamentFinalPosition() : ListOfInt() {
constructor(operator: Operator, finalPosition: Int) : this() { constructor(operator: Operator, finalPosition: Int) : this() {
this.operator = operator this.operator = operator
this.listOfValues = arrayListOf(finalPosition) this.listOfValues = arrayListOf(finalPosition)
@ -516,18 +483,14 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
open class NetAmount : ListOfDouble() { open class NetAmount : ListOfDouble()
override fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return DoubleValueListFilterItemRow(this, filterSectionRow)
}
}
class NetAmountWon : NetAmount() class NetAmountWon : NetAmount()
class NetAmountLost : NetAmount() { class NetAmountLost : NetAmount() {
override var sign: Int = -1 override var sign: Int = -1
} }
class TournamentNumberOfPlayer : UserInputListOfInt() { class TournamentNumberOfPlayer : ListOfInt() {
override fun labelForValue(value: Int, context: Context): String { 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)
} }
@ -594,7 +557,7 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
class PastDay(value: Int) : UserInputSingleInt(value) { class PastDay(value: Int) : SingleInt(value) {
override var operator = Operator.EQUALS override var operator = Operator.EQUALS
override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal override val viewType: Int = RowViewType.TITLE_VALUE_CHECK.ordinal
@ -609,7 +572,7 @@ sealed class QueryCondition : RowRepresentable {
// } // }
} }
class Duration(value: Int) : UserInputSingleInt(value) { class Duration(value: Int) : SingleInt(value) {
override var operator = Operator.EQUALS override var operator = Operator.EQUALS
var minutes: Int var minutes: Int
@ -728,10 +691,6 @@ sealed class QueryCondition : RowRepresentable {
} }
} }
open fun toRowWrapper(filterSectionRow: FilterSectionRow): FilterItemRow {
return FixedValueFilterItemRow(this, filterSectionRow)
}
/** /**
* main method of the enum * 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] * providing a base RealmQuery [realmQuery], the method is able to attached the corresponding query and returns the newly formed [RealmQuery]

@ -73,10 +73,32 @@ sealed class FilterSectionRow(override val resId: Int?) : RowRepresentable {
val filterItems: List<FilterItemRow> val filterItems: List<FilterItemRow>
get() { get() {
return this.queryConditions.map { return this.queryConditions.map {
it.toRowWrapper(this@FilterSectionRow) rowWrapper(it, this@FilterSectionRow)
// it.toRowWrapper(this@FilterSectionRow)
} }
} }
private fun rowWrapper(queryCondition: QueryCondition, section: FilterSectionRow): FilterItemRow {
return when (queryCondition) {
// Int List
is QueryCondition.TournamentFinalPosition -> IntValueListFilterItemRow(queryCondition, section)
is QueryCondition.TournamentNumberOfPlayer -> IntValueListFilterItemRow(queryCondition, section)
// Double List
is QueryCondition.NumberOfRebuy -> DoubleValueListFilterItemRow(queryCondition, section)
is QueryCondition.NetAmount -> DoubleValueListFilterItemRow(queryCondition, section)
// Int
is QueryCondition.PastDay -> IntFilterItemRow(queryCondition, section)
is QueryCondition.Duration -> IntFilterItemRow(queryCondition, section)
// Dates
is QueryCondition.StartedFromDate -> DateFilterItemRow(queryCondition, section)
is QueryCondition.StartedFromTime -> DateFilterItemRow(queryCondition, section)
is QueryCondition.StartedToDate -> DateFilterItemRow(queryCondition, section)
is QueryCondition.EndedToDate -> DateFilterItemRow(queryCondition, section)
is QueryCondition.EndedToTime -> DateFilterItemRow(queryCondition, section)
else -> FixedValueFilterItemRow(queryCondition, section)
}
}
private val queryConditions: List<QueryCondition> private val queryConditions: List<QueryCondition>
get() { get() {
return when (this@FilterSectionRow) { return when (this@FilterSectionRow) {

Loading…
Cancel
Save