@VisibleForTesting internal fun getSortedHistory( historyHighlights: List<HistoryHighlightInternal>, historyGroups: List<HistoryGroupInternal>, ): List<RecentlyVisitedItem> { return (historyHighlights + historyGroups) .sortedByDescending { it.lastAccessedTime } .map { when (it) { is HistoryHighlightInternal -> RecentHistoryHighlight( title = if (it.historyHighlight.title.isNullOrBlank()) { it.historyHighlight.url } else { it.historyHighlight.title!! }, url = it.historyHighlight.url, ) is HistoryGroupInternal -> RecentHistoryGroup( title = it.groupName, historyMetadata = it.groupItems, ) } } } override fun stop() { job?.cancel() } }
Maps the internal highlights and search groups to the final objects to be returned. Items will be sorted by their last accessed date so that the most recent will be first.