Fixes space header showing "Empty Space" after switching to newly created space
This commit is contained in:
parent
fc301c8a2e
commit
2fb794dd59
|
@ -42,12 +42,14 @@ interface SpaceStateHandler : DefaultLifecycleObserver {
|
|||
* @param session the current active session
|
||||
* @param persistNow if true, the current space will immediately be persisted in shared prefs
|
||||
* @param isForwardNavigation whether this navigation is a forward action to properly handle backstack
|
||||
* @param overriddenSpaceName overrides the display name of the space being set
|
||||
*/
|
||||
fun setCurrentSpace(
|
||||
spaceId: String?,
|
||||
session: Session? = null,
|
||||
persistNow: Boolean = false,
|
||||
isForwardNavigation: Boolean = true,
|
||||
overriddenSpaceName: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,10 +72,13 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||
session: Session?,
|
||||
persistNow: Boolean,
|
||||
isForwardNavigation: Boolean,
|
||||
overriddenSpaceName: String?,
|
||||
) {
|
||||
val activeSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||
val spaceToLeave = selectedSpaceDataSource.currentValue?.orNull()
|
||||
val spaceToSet = spaceId?.let { activeSession.getRoomSummary(spaceId) }
|
||||
val spaceToSet = spaceId?.let { activeSession.getRoomSummary(spaceId) }?.let {
|
||||
if (overriddenSpaceName != null) it.copy(displayName = overriddenSpaceName) else it
|
||||
}
|
||||
val sameSpaceSelected = spaceId == spaceToLeave?.roomId
|
||||
|
||||
if (sameSpaceSelected) {
|
||||
|
|
|
@ -55,6 +55,8 @@ import im.vector.app.features.analytics.plan.MobileScreen
|
|||
import im.vector.app.features.analytics.plan.ViewRoom
|
||||
import im.vector.app.features.crypto.recover.SetupMode
|
||||
import im.vector.app.features.disclaimer.showDisclaimerDialog
|
||||
import im.vector.app.features.home.room.list.actions.RoomListSharedAction
|
||||
import im.vector.app.features.home.room.list.actions.RoomListSharedActionViewModel
|
||||
import im.vector.app.features.matrixto.MatrixToBottomSheet
|
||||
import im.vector.app.features.matrixto.OriginOfMatrixTo
|
||||
import im.vector.app.features.navigation.Navigator
|
||||
|
@ -110,6 +112,7 @@ class HomeActivity :
|
|||
VectorMenuProvider {
|
||||
|
||||
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
|
||||
private lateinit var roomListSharedActionViewModel: RoomListSharedActionViewModel
|
||||
|
||||
private val homeActivityViewModel: HomeActivityViewModel by viewModel()
|
||||
|
||||
|
@ -139,6 +142,7 @@ class HomeActivity :
|
|||
private val createSpaceResultLauncher = registerStartForActivityResult { activityResult ->
|
||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||
val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data)
|
||||
val spaceName = SpaceCreationActivity.getCreatedSpaceName(activityResult.data)
|
||||
val defaultRoomId = SpaceCreationActivity.getDefaultRoomId(activityResult.data)
|
||||
val isJustMe = SpaceCreationActivity.isJustMeSpace(activityResult.data)
|
||||
views.drawerLayout.closeDrawer(GravityCompat.START)
|
||||
|
@ -155,8 +159,10 @@ class HomeActivity :
|
|||
navigator.switchToSpace(
|
||||
context = this,
|
||||
spaceId = spaceId,
|
||||
postSwitchOption
|
||||
postSwitchOption,
|
||||
overriddenSpaceName = spaceName,
|
||||
)
|
||||
roomListSharedActionViewModel.post(RoomListSharedAction.CloseBottomSheet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,6 +211,7 @@ class HomeActivity :
|
|||
}
|
||||
}
|
||||
sharedActionViewModel = viewModelProvider[HomeSharedActionViewModel::class.java]
|
||||
roomListSharedActionViewModel = viewModelProvider[RoomListSharedActionViewModel::class.java]
|
||||
views.drawerLayout.addDrawerListener(drawerListener)
|
||||
if (isFirstCreation()) {
|
||||
if (vectorFeatures.isNewAppLayoutEnabled()) {
|
||||
|
|
|
@ -177,12 +177,17 @@ class DefaultNavigator @Inject constructor(
|
|||
startActivity(context, intent, buildTask)
|
||||
}
|
||||
|
||||
override fun switchToSpace(context: Context, spaceId: String, postSwitchSpaceAction: Navigator.PostSwitchSpaceAction) {
|
||||
override fun switchToSpace(
|
||||
context: Context,
|
||||
spaceId: String,
|
||||
postSwitchSpaceAction: Navigator.PostSwitchSpaceAction,
|
||||
overriddenSpaceName: String?,
|
||||
) {
|
||||
if (sessionHolder.getSafeActiveSession()?.getRoomSummary(spaceId) == null) {
|
||||
fatalError("Trying to open an unknown space $spaceId", vectorPreferences.failFast())
|
||||
return
|
||||
}
|
||||
spaceStateHandler.setCurrentSpace(spaceId)
|
||||
spaceStateHandler.setCurrentSpace(spaceId, overriddenSpaceName = overriddenSpaceName)
|
||||
when (postSwitchSpaceAction) {
|
||||
Navigator.PostSwitchSpaceAction.None -> {
|
||||
// go back to home if we are showing room details?
|
||||
|
|
|
@ -68,7 +68,12 @@ interface Navigator {
|
|||
data class OpenDefaultRoom(val roomId: String, val showShareSheet: Boolean) : PostSwitchSpaceAction()
|
||||
}
|
||||
|
||||
fun switchToSpace(context: Context, spaceId: String, postSwitchSpaceAction: PostSwitchSpaceAction)
|
||||
fun switchToSpace(
|
||||
context: Context,
|
||||
spaceId: String,
|
||||
postSwitchSpaceAction: PostSwitchSpaceAction,
|
||||
overriddenSpaceName: String? = null,
|
||||
)
|
||||
|
||||
fun openSpacePreview(context: Context, spaceId: String)
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ class SpaceCreationActivity : SimpleFragmentActivity() {
|
|||
is CreateSpaceEvents.FinishSuccess -> {
|
||||
setResult(RESULT_OK, Intent().apply {
|
||||
putExtra(RESULT_DATA_CREATED_SPACE_ID, it.spaceId)
|
||||
putExtra(RESULT_DATA_CREATED_SPACE_NAME, it.spaceName)
|
||||
putExtra(RESULT_DATA_DEFAULT_ROOM_ID, it.defaultRoomId)
|
||||
putExtra(RESULT_DATA_CREATED_SPACE_IS_JUST_ME, it.topology == SpaceTopology.JustMe)
|
||||
})
|
||||
|
@ -159,6 +160,7 @@ class SpaceCreationActivity : SimpleFragmentActivity() {
|
|||
|
||||
companion object {
|
||||
private const val RESULT_DATA_CREATED_SPACE_ID = "RESULT_DATA_CREATED_SPACE_ID"
|
||||
private const val RESULT_DATA_CREATED_SPACE_NAME = "RESULT_DATA_CREATED_SPACE_NAME"
|
||||
private const val RESULT_DATA_DEFAULT_ROOM_ID = "RESULT_DATA_DEFAULT_ROOM_ID"
|
||||
private const val RESULT_DATA_CREATED_SPACE_IS_JUST_ME = "RESULT_DATA_CREATED_SPACE_IS_JUST_ME"
|
||||
|
||||
|
@ -172,6 +174,10 @@ class SpaceCreationActivity : SimpleFragmentActivity() {
|
|||
return data?.extras?.getString(RESULT_DATA_CREATED_SPACE_ID)
|
||||
}
|
||||
|
||||
fun getCreatedSpaceName(data: Intent?): String? {
|
||||
return data?.extras?.getString(RESULT_DATA_CREATED_SPACE_NAME)
|
||||
}
|
||||
|
||||
fun getDefaultRoomId(data: Intent?): String? {
|
||||
return data?.extras?.getString(RESULT_DATA_DEFAULT_ROOM_ID)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ sealed class CreateSpaceEvents : VectorViewEvents {
|
|||
object NavigateToAdd3Pid : CreateSpaceEvents()
|
||||
object NavigateToChoosePrivateType : CreateSpaceEvents()
|
||||
object Dismiss : CreateSpaceEvents()
|
||||
data class FinishSuccess(val spaceId: String, val defaultRoomId: String?, val topology: SpaceTopology?) : CreateSpaceEvents()
|
||||
data class FinishSuccess(val spaceId: String, val spaceName: String, val defaultRoomId: String?, val topology: SpaceTopology?) : CreateSpaceEvents()
|
||||
data class ShowModalError(val errorMessage: String) : CreateSpaceEvents()
|
||||
object HideModalLoading : CreateSpaceEvents()
|
||||
data class ShowModalLoading(val message: String?) : CreateSpaceEvents()
|
||||
|
|
|
@ -380,6 +380,7 @@ class CreateSpaceViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(
|
||||
CreateSpaceEvents.FinishSuccess(
|
||||
result.spaceId,
|
||||
spaceName,
|
||||
result.childIds.firstOrNull(),
|
||||
state.spaceTopology
|
||||
)
|
||||
|
@ -393,6 +394,7 @@ class CreateSpaceViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(
|
||||
CreateSpaceEvents.FinishSuccess(
|
||||
result.spaceId,
|
||||
spaceName,
|
||||
result.childIds.firstOrNull(),
|
||||
state.spaceTopology
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue