Improve date management for filters

feature/top10
Aurelien Hubert 7 years ago
parent 77376ac163
commit acd3a2c4d1
  1. 9
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt

@ -19,11 +19,13 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
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.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.shortDate
import net.pokeranalytics.android.util.extensions.toMinutes import net.pokeranalytics.android.util.extensions.toMinutes
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
@ -66,6 +68,9 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
is FilterElementRow.From -> DateTimePickerManager.create(requireContext(), row, this, row.date, onlyDate = true)
is FilterElementRow.To -> DateTimePickerManager.create(requireContext(), row, this, row.date, onlyDate = true)
is FilterElementRow.DurationMoreThan -> { is FilterElementRow.DurationMoreThan -> {
val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else "" val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else ""
val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else "" val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else ""
@ -116,6 +121,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
is FilterElementRow.From -> row.date.shortDate()
is FilterElementRow.To -> row.date.shortDate()
is FilterElementRow.DurationMoreThan -> row.minutes.toMinutes(requireContext()) is FilterElementRow.DurationMoreThan -> row.minutes.toMinutes(requireContext())
else -> super.stringForRow(row) else -> super.stringForRow(row)
} }
@ -130,6 +137,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("onRowValueChanged: $row $value") Timber.d("onRowValueChanged: $row $value")
when (row) { when (row) {
is FilterElementRow.From -> row.date = if (value != null && value is Date) value else Date()
is FilterElementRow.To -> row.date = if (value != null && value is Date) value else Date()
is FilterElementRow.DurationMoreThan -> { is FilterElementRow.DurationMoreThan -> {
if (value is ArrayList<*>) { if (value is ArrayList<*>) {
val hours = try { val hours = try {

@ -111,6 +111,7 @@ sealed class FilterElementRow : RowRepresentable {
is ResultLessThan -> QueryCondition.LESS_THAN_NET_RESULT is ResultLessThan -> QueryCondition.LESS_THAN_NET_RESULT
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this) else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
} }
} }
@ -150,8 +151,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, is DurationMoreThan -> R.string.more_than is MoreFilterElementRow -> R.string.more_than
is ResultLessThan, is DurationLessThan -> R.string.less_than is LessFilterElementRow -> R.string.less_than
else -> null else -> null
} }
} }
@ -159,6 +160,7 @@ sealed class FilterElementRow : RowRepresentable {
override val viewType: Int override val viewType: Int
get() { get() {
return when (this) { return when (this) {
is From, is To,
is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal
else -> RowViewType.TITLE_CHECK.ordinal else -> RowViewType.TITLE_CHECK.ordinal
} }

Loading…
Cancel
Save