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.realm.Filter
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
@ -23,11 +23,11 @@ class RealmFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() {
val filter = Filter()
filter.name = "testSaveLoadCashFilter"
val filterElement = FilterElement.Cash
filterElement.filterSection = FilterSection.CASH_TOURNAMENT
val filterElement = FilterElementRow.Cash
filterElement.filterSectionRow = FilterSectionRow.CASH_TOURNAMENT
filter.componentsFrom(arrayListOf(filterElement))
val useCount = filter.countBy(FilterCategory.GENERAL)
val useCount = filter.countBy(FilterCategoryRow.GENERAL)
Assert.assertEquals(1, useCount)
val isCash = filter.contains(filterElement)

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

@ -3,9 +3,9 @@ package net.pokeranalytics.android.model.realm
import io.realm.*
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.model.filter.interfaces.Filterable
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import java.util.*
//import net.pokeranalytics.android.FilterComponent
@ -26,23 +26,23 @@ open class Filter : RealmObject() {
var components: RealmList<FilterComponent> = RealmList()
private set
fun componentsFrom(filterElements: ArrayList<FilterElement>) {
fun componentsFrom(filterElementRows: ArrayList<FilterElementRow>) {
components.clear()
filterElements
filterElementRows
.map {
it.filterSection
it.filterSectionRow
}
.distinct()
.forEach { section ->
filterElements
filterElementRows
.filter {
it.filterSection == section
it.filterSectionRow == section
}
.apply {
if (this.size == 1) {
components.add(FilterComponent(this.first()))
} else {
val casted = arrayListOf<FilterElement>()
val casted = arrayListOf<FilterElementRow>()
casted.addAll(this)
components.add(FilterComponent(casted))
}
@ -50,21 +50,21 @@ open class Filter : RealmObject() {
}
}
fun countBy(filterCategory: FilterCategory) : Int {
val sections = FilterSection.filterSectionsFor(filterCategory)
fun countBy(filterCategoryRow: FilterCategoryRow) : Int {
val sections = filterCategoryRow.filterSectionRows
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 {
it.filterName == filterElement.filterName
it.filterName == filterElementRow.filterName
}
if (filtered.isEmpty()) {
return false
}
return filterElement.contains(filtered)
return filterElementRow.contains(filtered)
}
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.annotations.Ignore
import net.pokeranalytics.android.model.filter.FilterType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement.*
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.util.*
import kotlin.collections.ArrayList
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)) {
FilterType.GAME -> {
RealmList<String>().apply {
this.addAll(filterElements.map {
(it as FilterElement.Game).game.id
this.addAll(filterElementRows.map {
(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)) {
FilterType.LIMIT -> {
RealmList<Int>().apply {
this.addAll(filterElements.map {
(it as FilterElement.Limit).limit.ordinal
this.addAll(filterElementRows.map {
(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) {
when (filterElement) {
is From -> date = filterElement.date
is To -> date = filterElement.date
constructor(filterElementRow:FilterElementRow) : this(filterElementRow.filterName, filterElementRow.sectionName) {
when (filterElementRow) {
is From -> date = filterElementRow.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.view.RowRepresentable
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.SimpleRow
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.view.*
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.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
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.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import timber.log.Timber
import java.util.*
@ -33,13 +30,13 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
lateinit var rowRepresentableAdapter: RowRepresentableAdapter
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 filterCategory: FilterCategory? = null
private var filterCategoryRow: FilterCategoryRow? = null
val selectedRows = ArrayList<FilterElement>()
val selectedRows = ArrayList<FilterElementRow>()
var isUpdating = false
@ -68,10 +65,10 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
if (row is FilterElement) {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSection)
filterSectionToExclude.contains(it.filterSectionRow)
}
excludedFilters .forEach {
selectedRows.remove(it)
@ -106,7 +103,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
super.onRowValueChanged(value, row)
selectedRows.add(row as FilterElement)
selectedRows.add(row as FilterElementRow)
rowRepresentableAdapter.refreshRow(row)
}
@ -145,19 +142,19 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
this.appBar.toolbar.title = getString(R.string.filter)
filterCategory?.let {
filterCategoryRow?.let {
this.appBar.toolbar.title = it.localizedTitle(requireContext())
this.rows.clear()
this.rowsForFilterSubcategory.clear()
this.rowsForFilterSubcategoryRow.clear()
this.rows.addAll(it.filterElements)
//TODO
/*
var filter = Filter()
this.rows.forEach {element ->
if (filter.isFilterElementExists(element as FilterElement)) {
if (filter.isFilterElementExists(element as FilterElementRow)) {
this.selectedRows.add(element)
}
}
@ -198,7 +195,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
*/
fun setData(filterCategory: Int) {
this.filterCategory = FilterCategory.values()[filterCategory]
this.filterCategoryRow = FilterCategoryRow.values()[filterCategory]
/*
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.fragment.components.PokerAnalyticsFragment
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
@ -93,7 +93,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
super.onRowSelected(position, row, fromAction)
if (row is FilterCategory) {
if (row is FilterCategoryRow) {
selectedRow = row
FilterDetailsActivity.newInstanceForResult(this, row.ordinal, REQUEST_CODE_FILTER_DETAILS)
}
@ -103,7 +103,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
//TODO
/*
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)
rows.addAll(FilterCategory.values())
rows.addAll(FilterCategoryRow.values())
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this)
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.model.LiveData
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.ui.view.RowRepresentable
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.util.*
import kotlin.collections.ArrayList
sealed class FilterElement : RowRepresentable {
companion object {
fun filterElementsFor(filterSection: FilterSection) : List<FilterElement> {
return when (filterSection) {
CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
LIVE_ONLINE -> arrayListOf(Live, Online)
LIMIT_TYPE -> {
val limits = arrayListOf<Limit>()
net.pokeranalytics.android.model.Limit.values().forEach {
limits.add(FilterElement.Limit(it))
}
limits
}
TABLE_SIZE -> {
val tableSizes = arrayListOf<TableSize>()
net.pokeranalytics.android.model.TableSize.all.forEach {
tableSizes.add(FilterElement.TableSize(it))
}
tableSizes
}
DYNAMIC_DATE -> arrayListOf(Today, 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<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
sealed class FilterElementRow : RowRepresentable {
object Cash : FilterElementRow()
object Tournament : FilterElementRow()
object Live : FilterElementRow()
object Online : FilterElementRow()
object Today : FilterElementRow()
object Yesterday : FilterElementRow()
object TodayAndYesterday : FilterElementRow()
object CurrentWeek : FilterElementRow()
object CurrentMonth : FilterElementRow()
object CurrentYear: FilterElementRow()
object Weekday: FilterElementRow()
object Weekend : FilterElementRow()
data class From(var date: Date = Date()) : FilterElementRow()
data class To(var date: Date = Date()) : FilterElementRow()
data class Year(val day: Int) : FilterElementRow()
data class Month(val day: Int) : FilterElementRow()
data class Day(val day: Int) : FilterElementRow()
data class PastDays(var lastDays : Int = 0) : FilterElementRow()
data class Limit(val limit : net.pokeranalytics.android.model.Limit) : FilterElementRow()
data class TableSize(val tableSize : net.pokeranalytics.android.model.TableSize) : FilterElementRow()
data class Bankroll(val bankroll: net.pokeranalytics.android.model.realm.Bankroll) : FilterElementRow()
data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElementRow()
data class Location(val location: net.pokeranalytics.android.model.realm.Location) : FilterElementRow()
data class TournamentName(val tournamentName: net.pokeranalytics.android.model.realm.TournamentName) : FilterElementRow()
data class TournamentFeature(val tournamentFeature: net.pokeranalytics.android.model.realm.TournamentFeature) : FilterElementRow()
lateinit var filterSectionRow: FilterSectionRow
val filterName : String = this.filterType.name
val sectionName : String = this.filterSection.name
val sectionName : String = this.filterSectionRow.name
private val filterType : FilterType
get() {
@ -216,13 +143,13 @@ sealed class FilterElement : RowRepresentable {
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
val sectionToExclude : List < FilterSectionDataSource > ?
val sectionToExclude : List < FilterSectionRow > ?
get() {
val excluded = arrayListOf<FilterSectionDataSource>()
if (!this.filterSection.allowMultiSelection) {
excluded.add(this.filterSection)
val excluded = arrayListOf<FilterSectionRow>()
if (!this.filterSectionRow.allowMultiSelection) {
excluded.add(this.filterSectionRow)
}
this.filterSection.exclusiveWith?.let { exclusives ->
this.filterSectionRow.exclusiveWith?.let { exclusives ->
excluded.addAll(exclusives)
}

@ -1,35 +1,13 @@
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.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 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 {
enum class FilterSectionRow(override val resId: Int?): RowRepresentable {
CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament),
LIVE_ONLINE(net.pokeranalytics.android.R.string.live_or_online),
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),
;
private enum class SelectionType {
SINGLE,
MULTIPLE,
}
companion object {
fun filterSectionsFor(category: FilterCategory) : List < FilterSection > {
return when (category) {
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
)
override val viewType: Int = RowViewType.HEADER_TITLE.ordinal
val allowMultiSelection : Boolean
get() = (this.selectionType == SelectionType.MULTIPLE)
TIME_FRAME -> arrayListOf()
SESSION -> arrayListOf()
TRANSACTION_TYPES -> arrayListOf()
val filterElements : List < RowRepresentable > by lazy {
arrayListOf<RowRepresentable>(this).apply {
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 >
get() = arrayListOf<RowRepresentable>(this).apply {
this.addAll(FilterElement.filterElementsFor(this@FilterSection))
DYNAMIC_DATE -> arrayListOf(
Today,
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() {
return when (this) {
CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> FilterSectionDataSource.SelectionType.SINGLE
else -> FilterSectionDataSource.SelectionType.MULTIPLE
CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> SelectionType.SINGLE
else -> SelectionType.MULTIPLE
}
}
override val exclusiveWith: List<FilterSection>?
val exclusiveWith: List<FilterSectionRow>?
get() {
return when (this) {
DYNAMIC_DATE -> arrayListOf(FIXED_DATE)
Loading…
Cancel
Save