Changes AppStateHandler to SpaceStateHandler
This commit is contained in:
parent
9a649b6093
commit
f0ae458a54
|
@ -22,7 +22,7 @@ import kotlinx.coroutines.flow.Flow
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
|
|
||||||
interface AppStateHandler : DefaultLifecycleObserver {
|
interface SpaceStateHandler : DefaultLifecycleObserver {
|
||||||
|
|
||||||
fun getCurrentSpace(): RoomSummary?
|
fun getCurrentSpace(): RoomSummary?
|
||||||
|
|
|
@ -49,12 +49,12 @@ import javax.inject.Singleton
|
||||||
* It is required that this class is added as an observer to ProcessLifecycleOwner.get().lifecycle in [VectorApplication]
|
* It is required that this class is added as an observer to ProcessLifecycleOwner.get().lifecycle in [VectorApplication]
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class AppStateHandlerImpl @Inject constructor(
|
class SpaceStateHandlerImpl @Inject constructor(
|
||||||
private val sessionDataSource: ActiveSessionDataSource,
|
private val sessionDataSource: ActiveSessionDataSource,
|
||||||
private val uiStateRepository: UiStateRepository,
|
private val uiStateRepository: UiStateRepository,
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val analyticsTracker: AnalyticsTracker
|
private val analyticsTracker: AnalyticsTracker
|
||||||
) : AppStateHandler {
|
) : SpaceStateHandler {
|
||||||
|
|
||||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||||
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomSummary>>(Option.empty())
|
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomSummary>>(Option.empty())
|
|
@ -90,7 +90,7 @@ class VectorApplication :
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var versionProvider: VersionProvider
|
@Inject lateinit var versionProvider: VersionProvider
|
||||||
@Inject lateinit var notificationUtils: NotificationUtils
|
@Inject lateinit var notificationUtils: NotificationUtils
|
||||||
@Inject lateinit var appStateHandler: AppStateHandler
|
@Inject lateinit var spaceStateHandler: SpaceStateHandler
|
||||||
@Inject lateinit var popupAlertManager: PopupAlertManager
|
@Inject lateinit var popupAlertManager: PopupAlertManager
|
||||||
@Inject lateinit var pinLocker: PinLocker
|
@Inject lateinit var pinLocker: PinLocker
|
||||||
@Inject lateinit var callManager: WebRtcCallManager
|
@Inject lateinit var callManager: WebRtcCallManager
|
||||||
|
@ -187,7 +187,7 @@ class VectorApplication :
|
||||||
fcmHelper.onEnterBackground(activeSessionHolder)
|
fcmHelper.onEnterBackground(activeSessionHolder)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(appStateHandler)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(spaceStateHandler)
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(pinLocker)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(pinLocker)
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(callManager)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(callManager)
|
||||||
// This should be done as early as possible
|
// This should be done as early as possible
|
||||||
|
|
|
@ -28,8 +28,8 @@ import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.AppStateHandlerImpl
|
import im.vector.app.SpaceStateHandlerImpl
|
||||||
import im.vector.app.BuildConfig
|
import im.vector.app.BuildConfig
|
||||||
import im.vector.app.EmojiCompatWrapper
|
import im.vector.app.EmojiCompatWrapper
|
||||||
import im.vector.app.EmojiSpanify
|
import im.vector.app.EmojiSpanify
|
||||||
|
@ -112,7 +112,7 @@ abstract class VectorBindModule {
|
||||||
abstract fun bindSystemSettingsProvide(provider: AndroidSystemSettingsProvider): SystemSettingsProvider
|
abstract fun bindSystemSettingsProvide(provider: AndroidSystemSettingsProvider): SystemSettingsProvider
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindAppStateHandler(appStateHandlerImpl: AppStateHandlerImpl): AppStateHandler
|
abstract fun bindSpaceStateHandler(spaceStateHandlerImpl: SpaceStateHandlerImpl): SpaceStateHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.airbnb.mvrx.Mavericks
|
||||||
import com.airbnb.mvrx.viewModel
|
import com.airbnb.mvrx.viewModel
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.extensions.hideKeyboard
|
import im.vector.app.core.extensions.hideKeyboard
|
||||||
|
@ -129,7 +129,7 @@ class HomeActivity :
|
||||||
@Inject lateinit var permalinkHandler: PermalinkHandler
|
@Inject lateinit var permalinkHandler: PermalinkHandler
|
||||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||||
@Inject lateinit var initSyncStepFormatter: InitSyncStepFormatter
|
@Inject lateinit var initSyncStepFormatter: InitSyncStepFormatter
|
||||||
@Inject lateinit var appStateHandler: AppStateHandler
|
@Inject lateinit var spaceStateHandler: SpaceStateHandler
|
||||||
@Inject lateinit var unifiedPushHelper: UnifiedPushHelper
|
@Inject lateinit var unifiedPushHelper: UnifiedPushHelper
|
||||||
@Inject lateinit var fcmHelper: FcmHelper
|
@Inject lateinit var fcmHelper: FcmHelper
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import com.airbnb.mvrx.activityViewModel
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.commitTransaction
|
import im.vector.app.core.extensions.commitTransaction
|
||||||
import im.vector.app.core.extensions.toMvRxBundle
|
import im.vector.app.core.extensions.toMvRxBundle
|
||||||
|
@ -66,7 +66,7 @@ class HomeDetailFragment @Inject constructor(
|
||||||
private val alertManager: PopupAlertManager,
|
private val alertManager: PopupAlertManager,
|
||||||
private val callManager: WebRtcCallManager,
|
private val callManager: WebRtcCallManager,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val appStateHandler: AppStateHandler
|
private val spaceStateHandler: SpaceStateHandler
|
||||||
) : VectorBaseFragment<FragmentHomeDetailBinding>(),
|
) : VectorBaseFragment<FragmentHomeDetailBinding>(),
|
||||||
KeysBackupBanner.Delegate,
|
KeysBackupBanner.Delegate,
|
||||||
CurrentCallsView.Callback,
|
CurrentCallsView.Callback,
|
||||||
|
@ -183,13 +183,13 @@ class HomeDetailFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateBack() {
|
private fun navigateBack() {
|
||||||
val previousSpaceId = appStateHandler.getSpaceBackstack().removeLastOrNull()
|
val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull()
|
||||||
val parentSpaceId = appStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
||||||
setCurrentSpace(previousSpaceId ?: parentSpaceId)
|
setCurrentSpace(previousSpaceId ?: parentSpaceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCurrentSpace(spaceId: String?) {
|
private fun setCurrentSpace(spaceId: String?) {
|
||||||
appStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
||||||
sharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace)
|
sharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ class HomeDetailFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshSpaceState() {
|
private fun refreshSpaceState() {
|
||||||
appStateHandler.getCurrentSpace()?.let {
|
spaceStateHandler.getCurrentSpace()?.let {
|
||||||
onSpaceChange(it)
|
onSpaceChange(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,7 @@ class HomeDetailFragment @Inject constructor(
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(toolbarButton: Boolean) = if (appStateHandler.getCurrentSpace() != null) {
|
override fun onBackPressed(toolbarButton: Boolean) = if (spaceStateHandler.getCurrentSpace() != null) {
|
||||||
navigateBack()
|
navigateBack()
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import com.airbnb.mvrx.ViewModelContext
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.extensions.singletonEntryPoint
|
import im.vector.app.core.extensions.singletonEntryPoint
|
||||||
|
@ -68,7 +68,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
||||||
private val vectorDataStore: VectorDataStore,
|
private val vectorDataStore: VectorDataStore,
|
||||||
private val callManager: WebRtcCallManager,
|
private val callManager: WebRtcCallManager,
|
||||||
private val directRoomHelper: DirectRoomHelper,
|
private val directRoomHelper: DirectRoomHelper,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val spaceStateHandler: SpaceStateHandler,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites,
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
private val vectorOverrides: VectorOverrides
|
private val vectorOverrides: VectorOverrides
|
||||||
) : VectorViewModel<HomeDetailViewState, HomeDetailAction, HomeDetailViewEvents>(initialState),
|
) : VectorViewModel<HomeDetailViewState, HomeDetailAction, HomeDetailViewEvents>(initialState),
|
||||||
|
@ -207,7 +207,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomGroupingMethod() {
|
private fun observeRoomGroupingMethod() {
|
||||||
appStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.setOnEach {
|
.setOnEach {
|
||||||
copy(
|
copy(
|
||||||
selectedSpace = it.orNull()
|
selectedSpace = it.orNull()
|
||||||
|
@ -216,7 +216,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRoomSummaries() {
|
private fun observeRoomSummaries() {
|
||||||
appStateHandler.getSelectedSpaceFlow().distinctUntilChanged().flatMapLatest {
|
spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged().flatMapLatest {
|
||||||
// we use it as a trigger to all changes in room, but do not really load
|
// we use it as a trigger to all changes in room, but do not really load
|
||||||
// the actual models
|
// the actual models
|
||||||
session.roomService().getPagedRoomSummariesLive(
|
session.roomService().getPagedRoomSummariesLive(
|
||||||
|
@ -228,7 +228,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
.throttleFirst(300)
|
.throttleFirst(300)
|
||||||
.onEach {
|
.onEach {
|
||||||
val activeSpaceRoomId = appStateHandler.getCurrentSpace()?.roomId
|
val activeSpaceRoomId = spaceStateHandler.getCurrentSpace()?.roomId
|
||||||
var dmInvites = 0
|
var dmInvites = 0
|
||||||
var roomsInvite = 0
|
var roomsInvite = 0
|
||||||
if (autoAcceptInvites.showInvites()) {
|
if (autoAcceptInvites.showInvites()) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.EmptyAction
|
import im.vector.app.core.platform.EmptyAction
|
||||||
|
@ -58,7 +58,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: UnreadMessagesState,
|
@Assisted initialState: UnreadMessagesState,
|
||||||
session: Session,
|
session: Session,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
appStateHandler: AppStateHandler,
|
spaceStateHandler: SpaceStateHandler,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites
|
private val autoAcceptInvites: AutoAcceptInvites
|
||||||
) :
|
) :
|
||||||
VectorViewModel<UnreadMessagesState, EmptyAction, EmptyViewEvents>(initialState) {
|
VectorViewModel<UnreadMessagesState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||||
|
@ -109,8 +109,8 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
appStateHandler.getSelectedSpaceFlow().distinctUntilChanged(),
|
spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged(),
|
||||||
appStateHandler.getSelectedSpaceFlow().flatMapLatest {
|
spaceStateHandler.getSelectedSpaceFlow().flatMapLatest {
|
||||||
roomService.getPagedRoomSummariesLive(
|
roomService.getPagedRoomSummariesLive(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
this.memberships = Membership.activeMemberships()
|
this.memberships = Membership.activeMemberships()
|
||||||
|
|
|
@ -28,7 +28,7 @@ import com.airbnb.mvrx.Uninitialized
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
|
@ -136,7 +136,7 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
private val locationSharingServiceConnection: LocationSharingServiceConnection,
|
private val locationSharingServiceConnection: LocationSharingServiceConnection,
|
||||||
private val stopLiveLocationShareUseCase: StopLiveLocationShareUseCase,
|
private val stopLiveLocationShareUseCase: StopLiveLocationShareUseCase,
|
||||||
timelineFactory: TimelineFactory,
|
timelineFactory: TimelineFactory,
|
||||||
appStateHandler: AppStateHandler,
|
spaceStateHandler: SpaceStateHandler,
|
||||||
) : VectorViewModel<RoomDetailViewState, RoomDetailAction, RoomDetailViewEvents>(initialState),
|
) : VectorViewModel<RoomDetailViewState, RoomDetailAction, RoomDetailViewEvents>(initialState),
|
||||||
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener, LocationSharingServiceConnection.Callback {
|
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener, LocationSharingServiceConnection.Callback {
|
||||||
|
|
||||||
|
@ -218,16 +218,16 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
if (initialState.switchToParentSpace) {
|
if (initialState.switchToParentSpace) {
|
||||||
// We are coming from a notification, try to switch to the most relevant space
|
// We are coming from a notification, try to switch to the most relevant space
|
||||||
// so that when hitting back the room will appear in the list
|
// so that when hitting back the room will appear in the list
|
||||||
appStateHandler.getCurrentSpace().let { currentSpace ->
|
spaceStateHandler.getCurrentSpace().let { currentSpace ->
|
||||||
val currentRoomSummary = room.roomSummary() ?: return@let
|
val currentRoomSummary = room.roomSummary() ?: return@let
|
||||||
// nothing we are good
|
// nothing we are good
|
||||||
if ((currentSpace == null && !vectorPreferences.prefSpacesShowAllRoomInHome()) ||
|
if ((currentSpace == null && !vectorPreferences.prefSpacesShowAllRoomInHome()) ||
|
||||||
(currentSpace != null && !currentRoomSummary.flattenParentIds.contains(currentSpace.roomId))) {
|
(currentSpace != null && !currentRoomSummary.flattenParentIds.contains(currentSpace.roomId))) {
|
||||||
// take first one or switch to home
|
// take first one or switch to home
|
||||||
appStateHandler.setCurrentSpace(
|
spaceStateHandler.setCurrentSpace(
|
||||||
currentRoomSummary
|
currentRoomSummary
|
||||||
.flattenParentIds.firstOrNull { it.isNotBlank() },
|
.flattenParentIds.firstOrNull { it.isNotBlank() },
|
||||||
// force persist, because if not on resume the AppStateHandler will resume
|
// force persist, because if not on resume the SpaceStateHandler will resume
|
||||||
// the current space from what was persisted on enter background
|
// the current space from what was persisted on enter background
|
||||||
persistNow = true
|
persistNow = true
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,7 @@ import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.liveData
|
import androidx.lifecycle.liveData
|
||||||
import androidx.paging.PagedList
|
import androidx.paging.PagedList
|
||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.home.RoomListDisplayMode
|
import im.vector.app.features.home.RoomListDisplayMode
|
||||||
|
@ -58,7 +58,7 @@ import timber.log.Timber
|
||||||
class RoomListSectionBuilder(
|
class RoomListSectionBuilder(
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val spaceStateHandler: SpaceStateHandler,
|
||||||
private val viewModelScope: CoroutineScope,
|
private val viewModelScope: CoroutineScope,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites,
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
|
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
|
||||||
|
@ -94,7 +94,7 @@ class RoomListSectionBuilder(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.onEach { selectedSpaceOption ->
|
.onEach { selectedSpaceOption ->
|
||||||
val selectedSpace = selectedSpaceOption.orNull()
|
val selectedSpace = selectedSpaceOption.orNull()
|
||||||
|
@ -186,7 +186,7 @@ class RoomListSectionBuilder(
|
||||||
|
|
||||||
// add suggested rooms
|
// add suggested rooms
|
||||||
val suggestedRoomsFlow = // MutableLiveData<List<SpaceChildInfo>>()
|
val suggestedRoomsFlow = // MutableLiveData<List<SpaceChildInfo>>()
|
||||||
appStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.flatMapLatest { selectedSpaceOption ->
|
.flatMapLatest { selectedSpaceOption ->
|
||||||
val selectedSpace = selectedSpaceOption.orNull()
|
val selectedSpace = selectedSpaceOption.orNull()
|
||||||
|
@ -359,7 +359,7 @@ class RoomListSectionBuilder(
|
||||||
query: (RoomSummaryQueryParams.Builder) -> Unit
|
query: (RoomSummaryQueryParams.Builder) -> Unit
|
||||||
) {
|
) {
|
||||||
withQueryParams(query) { roomQueryParams ->
|
withQueryParams(query) { roomQueryParams ->
|
||||||
val updatedQueryParams = roomQueryParams.process(spaceFilterStrategy, appStateHandler.getSafeActiveSpaceId())
|
val updatedQueryParams = roomQueryParams.process(spaceFilterStrategy, spaceStateHandler.getSafeActiveSpaceId())
|
||||||
val liveQueryParams = MutableStateFlow(updatedQueryParams)
|
val liveQueryParams = MutableStateFlow(updatedQueryParams)
|
||||||
val itemCountFlow = liveQueryParams
|
val itemCountFlow = liveQueryParams
|
||||||
.flatMapLatest {
|
.flatMapLatest {
|
||||||
|
@ -370,7 +370,7 @@ class RoomListSectionBuilder(
|
||||||
|
|
||||||
val name = stringProvider.getString(nameRes)
|
val name = stringProvider.getString(nameRes)
|
||||||
val filteredPagedRoomSummariesLive = session.roomService().getFilteredPagedRoomSummariesLive(
|
val filteredPagedRoomSummariesLive = session.roomService().getFilteredPagedRoomSummariesLive(
|
||||||
roomQueryParams.process(spaceFilterStrategy, appStateHandler.getSafeActiveSpaceId()),
|
roomQueryParams.process(spaceFilterStrategy, spaceStateHandler.getSafeActiveSpaceId()),
|
||||||
pagedListConfig
|
pagedListConfig
|
||||||
)
|
)
|
||||||
when (spaceFilterStrategy) {
|
when (spaceFilterStrategy) {
|
||||||
|
@ -417,7 +417,7 @@ class RoomListSectionBuilder(
|
||||||
RoomAggregateNotificationCount(it.size, it.size)
|
RoomAggregateNotificationCount(it.size, it.size)
|
||||||
} else {
|
} else {
|
||||||
session.roomService().getNotificationCountForRooms(
|
session.roomService().getNotificationCountForRooms(
|
||||||
roomQueryParams.process(spaceFilterStrategy, appStateHandler.getSafeActiveSpaceId())
|
roomQueryParams.process(spaceFilterStrategy, spaceStateHandler.getSafeActiveSpaceId())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ import com.airbnb.mvrx.Success
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
@ -60,7 +60,7 @@ class RoomListViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: RoomListViewState,
|
@Assisted initialState: RoomListViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
stringProvider: StringProvider,
|
stringProvider: StringProvider,
|
||||||
appStateHandler: AppStateHandler,
|
spaceStateHandler: SpaceStateHandler,
|
||||||
vectorPreferences: VectorPreferences,
|
vectorPreferences: VectorPreferences,
|
||||||
autoAcceptInvites: AutoAcceptInvites,
|
autoAcceptInvites: AutoAcceptInvites,
|
||||||
private val analyticsTracker: AnalyticsTracker
|
private val analyticsTracker: AnalyticsTracker
|
||||||
|
@ -100,7 +100,7 @@ class RoomListViewModel @AssistedInject constructor(
|
||||||
observeMembershipChanges()
|
observeMembershipChanges()
|
||||||
observeLocalRooms()
|
observeLocalRooms()
|
||||||
|
|
||||||
appStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.execute {
|
.execute {
|
||||||
copy(
|
copy(
|
||||||
|
@ -148,7 +148,7 @@ class RoomListViewModel @AssistedInject constructor(
|
||||||
private val roomListSectionBuilder = RoomListSectionBuilder(
|
private val roomListSectionBuilder = RoomListSectionBuilder(
|
||||||
session,
|
session,
|
||||||
stringProvider,
|
stringProvider,
|
||||||
appStateHandler,
|
spaceStateHandler,
|
||||||
viewModelScope,
|
viewModelScope,
|
||||||
autoAcceptInvites,
|
autoAcceptInvites,
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@ import androidx.core.app.TaskStackBuilder
|
||||||
import androidx.core.util.Pair
|
import androidx.core.util.Pair
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.error.fatalError
|
import im.vector.app.core.error.fatalError
|
||||||
|
@ -120,7 +120,7 @@ class DefaultNavigator @Inject constructor(
|
||||||
private val sessionHolder: ActiveSessionHolder,
|
private val sessionHolder: ActiveSessionHolder,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val widgetArgsBuilder: WidgetArgsBuilder,
|
private val widgetArgsBuilder: WidgetArgsBuilder,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val spaceStateHandler: SpaceStateHandler,
|
||||||
private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider,
|
private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider,
|
||||||
private val features: VectorFeatures,
|
private val features: VectorFeatures,
|
||||||
private val analyticsTracker: AnalyticsTracker
|
private val analyticsTracker: AnalyticsTracker
|
||||||
|
@ -167,7 +167,7 @@ class DefaultNavigator @Inject constructor(
|
||||||
analyticsTracker.capture(
|
analyticsTracker.capture(
|
||||||
sessionHolder.getActiveSession().getRoomSummary(roomId).toAnalyticsViewRoom(
|
sessionHolder.getActiveSession().getRoomSummary(roomId).toAnalyticsViewRoom(
|
||||||
trigger = trigger,
|
trigger = trigger,
|
||||||
selectedSpace = appStateHandler.getCurrentSpace()
|
selectedSpace = spaceStateHandler.getCurrentSpace()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ class DefaultNavigator @Inject constructor(
|
||||||
fatalError("Trying to open an unknown space $spaceId", vectorPreferences.failFast())
|
fatalError("Trying to open an unknown space $spaceId", vectorPreferences.failFast())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
appStateHandler.setCurrentSpace(spaceId)
|
spaceStateHandler.setCurrentSpace(spaceId)
|
||||||
when (postSwitchSpaceAction) {
|
when (postSwitchSpaceAction) {
|
||||||
Navigator.PostSwitchSpaceAction.None -> {
|
Navigator.PostSwitchSpaceAction.None -> {
|
||||||
// go back to home if we are showing room details?
|
// go back to home if we are showing room details?
|
||||||
|
@ -318,7 +318,7 @@ class DefaultNavigator @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openRoomDirectory(context: Context, initialFilter: String) {
|
override fun openRoomDirectory(context: Context, initialFilter: String) {
|
||||||
when (val currentSpace = appStateHandler.getCurrentSpace()) {
|
when (val currentSpace = spaceStateHandler.getCurrentSpace()) {
|
||||||
null -> RoomDirectoryActivity.getIntent(context, initialFilter)
|
null -> RoomDirectoryActivity.getIntent(context, initialFilter)
|
||||||
else -> SpaceExploreActivity.newIntent(context, currentSpace.roomId)
|
else -> SpaceExploreActivity.newIntent(context, currentSpace.roomId)
|
||||||
}.start(context)
|
}.start(context)
|
||||||
|
@ -330,14 +330,14 @@ class DefaultNavigator @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openCreateDirectRoom(context: Context) {
|
override fun openCreateDirectRoom(context: Context) {
|
||||||
when (val currentSpace = appStateHandler.getCurrentSpace()) {
|
when (val currentSpace = spaceStateHandler.getCurrentSpace()) {
|
||||||
null -> CreateDirectRoomActivity.getIntent(context)
|
null -> CreateDirectRoomActivity.getIntent(context)
|
||||||
else -> SpacePeopleActivity.newIntent(context, currentSpace.roomId)
|
else -> SpacePeopleActivity.newIntent(context, currentSpace.roomId)
|
||||||
}.start(context)
|
}.start(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openInviteUsersToRoom(context: Context, roomId: String) {
|
override fun openInviteUsersToRoom(context: Context, roomId: String) {
|
||||||
when (val currentSpace = appStateHandler.getCurrentSpace()) {
|
when (val currentSpace = spaceStateHandler.getCurrentSpace()) {
|
||||||
null -> InviteUsersToRoomActivity.getIntent(context, roomId).start(context)
|
null -> InviteUsersToRoomActivity.getIntent(context, roomId).start(context)
|
||||||
else -> showInviteToDialog(context, currentSpace, roomId)
|
else -> showInviteToDialog(context, currentSpace, roomId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import com.airbnb.mvrx.Uninitialized
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
@ -58,7 +58,7 @@ class CreateRoomViewModel @AssistedInject constructor(
|
||||||
@Assisted private val initialState: CreateRoomViewState,
|
@Assisted private val initialState: CreateRoomViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val rawService: RawService,
|
private val rawService: RawService,
|
||||||
appStateHandler: AppStateHandler,
|
spaceStateHandler: SpaceStateHandler,
|
||||||
private val analyticsTracker: AnalyticsTracker
|
private val analyticsTracker: AnalyticsTracker
|
||||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class CreateRoomViewModel @AssistedInject constructor(
|
||||||
initHomeServerName()
|
initHomeServerName()
|
||||||
initAdminE2eByDefault()
|
initAdminE2eByDefault()
|
||||||
|
|
||||||
val parentSpaceId = initialState.parentSpaceId ?: appStateHandler.getSafeActiveSpaceId()
|
val parentSpaceId = initialState.parentSpaceId ?: spaceStateHandler.getSafeActiveSpaceId()
|
||||||
|
|
||||||
val restrictedSupport = session.homeServerCapabilitiesService().getHomeServerCapabilities()
|
val restrictedSupport = session.homeServerCapabilitiesService().getHomeServerCapabilities()
|
||||||
.isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED)
|
.isFeatureSupported(HomeServerCapabilities.ROOM_CAP_RESTRICTED)
|
||||||
|
|
|
@ -23,7 +23,7 @@ import com.airbnb.mvrx.Success
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
@ -61,7 +61,7 @@ import org.matrix.android.sdk.flow.flow
|
||||||
|
|
||||||
class SpaceListViewModel @AssistedInject constructor(
|
class SpaceListViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: SpaceListViewState,
|
@Assisted initialState: SpaceListViewState,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val spaceStateHandler: SpaceStateHandler,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites,
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
|
@ -85,7 +85,7 @@ class SpaceListViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
observeSpaceSummaries()
|
observeSpaceSummaries()
|
||||||
appStateHandler.getSelectedSpaceFlow()
|
spaceStateHandler.getSelectedSpaceFlow()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.setOnEach { selectedSpaceOption ->
|
.setOnEach { selectedSpaceOption ->
|
||||||
copy(
|
copy(
|
||||||
|
@ -217,7 +217,7 @@ class SpaceListViewModel @AssistedInject constructor(
|
||||||
if (state.selectedSpace?.roomId != action.spaceSummary?.roomId) {
|
if (state.selectedSpace?.roomId != action.spaceSummary?.roomId) {
|
||||||
analyticsTracker.capture(Interaction(null, null, Interaction.Name.SpacePanelSwitchSpace))
|
analyticsTracker.capture(Interaction(null, null, Interaction.Name.SpacePanelSwitchSpace))
|
||||||
setState { copy(selectedSpace = action.spaceSummary) }
|
setState { copy(selectedSpace = action.spaceSummary) }
|
||||||
appStateHandler.setCurrentSpace(action.spaceSummary?.roomId)
|
spaceStateHandler.setCurrentSpace(action.spaceSummary?.roomId)
|
||||||
_viewEvents.post(SpaceListViewEvents.CloseDrawer)
|
_viewEvents.post(SpaceListViewEvents.CloseDrawer)
|
||||||
} else {
|
} else {
|
||||||
analyticsTracker.capture(Interaction(null, null, Interaction.Name.SpacePanelSelectedSpace))
|
analyticsTracker.capture(Interaction(null, null, Interaction.Name.SpacePanelSelectedSpace))
|
||||||
|
|
|
@ -24,7 +24,7 @@ import com.airbnb.mvrx.Uninitialized
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
|
@ -50,7 +50,7 @@ import timber.log.Timber
|
||||||
class SpaceMenuViewModel @AssistedInject constructor(
|
class SpaceMenuViewModel @AssistedInject constructor(
|
||||||
@Assisted val initialState: SpaceMenuState,
|
@Assisted val initialState: SpaceMenuState,
|
||||||
val session: Session,
|
val session: Session,
|
||||||
val appStateHandler: AppStateHandler
|
val spaceStateHandler: SpaceStateHandler
|
||||||
) : VectorViewModel<SpaceMenuState, SpaceLeaveViewAction, EmptyViewEvents>(initialState) {
|
) : VectorViewModel<SpaceMenuState, SpaceLeaveViewAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
|
@ -73,9 +73,9 @@ class SpaceMenuViewModel @AssistedInject constructor(
|
||||||
it.getOrNull()?.let {
|
it.getOrNull()?.let {
|
||||||
if (it.membership == Membership.LEAVE) {
|
if (it.membership == Membership.LEAVE) {
|
||||||
setState { copy(leavingState = Success(Unit)) }
|
setState { copy(leavingState = Success(Unit)) }
|
||||||
if (appStateHandler.getSafeActiveSpaceId() == initialState.spaceId) {
|
if (spaceStateHandler.getSafeActiveSpaceId() == initialState.spaceId) {
|
||||||
// switch to home?
|
// switch to home?
|
||||||
appStateHandler.setCurrentSpace(null, session)
|
spaceStateHandler.setCurrentSpace(null, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import com.airbnb.mvrx.Uninitialized
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.AppStateHandler
|
import im.vector.app.SpaceStateHandler
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
|
@ -53,7 +53,7 @@ import timber.log.Timber
|
||||||
class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
||||||
@Assisted val initialState: SpaceLeaveAdvanceViewState,
|
@Assisted val initialState: SpaceLeaveAdvanceViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val appStateHandler: AppStateHandler
|
private val spaceStateHandler: SpaceStateHandler
|
||||||
) : VectorViewModel<SpaceLeaveAdvanceViewState, SpaceLeaveAdvanceViewAction, EmptyViewEvents>(initialState) {
|
) : VectorViewModel<SpaceLeaveAdvanceViewState, SpaceLeaveAdvanceViewAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -82,9 +82,9 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
||||||
?.onEach {
|
?.onEach {
|
||||||
if (it.membership == Membership.LEAVE) {
|
if (it.membership == Membership.LEAVE) {
|
||||||
setState { copy(leaveState = Success(Unit)) }
|
setState { copy(leaveState = Success(Unit)) }
|
||||||
if (appStateHandler.getSafeActiveSpaceId() == initialState.spaceId) {
|
if (spaceStateHandler.getSafeActiveSpaceId() == initialState.spaceId) {
|
||||||
// switch to home?
|
// switch to home?
|
||||||
appStateHandler.setCurrentSpace(null, session)
|
spaceStateHandler.setCurrentSpace(null, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}?.launchIn(viewModelScope)
|
}?.launchIn(viewModelScope)
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
|
|
||||||
internal class AppStateHandlerImplTest {
|
internal class SpaceStateHandlerImplTest {
|
||||||
|
|
||||||
private val spaceId = "spaceId"
|
private val spaceId = "spaceId"
|
||||||
private val spaceSummary: RoomSummary = mockk()
|
private val spaceSummary: RoomSummary = mockk()
|
||||||
|
@ -43,7 +43,7 @@ internal class AppStateHandlerImplTest {
|
||||||
private val activeSessionHolder = FakeActiveSessionHolder(session)
|
private val activeSessionHolder = FakeActiveSessionHolder(session)
|
||||||
private val analyticsTracker = FakeAnalyticsTracker()
|
private val analyticsTracker = FakeAnalyticsTracker()
|
||||||
|
|
||||||
private val appStateHandler = AppStateHandlerImpl(
|
private val spaceStateHandler = SpaceStateHandlerImpl(
|
||||||
sessionDataSource.instance,
|
sessionDataSource.instance,
|
||||||
uiStateRepository,
|
uiStateRepository,
|
||||||
activeSessionHolder.instance,
|
activeSessionHolder.instance,
|
||||||
|
@ -58,39 +58,39 @@ internal class AppStateHandlerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given selected space doesn't exist, when getCurrentSpace, then return null`() {
|
fun `given selected space doesn't exist, when getCurrentSpace, then return null`() {
|
||||||
val currentSpace = appStateHandler.getCurrentSpace()
|
val currentSpace = spaceStateHandler.getCurrentSpace()
|
||||||
|
|
||||||
currentSpace shouldBe null
|
currentSpace shouldBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given selected space exists, when getCurrentSpace, then return selected space`() {
|
fun `given selected space exists, when getCurrentSpace, then return selected space`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session)
|
spaceStateHandler.setCurrentSpace(spaceId, session)
|
||||||
|
|
||||||
val currentSpace = appStateHandler.getCurrentSpace()
|
val currentSpace = spaceStateHandler.getCurrentSpace()
|
||||||
|
|
||||||
currentSpace shouldBe spaceSummary
|
currentSpace shouldBe spaceSummary
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given persistNow is true, when setCurrentSpace, then immediately persist to ui state`() {
|
fun `given persistNow is true, when setCurrentSpace, then immediately persist to ui state`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session, persistNow = true)
|
spaceStateHandler.setCurrentSpace(spaceId, session, persistNow = true)
|
||||||
|
|
||||||
uiStateRepository.verifyStoreSelectedSpace(spaceId, session)
|
uiStateRepository.verifyStoreSelectedSpace(spaceId, session)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given persistNow is false, when setCurrentSpace, then don't immediately persist to ui state`() {
|
fun `given persistNow is false, when setCurrentSpace, then don't immediately persist to ui state`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session, persistNow = false)
|
spaceStateHandler.setCurrentSpace(spaceId, session, persistNow = false)
|
||||||
|
|
||||||
uiStateRepository.verifyStoreSelectedSpace(spaceId, session, inverse = true)
|
uiStateRepository.verifyStoreSelectedSpace(spaceId, session, inverse = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given is forward navigation and no current space, when setCurrentSpace, then null added to backstack`() {
|
fun `given is forward navigation and no current space, when setCurrentSpace, then null added to backstack`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = true)
|
spaceStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = true)
|
||||||
|
|
||||||
val backstack = appStateHandler.getSpaceBackstack()
|
val backstack = spaceStateHandler.getSpaceBackstack()
|
||||||
|
|
||||||
backstack.size shouldBe 1
|
backstack.size shouldBe 1
|
||||||
backstack.first() shouldBe null
|
backstack.first() shouldBe null
|
||||||
|
@ -98,10 +98,10 @@ internal class AppStateHandlerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given is forward navigation and is in space, when setCurrentSpace, then previous space added to backstack`() {
|
fun `given is forward navigation and is in space, when setCurrentSpace, then previous space added to backstack`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = true)
|
spaceStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = true)
|
||||||
appStateHandler.setCurrentSpace("secondSpaceId", session, isForwardNavigation = true)
|
spaceStateHandler.setCurrentSpace("secondSpaceId", session, isForwardNavigation = true)
|
||||||
|
|
||||||
val backstack = appStateHandler.getSpaceBackstack()
|
val backstack = spaceStateHandler.getSpaceBackstack()
|
||||||
|
|
||||||
backstack.size shouldBe 2
|
backstack.size shouldBe 2
|
||||||
backstack shouldBeEqualTo listOf(null, spaceId)
|
backstack shouldBeEqualTo listOf(null, spaceId)
|
||||||
|
@ -109,34 +109,34 @@ internal class AppStateHandlerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given is not forward navigation, when setCurrentSpace, then previous space not added to backstack`() {
|
fun `given is not forward navigation, when setCurrentSpace, then previous space not added to backstack`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = false)
|
spaceStateHandler.setCurrentSpace(spaceId, session, isForwardNavigation = false)
|
||||||
|
|
||||||
val backstack = appStateHandler.getSpaceBackstack()
|
val backstack = spaceStateHandler.getSpaceBackstack()
|
||||||
|
|
||||||
backstack.size shouldBe 0
|
backstack.size shouldBe 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when setCurrentSpace, then space is emitted to selectedSpaceFlow`() = runTest {
|
fun `when setCurrentSpace, then space is emitted to selectedSpaceFlow`() = runTest {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session)
|
spaceStateHandler.setCurrentSpace(spaceId, session)
|
||||||
|
|
||||||
val currentSpace = appStateHandler.getSelectedSpaceFlow().first().orNull()
|
val currentSpace = spaceStateHandler.getSelectedSpaceFlow().first().orNull()
|
||||||
|
|
||||||
currentSpace shouldBeEqualTo spaceSummary
|
currentSpace shouldBeEqualTo spaceSummary
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given current space exists, when getSafeActiveSpaceId, then return current space id`() {
|
fun `given current space exists, when getSafeActiveSpaceId, then return current space id`() {
|
||||||
appStateHandler.setCurrentSpace(spaceId, session)
|
spaceStateHandler.setCurrentSpace(spaceId, session)
|
||||||
|
|
||||||
val activeSpaceId = appStateHandler.getSafeActiveSpaceId()
|
val activeSpaceId = spaceStateHandler.getSafeActiveSpaceId()
|
||||||
|
|
||||||
activeSpaceId shouldBeEqualTo spaceId
|
activeSpaceId shouldBeEqualTo spaceId
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given current space doesn't exist, when getSafeActiveSpaceId, then return current null`() {
|
fun `given current space doesn't exist, when getSafeActiveSpaceId, then return current null`() {
|
||||||
val activeSpaceId = appStateHandler.getSafeActiveSpaceId()
|
val activeSpaceId = spaceStateHandler.getSafeActiveSpaceId()
|
||||||
|
|
||||||
activeSpaceId shouldBe null
|
activeSpaceId shouldBe null
|
||||||
}
|
}
|
Loading…
Reference in New Issue