1
0
Fork 0

Closes #1331 - Filter consecutive history items using simplified URL

master
James Hugman 2019-07-17 18:24:01 +01:00 committed by Emily Kager
parent 6fa022c2f8
commit ac359f6970
2 changed files with 26 additions and 0 deletions

View File

@ -43,3 +43,20 @@ fun String.urlToTrimmedHost(context: Context): String {
this
}
}
/**
* Trims a URL string of its scheme and common prefixes.
*
* This is intended to act much like [PublicSuffixList.getPublicSuffixPlusOne()] but unlike
* that method, leaves the path, anchor, etc intact.
*
*/
fun String.simplifiedUrl(): String {
val afterScheme = this.substringAfter("://")
for (prefix in listOf("www.", "m.", "mobile.")) {
if (afterScheme.startsWith(prefix)) {
return afterScheme.substring(prefix.length)
}
}
return afterScheme
}

View File

@ -39,6 +39,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getHostFromUrl
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.simplifiedUrl
import org.mozilla.fenix.share.ShareTab
import java.util.concurrent.TimeUnit
@ -256,12 +257,20 @@ class HistoryFragment : Fragment(), BackHandler {
// Until we have proper pagination, only display a limited set of history to avoid blowing up the UI.
// See https://github.com/mozilla-mobile/fenix/issues/1393
val sinceTimeMs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(HISTORY_TIME_DAYS)
var previous: String? = null
val items = requireComponents.core.historyStorage
.getDetailedVisits(sinceTimeMs, excludeTypes = excludeTypes)
// We potentially have a large amount of visits, and multiple processing steps.
// Wrapping iterator in a sequence should make this a little memory-more efficient.
.asSequence()
.sortedByDescending { it.visitTime }
.filter {
val current = it.url.simplifiedUrl()
val isNotDuplicate = current != previous
previous = current
isNotDuplicate
}
.mapIndexed { id, item ->
val title = item.title
?.takeIf(String::isNotEmpty)