Improve date filters

feature/top10
Aurelien Hubert 7 years ago
parent acd3a2c4d1
commit 30c2b100c4
  1. 1
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 22
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  3. 36
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -67,6 +67,7 @@ enum class QueryCondition(var operator: Operator? = null) {
THIS_WEEK,
THIS_MONTH,
THIS_YEAR,
PAST_DAYS,
MORE_THAN_DURATION(Operator.MORE),
LESS_THAN_DURATION(Operator.LESS),

@ -11,6 +11,7 @@ import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheet
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import java.text.DateFormatSymbols
import java.util.*
sealed class FilterElementRow : RowRepresentable {
@ -28,6 +29,8 @@ sealed class FilterElementRow : RowRepresentable {
object Weekday : FilterElementRow()
object Weekend : FilterElementRow()
open class SingleValueFilterElementRow(val value: Int) : FilterElementRow()
open class DataFilterElementRow(data: Manageable) : FilterElementRow() {
val id: String = data.id
val name: String = (data as RowRepresentable).getDisplayName()
@ -47,7 +50,6 @@ sealed class FilterElementRow : RowRepresentable {
open class MoreFilterElementRow : QuantityFilterElementRow()
open class LessFilterElementRow : QuantityFilterElementRow()
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()
@ -95,10 +97,7 @@ sealed class FilterElementRow : RowRepresentable {
is CurrentWeek -> QueryCondition.THIS_WEEK
is CurrentMonth -> QueryCondition.THIS_MONTH
is CurrentYear -> QueryCondition.THIS_YEAR
/*
is PastDays -> R.string.period_in_days
*/
is PastDays -> QueryCondition.PAST_DAYS
is Limit -> QueryCondition.LIMIT
is TableSize -> QueryCondition.TABLE_SIZE
is Game -> QueryCondition.GAME
@ -118,6 +117,9 @@ sealed class FilterElementRow : RowRepresentable {
fun contains(filterConditions: List<FilterCondition>): Boolean {
return when (this) {
is SingleValueFilterElementRow -> filterConditions.any {
it.values.contains(this.value)
}
is DataFilterElementRow -> filterConditions.any {
it.ids.contains(this.id)
}
@ -146,9 +148,6 @@ sealed class FilterElementRow : RowRepresentable {
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 Blind -> R.string.blinds
is MoreFilterElementRow -> R.string.more_than
@ -190,6 +189,13 @@ sealed class FilterElementRow : RowRepresentable {
override fun getDisplayName(): String {
return when (this) {
is SingleValueFilterElementRow -> {
when (this) {
is Day -> DateFormatSymbols.getInstance(Locale.getDefault()).weekdays[this.value]
is Month -> DateFormatSymbols.getInstance(Locale.getDefault()).months[this.value]
else -> "${this.value}"
}
}
is DataFilterElementRow -> this.name
is StaticDataFilterElementRow -> this.name
else -> super.getDisplayName()

@ -8,6 +8,7 @@ import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.text.DateFormatSymbols
import java.util.*
enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
@ -91,11 +92,38 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
CurrentYear
)
FIXED_DATE -> arrayListOf(From(), To())
DURATION -> arrayListOf()
DURATION -> arrayListOf(PastDays())
YEAR -> {
val years = arrayListOf<FilterElementRow.Year>()
val realm = Realm.getDefaultInstance()
val distinctYears = realm.where<Session>().distinct("year").findAll().sort("year", Sort.DESCENDING)
distinctYears.forEach { session ->
session.year?.let { year ->
years.add(Year(year))
}
}
realm.close()
years
}
WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend)
DAY_OF_WEEK -> arrayListOf()
MONTH_OF_YEAR -> arrayListOf()
YEAR -> arrayListOf()
DAY_OF_WEEK -> {
val daysOfWeek = arrayListOf<FilterElementRow.Day>()
DateFormatSymbols.getInstance(Locale.getDefault()).weekdays.forEachIndexed { index, day ->
if (day.isNotEmpty()) {
daysOfWeek.add(Day(index))
}
}
daysOfWeek
}
MONTH_OF_YEAR -> {
val months = arrayListOf<FilterElementRow.Month>()
DateFormatSymbols.getInstance(Locale.getDefault()).months.forEachIndexed { index, month ->
if (month.isNotEmpty()) {
months.add(Month(index))
}
}
months
}
GAME -> {
val games = arrayListOf<FilterElementRow.Game>()

Loading…
Cancel
Save