diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index e6aae879a5..e6ff828ef4 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -137,6 +137,7 @@ class HomeDetailFragment @Inject constructor( } is RoomGroupingMethod.BySpace -> { onSpaceChange(roomGroupingMethod.spaceSummary) + sharedActionViewModel.space.value = roomGroupingMethod.spaceSummary } } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeSharedActionViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeSharedActionViewModel.kt index b695f48ee5..7605b46d09 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeSharedActionViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeSharedActionViewModel.kt @@ -16,8 +16,13 @@ package im.vector.app.features.home +import androidx.lifecycle.MutableLiveData import im.vector.app.core.platform.VectorSharedActionViewModel import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.room.model.RoomSummary import javax.inject.Inject -class HomeSharedActionViewModel @Inject constructor(val session: Session) : VectorSharedActionViewModel() +class HomeSharedActionViewModel @Inject constructor(val session: Session) : VectorSharedActionViewModel() { + + val space = MutableLiveData() +} diff --git a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt index ad4ffc9098..7c80348e5f 100644 --- a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt @@ -24,10 +24,14 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import dagger.hilt.android.AndroidEntryPoint +import im.vector.app.core.extensions.observeNotNull import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentSpaceListModalBinding import im.vector.app.features.spaces.SpaceListAction import im.vector.app.features.spaces.SpaceListViewModel +import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.util.MatrixItem +import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @AndroidEntryPoint @@ -52,6 +56,7 @@ class SpaceListModalFragment : VectorBaseFragment sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) setupRecyclerView() setupAddSpace() + observeSpaceChange() } private fun setupRecyclerView() { @@ -70,6 +75,10 @@ class SpaceListModalFragment : VectorBaseFragment } } + private fun observeSpaceChange() = sharedActionViewModel.space.observeNotNull(viewLifecycleOwner) { + viewModel.setSpace(it) + } + override fun invalidate() { withState(viewModel) { state -> state.rootSpacesOrdered?.let { diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index 52b6cc0749..de2aba6f43 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -17,6 +17,7 @@ package im.vector.app.features.spaces import androidx.lifecycle.asFlow +import com.airbnb.mvrx.Async import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success @@ -54,6 +55,7 @@ import org.matrix.android.sdk.api.session.group.groupSummaryQueryParams import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataTypes 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.roomSummaryQueryParams import org.matrix.android.sdk.api.session.room.spaceSummaryQueryParams import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount @@ -71,6 +73,8 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa private val analyticsTracker: AnalyticsTracker ) : VectorViewModel(initialState) { + private var currentSpace: RoomSummary? = null + @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { override fun create(initialState: SpaceListViewState): SpaceListViewModel @@ -273,6 +277,8 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa _viewEvents.post(SpaceListViewEvents.AddSpace) } + var asyncSpaceList: Async>? = null + private fun observeSpaceSummaries() { val params = spaceSummaryQueryParams { memberships = listOf(Membership.JOIN, Membership.INVITE) @@ -287,22 +293,24 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa .asFlow() ) { spaces, _ -> spaces + }.execute { async -> + asyncSpaceList = async + val currentSpaceChildren = currentSpace?.let { space -> async.invoke()?.filter { it.flattenParentIds.contains(space.roomId) } } + val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() } + val displaySpaces = currentSpaceChildren ?: rootSpaces + val orders = displaySpaces.associate { + it.roomId to session.getRoom(it.roomId) + ?.roomAccountDataService() + ?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER) + ?.content.toModel() + ?.safeOrder() + } + copy( + asyncSpaces = async, + rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)), + spaceOrderInfo = orders + ) } - .execute { async -> - val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() } - val orders = rootSpaces.associate { - it.roomId to session.getRoom(it.roomId) - ?.roomAccountDataService() - ?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER) - ?.content.toModel() - ?.safeOrder() - } - copy( - asyncSpaces = async, - rootSpacesOrdered = rootSpaces.sortedWith(TopLevelSpaceComparator(orders)), - spaceOrderInfo = orders - ) - } // clear local echos on update session.accountDataService() @@ -314,4 +322,29 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa ) } } + + private fun emitSpaceViewState() = asyncSpaceList?.let { async -> + val currentSpaceChildren = currentSpace?.let { space -> asyncSpaceList?.invoke()?.filter { it.flattenParentIds.contains(space.roomId) } } + val rootSpaces = asyncSpaceList?.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() } + val displaySpaces = currentSpaceChildren ?: rootSpaces + val orders = displaySpaces.associate { + it.roomId to session.getRoom(it.roomId) + ?.roomAccountDataService() + ?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER) + ?.content.toModel() + ?.safeOrder() + } + setState { + copy( + asyncSpaces = async, + rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)), + spaceOrderInfo = orders + ) + } + } + + fun setSpace(space: RoomSummary) { + this.currentSpace = space + emitSpaceViewState() + } } diff --git a/vector/src/main/res/drawable/ripple_grey.xml b/vector/src/main/res/drawable/ripple_grey.xml new file mode 100644 index 0000000000..63f89683ac --- /dev/null +++ b/vector/src/main/res/drawable/ripple_grey.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/vector/src/main/res/layout/fragment_space_list_modal.xml b/vector/src/main/res/layout/fragment_space_list_modal.xml index de0e057a9c..01d4d4beab 100644 --- a/vector/src/main/res/layout/fragment_space_list_modal.xml +++ b/vector/src/main/res/layout/fragment_space_list_modal.xml @@ -50,7 +50,7 @@ android:id="@+id/add_space_clickbox" android:layout_width="match_parent" android:layout_height="0dp" - android:background="@drawable/ripple_selector_key_pf" + android:background="@drawable/ripple_grey" app:layout_constraintTop_toBottomOf="@id/bottom_divider" app:layout_constraintBottom_toBottomOf="parent" /> diff --git a/vector/src/main/res/layout/item_modal_space.xml b/vector/src/main/res/layout/item_modal_space.xml index 358fd785a3..8da5a3492a 100644 --- a/vector/src/main/res/layout/item_modal_space.xml +++ b/vector/src/main/res/layout/item_modal_space.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/ripple_selector_key_pf" + android:background="@drawable/ripple_grey" android:paddingTop="12dp" android:paddingBottom="12dp">