Improve filters / wip

feature/top10
Aurelien Hubert 7 years ago
parent 47c76e18c1
commit 1ff9e4f715
  1. 30
      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. 62
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  5. 36
      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. 42
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt

@ -1,6 +1,7 @@
package net.pokeranalytics.android.model
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSubcategoryRow
enum class Limit : RowRepresentable {
NO,
@ -32,33 +33,16 @@ enum class Limit : RowRepresentable {
}
}
override fun getDisplayName(): String {
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))
}
/**
* Filters management
*/
/**
* Get a limit name
*/
fun get(index: Int) : String? {
if (index >= 0 && index < values.size) {
return values[index]
}
return ""
}
override fun subcategoryRow(): FilterSubcategoryRow? {
return FilterSubcategoryRow.LIMIT_TYPE
}
}
*/
}

@ -5,7 +5,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.view.RowRepresentable
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 {
val all : List<TableSize>
get() {
@ -35,6 +35,6 @@ class TableSize(var numberOfPlayer: Int) : RowRepresentable {
}
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.view.RowRepresentable
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.SimpleRow
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
}
/**
* Filters management
*/
override fun subcategoryRow(): FilterSubcategoryRow? {
return FilterSubcategoryRow.GAME
}
}

@ -25,11 +25,16 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
lateinit var item: RealmObject
lateinit var rowRepresentableAdapter: RowRepresentableAdapter
private var rows: ArrayList<RowRepresentable> = ArrayList()
private var rowsForFilterSubcategory: HashMap<FilterSubcategoryRow, ArrayList<RowRepresentable>> = HashMap()
private var filterMenu: Menu? = null
private var filterCategory: FilterCategoryRow? = null
val selectedRows = ArrayList<RowRepresentable>()
var isUpdating = false
var shouldOpenKeyboard = true
@ -64,29 +69,51 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
super.onRowSelected(position, row, fromAction)
val oldRows = ArrayList<RowRepresentable>()
oldRows.addAll(rows)
filterCategory?.let {
for (subcategory in it.getSubcategories()) {
if (subcategory.getFilterRows(getRealm()).contains(row)) {
if (subcategory.getType() == FilterSubcategoryRow.Type.SINGLE) {
for (filterRow in subcategory.getFilterRows(getRealm())) {
selectedRows.remove(filterRow)
}
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
val excludedRows = ArrayList<RowRepresentable>()
// 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)
}
}
}
}
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
// 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)
}
}
selectedRows.add(row)
}
rowRepresentableAdapter.refreshRow(row)
rowRepresentableAdapter.notifyDataSetChanged()
}
val selectedRows = ArrayList<RowRepresentable>()
override fun isSelected(row: RowRepresentable): Boolean {
return selectedRows.contains(row)
@ -149,9 +176,14 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDat
this.appBar.toolbar.title = it.localizedTitle(requireContext())
this.rows.clear()
this.rowsForFilterSubcategory.clear()
for (subcategory in it.getSubcategories()) {
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)

@ -1,31 +1,57 @@
package net.pokeranalytics.android.ui.view
import android.content.Context
import android.inputmethodservice.Keyboard
import io.realm.RealmResults
import net.pokeranalytics.android.model.LiveData
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
/**
* 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 {
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 {
fun editingDescriptors(map:Map<String,Any?>): ArrayList<RowRepresentableEditDescriptor>? {
fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return null
}
}
interface DefaultEditable : Editable, Localizable {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue : String? by map
val defaultValue: String? by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))
}
}

@ -10,7 +10,22 @@ enum class FilterRow : RowRepresentable {
CASH_GAME,
TOURNAMENT,
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?
get() {
@ -19,9 +34,50 @@ enum class FilterRow : RowRepresentable {
TOURNAMENT -> R.string.tournament
LIVE -> R.string.live
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 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.RealmResults
import io.realm.kotlin.where
import net.pokeranalytics.android.R
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.RowViewType
@ -72,7 +75,7 @@ enum class FilterSubcategoryRow : RowRepresentable {
override val resId: Int?
get() {
return when(this) {
return when (this) {
CASH_TOURNAMENT -> R.string.cash_or_tournament
LIVE_ONLINE -> R.string.live_or_online
GAME -> R.string.game
@ -118,9 +121,10 @@ enum class FilterSubcategoryRow : RowRepresentable {
/**
* Return the type of the selection
*/
fun getType() : Type {
return when(this) {
GAME -> Type.MULTIPLE
fun getType(): Type {
return when (this) {
GAME, LIMIT_TYPE -> Type.MULTIPLE
FIXED_DATE, YEAR, WEEKDAYS_OR_WEEKEND, DAY_OF_WEEK, MONTH_OF_YEAR -> Type.MULTIPLE
else -> Type.SINGLE
}
}
@ -128,9 +132,11 @@ enum class FilterSubcategoryRow : RowRepresentable {
/**
* Returns the filter rows
*/
fun getFilterRows(realm: Realm) : ArrayList<RowRepresentable> {
fun getFilterRows(realm: Realm): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
when(this) {
when (this) {
// General
CASH_TOURNAMENT -> rows.addAll(arrayListOf(FilterRow.CASH_GAME, FilterRow.TOURNAMENT))
LIVE_ONLINE -> rows.addAll(arrayListOf(FilterRow.LIVE, FilterRow.ONLINE))
GAME -> {
@ -138,6 +144,30 @@ enum class FilterSubcategoryRow : RowRepresentable {
rows.addAll(games)
}
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())
}
return rows

Loading…
Cancel
Save