mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
For issue #5298 the same page appears in the History section multiple times
This commit is contained in:
parent
23ea13a3cf
commit
74406bef59
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.components.history
|
package org.mozilla.fenix.components.history
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting
|
||||||
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
||||||
import mozilla.components.concept.storage.VisitInfo
|
import mozilla.components.concept.storage.VisitInfo
|
||||||
import mozilla.components.concept.storage.VisitType
|
import mozilla.components.concept.storage.VisitType
|
||||||
@ -203,7 +204,8 @@ class DefaultPagedHistoryProvider(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return result.sortedByDescending { it.visitedAt }
|
return result.removeConsecutiveDuplicates()
|
||||||
|
.sortedByDescending { it.visitedAt }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun transformVisitInfoToHistoryItem(offset: Int): (id: Int, visit: VisitInfo) -> History.Regular {
|
private fun transformVisitInfoToHistoryItem(offset: Int): (id: Int, visit: VisitInfo) -> History.Regular {
|
||||||
@ -221,3 +223,18 @@ class DefaultPagedHistoryProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
internal fun List<History>.removeConsecutiveDuplicates(): List<History> {
|
||||||
|
var previousURL = ""
|
||||||
|
return filter {
|
||||||
|
var isNotDuplicate = true
|
||||||
|
previousURL = if (it is History.Regular) {
|
||||||
|
isNotDuplicate = it.url != previousURL
|
||||||
|
it.url
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
isNotDuplicate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -452,4 +452,74 @@ class PagedHistoryProviderTest {
|
|||||||
)
|
)
|
||||||
assertEquals(results, actualResults)
|
assertEquals(results, actualResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN removeConsecutiveDuplicates is called THEN all consecutive duplicates must be removed`() {
|
||||||
|
val results = listOf(
|
||||||
|
History.Group(
|
||||||
|
id = 1,
|
||||||
|
title = "Group 1",
|
||||||
|
visitedAt = 0,
|
||||||
|
items = emptyList()
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 2,
|
||||||
|
title = "No duplicate item",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 3,
|
||||||
|
title = "Duplicate item 1",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 4,
|
||||||
|
title = "Duplicate item 2",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
History.Group(
|
||||||
|
id = 5,
|
||||||
|
title = "Group 5",
|
||||||
|
visitedAt = 0,
|
||||||
|
items = emptyList()
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 6,
|
||||||
|
title = "No duplicate item",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
).removeConsecutiveDuplicates()
|
||||||
|
|
||||||
|
val expectedList = listOf(
|
||||||
|
History.Group(
|
||||||
|
id = 1,
|
||||||
|
title = "Group 1",
|
||||||
|
visitedAt = 0,
|
||||||
|
items = emptyList()
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 2,
|
||||||
|
title = "No duplicate item",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
History.Group(
|
||||||
|
id = 5,
|
||||||
|
title = "Group 5",
|
||||||
|
visitedAt = 0,
|
||||||
|
items = emptyList()
|
||||||
|
),
|
||||||
|
History.Regular(
|
||||||
|
id = 6,
|
||||||
|
title = "No duplicate item",
|
||||||
|
url = "url",
|
||||||
|
visitedAt = 0
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assertEquals(expectedList, results)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user