Fixes grid calendar item sorting

blinds
Laurent 5 years ago
parent 2e3d00ce41
commit 2d68256504
  1. 21
      app/src/main/java/net/pokeranalytics/android/ui/modules/calendar/GridCalendarViewModel.kt

@ -18,17 +18,12 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource {
var selectedTimeUnit: TimeUnit = TimeUnit.DAY var selectedTimeUnit: TimeUnit = TimeUnit.DAY
private var groups: TreeSet<Date> = TreeSet<Date>() private var groupDates: TreeSet<Date> = TreeSet<Date>()
private var results: HashMap<Date, CalendarItemCell> = HashMap() private var results: HashMap<Date, CalendarItemCell> = HashMap()
private fun addGroup(date: Date) { private fun addGroup(date: Date) {
this.groups.add(date) this.groupDates.add(date)
}
private fun result(index: Int): CalendarItemCell {
val group = this.groups.elementAt(index)
return this.results[group] ?: throw PAIllegalStateException("item not found")
} }
private fun addResult(group: Date, result: CellResult, unit: TimeUnit) { private fun addResult(group: Date, result: CellResult, unit: TimeUnit) {
@ -40,12 +35,14 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource {
} }
private fun clear() { private fun clear() {
this.groups.clear() this.groupDates.clear()
this.results.clear() this.results.clear()
} }
fun buildDataStructure() { fun buildDataStructure() {
// Timber.d(">>> Start buildDataStructure: ${this.selectedTimeUnit}") // Timber.d(">>> Start buildDataStructure: ${this.selectedTimeUnit}")
this.clear() this.clear()
@ -94,7 +91,7 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource {
// RowRepresentableDataSource // RowRepresentableDataSource
override fun adapterRows(): List<RowRepresentable> { override fun adapterRows(): List<RowRepresentable> {
return this.groups.descendingSet().map { this.results[it]!! } return this.groupDates.map { this.results[it]!! }
} }
override fun rowRepresentableForPosition(position: Int): RowRepresentable { override fun rowRepresentableForPosition(position: Int): RowRepresentable {
@ -109,12 +106,16 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource {
return RowViewType.CALENDAR_GRID_CELL.ordinal return RowViewType.CALENDAR_GRID_CELL.ordinal
} }
private fun result(index: Int): CalendarItemCell {
val group = this.groupDates.elementAt(this.results.size - index - 1) // sort descendingly
return this.results[group] ?: throw PAIllegalStateException("item not found")
}
} }
class CalendarItemCell(var date: Date, result: CellResult, var unit: TimeUnit) : RowRepresentable, RowRepresentableDataSource { class CalendarItemCell(var date: Date, result: CellResult, var unit: TimeUnit) : RowRepresentable, RowRepresentableDataSource {
private var results: MutableList<CellResult> = mutableListOf(result) private var results: MutableList<CellResult> = mutableListOf(result)
private set
fun add(result: CellResult) { fun add(result: CellResult) {
this.results.add(result) this.results.add(result)

Loading…
Cancel
Save