Add test for TimelineItemGrouper and fix a bug: the last group if any was not added to the list.
This commit is contained in:
parent
02842d978f
commit
d899a8e881
2 changed files with 194 additions and 11 deletions
|
|
@ -46,22 +46,15 @@ class TimelineItemGrouper @Inject constructor() {
|
|||
// timelineItem cannot be grouped
|
||||
if (currentGroup.isNotEmpty()) {
|
||||
// There is a pending group, create a TimelineItem.GroupedEvents if there is more than 1 Event in the pending group.
|
||||
if (currentGroup.size == 1) {
|
||||
// Do not create a group with just 1 item, just add the item to the result
|
||||
result.add(currentGroup.first())
|
||||
} else {
|
||||
result.add(
|
||||
TimelineItem.GroupedEvents(
|
||||
expanded = expandedGroups[currentGroup.first().id + "_group"].orFalse(),
|
||||
events = currentGroup.toImmutableList()
|
||||
)
|
||||
)
|
||||
}
|
||||
result.addGroup(currentGroup, expandedGroups)
|
||||
currentGroup.clear()
|
||||
}
|
||||
result.add(timelineItem)
|
||||
}
|
||||
}
|
||||
if (currentGroup.isNotEmpty()) {
|
||||
result.addGroup(currentGroup, expandedGroups)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
@ -80,3 +73,23 @@ class TimelineItemGrouper @Inject constructor() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will add a group if there is more than 1 item, else add the item to the list.
|
||||
*/
|
||||
private fun MutableList<TimelineItem>.addGroup(
|
||||
group: MutableList<TimelineItem.Event>,
|
||||
expandedGroups: Map<String, Boolean>,
|
||||
) {
|
||||
if (group.size == 1) {
|
||||
// Do not create a group with just 1 item, just add the item to the result
|
||||
add(group.first())
|
||||
} else {
|
||||
add(
|
||||
TimelineItem.GroupedEvents(
|
||||
expanded = expandedGroups[group.first().id + "_group"].orFalse(),
|
||||
events = group.toImmutableList()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue