Improve Filters, work in progres

feature/top10
Aurelien Hubert 7 years ago
parent 9c0987e2e1
commit 3b795f4885
  1. 4
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 50
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  3. 44
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -9,8 +9,6 @@ import net.pokeranalytics.android.model.realm.Session
import java.util.* import java.util.*
/** /**
* Enum describing the way a query should be handled * Enum describing the way a query should be handled
* Some queries requires a value to be checked upon through equals, in, more, less, between * Some queries requires a value to be checked upon through equals, in, more, less, between
@ -66,6 +64,8 @@ enum class QueryCondition(var operator: Operator? = null) {
THIS_WEEK, THIS_WEEK,
THIS_MONTH, THIS_MONTH,
THIS_YEAR, THIS_YEAR,
MORE_THAN_DURATION(Operator.MORE),
LESS_THAN_DURATION(Operator.LESS),
CURRENCY, CURRENCY,
CURRENCY_CODE, CURRENCY_CODE,

@ -24,8 +24,10 @@ import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import net.pokeranalytics.android.util.extensions.toMinutes
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
import kotlin.collections.ArrayList
open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
@ -64,9 +66,11 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
is FilterElementRow.ResultMoreThan -> { is FilterElementRow.DurationMoreThan -> {
val data = row.editingDescriptors(mapOf("defaultValue" to "")) val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else ""
BottomSheetFragment.create(fragmentManager, row, this, data, null) val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else ""
val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
else -> { else -> {
@ -88,7 +92,6 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
selectedRows.add(row) selectedRows.add(row)
} }
} }
} }
} }
@ -111,6 +114,13 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
is FilterElementRow.DurationMoreThan -> row.minutes.toMinutes(requireContext())
else -> super.stringForRow(row)
}
}
override fun isSelected(row: RowRepresentable): Boolean { override fun isSelected(row: RowRepresentable): Boolean {
return selectedRows.contains(row) return selectedRows.contains(row)
} }
@ -118,7 +128,37 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
super.onRowValueChanged(value, row) super.onRowValueChanged(value, row)
Timber.d("onRowValueChanged: $row $value") Timber.d("onRowValueChanged: $row $value")
when (row) {
is FilterElementRow.DurationMoreThan -> {
if (value is ArrayList<*>) {
val hours = try {
(value[0] as String? ?: "0").toInt()
} catch (e: Exception) {
0
}
val minutes = try {
(value[1] as String? ?: "0").toInt()
} catch (e: Exception) {
0
}
row.minutes = hours * 60 + minutes
} else {
row.minutes = 0
}
}
}
//TODO: Update management like in onRowSelected
if (value != null) {
if (!selectedRows.contains(row)) {
selectedRows.add(row as FilterElementRow) selectedRows.add(row as FilterElementRow)
}
} else {
selectedRows.remove(row as FilterElementRow)
}
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
@ -155,8 +195,6 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
*/ */
private fun initData() { private fun initData() {
Timber.d("initData")
primaryKey?.let { primaryKey?.let {
currentFilter = Filter.getFilterBydId(getRealm(), it) currentFilter = Filter.getFilterBydId(getRealm(), it)
} }

@ -1,12 +1,15 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context import android.content.Context
import android.text.InputType
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryCondition import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.interfaces.Manageable import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.realm.FilterCondition import net.pokeranalytics.android.model.realm.FilterCondition
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import java.util.* import java.util.*
@ -40,6 +43,10 @@ sealed class FilterElementRow : RowRepresentable {
} }
} }
open class QuantityFilterElementRow : FilterElementRow()
open class MoreFilterElementRow : QuantityFilterElementRow()
open class LessFilterElementRow : QuantityFilterElementRow()
open class SingleValueFilterElementRow(val value: Int) : FilterElementRow() 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 Blind(var sb: Double? = null, var bb: Double? = null, var code: String? = null) : FilterElementRow()
@ -57,8 +64,11 @@ sealed class FilterElementRow : RowRepresentable {
data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName) data class TournamentName(val tournamentName: Manageable) : DataFilterElementRow(tournamentName)
data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class AnyTournamentFeature(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() data class ResultMoreThan(var value: Double) : MoreFilterElementRow()
data class ResultLessThan(var value: Double) : LessFilterElementRow()
data class DurationMoreThan(var minutes: Int) : MoreFilterElementRow()
data class DurationLessThan(var minutes: Int) : LessFilterElementRow()
lateinit var filterSectionRow: FilterSectionRow lateinit var filterSectionRow: FilterSectionRow
@ -99,6 +109,8 @@ sealed class FilterElementRow : RowRepresentable {
is AllTournamentFeature -> QueryCondition.ALL_TOURNAMENT_FEATURES is AllTournamentFeature -> QueryCondition.ALL_TOURNAMENT_FEATURES
is ResultMoreThan -> QueryCondition.MORE_THAN_NET_RESULT is ResultMoreThan -> QueryCondition.MORE_THAN_NET_RESULT
is ResultLessThan -> QueryCondition.LESS_THAN_NET_RESULT is ResultLessThan -> QueryCondition.LESS_THAN_NET_RESULT
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this) else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
} }
} }
@ -138,8 +150,8 @@ sealed class FilterElementRow : RowRepresentable {
is Day -> R.string.day_of_the_week is Day -> R.string.day_of_the_week
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Blind -> R.string.blinds is Blind -> R.string.blinds
is ResultMoreThan -> R.string.more_than is ResultMoreThan, is DurationMoreThan -> R.string.more_than
is ResultLessThan -> R.string.less_than is ResultLessThan, is DurationLessThan -> R.string.less_than
else -> null else -> null
} }
} }
@ -147,11 +159,33 @@ sealed class FilterElementRow : RowRepresentable {
override val viewType: Int override val viewType: Int
get() { get() {
return when (this) { return when (this) {
is ResultMoreThan -> RowViewType.TITLE_VALUE_CHECK.ordinal is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal
else -> RowViewType.TITLE_CHECK.ordinal else -> RowViewType.TITLE_CHECK.ordinal
} }
} }
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
is DurationMoreThan, is DurationLessThan -> BottomSheetType.DOUBLE_EDIT_TEXT
else -> BottomSheetType.NONE
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
is DurationMoreThan, is DurationLessThan -> {
val hours: String? by map
val minutes: String? by map
arrayListOf(
RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER),
RowRepresentableEditDescriptor(minutes, R.string.minute, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
else -> super.editingDescriptors(map)
}
}
override fun getDisplayName(): String { override fun getDisplayName(): String {
return when (this) { return when (this) {
is DataFilterElementRow -> this.name is DataFilterElementRow -> this.name

@ -126,7 +126,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
MULTI_PLAYER -> arrayListOf() MULTI_PLAYER -> arrayListOf()
SESSION_DURATION -> arrayListOf(ResultMoreThan(0.0), ResultLessThan(0.0)) SESSION_DURATION -> arrayListOf(DurationMoreThan(0), DurationLessThan(0))
RANGE -> arrayListOf(From(Date()), To(Date())) RANGE -> arrayListOf(From(Date()), To(Date()))
VALUE -> arrayListOf() VALUE -> arrayListOf()

Loading…
Cancel
Save