Skip to content

Commit

Permalink
Filter empty searches
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Apr 9, 2024
1 parent fcb236d commit a413c59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/com/duckduckgo/app/history/HistoryEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ sealed class HistoryEntry(
) : HistoryEntry(url = url, title, visits = visits)
}

fun HistoryEntryWithVisits.toHistoryEntry(): HistoryEntry {
return when (historyEntry.isSerp) {
true -> VisitedSERP(historyEntry.url.toUri(), historyEntry.title, historyEntry.query ?: "", visits = visits.map { Date(it.date) })
false -> VisitedPage(historyEntry.url.toUri(), historyEntry.title, visits.map { Date(it.date) })
fun HistoryEntryWithVisits.toHistoryEntry(): HistoryEntry? {
if (historyEntry.url.isBlank()) return null
return if (historyEntry.isSerp && !historyEntry.query.isNullOrBlank()) {
VisitedSERP(historyEntry.url.toUri(), historyEntry.title, historyEntry.query, visits = visits.map { Date(it.date) })
} else {
VisitedPage(historyEntry.url.toUri(), historyEntry.title, visits.map { Date(it.date) })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RealHistoryRepository(
private fun fetchAndCacheHistoryEntries(): Single<List<HistoryEntry>> {
return historyDao.getHistoryEntriesWithVisits()
.map { entries ->
entries.map { it.toHistoryEntry() }.also {
entries.mapNotNull { it.toHistoryEntry() }.also {
cachedHistoryEntries = it
}
}
Expand Down

0 comments on commit a413c59

Please sign in to comment.