Improve filters (Sessions) & UI management

feature/top10
Aurelien Hubert 7 years ago
parent d92e2a30b3
commit f255589964
  1. 3
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  2. 87
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  4. 27
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt

@ -8,7 +8,6 @@ import net.pokeranalytics.android.model.realm.FilterElementBlind
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.extensions.endOfDay import net.pokeranalytics.android.util.extensions.endOfDay
import net.pokeranalytics.android.util.extensions.startOfDay import net.pokeranalytics.android.util.extensions.startOfDay
import java.time.*
import java.util.* import java.util.*
@ -33,6 +32,8 @@ enum class QueryCondition(var operator: Operator? = null) {
TABLE_SIZE, TABLE_SIZE,
TOURNAMENT_TYPE, TOURNAMENT_TYPE,
BLINDS, BLINDS,
LAST_GAMES,
LAST_SESSIONS,
MORE_NUMBER_OF_TABLE(Operator.MORE), MORE_NUMBER_OF_TABLE(Operator.MORE),
LESS_NUMBER_OF_TABLE(Operator.LESS), LESS_NUMBER_OF_TABLE(Operator.LESS),
BETWEEN_NUMBER_OF_TABLE(Operator.BETWEEN), BETWEEN_NUMBER_OF_TABLE(Operator.BETWEEN),

@ -76,6 +76,16 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
val data = row.editingDescriptors(mapOf("pastDays" to pastDays)) val data = row.editingDescriptors(mapOf("pastDays" to pastDays))
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
is FilterElementRow.LastGames -> {
val lastGames = if (row.lastGames > 0) row.lastGames.toString() else ""
val data = row.editingDescriptors(mapOf("lastGames" to lastGames))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is FilterElementRow.LastSessions -> {
val lastSessions = if (row.lastSessions > 0) row.lastSessions.toString() else ""
val data = row.editingDescriptors(mapOf("lastSessions" to lastSessions))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is FilterElementRow.DurationMoreThan -> { is FilterElementRow.DurationMoreThan -> {
val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else "" val hours = if (row.minutes / 60 > 0) (row.minutes / 60).toString() else ""
val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else "" val minutes = if (row.minutes % 60 > 0) (row.minutes % 60).toString() else ""
@ -89,50 +99,16 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
BottomSheetFragment.create(fragmentManager, row, this, data, true) BottomSheetFragment.create(fragmentManager, row, this, data, true)
} }
else -> { else -> {
updateRowsSelection(row)
val oldRows = ArrayList<RowRepresentable>()
oldRows.addAll(rows)
if (selectedRows.contains(row)) {
selectedRows.remove(row)
} else {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSectionRow)
} }
excludedFilters.forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
}
}
selectedRows.add(row)
}
}
}
}
/*
Timber.d("Row: $row")
when (row) {
FilterRow.FROM -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true)
FilterRow.TO -> DateTimePickerManager.create(requireContext(), row, this, Date(), onlyDate = true)
FilterRow.PAST_DAYS -> {
val data = row.editingDescriptors(mapOf("defaultValue" to ""))
BottomSheetFragment.create(fragmentManager, row, this, data, null)
}
else -> {
selectedRows.add(row)
} }
} }
}
*/
rowRepresentableAdapter.refreshRow(row)
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT is FilterElementRow.PastDays -> if (row.lastDays > 0) row.lastDays.toString() else NULL_TEXT
is FilterElementRow.LastGames -> if (row.lastGames > 0) row.lastGames.toString() else NULL_TEXT
is FilterElementRow.LastSessions -> if (row.lastSessions > 0) row.lastSessions.toString() else NULL_TEXT
is FilterElementRow.From -> row.date.shortDate() is FilterElementRow.From -> row.date.shortDate()
is FilterElementRow.To -> row.date.shortDate() is FilterElementRow.To -> row.date.shortDate()
is FilterElementRow.TimeFilterElementRow -> row.minutes.toMinutes(requireContext()) is FilterElementRow.TimeFilterElementRow -> row.minutes.toMinutes(requireContext())
@ -152,6 +128,8 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
is FilterElementRow.From -> row.date = if (value != null && value is Date) value else Date() is FilterElementRow.From -> row.date = if (value != null && value is Date) value else Date()
is FilterElementRow.To -> row.date = if (value != null && value is Date) value else Date() is FilterElementRow.To -> row.date = if (value != null && value is Date) value else Date()
is FilterElementRow.PastDays -> row.lastDays = if (value != null && value is String) value.toInt() else 0 is FilterElementRow.PastDays -> row.lastDays = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.LastGames -> row.lastGames = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.LastSessions -> row.lastSessions = if (value != null && value is String) value.toInt() else 0
is FilterElementRow.TimeFilterElementRow -> { is FilterElementRow.TimeFilterElementRow -> {
if (value is ArrayList<*>) { if (value is ArrayList<*>) {
val hours = try { val hours = try {
@ -172,16 +150,10 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
} }
} }
//TODO: Update management like in onRowSelected // Remove the row before updating the selected rows list
if (value != null) {
if (!selectedRows.contains(row)) {
selectedRows.add(row as FilterElementRow)
}
} else {
selectedRows.remove(row as FilterElementRow) selectedRows.remove(row as FilterElementRow)
} updateRowsSelection(row, value == null)
rowRepresentableAdapter.refreshRow(row)
} }
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {
@ -245,6 +217,31 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
} }
} }
/**
* Update rows selection
*/
private fun updateRowsSelection(row: RowRepresentable, forceDeselection: Boolean = false) {
if (selectedRows.contains(row) || forceDeselection) {
selectedRows.remove(row)
} else {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSectionRow)
}
excludedFilters.forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
}
}
selectedRows.add(row)
}
}
// Update UI
rowRepresentableAdapter.refreshRow(row)
}
/** /**
* Save data * Save data

@ -9,7 +9,7 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
GENERAL(R.string.general), GENERAL(R.string.general),
DATE(R.string.date), DATE(R.string.date),
TIME_FRAME(R.string.duration), TIME_FRAME(R.string.duration),
SESSION(R.string.session), SESSIONS(R.string.sessions),
CASH(R.string.cash), CASH(R.string.cash),
TOURNAMENT(R.string.tournament), TOURNAMENT(R.string.tournament),
ONLINE(R.string.online), ONLINE(R.string.online),
@ -49,6 +49,7 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
SESSION_DURATION, SESSION_DURATION,
RANGE RANGE
) )
SESSIONS -> arrayListOf(FilterSectionRow.SESSIONS)
BANKROLLS -> arrayListOf( BANKROLLS -> arrayListOf(
BANKROLL BANKROLL
) )
@ -78,7 +79,6 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
VALUE VALUE
) )
SESSION -> arrayListOf()
TRANSACTION_TYPES -> arrayListOf() TRANSACTION_TYPES -> arrayListOf()
} }
} }

@ -73,7 +73,12 @@ sealed class FilterElementRow : RowRepresentable {
data class Year(val year: Int) : SingleValueFilterElementRow(year) data class Year(val year: Int) : SingleValueFilterElementRow(year)
data class Month(val month: Int) : SingleValueFilterElementRow(month) data class Month(val month: Int) : SingleValueFilterElementRow(month)
data class Day(val day: Int) : SingleValueFilterElementRow(day) data class Day(val day: Int) : SingleValueFilterElementRow(day)
//TODO: Refactor?
data class PastDays(var lastDays: Int = 0) : FilterElementRow() data class PastDays(var lastDays: Int = 0) : FilterElementRow()
data class LastGames(var lastGames: Int) : FilterElementRow()
data class LastSessions(var lastSessions: Int) : FilterElementRow()
data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName) data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString()) data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString())
data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll) data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll)
@ -83,7 +88,6 @@ sealed class FilterElementRow : RowRepresentable {
data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) data class AllTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature) data class AnyTournamentFeature(val tournamentFeature: Manageable) : DataFilterElementRow(tournamentFeature)
lateinit var filterSectionRow: FilterSectionRow lateinit var filterSectionRow: FilterSectionRow
val filterName: String = this.queryCondition.name val filterName: String = this.queryCondition.name
@ -123,6 +127,10 @@ sealed class FilterElementRow : RowRepresentable {
is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION is DurationMoreThan -> QueryCondition.MORE_THAN_DURATION
is DurationLessThan -> QueryCondition.LESS_THAN_DURATION is DurationLessThan -> QueryCondition.LESS_THAN_DURATION
//TODO: Check the conditions
is LastGames -> QueryCondition.LAST_GAMES
is LastSessions -> QueryCondition.LAST_SESSIONS
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this) else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
} }
} }
@ -162,6 +170,8 @@ sealed class FilterElementRow : RowRepresentable {
is Weekend -> R.string.weekend is Weekend -> R.string.weekend
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Blind -> R.string.blinds is Blind -> R.string.blinds
is LastGames -> R.string.last_records
is LastSessions -> R.string.last_sessions
is MoreFilterElementRow, is MoreTimeFilterElementRow -> R.string.more_than is MoreFilterElementRow, is MoreTimeFilterElementRow -> R.string.more_than
is LessFilterElementRow, is LessTimeFilterElementRow -> R.string.less_than is LessFilterElementRow, is LessTimeFilterElementRow -> R.string.less_than
else -> null else -> null
@ -173,6 +183,7 @@ sealed class FilterElementRow : RowRepresentable {
return when (this) { return when (this) {
is PastDays, is PastDays,
is From, is To, is From, is To,
is LastGames, is LastSessions,
is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal is DurationMoreThan, is DurationLessThan -> RowViewType.TITLE_VALUE_CHECK.ordinal
else -> RowViewType.TITLE_CHECK.ordinal else -> RowViewType.TITLE_CHECK.ordinal
} }
@ -181,7 +192,7 @@ sealed class FilterElementRow : RowRepresentable {
override val bottomSheetType: BottomSheetType override val bottomSheetType: BottomSheetType
get() { get() {
return when (this) { return when (this) {
is PastDays -> BottomSheetType.EDIT_TEXT is PastDays, is LastGames, is LastSessions -> BottomSheetType.EDIT_TEXT
is DurationMoreThan, is DurationLessThan -> BottomSheetType.DOUBLE_EDIT_TEXT is DurationMoreThan, is DurationLessThan -> BottomSheetType.DOUBLE_EDIT_TEXT
else -> BottomSheetType.NONE else -> BottomSheetType.NONE
} }
@ -195,6 +206,18 @@ sealed class FilterElementRow : RowRepresentable {
RowRepresentableEditDescriptor(pastDays, R.string.period_in_days, inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(pastDays, R.string.period_in_days, inputType = InputType.TYPE_CLASS_NUMBER)
) )
} }
is LastGames -> {
val lastGames: String? by map
arrayListOf(
RowRepresentableEditDescriptor(lastGames, R.string.last_records, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is LastSessions -> {
val lastSessions: String? by map
arrayListOf(
RowRepresentableEditDescriptor(lastSessions, R.string.last_sessions, inputType = InputType.TYPE_CLASS_NUMBER)
)
}
is DurationMoreThan, is DurationLessThan -> { is DurationMoreThan, is DurationLessThan -> {
val hours: String? by map val hours: String? by map
val minutes: String? by map val minutes: String? by map

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import io.realm.Realm import io.realm.Realm
import io.realm.Sort import io.realm.Sort
import io.realm.kotlin.where import io.realm.kotlin.where
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
@ -26,6 +27,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
MONTH_OF_YEAR(net.pokeranalytics.android.R.string.month_of_the_year), MONTH_OF_YEAR(net.pokeranalytics.android.R.string.month_of_the_year),
SESSION_DURATION(net.pokeranalytics.android.R.string.session_duration), SESSION_DURATION(net.pokeranalytics.android.R.string.session_duration),
RANGE(net.pokeranalytics.android.R.string.hour_slot), RANGE(net.pokeranalytics.android.R.string.hour_slot),
SESSIONS(R.string.sessions),
BLINDS(net.pokeranalytics.android.R.string.blinds), BLINDS(net.pokeranalytics.android.R.string.blinds),
CASH_RE_BUY_COUNT(net.pokeranalytics.android.R.string.cash_game), CASH_RE_BUY_COUNT(net.pokeranalytics.android.R.string.cash_game),
TOURNAMENT_TYPE(net.pokeranalytics.android.R.string.tournament_types), TOURNAMENT_TYPE(net.pokeranalytics.android.R.string.tournament_types),
@ -157,6 +159,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
SESSION_DURATION -> arrayListOf(DurationMoreThan, DurationLessThan) SESSION_DURATION -> arrayListOf(DurationMoreThan, DurationLessThan)
RANGE -> arrayListOf(From(Date()), To(Date())) RANGE -> arrayListOf(From(Date()), To(Date()))
SESSIONS -> arrayListOf(LastGames(0), LastSessions(0))
VALUE -> arrayListOf() VALUE -> arrayListOf()
}.apply { }.apply {
@ -178,7 +182,7 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
private val selectionType: SelectionType private val selectionType: SelectionType
get() { get() {
return when (this) { return when (this) {
CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE -> SelectionType.SINGLE CASH_TOURNAMENT, DYNAMIC_DATE, LIVE_ONLINE, SESSIONS -> SelectionType.SINGLE
else -> SelectionType.MULTIPLE else -> SelectionType.MULTIPLE
} }
} }

Loading…
Cancel
Save