Add Time picker for filters

feature/top10
Aurelien Hubert 7 years ago
parent 6aaa5e4fae
commit e86cfbd610
  1. 3
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt
  3. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  4. 33
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  5. 38
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -6,6 +6,7 @@ import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.FilterCondition import net.pokeranalytics.android.model.realm.FilterCondition
import net.pokeranalytics.android.model.realm.FilterElementBlind import net.pokeranalytics.android.model.realm.FilterElementBlind
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.Preferences
import net.pokeranalytics.android.util.extensions.endOfDay import net.pokeranalytics.android.util.extensions.endOfDay
import net.pokeranalytics.android.util.extensions.startOfDay import net.pokeranalytics.android.util.extensions.startOfDay
import java.util.* import java.util.*
@ -73,6 +74,8 @@ enum class QueryCondition(var operator: Operator? = null) {
PAST_DAYS, PAST_DAYS,
MORE_THAN_DURATION(Operator.MORE), MORE_THAN_DURATION(Operator.MORE),
LESS_THAN_DURATION(Operator.LESS), LESS_THAN_DURATION(Operator.LESS),
STARTED_FROM_TIME,
ENDED_TO_TIME,
CURRENCY, CURRENCY,
CURRENCY_CODE, CURRENCY_CODE,

@ -116,7 +116,7 @@ open class FilterCondition() : RealmObject() {
*/ */
fun getFilterConditionValue(filterElementRow: FilterElementRow): Any? { fun getFilterConditionValue(filterElementRow: FilterElementRow): Any? {
return when (filterElementRow) { return when (filterElementRow) {
is From, is To -> dateValue //TODO: Probably change by 'date' (doesn't work now because the value isn't correctly saved is DateFilterElementRow -> date
is PastDays -> values is PastDays -> values
else -> throw PokerAnalyticsException.FilterElementTypeMissing(filterElementRow) else -> throw PokerAnalyticsException.FilterElementTypeMissing(filterElementRow)
} }

@ -27,12 +27,13 @@ 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.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.shortDate import net.pokeranalytics.android.util.extensions.shortDate
import net.pokeranalytics.android.util.extensions.shortTime
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.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
lateinit var parentActivity: PokerAnalyticsActivity lateinit var parentActivity: PokerAnalyticsActivity
lateinit var rowRepresentableAdapter: RowRepresentableAdapter lateinit var rowRepresentableAdapter: RowRepresentableAdapter
@ -69,7 +70,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
is FilterElementRow.DateFilterElementRow -> DateTimePickerManager.create(requireContext(), row, this, row.dateValue, onlyDate = true) is FilterElementRow.DateFilterElementRow -> DateTimePickerManager.create(requireContext(), row, this, row.dateValue, onlyDate = !row.showTime, onlyTime = row.showTime)
is FilterElementRow.PastDays -> { is FilterElementRow.PastDays -> {
val pastDays = if (row.lastDays > 0) row.lastDays.toString() else "" val pastDays = if (row.lastDays > 0) row.lastDays.toString() else ""
val data = row.editingDescriptors(mapOf("pastDays" to pastDays)) val data = row.editingDescriptors(mapOf("pastDays" to pastDays))
@ -107,7 +108,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT
is FilterElementRow.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT is FilterElementRow.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT
is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT
is FilterElementRow.DateFilterElementRow -> row.dateValue.shortDate() is FilterElementRow.DateFilterElementRow -> if (row.showTime) row.dateValue.shortTime() else row.dateValue.shortDate()
is FilterElementRow.AmountFilterElement -> if (row.amount > 0) row.amount.toString() else NULL_TEXT is FilterElementRow.AmountFilterElement -> if (row.amount > 0) row.amount.toString() else NULL_TEXT
is FilterElementRow.DurationFilterElement -> row.minutes.toMinutes(requireContext()) is FilterElementRow.DurationFilterElement -> row.minutes.toMinutes(requireContext())
else -> super.stringForRow(row) else -> super.stringForRow(row)

@ -28,7 +28,7 @@ sealed class FilterElementRow : RowRepresentable {
interface LessOperator : Operator interface LessOperator : Operator
open class BoolFilterElementRow : FilterElementRow() open class BoolFilterElementRow : FilterElementRow()
open class DateFilterElementRow(var dateValue: Date = Date()) : FilterElementRow() open class DateFilterElementRow(var dateValue: Date = Date(), var showTime: Boolean = false) : FilterElementRow()
open class NumericFilterElementRow(open val doubleValue: Double = 0.0) : FilterElementRow() open class NumericFilterElementRow(open val doubleValue: Double = 0.0) : FilterElementRow()
open class StringFilterElementRow(val stringValue: String = "") : FilterElementRow() open class StringFilterElementRow(val stringValue: String = "") : FilterElementRow()
@ -86,6 +86,10 @@ sealed class FilterElementRow : RowRepresentable {
object From : DateFilterElementRow() object From : DateFilterElementRow()
object To : DateFilterElementRow() object To : DateFilterElementRow()
object FromTime : DateFilterElementRow(showTime = true)
object ToTime : DateFilterElementRow(showTime = true)
// Data classes - holding value // Data classes - holding value
object ResultMoreThan : AmountFilterElement(), MoreOperator object ResultMoreThan : AmountFilterElement(), MoreOperator
@ -153,6 +157,8 @@ sealed class FilterElementRow : RowRepresentable {
is Blind -> QueryCondition.BLINDS is Blind -> QueryCondition.BLINDS
is From -> QueryCondition.STARTED_FROM_DATE is From -> QueryCondition.STARTED_FROM_DATE
is To -> QueryCondition.ENDED_TO_DATE is To -> QueryCondition.ENDED_TO_DATE
is FromTime -> QueryCondition.STARTED_FROM_TIME
is ToTime -> QueryCondition.ENDED_TO_TIME
is Month -> QueryCondition.MONTH is Month -> QueryCondition.MONTH
is Day -> QueryCondition.DAY_OF_WEEK is Day -> QueryCondition.DAY_OF_WEEK
is Year -> QueryCondition.YEAR is Year -> QueryCondition.YEAR
@ -180,7 +186,6 @@ sealed class FilterElementRow : RowRepresentable {
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
//TODO: Check the conditions //TODO: Check the conditions
is LastGames -> QueryCondition.LAST_GAMES is LastGames -> QueryCondition.LAST_GAMES
is LastSessions -> QueryCondition.LAST_SESSIONS is LastSessions -> QueryCondition.LAST_SESSIONS
@ -215,8 +220,8 @@ sealed class FilterElementRow : RowRepresentable {
is CurrentWeek -> R.string.current_week is CurrentWeek -> R.string.current_week
is CurrentMonth -> R.string.current_month is CurrentMonth -> R.string.current_month
is CurrentYear -> R.string.current_year is CurrentYear -> R.string.current_year
is From -> R.string.from is From, FromTime -> R.string.from
is To -> R.string.to is To, ToTime -> R.string.to
is Live -> R.string.live is Live -> R.string.live
is Online -> R.string.online is Online -> R.string.online
is Weekday -> R.string.week_days is Weekday -> R.string.week_days
@ -235,7 +240,7 @@ sealed class FilterElementRow : RowRepresentable {
override val viewType: Int override val viewType: Int
get() { get() {
return when (this) { return when (this) {
is PastDays, is From, is To, is LastGames, is LastSessions, is ReBuyMoreThan, is ReBuyLessThan, is PastDays, is From, is To, is FromTime, is ToTime, is LastGames, is LastSessions, is ReBuyMoreThan, is ReBuyLessThan,
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
} }
@ -330,22 +335,4 @@ sealed class FilterElementRow : RowRepresentable {
return null return null
} }
/*
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
when (this) {
PAST_DAYS -> {
val defaultValue: String? by map
val data = arrayListOf<RowRepresentableEditDescriptor>()
data.add(
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
}
return super.editingDescriptors(map)
}
*/
} }

@ -9,6 +9,8 @@ import net.pokeranalytics.android.model.realm.Session
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.FilterElementRow.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import net.pokeranalytics.android.util.extensions.endOfDay
import net.pokeranalytics.android.util.extensions.startOfDay
import java.text.DateFormatSymbols import java.text.DateFormatSymbols
import java.util.* import java.util.*
@ -86,7 +88,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
TABLE_SIZE -> { TABLE_SIZE -> {
val tableSizes = arrayListOf<FilterElementRow.TableSize>() val tableSizes = arrayListOf<FilterElementRow.TableSize>()
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val distinctTableSizes = realm.where<Session>().distinct("tableSize").findAll().sort("tableSize", Sort.ASCENDING) val distinctTableSizes =
realm.where<Session>().distinct("tableSize").findAll().sort("tableSize", Sort.ASCENDING)
distinctTableSizes.forEach { session -> distinctTableSizes.forEach { session ->
session.tableSize?.let { tableSize -> session.tableSize?.let { tableSize ->
tableSizes.add(TableSize(net.pokeranalytics.android.model.TableSize(tableSize))) tableSizes.add(TableSize(net.pokeranalytics.android.model.TableSize(tableSize)))
@ -110,7 +113,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
YEAR -> { YEAR -> {
val years = arrayListOf<FilterElementRow.Year>() val years = arrayListOf<FilterElementRow.Year>()
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val distinctYears = realm.where<Session>().distinct("year").findAll().sort("year", Sort.DESCENDING) val distinctYears =
realm.where<Session>().distinct("year").findAll().sort("year", Sort.DESCENDING)
distinctYears.forEach { session -> distinctYears.forEach { session ->
session.year?.let { year -> session.year?.let { year ->
years.add(Year(year)) years.add(Year(year))
@ -140,8 +144,17 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
} }
// Duration // Duration
SESSION_DURATION -> arrayListOf(DurationMoreThan as FilterElementRow, DurationLessThan as FilterElementRow) SESSION_DURATION -> arrayListOf(
RANGE -> arrayListOf(From, To) DurationMoreThan as FilterElementRow,
DurationLessThan as FilterElementRow
)
RANGE -> {
val fromTime = FromTime
fromTime.dateValue = Date().startOfDay()
val toTime = ToTime
toTime.dateValue = Date().endOfDay()
arrayListOf(fromTime, toTime)
}
// Sessions // Sessions
SESSIONS -> arrayListOf(LastGames(0), LastSessions(0)) SESSIONS -> arrayListOf(LastGames(0), LastSessions(0))
@ -152,7 +165,9 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
// TODO: Improve the way we get the blinds distinctly // TODO: Improve the way we get the blinds distinctly
val blinds = arrayListOf<FilterElementRow.Blind>() val blinds = arrayListOf<FilterElementRow.Blind>()
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val sessions = realm.where<Session>().findAll().sort("cgSmallBlind", Sort.ASCENDING) val sessions =
realm.where<Session>().isNotNull("cgSmallBlind").isNotNull("cgBigBlind").findAll()
.sort("cgSmallBlind", Sort.ASCENDING)
val distinctBlinds: ArrayList<Session> = ArrayList() val distinctBlinds: ArrayList<Session> = ArrayList()
val blindsHashMap: ArrayList<String> = ArrayList() val blindsHashMap: ArrayList<String> = ArrayList()
@ -164,14 +179,23 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
} }
distinctBlinds.forEach { session -> distinctBlinds.forEach { session ->
blinds.add(Blind(session.cgSmallBlind, session.cgBigBlind, session.bankroll?.currency?.code)) blinds.add(
Blind(
session.cgSmallBlind,
session.cgBigBlind,
session.bankroll?.currency?.code
)
)
session.getBlinds() session.getBlinds()
} }
realm.close() realm.close()
blinds blinds
} }
CASH_RE_BUY_COUNT -> arrayListOf(ReBuyMoreThan as FilterElementRow, ReBuyLessThan as FilterElementRow) CASH_RE_BUY_COUNT -> arrayListOf(
ReBuyMoreThan as FilterElementRow,
ReBuyLessThan as FilterElementRow
)
// Tournament // Tournament
TOURNAMENT_TYPE -> arrayListOf() TOURNAMENT_TYPE -> arrayListOf()

Loading…
Cancel
Save