Improve filters / wip

feature/top10
Aurelien Hubert 7 years ago
parent 47c76e18c1
commit 1ff9e4f715
  1. 26
      app/src/main/java/net/pokeranalytics/android/model/Limit.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/model/TableSize.kt
  3. 9
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  4. 58
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  5. 32
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  6. 58
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterRow.kt
  7. 32
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt

@ -1,6 +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
enum class Limit : RowRepresentable { enum class Limit : RowRepresentable {
NO, NO,
@ -32,33 +33,16 @@ enum class Limit : RowRepresentable {
} }
} }
override fun getDisplayName(): String { override fun getDisplayName(): String {
return this.longName return this.longName
} }
}
/*
class Limit {
companion object {
private val values = ArrayList<String>()
fun init(context: Context) {
values.clear()
values.addAll(context.resources.getStringArray(R.array.limit_short_name))
}
/** /**
* Get a limit name * Filters management
*/ */
fun get(index: Int) : String? {
if (index >= 0 && index < values.size) { override fun subcategoryRow(): FilterSubcategoryRow? {
return values[index] return FilterSubcategoryRow.LIMIT_TYPE
}
return ""
}
} }
} }
*/

@ -5,7 +5,7 @@ import net.pokeranalytics.android.R
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
class TableSize(var numberOfPlayer: Int) : RowRepresentable { class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal) : RowRepresentable {
companion object { companion object {
val all : List<TableSize> val all : List<TableSize>
get() { get() {
@ -35,6 +35,6 @@ class TableSize(var numberOfPlayer: Int) : RowRepresentable {
} }
override val viewType: Int override val viewType: Int
get() = RowViewType.TITLE_GRID.ordinal get() = rowViewType
} }

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

@ -25,11 +25,16 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
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 filterMenu: Menu? = null private var filterMenu: Menu? = null
private var filterCategory: FilterCategoryRow? = null private var filterCategory: FilterCategoryRow? = null
val selectedRows = ArrayList<RowRepresentable>()
var isUpdating = false var isUpdating = false
var shouldOpenKeyboard = true var shouldOpenKeyboard = true
@ -64,29 +69,51 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
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)
val oldRows = ArrayList<RowRepresentable>()
oldRows.addAll(rows)
filterCategory?.let { if (selectedRows.contains(row)) {
for (subcategory in it.getSubcategories()) { selectedRows.remove(row)
if (subcategory.getFilterRows(getRealm()).contains(row)) { } else {
if (subcategory.getType() == FilterSubcategoryRow.Type.SINGLE) {
for (filterRow in subcategory.getFilterRows(getRealm())) { val excludedRows = ArrayList<RowRepresentable>()
selectedRows.remove(filterRow)
// Exclude the rows of the same subcategory if we are an a single row selection
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)
}
}
}
// Exclude the filter rows
row.excludedFilterRows()?.let {
excludedRows.addAll(it)
}
for (filterRow in excludedRows) {
if (selectedRows.contains(filterRow)) {
selectedRows.remove(filterRow)
rowRepresentableAdapter.refreshRow(filterRow)
} }
} }
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
selectedRows.add(row) selectedRows.add(row)
} }
rowRepresentableAdapter.refreshRow(row)
rowRepresentableAdapter.notifyDataSetChanged()
} }
val selectedRows = ArrayList<RowRepresentable>()
override fun isSelected(row: RowRepresentable): Boolean { override fun isSelected(row: RowRepresentable): Boolean {
return selectedRows.contains(row) return selectedRows.contains(row)
@ -149,9 +176,14 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
this.appBar.toolbar.title = it.localizedTitle(requireContext()) this.appBar.toolbar.title = it.localizedTitle(requireContext())
this.rows.clear() this.rows.clear()
this.rowsForFilterSubcategory.clear()
for (subcategory in it.getSubcategories()) { for (subcategory in it.getSubcategories()) {
this.rows.add(subcategory) this.rows.add(subcategory)
this.rows.addAll(subcategory.getFilterRows(getRealm()))
val subcategoryRows = subcategory.getFilterRows(getRealm())
this.rowsForFilterSubcategory.put(subcategory, subcategoryRows)
this.rows.addAll(subcategoryRows)
} }
this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) this.rowRepresentableAdapter = RowRepresentableAdapter(this, this)

@ -1,22 +1,48 @@
package net.pokeranalytics.android.ui.view package net.pokeranalytics.android.ui.view
import android.content.Context import android.content.Context
import android.inputmethodservice.Keyboard
import io.realm.RealmResults
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 { interface RowRepresentable : Displayable, Editable, Filterable {
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

@ -10,7 +10,22 @@ enum class FilterRow : RowRepresentable {
CASH_GAME, CASH_GAME,
TOURNAMENT, TOURNAMENT,
LIVE, LIVE,
ONLINE; ONLINE,
// Date
TODAY,
YESTERDAY,
TODAY_AND_YESTERDAY,
CURRENT_WEEK,
CURRENT_MONTH,
CURRENT_YEAR,
FROM,
TO,
PAST_DAYS,
WEEKDAYS,
WEEKEND,
;
override val resId: Int? override val resId: Int?
get() { get() {
@ -19,9 +34,50 @@ enum class FilterRow : RowRepresentable {
TOURNAMENT -> R.string.tournament TOURNAMENT -> R.string.tournament
LIVE -> R.string.live LIVE -> R.string.live
ONLINE -> R.string.online ONLINE -> R.string.online
TODAY -> R.string.today
YESTERDAY -> R.string.yesterday
TODAY_AND_YESTERDAY -> R.string.yesterday_and_today
CURRENT_WEEK -> R.string.current_week
CURRENT_MONTH -> R.string.current_month
CURRENT_YEAR -> R.string.current_year
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
} }
} }
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
override fun excludedFilterRows(): ArrayList<FilterRow>? {
return when (this) {
CASH_GAME, TOURNAMENT -> arrayListOf(CASH_GAME, TOURNAMENT)
LIVE, ONLINE -> arrayListOf(LIVE, ONLINE)
else -> ArrayList()
}
}
override fun excludedFilterSubcategoryRows(): ArrayList<FilterSubcategoryRow>? {
return when(this) {
TODAY, YESTERDAY, TODAY_AND_YESTERDAY, CURRENT_WEEK, CURRENT_MONTH, CURRENT_YEAR -> arrayListOf(FilterSubcategoryRow.FIXED_DATE)
FROM, TO -> arrayListOf(FilterSubcategoryRow.DYNAMIC_DATE)
else -> null
}
}
override fun subcategoryRow(): FilterSubcategoryRow? {
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
}
}
} }

@ -2,10 +2,13 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm import io.realm.Realm
import io.realm.RealmResults import io.realm.RealmResults
import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.Limit import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData 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.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
@ -120,7 +123,8 @@ enum class FilterSubcategoryRow : RowRepresentable {
*/ */
fun getType(): Type { fun getType(): Type {
return when (this) { return when (this) {
GAME -> Type.MULTIPLE GAME, LIMIT_TYPE -> Type.MULTIPLE
FIXED_DATE, YEAR, WEEKDAYS_OR_WEEKEND, DAY_OF_WEEK, MONTH_OF_YEAR -> Type.MULTIPLE
else -> Type.SINGLE else -> Type.SINGLE
} }
} }
@ -131,6 +135,8 @@ enum class FilterSubcategoryRow : RowRepresentable {
fun getFilterRows(realm: Realm): ArrayList<RowRepresentable> { fun getFilterRows(realm: Realm): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>() val rows = ArrayList<RowRepresentable>()
when (this) { when (this) {
// General
CASH_TOURNAMENT -> rows.addAll(arrayListOf(FilterRow.CASH_GAME, FilterRow.TOURNAMENT)) CASH_TOURNAMENT -> rows.addAll(arrayListOf(FilterRow.CASH_GAME, FilterRow.TOURNAMENT))
LIVE_ONLINE -> rows.addAll(arrayListOf(FilterRow.LIVE, FilterRow.ONLINE)) LIVE_ONLINE -> rows.addAll(arrayListOf(FilterRow.LIVE, FilterRow.ONLINE))
GAME -> { GAME -> {
@ -138,6 +144,30 @@ enum class FilterSubcategoryRow : RowRepresentable {
rows.addAll(games) rows.addAll(games)
} }
LIMIT_TYPE -> rows.addAll(Limit.values()) LIMIT_TYPE -> rows.addAll(Limit.values())
TABLE_SIZE -> {
val sessions = realm.where<Session>().sort("tableSize").distinct("tableSize").findAll()
for (session in sessions) {
session.tableSize?.let {
rows.add(TableSize(it, RowViewType.TITLE_CHECK.ordinal))
}
}
}
// Date
DYNAMIC_DATE -> rows.addAll(
arrayListOf(
FilterRow.TODAY, FilterRow.YESTERDAY, FilterRow.TODAY_AND_YESTERDAY, FilterRow.CURRENT_WEEK,
FilterRow.CURRENT_MONTH, FilterRow.CURRENT_YEAR
)
)
FIXED_DATE -> rows.addAll(arrayListOf(FilterRow.FROM, FilterRow.TO))
DURATION -> rows.addAll(arrayListOf(FilterRow.PAST_DAYS))
YEAR -> rows.addAll(arrayListOf()) //TODO
WEEKDAYS_OR_WEEKEND -> rows.addAll(arrayListOf(FilterRow.WEEKDAYS, FilterRow.WEEKEND))
DAY_OF_WEEK -> rows.addAll(arrayListOf()) //TODO
MONTH_OF_YEAR -> rows.addAll(arrayListOf()) //TODO
else -> rows.addAll(arrayListOf()) else -> rows.addAll(arrayListOf())
} }
return rows return rows

Loading…
Cancel
Save