mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +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)
|
||||
}
|
||||
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)
|
||||
startActivity(context, intent, false)
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ import javax.inject.Inject
|
||||
|
||||
@Parcelize
|
||||
data class CreateRoomArgs(
|
||||
val initialName: String
|
||||
val initialName: String,
|
||||
val parentSpaceId: String? = null
|
||||
) : Parcelable
|
||||
|
||||
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.create.CreateRoomParams
|
||||
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 rawService: RawService
|
||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||
@ -133,7 +134,8 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
||||
|
||||
CreateRoomViewState(
|
||||
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?
|
||||
viewModelScope.launch {
|
||||
val result = runCatching { session.createRoom(createRoomParams) }
|
||||
result.fold(
|
||||
runCatching { session.createRoom(createRoomParams) }.fold(
|
||||
{ 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 {
|
||||
copy(asyncCreateRoomRequest = Success(roomId))
|
||||
}
|
||||
|
@ -32,11 +32,13 @@ data class CreateRoomViewState(
|
||||
val disableFederation: Boolean = false,
|
||||
val homeServerName: String = "",
|
||||
val hsAdminHasDisabledE2E: Boolean = false,
|
||||
val asyncCreateRoomRequest: Async<String> = Uninitialized
|
||||
val asyncCreateRoomRequest: Async<String> = Uninitialized,
|
||||
val parentSpaceId: String?
|
||||
) : MvRxState {
|
||||
|
||||
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 {
|
||||
startActivity(SpaceManageActivity.newIntent(requireContext(), spaceArgs.spaceId))
|
||||
dismiss()
|
||||
startActivity(SpaceManageActivity.newIntent(requireActivity(), spaceArgs.spaceId))
|
||||
}
|
||||
|
||||
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks {
|
||||
|
@ -112,9 +112,9 @@ class SpaceAddRoomFragment @Inject constructor(
|
||||
}
|
||||
}.disposeOnDestroyView()
|
||||
|
||||
// views.createNewRoom.debouncedClicks {
|
||||
// sharedActionViewModel.post(RoomDirectorySharedAction.CreateRoom)
|
||||
// }
|
||||
views.createNewRoom.debouncedClicks {
|
||||
sharedViewModel.handle(SpaceManagedSharedAction.CreateRoom)
|
||||
}
|
||||
|
||||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
|
@ -25,9 +25,14 @@ import com.airbnb.mvrx.MvRx
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import im.vector.app.R
|
||||
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.platform.VectorBaseActivity
|
||||
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 javax.inject.Inject
|
||||
|
||||
@ -39,6 +44,7 @@ data class SpaceManageArgs(
|
||||
class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceManageSharedViewModel.Factory {
|
||||
|
||||
@Inject lateinit var sharedViewModelFactory: SpaceManageSharedViewModel.Factory
|
||||
private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel
|
||||
|
||||
override fun injectWith(injector: ScreenComponent) {
|
||||
injector.inject(this)
|
||||
@ -53,9 +59,20 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceMa
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
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()) {
|
||||
val simpleName = SpaceAddRoomFragment::class.java.simpleName
|
||||
val args = intent?.getParcelableExtra<SpaceManageArgs>(MvRx.KEY_ARG)
|
||||
if (supportFragmentManager.findFragmentByTag(simpleName) == null) {
|
||||
supportFragmentManager.commitTransaction {
|
||||
replace(R.id.simpleFragmentContainer,
|
||||
@ -78,6 +95,13 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleBinding>(), SpaceMa
|
||||
SpaceManagedSharedViewEvents.ShowLoading -> {
|
||||
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.ShowLoading -> _viewEvents.post(SpaceManagedSharedViewEvents.ShowLoading)
|
||||
SpaceManagedSharedAction.CreateRoom -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToCreateRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,5 @@ sealed class SpaceManagedSharedAction : VectorViewModelAction {
|
||||
object HandleBack : SpaceManagedSharedAction()
|
||||
object ShowLoading : SpaceManagedSharedAction()
|
||||
object HideLoading : SpaceManagedSharedAction()
|
||||
object CreateRoom : SpaceManagedSharedAction()
|
||||
}
|
||||
|
@ -22,4 +22,5 @@ sealed class SpaceManagedSharedViewEvents : VectorViewEvents {
|
||||
object Finish : SpaceManagedSharedViewEvents()
|
||||
object ShowLoading : SpaceManagedSharedViewEvents()
|
||||
object HideLoading : SpaceManagedSharedViewEvents()
|
||||
object NavigateToCreateRoom : SpaceManagedSharedViewEvents()
|
||||
}
|
||||
|
@ -82,21 +82,21 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar"
|
||||
app:queryHint="@string/search_hint_room_name" />
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- android:id="@+id/createNewRoom"-->
|
||||
<!-- style="@style/VectorButtonStyleText"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="16dp"-->
|
||||
<!-- android:layout_marginTop="8dp"-->
|
||||
<!-- android:layout_marginBottom="8dp"-->
|
||||
<!-- android:minHeight="@dimen/layout_touch_size"-->
|
||||
<!-- android:text="@string/create_new_room"-->
|
||||
<!-- app:icon="@drawable/ic_plus_circle"-->
|
||||
<!-- app:iconPadding="13dp"-->
|
||||
<!-- app:iconTint="@color/riotx_accent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar" />-->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/createNewRoom"
|
||||
style="@style/VectorButtonStyleText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:minHeight="@dimen/layout_touch_size"
|
||||
android:text="@string/create_new_room"
|
||||
app:icon="@drawable/ic_plus_circle"
|
||||
app:iconPadding="13dp"
|
||||
app:iconTint="@color/riotx_accent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/addRoomToSpaceToolbar" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user