@ -1,17 +1,23 @@
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.text.DateFormatSymbols
import java.util.*
import java.util.*
sealed class FilterElementRow : RowRepresentable {
sealed class FilterElementRow : RowRepresentable {
// Objects
object Cash : FilterElementRow ( )
object Cash : FilterElementRow ( )
object Tournament : FilterElementRow ( )
object Tournament : FilterElementRow ( )
object Live : FilterElementRow ( )
object Live : FilterElementRow ( )
@ -25,6 +31,15 @@ sealed class FilterElementRow : RowRepresentable {
object Weekday : FilterElementRow ( )
object Weekday : FilterElementRow ( )
object Weekend : FilterElementRow ( )
object Weekend : FilterElementRow ( )
object ResultMoreThan : MoreFilterElementRow ( )
object ResultLessThan : LessFilterElementRow ( )
object DurationMoreThan : MoreTimeFilterElementRow ( )
object DurationLessThan : LessTimeFilterElementRow ( )
// Subclasses
open class SingleValueFilterElementRow ( val value : Int ) : FilterElementRow ( )
open class DataFilterElementRow ( data : Manageable ) : FilterElementRow ( ) {
open class DataFilterElementRow ( data : Manageable ) : FilterElementRow ( ) {
val id : String = data . id
val id : String = data . id
val name : String = ( data as RowRepresentable ) . getDisplayName ( )
val name : String = ( data as RowRepresentable ) . getDisplayName ( )
@ -40,7 +55,17 @@ sealed class FilterElementRow : RowRepresentable {
}
}
}
}
open class SingleValueFilterElementRow ( val value : Int ) : FilterElementRow ( )
open class QuantityFilterElementRow ( var value : Double = 0.0 ) : FilterElementRow ( )
open class TimeFilterElementRow : QuantityFilterElementRow ( ) {
var minutes = value . toInt ( )
}
open class MoreFilterElementRow : QuantityFilterElementRow ( )
open class LessFilterElementRow : QuantityFilterElementRow ( )
open class MoreTimeFilterElementRow : TimeFilterElementRow ( )
open class LessTimeFilterElementRow : TimeFilterElementRow ( )
// Data classes
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 ( )
data class From ( var date : Date = Date ( ) ) : FilterElementRow ( )
data class From ( var date : Date = Date ( ) ) : FilterElementRow ( )
@ -57,8 +82,7 @@ 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 ( )
lateinit var filterSectionRow : FilterSectionRow
lateinit var filterSectionRow : FilterSectionRow
@ -85,10 +109,7 @@ sealed class FilterElementRow : RowRepresentable {
is CurrentWeek -> QueryCondition . THIS _WEEK
is CurrentWeek -> QueryCondition . THIS _WEEK
is CurrentMonth -> QueryCondition . THIS _MONTH
is CurrentMonth -> QueryCondition . THIS _MONTH
is CurrentYear -> QueryCondition . THIS _YEAR
is CurrentYear -> QueryCondition . THIS _YEAR
/ *
is PastDays -> QueryCondition . PAST _DAYS
is PastDays -> R . string . period _in _days
* /
is Limit -> QueryCondition . LIMIT
is Limit -> QueryCondition . LIMIT
is TableSize -> QueryCondition . TABLE _SIZE
is TableSize -> QueryCondition . TABLE _SIZE
is Game -> QueryCondition . GAME
is Game -> QueryCondition . GAME
@ -99,12 +120,18 @@ 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 )
}
}
}
}
fun contains ( filterConditions : List < FilterCondition > ) : Boolean {
fun contains ( filterConditions : List < FilterCondition > ) : Boolean {
return when ( this ) {
return when ( this ) {
is SingleValueFilterElementRow -> filterConditions . any {
it . values . contains ( this . value )
}
is DataFilterElementRow -> filterConditions . any {
is DataFilterElementRow -> filterConditions . any {
it . ids . contains ( this . id )
it . ids . contains ( this . id )
}
}
@ -133,13 +160,10 @@ sealed class FilterElementRow : RowRepresentable {
is Online -> R . string . online
is Online -> R . string . online
is Weekday -> R . string . week _days
is Weekday -> R . string . week _days
is Weekend -> R . string . weekend
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 PastDays -> R . string . period _in _days
is Blind -> R . string . blinds
is Blind -> R . string . blinds
is ResultMoreThan -> R . string . more _than
is MoreFilterElementRow , is MoreTimeFilterElementRow -> R . string . more _than
is ResultLessThan -> R . string . less _than
is LessFilterElementRow , is LessTimeFilterElementRow -> R . string . less _than
else -> null
else -> null
}
}
}
}
@ -147,13 +171,51 @@ 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 PastDays ,
is From , is To ,
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 PastDays -> BottomSheetType . EDIT _TEXT
is DurationMoreThan , is DurationLessThan -> BottomSheetType . DOUBLE _EDIT _TEXT
else -> BottomSheetType . NONE
}
}
override fun editingDescriptors ( map : Map < String , Any ? > ) : ArrayList < RowRepresentableEditDescriptor > ? {
return when ( this ) {
is PastDays -> {
val pastDays : String ? by map
arrayListOf (
RowRepresentableEditDescriptor ( pastDays , R . string . period _in _days , inputType = InputType . TYPE _CLASS _NUMBER )
)
}
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 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 DataFilterElementRow -> this . name
is StaticDataFilterElementRow -> this . name
is StaticDataFilterElementRow -> this . name
else -> super . getDisplayName ( )
else -> super . getDisplayName ( )