History UI limits: visit type & time
These are temporary limitations to make History UI somewhat functional, until we get relevant UI and API changes in place.
This commit is contained in:
parent
fef5680068
commit
0bcad0d364
|
@ -10,21 +10,8 @@ import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.mvi.Change
|
import org.mozilla.fenix.mvi.Change
|
||||||
import org.mozilla.fenix.mvi.UIComponent
|
import org.mozilla.fenix.mvi.UIComponent
|
||||||
import org.mozilla.fenix.mvi.ViewState
|
import org.mozilla.fenix.mvi.ViewState
|
||||||
import java.net.URL
|
|
||||||
|
|
||||||
data class HistoryItem(val id: Int, val url: String, val visitedAt: Long) {
|
data class HistoryItem(val id: Int, val title: String, val url: String, val visitedAt: Long)
|
||||||
val title: String
|
|
||||||
get() = siteTitle()
|
|
||||||
|
|
||||||
@SuppressWarnings("TooGenericExceptionCaught")
|
|
||||||
private fun siteTitle(): String {
|
|
||||||
return try {
|
|
||||||
URL(url).host
|
|
||||||
} catch (e: Exception) {
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mockable
|
@Mockable
|
||||||
class HistoryComponent(
|
class HistoryComponent(
|
||||||
|
|
|
@ -21,6 +21,7 @@ import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import mozilla.components.concept.storage.VisitType
|
||||||
import mozilla.components.support.base.feature.BackHandler
|
import mozilla.components.support.base.feature.BackHandler
|
||||||
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
@ -28,6 +29,7 @@ import org.mozilla.fenix.ext.requireComponents
|
||||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||||
import org.mozilla.fenix.mvi.getManagedEmitter
|
import org.mozilla.fenix.mvi.getManagedEmitter
|
||||||
|
import java.net.URL
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions")
|
@SuppressWarnings("TooManyFunctions")
|
||||||
|
@ -141,9 +143,25 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
|
||||||
override fun onBackPressed(): Boolean = (historyComponent.uiView as HistoryUIView).onBackPressed()
|
override fun onBackPressed(): Boolean = (historyComponent.uiView as HistoryUIView).onBackPressed()
|
||||||
|
|
||||||
private suspend fun reloadData() {
|
private suspend fun reloadData() {
|
||||||
val items = requireComponents.core.historyStorage.getDetailedVisits(0)
|
val allowedVisitTypes = listOf(VisitType.LINK, VisitType.TYPED, VisitType.BOOKMARK)
|
||||||
.asReversed()
|
// Until we have proper pagination, only display a limited set of history to avoid blowing up the UI.
|
||||||
.mapIndexed { id, item -> HistoryItem(id, item.url, item.visitTime) }
|
// See https://github.com/mozilla-mobile/fenix/issues/1393
|
||||||
|
@SuppressWarnings("MagicNumber")
|
||||||
|
val historyCutoffMs = 1000L * 60 * 60 * 24 * 3 // past few days
|
||||||
|
val items = requireComponents.core.historyStorage.getDetailedVisits(
|
||||||
|
System.currentTimeMillis() - historyCutoffMs
|
||||||
|
)
|
||||||
|
// We potentially have a large amount of visits, and multiple processing steps.
|
||||||
|
// Wrapping iterator in a sequence should make this a little more efficient.
|
||||||
|
.asSequence()
|
||||||
|
.sortedByDescending { it.visitTime }
|
||||||
|
|
||||||
|
// Temporary filtering until we can do it at the API level.
|
||||||
|
// See https://github.com/mozilla-mobile/android-components/issues/2643
|
||||||
|
.filter { allowedVisitTypes.contains(it.visitType) }
|
||||||
|
|
||||||
|
.mapIndexed { id, item -> HistoryItem(id, item.title ?: URL(item.url).host, item.url, item.visitTime) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
launch(Dispatchers.Main) {
|
launch(Dispatchers.Main) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ class HistoryComponentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `add and remove one history item normally`() {
|
fun `add and remove one history item normally`() {
|
||||||
val historyItem = HistoryItem(123, "http://mozilla.org", 0)
|
val historyItem = HistoryItem(123, "Mozilla", "http://mozilla.org", 0)
|
||||||
|
|
||||||
emitter.onNext(HistoryChange.Change(listOf(historyItem)))
|
emitter.onNext(HistoryChange.Change(listOf(historyItem)))
|
||||||
emitter.onNext(HistoryChange.EnterEditMode(historyItem))
|
emitter.onNext(HistoryChange.EnterEditMode(historyItem))
|
||||||
|
@ -62,8 +62,8 @@ class HistoryComponentTest {
|
||||||
@Test
|
@Test
|
||||||
fun `try making changes when not in edit mode`() {
|
fun `try making changes when not in edit mode`() {
|
||||||
val historyItems = listOf(
|
val historyItems = listOf(
|
||||||
HistoryItem(1337, "http://reddit.com", 0),
|
HistoryItem(1337, "Reddit", "http://reddit.com", 0),
|
||||||
HistoryItem(31337, "http://leethaxor.com", 0)
|
HistoryItem(31337, "Haxor", "http://leethaxor.com", 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
emitter.onNext(HistoryChange.Change(historyItems))
|
emitter.onNext(HistoryChange.Change(historyItems))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user