parent
ed39b7828b
commit
acea0d5668
|
@ -128,7 +128,14 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
this,
|
||||
SessionControlViewModel::class.java
|
||||
) {
|
||||
SessionControlViewModel(SessionControlState(listOf(), setOf(), listOf(), mode))
|
||||
SessionControlViewModel(
|
||||
SessionControlState(
|
||||
getListOfTabs(requireComponents.core.sessionManager),
|
||||
setOf(),
|
||||
requireComponents.core.tabCollectionStorage.cachedTabCollections,
|
||||
mode
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -269,10 +276,14 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
}
|
||||
}
|
||||
|
||||
val mode = currentMode()
|
||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
|
||||
getManagedEmitter<SessionControlChange>().onNext(
|
||||
SessionControlChange.Change(
|
||||
tabs = getListOfTabs(sessionManager = requireComponents.core.sessionManager),
|
||||
mode = currentMode(),
|
||||
collections = requireComponents.core.tabCollectionStorage.cachedTabCollections
|
||||
)
|
||||
)
|
||||
|
||||
emitSessionChanges()
|
||||
sessionObserver.onStart()
|
||||
tabCollectionObserver = subscribeToTabCollections()
|
||||
}
|
||||
|
@ -609,27 +620,30 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
}
|
||||
|
||||
private fun emitSessionChanges() {
|
||||
val sessionManager = requireComponents.core.sessionManager
|
||||
|
||||
val sessionManager = context?.components?.core?.sessionManager ?: return
|
||||
getManagedEmitter<SessionControlChange>().onNext(
|
||||
SessionControlChange.TabsChange(
|
||||
sessionManager.sessions
|
||||
.filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private }
|
||||
.map {
|
||||
val selected = it == sessionManager.selectedSession
|
||||
Tab(
|
||||
it.id,
|
||||
it.url,
|
||||
it.url.urlToTrimmedHost(),
|
||||
it.title,
|
||||
selected,
|
||||
it.thumbnail
|
||||
)
|
||||
}
|
||||
getListOfTabs(sessionManager)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun getListOfTabs(sessionManager: SessionManager): List<Tab> {
|
||||
return sessionManager.sessions
|
||||
.filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private }
|
||||
.map {
|
||||
val selected = it == sessionManager.selectedSession
|
||||
Tab(
|
||||
it.id,
|
||||
it.url,
|
||||
it.url.urlToTrimmedHost(),
|
||||
it.title,
|
||||
selected,
|
||||
it.thumbnail
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun emitAccountChanges() {
|
||||
val mode = currentMode()
|
||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
|
||||
|
|
|
@ -139,6 +139,8 @@ fun Observer<SessionControlAction>.onNext(onboardingAction: OnboardingAction) {
|
|||
}
|
||||
|
||||
sealed class SessionControlChange : Change {
|
||||
data class Change(val tabs: List<Tab>, val mode: Mode, val collections: List<TabCollection>) :
|
||||
SessionControlChange()
|
||||
data class TabsChange(val tabs: List<Tab>) : SessionControlChange()
|
||||
data class ModeChange(val mode: Mode) : SessionControlChange()
|
||||
data class CollectionsChange(val collections: List<TabCollection>) : SessionControlChange()
|
||||
|
@ -165,6 +167,11 @@ class SessionControlViewModel(
|
|||
|
||||
state.copy(expandedCollections = newExpandedCollection)
|
||||
}
|
||||
is SessionControlChange.Change -> state.copy(
|
||||
tabs = change.tabs,
|
||||
mode = change.mode,
|
||||
collections = change.collections
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,6 @@ class SessionControlUIView(
|
|||
view.apply {
|
||||
adapter = sessionControlAdapter
|
||||
layoutManager = LinearLayoutManager(container.context)
|
||||
itemAnimator = null // TODO #2785: Remove this line
|
||||
val itemTouchHelper =
|
||||
ItemTouchHelper(
|
||||
SwipeToDeleteCallback(
|
||||
|
|
Loading…
Reference in New Issue