parent
ed39b7828b
commit
acea0d5668
|
@ -128,7 +128,14 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
this,
|
this,
|
||||||
SessionControlViewModel::class.java
|
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(
|
||||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
|
SessionControlChange.Change(
|
||||||
|
tabs = getListOfTabs(sessionManager = requireComponents.core.sessionManager),
|
||||||
|
mode = currentMode(),
|
||||||
|
collections = requireComponents.core.tabCollectionStorage.cachedTabCollections
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
emitSessionChanges()
|
|
||||||
sessionObserver.onStart()
|
sessionObserver.onStart()
|
||||||
tabCollectionObserver = subscribeToTabCollections()
|
tabCollectionObserver = subscribeToTabCollections()
|
||||||
}
|
}
|
||||||
|
@ -609,27 +620,30 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitSessionChanges() {
|
private fun emitSessionChanges() {
|
||||||
val sessionManager = requireComponents.core.sessionManager
|
val sessionManager = context?.components?.core?.sessionManager ?: return
|
||||||
|
|
||||||
getManagedEmitter<SessionControlChange>().onNext(
|
getManagedEmitter<SessionControlChange>().onNext(
|
||||||
SessionControlChange.TabsChange(
|
SessionControlChange.TabsChange(
|
||||||
sessionManager.sessions
|
getListOfTabs(sessionManager)
|
||||||
.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 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() {
|
private fun emitAccountChanges() {
|
||||||
val mode = currentMode()
|
val mode = currentMode()
|
||||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
|
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
|
||||||
|
|
|
@ -139,6 +139,8 @@ fun Observer<SessionControlAction>.onNext(onboardingAction: OnboardingAction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class SessionControlChange : Change {
|
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 TabsChange(val tabs: List<Tab>) : SessionControlChange()
|
||||||
data class ModeChange(val mode: Mode) : SessionControlChange()
|
data class ModeChange(val mode: Mode) : SessionControlChange()
|
||||||
data class CollectionsChange(val collections: List<TabCollection>) : SessionControlChange()
|
data class CollectionsChange(val collections: List<TabCollection>) : SessionControlChange()
|
||||||
|
@ -165,6 +167,11 @@ class SessionControlViewModel(
|
||||||
|
|
||||||
state.copy(expandedCollections = newExpandedCollection)
|
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 {
|
view.apply {
|
||||||
adapter = sessionControlAdapter
|
adapter = sessionControlAdapter
|
||||||
layoutManager = LinearLayoutManager(container.context)
|
layoutManager = LinearLayoutManager(container.context)
|
||||||
itemAnimator = null // TODO #2785: Remove this line
|
|
||||||
val itemTouchHelper =
|
val itemTouchHelper =
|
||||||
ItemTouchHelper(
|
ItemTouchHelper(
|
||||||
SwipeToDeleteCallback(
|
SwipeToDeleteCallback(
|
||||||
|
|
Loading…
Reference in New Issue