Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Aurelien Hubert 7 years ago
commit eeb5143f46
  1. 11
      app/src/main/java/net/pokeranalytics/android/model/Limit.kt
  2. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  3. 84
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FiltersFragment.kt
  5. 30
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  6. 81
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategory.kt
  7. 117
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  8. 140
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterRow.kt
  9. 150
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSection.kt

@ -1,7 +1,7 @@
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.FilterSubcategoryRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
enum class Limit : RowRepresentable { enum class Limit : RowRepresentable {
NO, NO,
@ -36,13 +36,4 @@ enum class Limit : RowRepresentable {
override fun getDisplayName(): String { override fun getDisplayName(): String {
return this.longName return this.longName
} }
/**
* Filters management
*/
override fun subcategoryRow(): FilterSubcategoryRow? {
return FilterSubcategoryRow.LIMIT_TYPE
}
} }

@ -8,7 +8,7 @@ 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.FilterSubcategoryRow 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
@ -76,13 +76,4 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
override fun getFailedSaveMessage(): Int { override fun getFailedSaveMessage(): Int {
return R.string.variant_empty_name_error return R.string.variant_empty_name_error
} }
/**
* Filters management
*/
override fun subcategoryRow(): FilterSubcategoryRow? {
return FilterSubcategoryRow.GAME
}
} }

@ -12,34 +12,33 @@ import kotlinx.android.synthetic.main.fragment_filter_details.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
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.RowRepresentableDataSource
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.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.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.FilterCategory
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSubcategoryRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, RowRepresentableDelegate {
lateinit var parentActivity: PokerAnalyticsActivity lateinit var parentActivity: PokerAnalyticsActivity
lateinit var item: RealmObject lateinit var item: RealmObject
lateinit var rowRepresentableAdapter: RowRepresentableAdapter lateinit var rowRepresentableAdapter: RowRepresentableAdapter
private var rows: ArrayList<RowRepresentable> = ArrayList() private var rows: ArrayList<RowRepresentable> = ArrayList()
private var rowsForFilterSubcategory: HashMap<FilterSubcategoryRow, ArrayList<RowRepresentable>> = HashMap() private var rowsForFilterSubcategory: HashMap<FilterSection, ArrayList<RowRepresentable>> = HashMap()
private var filterMenu: Menu? = null private var filterMenu: Menu? = null
private var filterCategory: FilterCategoryRow? = null private var filterCategory: FilterCategory? = null
val selectedRows = ArrayList<RowRepresentable>() val selectedRows = ArrayList<FilterElement>()
var isUpdating = false var isUpdating = false
@ -65,43 +64,23 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
val oldRows = ArrayList<RowRepresentable>() val oldRows = ArrayList<RowRepresentable>()
oldRows.addAll(rows) oldRows.addAll(rows)
if (selectedRows.contains(row)) { if (selectedRows.contains(row)) {
selectedRows.remove(row) selectedRows.remove(row)
} else { } else {
if (row is FilterElement) {
val excludedRows = ArrayList<RowRepresentable>() row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
// Exclude the rows of the same subcategory if we are an a single row selection filterSectionToExclude.contains(it.filterSection)
if (row.subcategoryRow()?.getType() == FilterSubcategoryRow.Type.SINGLE) {
row.subcategoryRow()?.let { filterSubcategory ->
rowsForFilterSubcategory[filterSubcategory]?.let { filterRows ->
excludedRows.addAll(filterRows)
}
}
}
// Exclude the filter rows of the subcategories
row.excludedFilterSubcategoryRows()?.let { subcategories ->
for (subcategory in subcategories) {
rowsForFilterSubcategory[subcategory]?.let { rows ->
excludedRows.addAll(rows)
}
} }
excludedFilters .forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
} }
// Exclude the filter rows
row.excludedFilterRows()?.let {
excludedRows.addAll(it)
} }
selectedRows.add(row)
for (filterRow in excludedRows) {
if (selectedRows.contains(filterRow)) {
selectedRows.remove(filterRow)
rowRepresentableAdapter.refreshRow(filterRow)
} }
} }
/*
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
FilterRow.FROM -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true) FilterRow.FROM -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true)
@ -116,8 +95,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
} }
} }
*/
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
override fun isSelected(row: RowRepresentable): Boolean { override fun isSelected(row: RowRepresentable): Boolean {
@ -126,7 +105,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
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) selectedRows.add(row as FilterElement)
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }
@ -134,24 +113,11 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
return rows return rows
} }
override fun rowRepresentableForPosition(position: Int): RowRepresentable? {
return rows[position]
}
override fun numberOfRows(): Int {
return rows.size
}
override fun viewTypeForPosition(position: Int): Int { override fun viewTypeForPosition(position: Int): Int {
val rowViewType = rowRepresentableForPosition(position)?.viewType ?: -1 val rowViewType = rowRepresentableForPosition(position)?.viewType ?: -1
return if (rowViewType != -1) rowViewType else RowViewType.TITLE_CHECK.ordinal return if (rowViewType != -1) rowViewType else RowViewType.TITLE_CHECK.ordinal
} }
override fun indexForRow(row: RowRepresentable): Int {
return rows.indexOf(row)
}
/** /**
* Init UI * Init UI
*/ */
@ -184,15 +150,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
this.rows.clear() this.rows.clear()
this.rowsForFilterSubcategory.clear() this.rowsForFilterSubcategory.clear()
this.rows.addAll(it.filterElements)
for (subcategory in it.getSubcategories()) {
this.rows.add(subcategory)
val subcategoryRows = subcategory.getFilterRows(getRealm())
this.rowsForFilterSubcategory.put(subcategory, subcategoryRows)
this.rows.addAll(subcategoryRows)
}
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) this.rowRepresentableAdapter = RowRepresentableAdapter(this, this)
this.recyclerView.adapter = rowRepresentableAdapter this.recyclerView.adapter = rowRepresentableAdapter
} }
@ -229,7 +187,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
*/ */
fun setData(filterCategory: Int) { fun setData(filterCategory: Int) {
this.filterCategory = FilterCategoryRow.values()[filterCategory] this.filterCategory = FilterCategory.values()[filterCategory]
/* /*
this.dataType = dataType this.dataType = dataType

@ -15,7 +15,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.FilterCategoryRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory
import timber.log.Timber import timber.log.Timber
@ -90,8 +90,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 FilterCategoryRow) { if (row is FilterCategory) {
Timber.d("Subcategories: ${row.getSubcategories()}")
selectedRow = row selectedRow = row
FilterDetailsActivity.newInstanceForResult(this, row.ordinal, REQUEST_CODE_FILTER_DETAILS) FilterDetailsActivity.newInstanceForResult(this, row.ordinal, REQUEST_CODE_FILTER_DETAILS)
} }
@ -126,7 +125,7 @@ open class FiltersFragment : PokerAnalyticsFragment(), StaticRowRepresentableDat
this.appBar.toolbar.title = getString(R.string.filter) this.appBar.toolbar.title = getString(R.string.filter)
rows.addAll(FilterCategoryRow.values()) rows.addAll(FilterCategory.values())
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) this.rowRepresentableAdapter = RowRepresentableAdapter(this, this)
this.recyclerView.adapter = rowRepresentableAdapter this.recyclerView.adapter = rowRepresentableAdapter

@ -3,46 +3,18 @@ package net.pokeranalytics.android.ui.view
import android.content.Context import android.content.Context
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSubcategoryRow
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
/** /**
* An interface extending Displayable to add a way to represent an object as a String * An interface extending Displayable to add a way to represent an object as a String
*/ */
interface RowRepresentable : Displayable, Editable, Filterable { interface RowRepresentable : Displayable, Editable {
fun getDisplayName(): String { fun getDisplayName(): String {
return NULL_TEXT return NULL_TEXT
} }
} }
/**
* An interface used to manage the filters
*/
interface Filterable {
/**
* The subcategory of a filter
*/
fun subcategoryRow(): FilterSubcategoryRow? {
return null
}
/**
* Return the filter rows to deactivate
*/
fun excludedFilterRows(): ArrayList<FilterRow>? {
return null
}
/**
* Return the Filter Subcategory rows to deactivate
*/
fun excludedFilterSubcategoryRows(): ArrayList<FilterSubcategoryRow>? {
return null
}
}
interface Editable { interface Editable {
fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return null return null

@ -0,0 +1,81 @@
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),
/*
DURATION(R.string.duration, DurationSubCategory.values()),
SESSION(R.string.session, SessionSubCategory.values()),
CASH(R.string.cash, CashSubCategory.values()),
TOURNAMENT(R.string.tournament, TournamentSubCategory.values()),
ONLINE(R.string.online, OnlineSubCategory.values()),
RESULT(R.string.result, ResultSubCategory.values()),
TRANSACTION_TYPES(R.string.operation_types, TransactionSubCategory.values()),
LOCATION(R.string.locations, LocationSubCategory.values()),
BANKROLL(R.string.bankrolls, BankrollSubCategory.values()),
PLAYERS(R.string.players, PlayerSubCategory.values());
*/
;
val filterElements : List < RowRepresentable >
get() {
return filterSections.flatMap {
it.filterElements
}
}
private val filterSections : List < FilterSectionDataSource >
get() {
return FilterSection.filterSectionsFor(this)
}
/*
private enum class DurationSubCategory(val category : FilterCategory = DURATION): RowRepresentable {
SESSION_DURATION,
RANGE,
}
private enum class CashSubCategory(val category : FilterCategory = CASH): RowRepresentable {
BLINDS,
CASH_RE_BUY_COUNT,
}
private enum class TournamentSubCategory(val category : FilterCategory = TOURNAMENT): RowRepresentable {
TOURNAMENT_TYPE,
COMPLETION_PERCENTAGE,
PLACE,
PLAYERS_COUNT,
TOURNAMENT_RE_BUY_COUNT,
BUY_IN,
}
private enum class OnlineSubCategory(val category : FilterCategory = ONLINE): RowRepresentable {
MULTI_TABLING,
}
private enum class SessionSubCategory(val category : FilterCategory = SESSION): RowRepresentable
private enum class TransactionSubCategory(val category : FilterCategory = TRANSACTION_TYPES): RowRepresentable
private enum class ResultSubCategory(val category : FilterCategory = RESULT): RowRepresentable {
VALUE,
}
private enum class LocationSubCategory(val category : FilterCategory = FilterCategory.LOCATION): RowRepresentable {
LOCATION,
}
private enum class BankrollSubCategory(val category : FilterCategory = FilterCategory.BANKROLL): RowRepresentable {
BANKROLL,
}
private enum class PlayerSubCategory(val category : FilterCategory = PLAYERS): RowRepresentable {
NUMBER_OF_PLAYERS,
MULTI_PLAYER;
}
*/
}

@ -1,117 +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 FilterCategoryRow(override val resId: Int?, val subCategories:Array<out RowRepresentable>, override val viewType: Int = RowViewType.TITLE_VALUE_ARROW.ordinal) : RowRepresentable {
GENERAL(R.string.general, GeneralSubCategory.values()),
DATE,
DURATION,
SESSION,
CASH,
TOURNAMENT,
ONLINE,
RESULT,
TRANSACTION_TYPES,
// Title Custom fields
LOCATION,
BANKROLL,
PLAYERS;
private enum class GeneralSubCategory(val category : FilterCategoryRow = GENERAL): RowRepresentable {
CASH_TOURNAMENT,
LIVE_ONLINE,
GAME,
LIMIT_TYPE,
TABLE_SIZE,
}
*/
enum class FilterCategoryRow : RowRepresentable {
GENERAL,
DATE,
DURATION,
SESSION,
CASH,
TOURNAMENT,
ONLINE,
RESULT,
TRANSACTION_TYPES,
// Title Custom fields
LOCATION,
BANKROLL,
PLAYERS;
override val resId: Int?
get() {
return when (this) {
GENERAL -> R.string.general
DATE -> R.string.date
DURATION -> 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
LOCATION -> R.string.location
BANKROLL -> R.string.bankroll
PLAYERS -> R.string.players
}
}
override val viewType: Int
get() {
return when (this) {
GENERAL, DATE, DURATION, SESSION, CASH, TOURNAMENT, ONLINE, RESULT, TRANSACTION_TYPES,
LOCATION, BANKROLL, PLAYERS -> RowViewType.TITLE_VALUE_ARROW.ordinal
}
}
/**
* Get subcategories of filters
*/
fun getSubcategories(): ArrayList<FilterSubcategoryRow> {
val subcategories = ArrayList<FilterSubcategoryRow>()
when (this) {
GENERAL -> subcategories.addAll(
arrayListOf(
FilterSubcategoryRow.CASH_TOURNAMENT, FilterSubcategoryRow.LIVE_ONLINE, FilterSubcategoryRow.GAME,
FilterSubcategoryRow.LIMIT_TYPE, FilterSubcategoryRow.TABLE_SIZE
)
)
DATE -> subcategories.addAll(
arrayListOf(
FilterSubcategoryRow.DYNAMIC_DATE, FilterSubcategoryRow.FIXED_DATE, FilterSubcategoryRow.DURATION, FilterSubcategoryRow.YEAR,
FilterSubcategoryRow.WEEKDAYS_OR_WEEKEND, FilterSubcategoryRow.DAY_OF_WEEK, FilterSubcategoryRow.MONTH_OF_YEAR
)
)
DURATION -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.SESSION_DURATION, FilterSubcategoryRow.RANGE))
SESSION -> subcategories.addAll(arrayListOf())
CASH -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.BLINDS, FilterSubcategoryRow.CASH_RE_BUY_COUNT))
TOURNAMENT -> subcategories.addAll(
arrayListOf(
FilterSubcategoryRow.TOURNAMENT_TYPE, FilterSubcategoryRow.COMPLETION_PERCENTAGE, FilterSubcategoryRow.PLACE,
FilterSubcategoryRow.PLAYERS_COUNT, FilterSubcategoryRow.TOURNAMENT_RE_BUY_COUNT, FilterSubcategoryRow.BUY_IN
)
)
ONLINE -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.MULTI_TABLING))
RESULT -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.VALUE))
TRANSACTION_TYPES -> subcategories.addAll(arrayListOf())
LOCATION -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.LOCATION))
BANKROLL -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.BANKROLL))
PLAYERS -> subcategories.addAll(arrayListOf(FilterSubcategoryRow.NUMBER_OF_PLAYERS, FilterSubcategoryRow.MULTI_PLAYER))
}
return subcategories
}
}

@ -1,120 +1,102 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm
import android.text.InputType import android.text.InputType
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
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.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import java.lang.Exception
/* import java.util.*
sealed class FilterElement : RowRepresentable { sealed class FilterElement : RowRepresentable {
class Cash : FilterElement()
class Tournament : FilterElement()
data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElement()
var value : Any? = null companion object {
fun filterElementsFor(filterSection: FilterSectionDataSource) : List<FilterElement> {
override val resId: Int? return when (filterSection) {
get() { FilterSection.CASH_TOURNAMENT -> arrayListOf(Cash, Tournament)
return when (this) { FilterSection.DYNAMIC_DATE -> arrayListOf(Today, Yesterday, TodayAndYesterday, CurrentWeek, CurrentMonth, CurrentYear)
is Cash -> R.string.cash_game FilterSection.FIXED_DATE -> arrayListOf(From(), To())
is Tournament -> R.string.tournament FilterSection.GAMES -> {
else -> null val games = arrayListOf<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 else -> throw Exception() //TODO create exception
get() {
return when (this) {
else -> RowViewType.TITLE_CHECK.ordinal
} }
} }
} }
*/
enum class FilterRow : RowRepresentable {
// General object Cash : FilterElement()
CASH_GAME, object Tournament : FilterElement()
TOURNAMENT, object Today : FilterElement()
LIVE, object Yesterday : FilterElement()
ONLINE, object TodayAndYesterday : FilterElement()
object CurrentWeek : FilterElement()
object CurrentMonth : FilterElement()
object CurrentYear: FilterElement()
data class From(var date: Date = Date()) : FilterElement()
data class To(var date: Date = Date()) : FilterElement()
// Date data class Game(val game: net.pokeranalytics.android.model.realm.Game) : FilterElement()
TODAY,
YESTERDAY,
TODAY_AND_YESTERDAY,
CURRENT_WEEK,
CURRENT_MONTH,
CURRENT_YEAR,
FROM,
TO,
PAST_DAYS,
WEEKDAYS,
WEEKEND,
; var filterSection: FilterSectionDataSource? = null
override val resId: Int? override val resId: Int?
get() { get() {
return when (this) { return when (this) {
CASH_GAME -> R.string.cash_game is Cash -> R.string.cash_game
TOURNAMENT -> R.string.tournament is Tournament -> R.string.tournament
LIVE -> R.string.live is Today -> R.string.today
ONLINE -> R.string.online is Yesterday -> R.string.yesterday
TODAY -> R.string.today is TodayAndYesterday -> R.string.yesterday_and_today
YESTERDAY -> R.string.yesterday is CurrentWeek -> R.string.current_week
TODAY_AND_YESTERDAY -> R.string.yesterday_and_today is CurrentMonth -> R.string.current_month
CURRENT_WEEK -> R.string.current_week is CurrentYear -> R.string.current_year
CURRENT_MONTH -> R.string.current_month is From -> R.string.from
CURRENT_YEAR -> R.string.current_year is To -> R.string.to
FROM -> R.string.from
TO -> R.string.to
PAST_DAYS -> R.string.period_in_days
WEEKDAYS -> R.string.week_days
WEEKEND -> R.string.weekend
else -> null else -> null
} }
} }
override val viewType: Int override fun getDisplayName(): String {
get() {
return when (this) { return when (this) {
FROM, TO -> RowViewType.TITLE_VALUE_CHECK.ordinal is Game -> game.getDisplayName()
else -> RowViewType.TITLE_CHECK.ordinal else -> return super.getDisplayName()
} }
} }
override fun excludedFilterRows(): ArrayList<FilterRow>? { override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
return when (this) {
CASH_GAME, TOURNAMENT -> arrayListOf(CASH_GAME, TOURNAMENT) val sectionToExclude : List < FilterSectionDataSource > ?
LIVE, ONLINE -> arrayListOf(LIVE, ONLINE) get() {
else -> ArrayList() val excluded = arrayListOf<FilterSectionDataSource>()
this.filterSection?.let {
if (!it.allowMultiSelection) {
excluded.add(it)
} }
it.exclusiveWith?.let { exclusives ->
excluded.addAll(exclusives)
} }
override fun excludedFilterSubcategoryRows(): ArrayList<FilterSubcategoryRow>? { if (excluded.size > 0) {
return when (this) { return excluded
TODAY, YESTERDAY, TODAY_AND_YESTERDAY, CURRENT_WEEK, CURRENT_MONTH, CURRENT_YEAR -> arrayListOf(FilterSubcategoryRow.FIXED_DATE)
FROM, TO -> arrayListOf(FilterSubcategoryRow.DYNAMIC_DATE)
else -> null
} }
} ?: run {
return null
} }
override fun subcategoryRow(): FilterSubcategoryRow? { return null
return when (this) {
CASH_GAME, TOURNAMENT -> FilterSubcategoryRow.TOURNAMENT_TYPE
LIVE, ONLINE -> FilterSubcategoryRow.LIVE_ONLINE
TODAY, YESTERDAY, TODAY_AND_YESTERDAY, CURRENT_WEEK, CURRENT_MONTH, CURRENT_YEAR -> FilterSubcategoryRow.DYNAMIC_DATE
FROM, TO -> FilterSubcategoryRow.FIXED_DATE
PAST_DAYS -> FilterSubcategoryRow.DURATION
WEEKDAYS, WEEKEND -> FilterSubcategoryRow.WEEKDAYS_OR_WEEKEND
else -> null
}
} }
/*
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? { override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
when (this) { when (this) {
PAST_DAYS -> { PAST_DAYS -> {
@ -131,5 +113,5 @@ enum class FilterRow : RowRepresentable {
return super.editingDescriptors(map) return super.editingDescriptors(map)
} }
*/
} }

@ -1,19 +1,139 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm
import io.realm.RealmResults
import io.realm.Sort
import io.realm.kotlin.where
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.TableSize
import net.pokeranalytics.android.model.realm.Game
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 java.text.DateFormatSymbols
import java.util.* interface FilterSectionDataSource : RowRepresentable {
import kotlin.collections.ArrayList enum class SelectionType {
SINGLE,
MULTIPLE,
}
val allowMultiSelection : Boolean
val exclusiveWith : List < FilterSectionDataSource > ?
val filterElementRows : List < FilterElement >
val filterElements : List < RowRepresentable >
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
override val filterElementRows: List < FilterElement >
get() = FilterElement.filterElementsFor(this)
override val filterElements : List < RowRepresentable >
get() {
val elements = arrayListOf<RowRepresentable>(this)
filterElementRows.forEach {
it.filterSection = this
elements.add(it)
}
return elements
}
}
enum class FilterSection(override val resId: Int?): DefaultFilterSectionDataSource, RowRepresentable {
CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament),
GAMES(net.pokeranalytics.android.R.string.games),
/*
LIVE_ONLINE,
GAME,
LIMIT_TYPE,
TABLE_SIZE,
*/
DYNAMIC_DATE(net.pokeranalytics.android.R.string.dynamic_date),
FIXED_DATE(net.pokeranalytics.android.R.string.fixed_date),
/*
DURATION,
YEAR,
WEEKDAYS_OR_WEEKEND,
DAY_OF_WEEK,
MONTH_OF_YEAR,
// Duration
SESSION_DURATION,
RANGE,
// Sessions
// -
// Cash
BLINDS,
CASH_RE_BUY_COUNT,
// Tournament
TOURNAMENT_TYPE,
COMPLETION_PERCENTAGE,
PLACE,
PLAYERS_COUNT,
TOURNAMENT_RE_BUY_COUNT,
BUY_IN,
// Online
MULTI_TABLING,
// Result
VALUE,
// Transaction types
// -
// Location
LOCATION,
// Bankroll
BANKROLL,
// Players
NUMBER_OF_PLAYERS,
MULTI_PLAYER;
*/
;
companion object {
fun filterSectionsFor(category: FilterCategory) : List < FilterSection > {
return when (category) {
FilterCategory.GENERAL -> arrayListOf(CASH_TOURNAMENT, GAMES)
FilterCategory.DATE -> arrayListOf(DYNAMIC_DATE, FIXED_DATE)
}
}
}
override val viewType: Int = RowViewType.HEADER_TITLE.ordinal
override val selectionType: FilterSectionDataSource.SelectionType
get() {
return when (this) {
CASH_TOURNAMENT, DYNAMIC_DATE -> FilterSectionDataSource.SelectionType.SINGLE
else -> FilterSectionDataSource.SelectionType.MULTIPLE
}
}
override val exclusiveWith: List<FilterSection>?
get() {
return when (this) {
DYNAMIC_DATE -> arrayListOf(FIXED_DATE)
FIXED_DATE -> arrayListOf(DYNAMIC_DATE)
else -> null
}
}
}
/* /*
GAME -> { GAME -> {
@ -23,7 +143,9 @@ import kotlin.collections.ArrayList
} }
} }
*/ */
enum class FilterSubcategoryRow : RowRepresentable {
/*
enum class FilterSection : RowRepresentable {
// General // General
CASH_TOURNAMENT, CASH_TOURNAMENT,
@ -223,3 +345,5 @@ enum class FilterSubcategoryRow : RowRepresentable {
} }
} }
*/
Loading…
Cancel
Save