Modal changes space children

This commit is contained in:
ericdecanini 2022-05-09 15:12:18 +02:00
parent 952e3102d8
commit 20a72e640b
7 changed files with 76 additions and 18 deletions

View File

@ -137,6 +137,7 @@ class HomeDetailFragment @Inject constructor(
} }
is RoomGroupingMethod.BySpace -> { is RoomGroupingMethod.BySpace -> {
onSpaceChange(roomGroupingMethod.spaceSummary) onSpaceChange(roomGroupingMethod.spaceSummary)
sharedActionViewModel.space.value = roomGroupingMethod.spaceSummary
} }
} }
} }

View File

@ -16,8 +16,13 @@
package im.vector.app.features.home package im.vector.app.features.home
import androidx.lifecycle.MutableLiveData
import im.vector.app.core.platform.VectorSharedActionViewModel import im.vector.app.core.platform.VectorSharedActionViewModel
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject import javax.inject.Inject
class HomeSharedActionViewModel @Inject constructor(val session: Session) : VectorSharedActionViewModel<HomeActivitySharedAction>() class HomeSharedActionViewModel @Inject constructor(val session: Session) : VectorSharedActionViewModel<HomeActivitySharedAction>() {
val space = MutableLiveData<RoomSummary>()
}

View File

@ -24,10 +24,14 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.observeNotNull
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentSpaceListModalBinding import im.vector.app.databinding.FragmentSpaceListModalBinding
import im.vector.app.features.spaces.SpaceListAction import im.vector.app.features.spaces.SpaceListAction
import im.vector.app.features.spaces.SpaceListViewModel 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 import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -52,6 +56,7 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java) sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java)
setupRecyclerView() setupRecyclerView()
setupAddSpace() setupAddSpace()
observeSpaceChange()
} }
private fun setupRecyclerView() { private fun setupRecyclerView() {
@ -70,6 +75,10 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
} }
} }
private fun observeSpaceChange() = sharedActionViewModel.space.observeNotNull(viewLifecycleOwner) {
viewModel.setSpace(it)
}
override fun invalidate() { override fun invalidate() {
withState(viewModel) { state -> withState(viewModel) { state ->
state.rootSpacesOrdered?.let { state.rootSpacesOrdered?.let {

View File

@ -17,6 +17,7 @@
package im.vector.app.features.spaces package im.vector.app.features.spaces
import androidx.lifecycle.asFlow import androidx.lifecycle.asFlow
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success 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.RoomSortOrder
import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataTypes 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.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.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.spaceSummaryQueryParams import org.matrix.android.sdk.api.session.room.spaceSummaryQueryParams
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount 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 private val analyticsTracker: AnalyticsTracker
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) { ) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
private var currentSpace: RoomSummary? = null
@AssistedFactory @AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<SpaceListViewModel, SpaceListViewState> { interface Factory : MavericksAssistedViewModelFactory<SpaceListViewModel, SpaceListViewState> {
override fun create(initialState: SpaceListViewState): SpaceListViewModel override fun create(initialState: SpaceListViewState): SpaceListViewModel
@ -273,6 +277,8 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
_viewEvents.post(SpaceListViewEvents.AddSpace) _viewEvents.post(SpaceListViewEvents.AddSpace)
} }
var asyncSpaceList: Async<List<RoomSummary>>? = null
private fun observeSpaceSummaries() { private fun observeSpaceSummaries() {
val params = spaceSummaryQueryParams { val params = spaceSummaryQueryParams {
memberships = listOf(Membership.JOIN, Membership.INVITE) memberships = listOf(Membership.JOIN, Membership.INVITE)
@ -287,10 +293,12 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
.asFlow() .asFlow()
) { spaces, _ -> ) { spaces, _ ->
spaces spaces
} }.execute { async ->
.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 rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
val orders = rootSpaces.associate { val displaySpaces = currentSpaceChildren ?: rootSpaces
val orders = displaySpaces.associate {
it.roomId to session.getRoom(it.roomId) it.roomId to session.getRoom(it.roomId)
?.roomAccountDataService() ?.roomAccountDataService()
?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER) ?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)
@ -299,7 +307,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
} }
copy( copy(
asyncSpaces = async, asyncSpaces = async,
rootSpacesOrdered = rootSpaces.sortedWith(TopLevelSpaceComparator(orders)), rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
spaceOrderInfo = orders spaceOrderInfo = orders
) )
} }
@ -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<SpaceOrderContent>()
?.safeOrder()
}
setState {
copy(
asyncSpaces = async,
rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
spaceOrderInfo = orders
)
}
}
fun setSpace(space: RoomSummary) {
this.currentSpace = space
emitSpaceViewState()
}
} }

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/vctr_content_secondary">
<!--this creates the mask with the ripple effect-->
<item
android:id="@+id/mask"
android:drawable="@android:color/white" />
</ripple>

View File

@ -50,7 +50,7 @@
android:id="@+id/add_space_clickbox" android:id="@+id/add_space_clickbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" 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_constraintTop_toBottomOf="@id/bottom_divider"
app:layout_constraintBottom_toBottomOf="parent" /> app:layout_constraintBottom_toBottomOf="parent" />

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/ripple_selector_key_pf" android:background="@drawable/ripple_grey"
android:paddingTop="12dp" android:paddingTop="12dp"
android:paddingBottom="12dp"> android:paddingBottom="12dp">