feature/top10
Razmig Sarkissian 7 years ago
parent 9118ebc3dd
commit f8e78e6a51
  1. 12
      app/src/androidTest/java/net/pokeranalytics/android/filter/RealmFilterInstrumentedUnitTest.kt
  2. 1
      app/src/main/java/net/pokeranalytics/android/model/Limit.kt
  3. 30
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  4. 22
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterComponent.kt
  5. 1
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  6. 29
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  7. 8
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FiltersFragment.kt
  8. 33
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategory.kt
  9. 82
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  10. 147
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  11. 175
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -4,9 +4,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pokeranalytics.android.model.filter.FilterType import net.pokeranalytics.android.model.filter.FilterType
import net.pokeranalytics.android.model.realm.Filter import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -23,11 +23,11 @@ class RealmFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() {
val filter = Filter() val filter = Filter()
filter.name = "testSaveLoadCashFilter" filter.name = "testSaveLoadCashFilter"
val filterElement = FilterElement.Cash val filterElement = FilterElementRow.Cash
filterElement.filterSection = FilterSection.CASH_TOURNAMENT filterElement.filterSectionRow = FilterSectionRow.CASH_TOURNAMENT
filter.componentsFrom(arrayListOf(filterElement)) filter.componentsFrom(arrayListOf(filterElement))
val useCount = filter.countBy(FilterCategory.GENERAL) val useCount = filter.countBy(FilterCategoryRow.GENERAL)
Assert.assertEquals(1, useCount) Assert.assertEquals(1, useCount)
val isCash = filter.contains(filterElement) val isCash = filter.contains(filterElement)

@ -1,7 +1,6 @@
package net.pokeranalytics.android.model package net.pokeranalytics.android.model
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
enum class Limit : RowRepresentable { enum class Limit : RowRepresentable {
NO, NO,

@ -3,9 +3,9 @@ package net.pokeranalytics.android.model.realm
import io.realm.* import io.realm.*
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.model.filter.interfaces.Filterable import net.pokeranalytics.android.model.filter.interfaces.Filterable
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import java.util.* import java.util.*
//import net.pokeranalytics.android.FilterComponent //import net.pokeranalytics.android.FilterComponent
@ -26,23 +26,23 @@ open class Filter : RealmObject() {
var components: RealmList<FilterComponent> = RealmList() var components: RealmList<FilterComponent> = RealmList()
private set private set
fun componentsFrom(filterElements: ArrayList<FilterElement>) { fun componentsFrom(filterElementRows: ArrayList<FilterElementRow>) {
components.clear() components.clear()
filterElements filterElementRows
.map { .map {
it.filterSection it.filterSectionRow
} }
.distinct() .distinct()
.forEach { section -> .forEach { section ->
filterElements filterElementRows
.filter { .filter {
it.filterSection == section it.filterSectionRow == section
} }
.apply { .apply {
if (this.size == 1) { if (this.size == 1) {
components.add(FilterComponent(this.first())) components.add(FilterComponent(this.first()))
} else { } else {
val casted = arrayListOf<FilterElement>() val casted = arrayListOf<FilterElementRow>()
casted.addAll(this) casted.addAll(this)
components.add(FilterComponent(casted)) components.add(FilterComponent(casted))
} }
@ -50,21 +50,21 @@ open class Filter : RealmObject() {
} }
} }
fun countBy(filterCategory: FilterCategory) : Int { fun countBy(filterCategoryRow: FilterCategoryRow) : Int {
val sections = FilterSection.filterSectionsFor(filterCategory) val sections = filterCategoryRow.filterSectionRows
return components.count { return components.count {
sections.contains(FilterSection.valueOf(it.sectionName)) sections.contains(FilterSectionRow.valueOf(it.sectionName))
} }
} }
fun contains(filterElement:FilterElement) : Boolean { fun contains(filterElementRow:FilterElementRow) : Boolean {
val filtered = components.filter { val filtered = components.filter {
it.filterName == filterElement.filterName it.filterName == filterElementRow.filterName
} }
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
return false return false
} }
return filterElement.contains(filtered) return filterElementRow.contains(filtered)
} }
fun filter(realm: Realm, relatedEntity: Class<out RealmObject>, queries:List<Filterable>): RealmResults<*> { fun filter(realm: Realm, relatedEntity: Class<out RealmObject>, queries:List<Filterable>): RealmResults<*> {

@ -4,19 +4,19 @@ import io.realm.RealmList
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.Ignore import io.realm.annotations.Ignore
import net.pokeranalytics.android.model.filter.FilterType import net.pokeranalytics.android.model.filter.FilterType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class FilterComponent(var filterName : String = "", var sectionName: String = "") : RealmObject() { open class FilterComponent(var filterName : String = "", var sectionName: String = "") : RealmObject() {
constructor(filterElements: ArrayList<FilterElement>) : this(filterElements.first().filterName, filterElements.first().sectionName) { constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().sectionName) {
this.ids = when (FilterType.valueOf(this.filterName)) { this.ids = when (FilterType.valueOf(this.filterName)) {
FilterType.GAME -> { FilterType.GAME -> {
RealmList<String>().apply { RealmList<String>().apply {
this.addAll(filterElements.map { this.addAll(filterElementRows.map {
(it as FilterElement.Game).game.id (it as FilterElementRow.Game).game.id
}) })
} }
} }
@ -26,8 +26,8 @@ open class FilterComponent(var filterName : String = "", var sectionName: String
this.values = when (FilterType.valueOf(filterName)) { this.values = when (FilterType.valueOf(filterName)) {
FilterType.LIMIT -> { FilterType.LIMIT -> {
RealmList<Int>().apply { RealmList<Int>().apply {
this.addAll(filterElements.map { this.addAll(filterElementRows.map {
(it as FilterElement.Limit).limit.ordinal (it as FilterElementRow.Limit).limit.ordinal
}) })
} }
} }
@ -35,10 +35,10 @@ open class FilterComponent(var filterName : String = "", var sectionName: String
} }
} }
constructor(filterElement:FilterElement) : this(filterElement.filterName, filterElement.sectionName) { constructor(filterElementRow:FilterElementRow) : this(filterElementRow.filterName, filterElementRow.sectionName) {
when (filterElement) { when (filterElementRow) {
is From -> date = filterElement.date is From -> date = filterElementRow.date
is To -> date = filterElement.date is To -> date = filterElementRow.date
} }
} }

@ -8,7 +8,6 @@ import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
import net.pokeranalytics.android.ui.view.rowrepresentable.GameRow import net.pokeranalytics.android.ui.view.rowrepresentable.GameRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT

@ -10,19 +10,16 @@ import io.realm.RealmObject
import kotlinx.android.synthetic.main.fragment_filter_details.* import kotlinx.android.synthetic.main.fragment_filter_details.*
import kotlinx.android.synthetic.main.fragment_filter_details.view.* import kotlinx.android.synthetic.main.fragment_filter_details.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate 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.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.FilterCategory import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
@ -33,13 +30,13 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
lateinit var rowRepresentableAdapter: RowRepresentableAdapter lateinit var rowRepresentableAdapter: RowRepresentableAdapter
private var rows: ArrayList<RowRepresentable> = ArrayList() private var rows: ArrayList<RowRepresentable> = ArrayList()
private var rowsForFilterSubcategory: HashMap<FilterSection, ArrayList<RowRepresentable>> = HashMap() private var rowsForFilterSubcategoryRow: HashMap<FilterSectionRow, ArrayList<RowRepresentable>> = HashMap()
private var filterMenu: Menu? = null private var filterMenu: Menu? = null
private var filterCategory: FilterCategory? = null private var filterCategoryRow: FilterCategoryRow? = null
val selectedRows = ArrayList<FilterElement>() val selectedRows = ArrayList<FilterElementRow>()
var isUpdating = false var isUpdating = false
@ -68,10 +65,10 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
if (selectedRows.contains(row)) { if (selectedRows.contains(row)) {
selectedRows.remove(row) selectedRows.remove(row)
} else { } else {
if (row is FilterElement) { if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude -> row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter { val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSection) filterSectionToExclude.contains(it.filterSectionRow)
} }
excludedFilters .forEach { excludedFilters .forEach {
selectedRows.remove(it) selectedRows.remove(it)
@ -106,7 +103,7 @@ 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)
selectedRows.add(row as FilterElement) selectedRows.add(row as FilterElementRow)
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
@ -145,19 +142,19 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
this.appBar.toolbar.title = getString(R.string.filter) this.appBar.toolbar.title = getString(R.string.filter)
filterCategory?.let { filterCategoryRow?.let {
this.appBar.toolbar.title = it.localizedTitle(requireContext()) this.appBar.toolbar.title = it.localizedTitle(requireContext())
this.rows.clear() this.rows.clear()
this.rowsForFilterSubcategory.clear() this.rowsForFilterSubcategoryRow.clear()
this.rows.addAll(it.filterElements) this.rows.addAll(it.filterElements)
//TODO //TODO
/* /*
var filter = Filter() var filter = Filter()
this.rows.forEach {element -> this.rows.forEach {element ->
if (filter.isFilterElementExists(element as FilterElement)) { if (filter.isFilterElementExists(element as FilterElementRow)) {
this.selectedRows.add(element) this.selectedRows.add(element)
} }
} }
@ -198,7 +195,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
*/ */
fun setData(filterCategory: Int) { fun setData(filterCategory: Int) {
this.filterCategory = FilterCategory.values()[filterCategory] this.filterCategoryRow = FilterCategoryRow.values()[filterCategory]
/* /*
this.dataType = dataType this.dataType = dataType

@ -16,7 +16,7 @@ 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.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import timber.log.Timber import timber.log.Timber
@ -93,7 +93,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
super.onRowSelected(position, row, fromAction) super.onRowSelected(position, row, fromAction)
if (row is FilterCategory) { if (row is FilterCategoryRow) {
selectedRow = row selectedRow = row
FilterDetailsActivity.newInstanceForResult(this, row.ordinal, REQUEST_CODE_FILTER_DETAILS) FilterDetailsActivity.newInstanceForResult(this, row.ordinal, REQUEST_CODE_FILTER_DETAILS)
} }
@ -103,7 +103,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
//TODO //TODO
/* /*
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return this.filter?.numberOfElementIn(row as FilterCategory).toString() return this.filter?.numberOfElementIn(row as FilterCategoryRow).toString()
} }
*/ */
@ -135,7 +135,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
this.appBar.toolbar.title = getString(R.string.filter) this.appBar.toolbar.title = getString(R.string.filter)
rows.addAll(FilterCategory.values()) rows.addAll(FilterCategoryRow.values())
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) this.rowRepresentableAdapter = RowRepresentableAdapter(this, this)
this.recyclerView.adapter = rowRepresentableAdapter this.recyclerView.adapter = rowRepresentableAdapter

@ -1,33 +0,0 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
enum class FilterCategory(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable {
GENERAL(R.string.general),
DATE(R.string.date),
TIME_FRAME(R.string.duration),
SESSION(R.string.session),
CASH(R.string.cash),
TOURNAMENT(R.string.tournament),
ONLINE(R.string.online),
RESULT(R.string.result),
TRANSACTION_TYPES(R.string.operation_types),
LOCATIONS(R.string.locations),
BANKROLLS(R.string.bankrolls),
PLAYERS(R.string.players),
;
val filterElements : List < RowRepresentable >
get() {
return filterSections.flatMap {
it.filterElements
}
}
private val filterSections : List < FilterSection >
get() {
return FilterSection.filterSectionsFor(this)
}
}

@ -0,0 +1,82 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow.*
enum class FilterCategoryRow(override val resId: Int?, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable {
GENERAL(R.string.general),
DATE(R.string.date),
TIME_FRAME(R.string.duration),
SESSION(R.string.session),
CASH(R.string.cash),
TOURNAMENT(R.string.tournament),
ONLINE(R.string.online),
RESULT(R.string.result),
TRANSACTION_TYPES(R.string.operation_types),
LOCATIONS(R.string.locations),
BANKROLLS(R.string.bankrolls),
PLAYERS(R.string.players),
;
val filterElements : List < RowRepresentable >
get() {
return filterSectionRows.flatMap {
it.filterElements
}
}
val filterSectionRows : List < FilterSectionRow >
get() {
return when (this) {
GENERAL -> arrayListOf(
CASH_TOURNAMENT,
LIVE_ONLINE,
GAME, LIMIT_TYPE,
TABLE_SIZE
)
DATE -> arrayListOf(
DYNAMIC_DATE,
FIXED_DATE,
DURATION,
YEAR,
WEEKDAYS_OR_WEEKEND,
DAY_OF_WEEK,
MONTH_OF_YEAR
)
BANKROLLS -> arrayListOf(
BANKROLL
)
CASH -> arrayListOf(
BLINDS,
CASH_RE_BUY_COUNT
)
TOURNAMENT -> arrayListOf(
TOURNAMENT_TYPE,
COMPLETION_PERCENTAGE,
PLACE,
PLAYERS_COUNT,
TOURNAMENT_RE_BUY_COUNT,
BUY_IN
)
ONLINE -> arrayListOf(
MULTI_TABLING
)
LOCATIONS -> arrayListOf(
LOCATION
)
PLAYERS -> arrayListOf(
NUMBER_OF_PLAYERS,
MULTI_PLAYER
)
RESULT -> arrayListOf(
VALUE
)
TIME_FRAME -> arrayListOf()
SESSION -> arrayListOf()
TRANSACTION_TYPES -> arrayListOf()
}
}
}

@ -5,119 +5,46 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.FilterValueMapException import net.pokeranalytics.android.exceptions.FilterValueMapException
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.filter.FilterType import net.pokeranalytics.android.model.filter.FilterType
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.FilterComponent import net.pokeranalytics.android.model.realm.FilterComponent
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.FilterSection.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow.*
import java.lang.Exception import java.lang.Exception
import java.util.* import java.util.*
import kotlin.collections.ArrayList
sealed class FilterElement : RowRepresentable { sealed class FilterElementRow : RowRepresentable {
companion object {
fun filterElementsFor(filterSection: FilterSection) : List<FilterElement> { object Cash : FilterElementRow()
return when (filterSection) { object Tournament : FilterElementRow()
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament) object Live : FilterElementRow()
LIVE_ONLINE -> arrayListOf(Live, Online) object Online : FilterElementRow()
LIMIT_TYPE -> { object Today : FilterElementRow()
val limits = arrayListOf<Limit>() object Yesterday : FilterElementRow()
net.pokeranalytics.android.model.Limit.values().forEach { object TodayAndYesterday : FilterElementRow()
limits.add(FilterElement.Limit(it)) object CurrentWeek : FilterElementRow()
} object CurrentMonth : FilterElementRow()
limits object CurrentYear: FilterElementRow()
} object Weekday: FilterElementRow()
TABLE_SIZE -> { object Weekend : FilterElementRow()
val tableSizes = arrayListOf<TableSize>()
net.pokeranalytics.android.model.TableSize.all.forEach { data class From(var date: Date = Date()) : FilterElementRow()
tableSizes.add(FilterElement.TableSize(it)) data class To(var date: Date = Date()) : FilterElementRow()
} data class Year(val day: Int) : FilterElementRow()
tableSizes data class Month(val day: Int) : FilterElementRow()
} data class Day(val day: Int) : FilterElementRow()
data class PastDays(var lastDays : Int = 0) : FilterElementRow()
DYNAMIC_DATE -> arrayListOf(Today, Yesterday, TodayAndYesterday, CurrentWeek, CurrentMonth, CurrentYear) data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElementRow()
FIXED_DATE -> arrayListOf(From(), To()) data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElementRow()
DURATION -> arrayListOf() data class Bankroll(val bankroll: net.pokeranalytics.android.model.realm.Bankroll) : FilterElementRow()
WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend) data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElementRow()
DAY_OF_WEEK -> arrayListOf() data class Location(val location: net.pokeranalytics.android.model.realm.Location) : FilterElementRow()
MONTH_OF_YEAR -> arrayListOf() data class TournamentName(val tournamentName: net.pokeranalytics.android.model.realm.TournamentName) : FilterElementRow()
YEAR -> arrayListOf() data class TournamentFeature(val tournamentFeature: net.pokeranalytics.android.model.realm.TournamentFeature) : FilterElementRow()
GAME -> { lateinit var filterSectionRow: FilterSectionRow
val games = arrayListOf<Game>()
val realm = Realm.getDefaultInstance()
LiveData.GAME.items(realm).forEach {
val game = FilterElement.Game(it as net.pokeranalytics.android.model.realm.Game)
games.add(game)
}
realm.close()
games
}
LOCATION -> arrayListOf()
BANKROLL -> arrayListOf()
MULTI_TABLING -> arrayListOf()
BLINDS -> arrayListOf()
CASH_RE_BUY_COUNT -> arrayListOf()
BUY_IN -> arrayListOf()
COMPLETION_PERCENTAGE -> arrayListOf()
NUMBER_OF_PLAYERS -> arrayListOf()
TOURNAMENT_TYPE -> arrayListOf()
PLAYERS_COUNT -> arrayListOf()
PLACE -> arrayListOf()
TOURNAMENT_RE_BUY_COUNT -> arrayListOf()
MULTI_PLAYER -> arrayListOf()
RANGE -> arrayListOf()
SESSION_DURATION -> arrayListOf()
VALUE -> arrayListOf()
else -> throw Exception("unknown filtersection") //TODO create exception
}.apply {
this.forEach {
it.filterSection = filterSection
}
}
}
}
object Cash : FilterElement()
object Tournament : FilterElement()
object Live : FilterElement()
object Online : FilterElement()
object Today : FilterElement()
object Yesterday : FilterElement()
object TodayAndYesterday : FilterElement()
object CurrentWeek : FilterElement()
object CurrentMonth : FilterElement()
object CurrentYear: FilterElement()
object Weekday: FilterElement()
object Weekend : FilterElement()
data class From(var date: Date = Date()) : FilterElement()
data class To(var date: Date = Date()) : FilterElement()
data class Year(val day: Int) : FilterElement()
data class Month(val day: Int) : FilterElement()
data class Day(val day: Int) : FilterElement()
data class PastDays(var lastDays : Int = 0) : FilterElement()
data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElement()
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElement()
data class Bankroll(val bankroll: net.pokeranalytics.android.model.realm.Bankroll) : FilterElement()
data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElement()
data class Location(val location: net.pokeranalytics.android.model.realm.Location) : FilterElement()
data class TournamentName(val tournamentName: net.pokeranalytics.android.model.realm.TournamentName) : FilterElement()
data class TournamentFeature(val tournamentFeature: net.pokeranalytics.android.model.realm.TournamentFeature) : FilterElement()
lateinit var filterSection: FilterSection
val filterName : String = this.filterType.name val filterName : String = this.filterType.name
val sectionName : String = this.filterSection.name val sectionName : String = this.filterSectionRow.name
private val filterType : FilterType private val filterType : FilterType
get() { get() {
@ -216,13 +143,13 @@ sealed class FilterElement : RowRepresentable {
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
val sectionToExclude : List < FilterSectionDataSource > ? val sectionToExclude : List < FilterSectionRow > ?
get() { get() {
val excluded = arrayListOf<FilterSectionDataSource>() val excluded = arrayListOf<FilterSectionRow>()
if (!this.filterSection.allowMultiSelection) { if (!this.filterSectionRow.allowMultiSelection) {
excluded.add(this.filterSection) excluded.add(this.filterSectionRow)
} }
this.filterSection.exclusiveWith?.let { exclusives -> this.filterSectionRow.exclusiveWith?.let { exclusives ->
excluded.addAll(exclusives) excluded.addAll(exclusives)
} }

@ -1,35 +1,13 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm
import net.pokeranalytics.android.model.LiveData
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.FilterCategory.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.lang.Exception
interface FilterSectionDataSource : RowRepresentable { enum class FilterSectionRow(override val resId: Int?): RowRepresentable {
enum class SelectionType {
SINGLE,
MULTIPLE,
}
val allowMultiSelection : Boolean
val exclusiveWith : List < FilterSectionDataSource > ?
val selectionType : SelectionType
}
private interface DefaultFilterSectionDataSource : FilterSectionDataSource {
override val viewType: Int
get() = RowViewType.HEADER_TITLE.ordinal
override val exclusiveWith: List<FilterSectionDataSource>?
get() = null
override val allowMultiSelection : Boolean
get() = (this.selectionType == FilterSectionDataSource.SelectionType.MULTIPLE)
override val selectionType: FilterSectionDataSource.SelectionType
get() = FilterSectionDataSource.SelectionType.MULTIPLE
}
enum class FilterSection(override val resId: Int?): DefaultFilterSectionDataSource, RowRepresentable {
CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament), CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament),
LIVE_ONLINE(net.pokeranalytics.android.R.string.live_or_online), LIVE_ONLINE(net.pokeranalytics.android.R.string.live_or_online),
GAME(net.pokeranalytics.android.R.string.games), GAME(net.pokeranalytics.android.R.string.games),
@ -60,77 +38,106 @@ enum class FilterSection(override val resId: Int?): DefaultFilterSectionDataSour
MULTI_PLAYER(net.pokeranalytics.android.R.string.multiplayer), MULTI_PLAYER(net.pokeranalytics.android.R.string.multiplayer),
; ;
private enum class SelectionType {
SINGLE,
MULTIPLE,
}
companion object { override val viewType: Int = RowViewType.HEADER_TITLE.ordinal
fun filterSectionsFor(category: FilterCategory) : List < FilterSection > {
return when (category) { val allowMultiSelection : Boolean
GENERAL -> arrayListOf( get() = (this.selectionType == SelectionType.MULTIPLE)
CASH_TOURNAMENT,
LIVE_ONLINE,
GAME, LIMIT_TYPE,
TABLE_SIZE
)
DATE -> arrayListOf(
DYNAMIC_DATE,
FIXED_DATE,
DURATION,
YEAR,
WEEKDAYS_OR_WEEKEND,
DAY_OF_WEEK,
MONTH_OF_YEAR
)
BANKROLLS -> arrayListOf(
BANKROLL
)
CASH -> arrayListOf(
BLINDS,
CASH_RE_BUY_COUNT
)
TOURNAMENT -> arrayListOf(
TOURNAMENT_TYPE,
COMPLETION_PERCENTAGE,
PLACE,
PLAYERS_COUNT,
TOURNAMENT_RE_BUY_COUNT,
BUY_IN
)
ONLINE -> arrayListOf(
MULTI_TABLING
)
LOCATIONS -> arrayListOf(
LOCATION
)
PLAYERS -> arrayListOf(
NUMBER_OF_PLAYERS,
MULTI_PLAYER
)
RESULT -> arrayListOf(
VALUE
)
TIME_FRAME -> arrayListOf() val filterElements : List < RowRepresentable > by lazy {
SESSION -> arrayListOf() arrayListOf<RowRepresentable>(this).apply {
TRANSACTION_TYPES -> arrayListOf() this.addAll(
when (this@FilterSectionRow) {
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
LIVE_ONLINE -> arrayListOf(Live, Online)
LIMIT_TYPE -> {
val limits = arrayListOf<FilterElementRow.Limit>()
net.pokeranalytics.android.model.Limit.values().forEach {
limits.add(Limit(it))
} }
limits
} }
TABLE_SIZE -> {
val tableSizes = arrayListOf<FilterElementRow.TableSize>()
net.pokeranalytics.android.model.TableSize.all.forEach {
tableSizes.add(TableSize(it))
}
tableSizes
} }
val filterElements : List < RowRepresentable > DYNAMIC_DATE -> arrayListOf(
get() = arrayListOf<RowRepresentable>(this).apply { Today,
this.addAll(FilterElement.filterElementsFor(this@FilterSection)) Yesterday,
TodayAndYesterday,
CurrentWeek,
CurrentMonth,
CurrentYear
)
FIXED_DATE -> arrayListOf(From(), To())
DURATION -> arrayListOf()
WEEKDAYS_OR_WEEKEND -> arrayListOf(Weekday, Weekend)
DAY_OF_WEEK -> arrayListOf()
MONTH_OF_YEAR -> arrayListOf()
YEAR -> arrayListOf()
GAME -> {
val games = arrayListOf<FilterElementRow.Game>()
val realm = Realm.getDefaultInstance()
LiveData.GAME.items(realm).forEach {
val game = Game(it as net.pokeranalytics.android.model.realm.Game)
games.add(game)
}
realm.close()
games
} }
override val viewType: Int = RowViewType.HEADER_TITLE.ordinal LOCATION -> arrayListOf()
BANKROLL -> arrayListOf()
MULTI_TABLING -> arrayListOf()
BLINDS -> arrayListOf()
CASH_RE_BUY_COUNT -> arrayListOf()
BUY_IN -> arrayListOf()
COMPLETION_PERCENTAGE -> arrayListOf()
NUMBER_OF_PLAYERS -> arrayListOf()
TOURNAMENT_TYPE -> arrayListOf()
PLAYERS_COUNT -> arrayListOf()
PLACE -> arrayListOf()
TOURNAMENT_RE_BUY_COUNT -> arrayListOf()
MULTI_PLAYER -> arrayListOf()
RANGE -> arrayListOf()
SESSION_DURATION -> arrayListOf()
VALUE -> arrayListOf()
else -> throw Exception("unknown filtersection") //TODO create exception
}.apply {
this.forEach {
it.filterSectionRow = this@FilterSectionRow
}
}
)
}
}
override val selectionType: FilterSectionDataSource.SelectionType private val selectionType: SelectionType
get() { get() {
return when (this) { return when (this) {
CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> FilterSectionDataSource.SelectionType.SINGLE CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> SelectionType.SINGLE
else -> FilterSectionDataSource.SelectionType.MULTIPLE else -> SelectionType.MULTIPLE
} }
} }
override val exclusiveWith: List<FilterSection>? val exclusiveWith: List<FilterSectionRow>?
get() { get() {
return when (this) { return when (this) {
DYNAMIC_DATE -> arrayListOf(FIXED_DATE) DYNAMIC_DATE -> arrayListOf(FIXED_DATE)
Loading…
Cancel
Save