diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt new file mode 100644 index 0000000000..8adfbae3bd --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces + +import im.vector.app.core.platform.VectorViewModelAction +import org.matrix.android.sdk.api.session.room.model.RoomSummary + +sealed class SpaceListAction : VectorViewModelAction { + data class SelectSpace(val spaceSummary: RoomSummary) : SpaceListAction() + data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction() + data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction() + object AddSpace : SpaceListAction() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewEvents.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewEvents.kt new file mode 100644 index 0000000000..7f05172cd1 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewEvents.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces + +import im.vector.app.core.platform.VectorViewEvents + +/** + * Transient events for group list screen + */ +sealed class SpaceListViewEvents : VectorViewEvents { + object OpenSpace : SpaceListViewEvents() + data class OpenSpaceSummary(val id: String) : SpaceListViewEvents() + object AddSpace : SpaceListViewEvents() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewState.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewState.kt new file mode 100644 index 0000000000..cd578bce11 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewState.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces + +import com.airbnb.mvrx.Async +import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Uninitialized +import org.matrix.android.sdk.api.session.room.model.RoomSummary + +data class SpaceListViewState( + val asyncSpaces: Async> = Uninitialized, + val selectedSpace: RoomSummary? = null, + val rootSpaces: List? = null, + val expandedStates: Map = emptyMap() +) : MvRxState diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt index 8c13584b43..f21f51a57e 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt @@ -18,19 +18,14 @@ package im.vector.app.features.spaces import androidx.lifecycle.viewModelScope import arrow.core.Option -import com.airbnb.mvrx.Async import com.airbnb.mvrx.FragmentViewModelContext -import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory -import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.R -import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewModel -import im.vector.app.core.platform.VectorViewModelAction import im.vector.app.core.resources.StringProvider import im.vector.app.features.grouplist.SelectedSpaceDataSource import im.vector.app.features.ui.UiStateRepository @@ -48,29 +43,6 @@ import org.matrix.android.sdk.rx.rx const val ALL_COMMUNITIES_GROUP_ID = "+ALL_COMMUNITIES_GROUP_ID" -sealed class SpaceListAction : VectorViewModelAction { - data class SelectSpace(val spaceSummary: RoomSummary) : SpaceListAction() - data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction() - data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction() - object AddSpace : SpaceListAction() -} - -/** - * Transient events for group list screen - */ -sealed class SpaceListViewEvents : VectorViewEvents { - object OpenSpace : SpaceListViewEvents() - data class OpenSpaceSummary(val id: String) : SpaceListViewEvents() - object AddSpace : SpaceListViewEvents() -} - -data class SpaceListViewState( - val asyncSpaces: Async> = Uninitialized, - val selectedSpace: RoomSummary? = null, - val rootSpaces: List? = null, - val expandedStates: Map = emptyMap() -) : MvRxState - class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState, private val selectedSpaceDataSource: SelectedSpaceDataSource, private val session: Session, diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceAction.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceAction.kt new file mode 100644 index 0000000000..14f219ffc4 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceAction.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.create + +import android.net.Uri +import im.vector.app.core.platform.VectorViewModelAction + +sealed class CreateSpaceAction : VectorViewModelAction { + data class SetRoomType(val type: SpaceType) : CreateSpaceAction() + data class NameChanged(val name: String) : CreateSpaceAction() + data class TopicChanged(val topic: String) : CreateSpaceAction() + data class SetAvatar(val uri: Uri?) : CreateSpaceAction() + object OnBackPressed : CreateSpaceAction() + object NextFromDetails : CreateSpaceAction() + object NextFromDefaultRooms : CreateSpaceAction() + data class DefaultRoomNameChanged(val index: Int, val name: String) : CreateSpaceAction() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceEvents.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceEvents.kt new file mode 100644 index 0000000000..d89c24e5d0 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceEvents.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.create + +import im.vector.app.core.platform.VectorViewEvents + +sealed class CreateSpaceEvents : VectorViewEvents { + object NavigateToDetails : CreateSpaceEvents() + object NavigateToChooseType : CreateSpaceEvents() + object NavigateToAddRooms : CreateSpaceEvents() + object Dismiss : CreateSpaceEvents() + data class FinishSuccess(val spaceId: String, val defaultRoomId: String?) : CreateSpaceEvents() + data class ShowModalError(val errorMessage: String) : CreateSpaceEvents() + object HideModalLoading : CreateSpaceEvents() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt new file mode 100644 index 0000000000..5449385610 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceState.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.create + +import android.net.Uri +import com.airbnb.mvrx.Async +import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Uninitialized + +data class CreateSpaceState( + val name: String? = null, + val avatarUri: Uri? = null, + val topic: String = "", + val step: Step = Step.ChooseType, + val spaceType: SpaceType? = null, + val nameInlineError: String? = null, + val defaultRooms: Map? = null, + val creationResult: Async = Uninitialized +) : MvRxState { + + enum class Step { + ChooseType, + SetDetails, + AddRooms + } +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt index 9988bbe003..18cccbe62a 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/create/CreateSpaceViewModel.kt @@ -16,17 +16,13 @@ package im.vector.app.features.spaces.create -import android.net.Uri import androidx.lifecycle.viewModelScope import com.airbnb.mvrx.ActivityViewModelContext -import com.airbnb.mvrx.Async import com.airbnb.mvrx.Fail import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.Loading -import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.Success -import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory @@ -34,61 +30,13 @@ import dagger.assisted.AssistedInject import im.vector.app.R import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.extensions.exhaustive -import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewModel -import im.vector.app.core.platform.VectorViewModelAction import im.vector.app.core.resources.StringProvider import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import org.matrix.android.sdk.api.session.Session - -data class CreateSpaceState( - val name: String? = null, - val avatarUri: Uri? = null, - val topic: String = "", - val step: Step = Step.ChooseType, - val spaceType: SpaceType? = null, - val nameInlineError: String? = null, - val defaultRooms: Map? = null, - val creationResult: Async = Uninitialized -) : MvRxState { - - enum class Step { - ChooseType, - SetDetails, - AddRooms - } -} - -enum class SpaceType { - Public, - Private -} - -sealed class CreateSpaceAction : VectorViewModelAction { - data class SetRoomType(val type: SpaceType) : CreateSpaceAction() - data class NameChanged(val name: String) : CreateSpaceAction() - data class TopicChanged(val topic: String) : CreateSpaceAction() - data class SetAvatar(val uri: Uri?) : CreateSpaceAction() - object OnBackPressed : CreateSpaceAction() - object NextFromDetails : CreateSpaceAction() - object NextFromDefaultRooms : CreateSpaceAction() - data class DefaultRoomNameChanged(val index: Int, val name: String) : CreateSpaceAction() -} - -sealed class CreateSpaceEvents : VectorViewEvents { - object NavigateToDetails : CreateSpaceEvents() - object NavigateToChooseType : CreateSpaceEvents() - object NavigateToAddRooms : CreateSpaceEvents() - object Dismiss : CreateSpaceEvents() - data class FinishSuccess(val spaceId: String, val defaultRoomId: String?) : CreateSpaceEvents() - data class ShowModalError(val errorMessage: String) : CreateSpaceEvents() - object HideModalLoading : CreateSpaceEvents() -} class CreateSpaceViewModel @AssistedInject constructor( @Assisted initialState: CreateSpaceState, - private val session: Session, private val stringProvider: StringProvider, private val createSpaceViewModelTask: CreateSpaceViewModelTask, private val errorFormatter: ErrorFormatter diff --git a/vector/src/main/java/im/vector/app/features/spaces/create/SpaceType.kt b/vector/src/main/java/im/vector/app/features/spaces/create/SpaceType.kt new file mode 100644 index 0000000000..7df036de46 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/create/SpaceType.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.create + +enum class SpaceType { + Public, + Private +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryState.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryState.kt new file mode 100644 index 0000000000..75adc659d5 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryState.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.explore + +import com.airbnb.mvrx.Async +import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Uninitialized +import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState +import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo + +data class SpaceDirectoryState( + // The current filter + val spaceId: String, + val currentFilter: String = "", + val spaceSummary: Async = Uninitialized, + val spaceSummaryApiResult: Async> = Uninitialized, + val childList: List = emptyList(), + val hierarchyStack: List = emptyList(), + // True if more result are available server side + val hasMore: Boolean = false, + // Set of joined roomId / spaces, + val joinedRoomsIds: Set = emptySet(), + // keys are room alias or roomId + val changeMembershipStates: Map = emptyMap() +) : MvRxState { + constructor(args: SpaceDirectoryArgs) : this( + spaceId = args.spaceId + ) +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewAction.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewAction.kt new file mode 100644 index 0000000000..a74662759e --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewAction.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.explore + +import im.vector.app.core.platform.VectorViewModelAction +import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo + +sealed class SpaceDirectoryViewAction : VectorViewModelAction { + data class ExploreSubSpace(val spaceChildInfo: SpaceChildInfo) : SpaceDirectoryViewAction() + data class JoinOrOpen(val spaceChildInfo: SpaceChildInfo) : SpaceDirectoryViewAction() + object HandleBack : SpaceDirectoryViewAction() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewEvents.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewEvents.kt new file mode 100644 index 0000000000..ef6f5385d3 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewEvents.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.spaces.explore + +import im.vector.app.core.platform.VectorViewEvents + +sealed class SpaceDirectoryViewEvents : VectorViewEvents { + object Dismiss : SpaceDirectoryViewEvents() + data class NavigateToRoom(val roomId: String) : SpaceDirectoryViewEvents() +} diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt index 107ce9ee19..2ba4d4101a 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt @@ -18,27 +18,20 @@ package im.vector.app.features.spaces.explore import androidx.lifecycle.viewModelScope import com.airbnb.mvrx.ActivityViewModelContext -import com.airbnb.mvrx.Async import com.airbnb.mvrx.Fail import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.Loading -import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.Success -import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewModel -import im.vector.app.core.platform.VectorViewModelAction import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.Session -import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.Membership -import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams @@ -46,37 +39,6 @@ import org.matrix.android.sdk.internal.util.awaitCallback import org.matrix.android.sdk.rx.rx import timber.log.Timber -data class SpaceDirectoryState( - // The current filter - val spaceId: String, - val currentFilter: String = "", - val spaceSummary: Async = Uninitialized, - val spaceSummaryApiResult: Async> = Uninitialized, - val childList: List = emptyList(), - val hierarchyStack: List = emptyList(), - // True if more result are available server side - val hasMore: Boolean = false, - // Set of joined roomId / spaces, - val joinedRoomsIds: Set = emptySet(), - // keys are room alias or roomId - val changeMembershipStates: Map = emptyMap() -) : MvRxState { - constructor(args: SpaceDirectoryArgs) : this( - spaceId = args.spaceId - ) -} - -sealed class SpaceDirectoryViewAction : VectorViewModelAction { - data class ExploreSubSpace(val spaceChildInfo: SpaceChildInfo) : SpaceDirectoryViewAction() - data class JoinOrOpen(val spaceChildInfo: SpaceChildInfo) : SpaceDirectoryViewAction() - object HandleBack : SpaceDirectoryViewAction() -} - -sealed class SpaceDirectoryViewEvents : VectorViewEvents { - object Dismiss : SpaceDirectoryViewEvents() - data class NavigateToRoom(val roomId: String) : SpaceDirectoryViewEvents() -} - class SpaceDirectoryViewModel @AssistedInject constructor( @Assisted initialState: SpaceDirectoryState, private val session: Session