|
|
|
|
@ -18,17 +18,12 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource { |
|
|
|
|
|
|
|
|
|
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 fun addGroup(date: Date) { |
|
|
|
|
this.groups.add(date) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun result(index: Int): CalendarItemCell { |
|
|
|
|
val group = this.groups.elementAt(index) |
|
|
|
|
return this.results[group] ?: throw PAIllegalStateException("item not found") |
|
|
|
|
this.groupDates.add(date) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun addResult(group: Date, result: CellResult, unit: TimeUnit) { |
|
|
|
|
@ -40,12 +35,14 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun clear() { |
|
|
|
|
this.groups.clear() |
|
|
|
|
this.groupDates.clear() |
|
|
|
|
this.results.clear() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun buildDataStructure() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Timber.d(">>> Start buildDataStructure: ${this.selectedTimeUnit}") |
|
|
|
|
|
|
|
|
|
this.clear() |
|
|
|
|
@ -94,7 +91,7 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource { |
|
|
|
|
// RowRepresentableDataSource |
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
@ -109,12 +106,16 @@ class GridCalendarViewModel : ViewModel(), RowRepresentableDataSource { |
|
|
|
|
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 { |
|
|
|
|
|
|
|
|
|
private var results: MutableList<CellResult> = mutableListOf(result) |
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
fun add(result: CellResult) { |
|
|
|
|
this.results.add(result) |
|
|
|
|
|