mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Add action to create new room
This commit is contained in:
parent
31ffa65fd0
commit
f89a7496aa
@ -125,7 +125,11 @@ class DefaultNavigator @Inject constructor(
|
|||||||
startActivity(context, SpaceManageActivity.newIntent(context, spaceId), false)
|
startActivity(context, SpaceManageActivity.newIntent(context, spaceId), false)
|
||||||
}
|
}
|
||||||
is Navigator.PostSwitchSpaceAction.OpenDefaultRoom -> {
|
is Navigator.PostSwitchSpaceAction.OpenDefaultRoom -> {
|
||||||
val args = RoomDetailArgs(postSwitchSpaceAction.roomId, eventId = null, openShareSpaceForId = spaceId.takeIf { postSwitchSpaceAction.showShareSheet })
|
val args = RoomDetailArgs(
|
||||||
|
postSwitchSpaceAction.roomId,
|
||||||
|
eventId = null,
|
||||||
|
openShareSpaceForId = spaceId.takeIf { postSwitchSpaceAction.showShareSheet }
|
||||||
|
)
|
||||||
val intent = RoomDetailActivity.newIntent(context, args)
|
val intent = RoomDetailActivity.newIntent(context, args)
|
||||||
startActivity(context, intent, false)
|
startActivity(context, intent, false)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,8 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class CreateRoomArgs(
|
data class CreateRoomArgs(
|
||||||
val initialName: String
|
val initialName: String,
|
||||||
|
val parentSpaceId: String? = null
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
class CreateRoomFragment @Inject constructor(
|
class CreateRoomFragment @Inject constructor(
|
||||||
|
@ -42,8 +42,9 @@ import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure
|
|||||||
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
|
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
|
||||||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
||||||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
|
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: CreateRoomViewState,
|
class CreateRoomViewModel @AssistedInject constructor(@Assisted val initialState: CreateRoomViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val rawService: RawService
|
private val rawService: RawService
|
||||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||||
@ -133,7 +134,8 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||||||
|
|
||||||
CreateRoomViewState(
|
CreateRoomViewState(
|
||||||
isEncrypted = adminE2EByDefault,
|
isEncrypted = adminE2EByDefault,
|
||||||
hsAdminHasDisabledE2E = !adminE2EByDefault
|
hsAdminHasDisabledE2E = !adminE2EByDefault,
|
||||||
|
parentSpaceId = initialState.parentSpaceId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,9 +230,21 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||||||
|
|
||||||
// TODO: Should this be non-cancellable?
|
// TODO: Should this be non-cancellable?
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val result = runCatching { session.createRoom(createRoomParams) }
|
runCatching { session.createRoom(createRoomParams) }.fold(
|
||||||
result.fold(
|
|
||||||
{ roomId ->
|
{ roomId ->
|
||||||
|
|
||||||
|
if (initialState.parentSpaceId != null) {
|
||||||
|
// add it as a child
|
||||||
|
try {
|
||||||
|
val via = session.sessionParams.homeServerHost?.let { listOf(it) } ?: emptyList()
|
||||||
|
session.spaceService()
|
||||||
|
.getSpace(initialState.parentSpaceId)
|
||||||
|
?.addChildren(roomId, viaServers = via, order = null)
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
Timber.w(failure, "Failed to add as a child")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(asyncCreateRoomRequest = Success(roomId))
|
copy(asyncCreateRoomRequest = Success(roomId))
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,13 @@ data class CreateRoomViewState(
|
|||||||
val disableFederation: Boolean = false,
|
val disableFederation: Boolean = false,
|
||||||
val homeServerName: String = "",
|
val homeServerName: String = "",
|
||||||
val hsAdminHasDisabledE2E: Boolean = false,
|
val hsAdminHasDisabledE2E: Boolean = false,
|
||||||
val asyncCreateRoomRequest: Async<String> = Uninitialized
|
val asyncCreateRoomRequest: Async<String> = Uninitialized,
|
||||||
|
val parentSpaceId: String?
|
||||||
) : MvRxState {
|
) : MvRxState {
|
||||||
|
|
||||||
constructor(args: CreateRoomArgs) : this(
|
constructor(args: CreateRoomArgs) : this(
|
||||||
roomName = args.initialName
|
roomName = args.initialName,
|
||||||
|
parentSpaceId = args.parentSpaceId
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +117,8 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
|
|||||||
}
|
}
|
||||||
|
|
||||||
views.addRooms.views.bottomSheetActionClickableZone.debouncedClicks {
|
views.addRooms.views.bottomSheetActionClickableZone.debouncedClicks {
|
||||||
startActivity(SpaceManageActivity.newIntent(requireContext(), spaceArgs.spaceId))
|
dismiss()
|
||||||
|
startActivity(SpaceManageActivity.newIntent(requireActivity(), spaceArgs.spaceId))
|
||||||
}
|
}
|
||||||
|
|
||||||
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks {
|
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks {
|
||||||
|
@ -112,9 +112,9 @@ class SpaceAddRoomFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
}.disposeOnDestroyView()
|
}.disposeOnDestroyView()
|
||||||
|
|
||||||
// views.createNewRoom.debouncedClicks {
|
views.createNewRoom.debouncedClicks {
|
||||||
// sharedActionViewModel.post(RoomDirectorySharedAction.CreateRoom)
|
sharedViewModel.handle(SpaceManagedSharedAction.CreateRoom)
|
||||||
// }
|
}
|
||||||
|
|
||||||
viewModel.observeViewEvents {
|
viewModel.observeViewEvents {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -25,9 +25,14 @@ import com.airbnb.mvrx.MvRx
|
|||||||
import com.airbnb.mvrx.viewModel
|
import com.airbnb.mvrx.viewModel
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ScreenComponent
|
import im.vector.app.core.di.ScreenComponent
|
||||||
|
import im.vector.app.core.extensions.addFragmentToBackstack
|
||||||
import im.vector.app.core.extensions.commitTransaction
|
import im.vector.app.core.extensions.commitTransaction
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.databinding.ActivitySimpleBinding
|
import im.vector.app.databinding.ActivitySimpleBinding
|
||||||
|
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
|
||||||
|
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
||||||
|
import im.vector.app.features.roomdirectory.createroom.CreateRoomArgs
|
||||||
|
import im.vector.app.features.roomdirectory.createroom.CreateRoomFragment
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -39,6 +44,7 @@ data class SpaceManageArgs(
|
|||||||
class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceManageSharedViewModel.Factory {
|
class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceManageSharedViewModel.Factory {
|
||||||
|
|
||||||
@Inject lateinit var sharedViewModelFactory: SpaceManageSharedViewModel.Factory
|
@Inject lateinit var sharedViewModelFactory: SpaceManageSharedViewModel.Factory
|
||||||
|
private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel
|
||||||
|
|
||||||
override fun injectWith(injector: ScreenComponent) {
|
override fun injectWith(injector: ScreenComponent) {
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
@ -53,9 +59,20 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceMa
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
sharedDirectoryActionViewModel = viewModelProvider.get(RoomDirectorySharedActionViewModel::class.java)
|
||||||
|
sharedDirectoryActionViewModel
|
||||||
|
.observe()
|
||||||
|
.subscribe { sharedAction ->
|
||||||
|
when (sharedAction) {
|
||||||
|
is RoomDirectorySharedAction.Back,
|
||||||
|
is RoomDirectorySharedAction.Close -> finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.disposeOnDestroy()
|
||||||
|
|
||||||
|
val args = intent?.getParcelableExtra<SpaceManageArgs>(MvRx.KEY_ARG)
|
||||||
if (isFirstCreation()) {
|
if (isFirstCreation()) {
|
||||||
val simpleName = SpaceAddRoomFragment::class.java.simpleName
|
val simpleName = SpaceAddRoomFragment::class.java.simpleName
|
||||||
val args = intent?.getParcelableExtra<SpaceManageArgs>(MvRx.KEY_ARG)
|
|
||||||
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
|
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
|
||||||
supportFragmentManager.commitTransaction {
|
supportFragmentManager.commitTransaction {
|
||||||
replace(R.id.simpleFragmentContainer,
|
replace(R.id.simpleFragmentContainer,
|
||||||
@ -78,6 +95,13 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceMa
|
|||||||
SpaceManagedSharedViewEvents.ShowLoading -> {
|
SpaceManagedSharedViewEvents.ShowLoading -> {
|
||||||
views.simpleActivityWaitingView.isVisible = true
|
views.simpleActivityWaitingView.isVisible = true
|
||||||
}
|
}
|
||||||
|
SpaceManagedSharedViewEvents.NavigateToCreateRoom -> {
|
||||||
|
addFragmentToBackstack(
|
||||||
|
R.id.simpleFragmentContainer,
|
||||||
|
CreateRoomFragment::class.java,
|
||||||
|
CreateRoomArgs("", parentSpaceId = args?.spaceId)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ class SpaceManageSharedViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
SpaceManagedSharedAction.HideLoading -> _viewEvents.post(SpaceManagedSharedViewEvents.HideLoading)
|
SpaceManagedSharedAction.HideLoading -> _viewEvents.post(SpaceManagedSharedViewEvents.HideLoading)
|
||||||
SpaceManagedSharedAction.ShowLoading -> _viewEvents.post(SpaceManagedSharedViewEvents.ShowLoading)
|
SpaceManagedSharedAction.ShowLoading -> _viewEvents.post(SpaceManagedSharedViewEvents.ShowLoading)
|
||||||
|
SpaceManagedSharedAction.CreateRoom -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToCreateRoom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,5 @@ sealed class SpaceManagedSharedAction : VectorViewModelAction {
|
|||||||
object HandleBack : SpaceManagedSharedAction()
|
object HandleBack : SpaceManagedSharedAction()
|
||||||
object ShowLoading : SpaceManagedSharedAction()
|
object ShowLoading : SpaceManagedSharedAction()
|
||||||
object HideLoading : SpaceManagedSharedAction()
|
object HideLoading : SpaceManagedSharedAction()
|
||||||
|
object CreateRoom : SpaceManagedSharedAction()
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,5 @@ sealed class SpaceManagedSharedViewEvents : VectorViewEvents {
|
|||||||
object Finish : SpaceManagedSharedViewEvents()
|
object Finish : SpaceManagedSharedViewEvents()
|
||||||
object ShowLoading : SpaceManagedSharedViewEvents()
|
object ShowLoading : SpaceManagedSharedViewEvents()
|
||||||
object HideLoading : SpaceManagedSharedViewEvents()
|
object HideLoading : SpaceManagedSharedViewEvents()
|
||||||
|
object NavigateToCreateRoom : SpaceManagedSharedViewEvents()
|
||||||
}
|
}
|
||||||
|
@ -82,21 +82,21 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar"
|
app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar"
|
||||||
app:queryHint="@string/search_hint_room_name" />
|
app:queryHint="@string/search_hint_room_name" />
|
||||||
|
|
||||||
<!-- <com.google.android.material.button.MaterialButton-->
|
<com.google.android.material.button.MaterialButton
|
||||||
<!-- android:id="@+id/createNewRoom"-->
|
android:id="@+id/createNewRoom"
|
||||||
<!-- style="@style/VectorButtonStyleText"-->
|
style="@style/VectorButtonStyleText"
|
||||||
<!-- android:layout_width="wrap_content"-->
|
android:layout_width="wrap_content"
|
||||||
<!-- android:layout_height="wrap_content"-->
|
android:layout_height="wrap_content"
|
||||||
<!-- android:layout_marginStart="16dp"-->
|
android:layout_marginStart="16dp"
|
||||||
<!-- android:layout_marginTop="8dp"-->
|
android:layout_marginTop="8dp"
|
||||||
<!-- android:layout_marginBottom="8dp"-->
|
android:layout_marginBottom="8dp"
|
||||||
<!-- android:minHeight="@dimen/layout_touch_size"-->
|
android:minHeight="@dimen/layout_touch_size"
|
||||||
<!-- android:text="@string/create_new_room"-->
|
android:text="@string/create_new_room"
|
||||||
<!-- app:icon="@drawable/ic_plus_circle"-->
|
app:icon="@drawable/ic_plus_circle"
|
||||||
<!-- app:iconPadding="13dp"-->
|
app:iconPadding="13dp"
|
||||||
<!-- app:iconTint="@color/riotx_accent"-->
|
app:iconTint="@color/riotx_accent"
|
||||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
<!-- app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar" />-->
|
app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user