Merge pull request #3235 from vector-im/feature/bca/spaces_justme_beta

Just me spaces support
This commit is contained in:
Benoit Marty 2021-04-29 17:47:19 +02:00 committed by GitHub
commit 5d9d984c73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 316 additions and 66 deletions

View File

@ -24,4 +24,12 @@ interface UpdatableLivePageResult {
val livePagedList: LiveData<PagedList<RoomSummary>>
fun updateQuery(builder: (RoomSummaryQueryParams) -> RoomSummaryQueryParams)
val liveBoundaries: LiveData<ResultBoundaries>
}
data class ResultBoundaries(
val frontLoaded: Boolean = false,
val endLoaded: Boolean = false,
val zeroItemLoaded: Boolean = false
)

View File

@ -18,6 +18,7 @@
package org.matrix.android.sdk.internal.session.room.summary
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
@ -28,6 +29,7 @@ import io.realm.Sort
import io.realm.kotlin.where
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.session.room.ResultBoundaries
import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
@ -187,9 +189,25 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
roomSummaryMapper.map(it)
}
val boundaries = MutableLiveData(ResultBoundaries())
val mapped = monarchy.findAllPagedWithChanges(
realmDataSourceFactory,
LivePagedListBuilder(dataSourceFactory, pagedListConfig)
LivePagedListBuilder(dataSourceFactory, pagedListConfig).also {
it.setBoundaryCallback(object : PagedList.BoundaryCallback<RoomSummary>() {
override fun onItemAtEndLoaded(itemAtEnd: RoomSummary) {
boundaries.postValue(boundaries.value?.copy(frontLoaded = true))
}
override fun onItemAtFrontLoaded(itemAtFront: RoomSummary) {
boundaries.postValue(boundaries.value?.copy(endLoaded = true))
}
override fun onZeroItemsLoaded() {
boundaries.postValue(boundaries.value?.copy(zeroItemLoaded = true))
}
})
}
)
return object : UpdatableLivePageResult {
@ -200,6 +218,9 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
roomSummariesQuery(it, builder.invoke(queryParams)).process(sortOrder)
}
}
override val liveBoundaries: LiveData<ResultBoundaries>
get() = boundaries
}
}

View File

@ -48,6 +48,7 @@ import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
import im.vector.app.features.disclaimer.showDisclaimerDialog
import im.vector.app.features.matrixto.MatrixToBottomSheet
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.notifications.NotificationDrawerManager
import im.vector.app.features.permalink.NavigationInterceptor
import im.vector.app.features.permalink.PermalinkHandler
@ -115,11 +116,21 @@ class HomeActivity :
if (activityResult.resultCode == Activity.RESULT_OK) {
val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data)
val defaultRoomId = SpaceCreationActivity.getDefaultRoomId(activityResult.data)
val isJustMe = SpaceCreationActivity.isJustMeSpace(activityResult.data)
views.drawerLayout.closeDrawer(GravityCompat.START)
val postSwitchOption: Navigator.PostSwitchSpaceAction = if (defaultRoomId != null) {
Navigator.PostSwitchSpaceAction.OpenDefaultRoom(defaultRoomId, !isJustMe)
} else if (isJustMe) {
Navigator.PostSwitchSpaceAction.OpenAddExistingRooms
} else {
Navigator.PostSwitchSpaceAction.None
}
// Here we want to change current space to the newly created one, and then immediately open the default room
if (spaceId != null) {
navigator.switchToSpace(this, spaceId, defaultRoomId, true)
navigator.switchToSpace(context = this,
spaceId = spaceId,
postSwitchOption)
}
}
}
@ -267,7 +278,7 @@ class HomeActivity :
private fun renderState(state: HomeActivityViewState) {
when (val status = state.initialSyncProgressServiceStatus) {
is InitialSyncProgressService.Status.Idle -> {
is InitialSyncProgressService.Status.Idle -> {
views.waitingView.root.isVisible = false
}
is InitialSyncProgressService.Status.Progressing -> {
@ -494,7 +505,7 @@ class HomeActivity :
}
override fun switchToSpace(spaceId: String) {
navigator.switchToSpace(this@HomeActivity, spaceId, null, false)
navigator.switchToSpace(this@HomeActivity, spaceId, Navigator.PostSwitchSpaceAction.None)
}
}

View File

@ -74,6 +74,7 @@ import im.vector.app.features.share.SharedData
import im.vector.app.features.spaces.InviteRoomSpaceChooserBottomSheet
import im.vector.app.features.spaces.SpaceExploreActivity
import im.vector.app.features.spaces.SpacePreviewActivity
import im.vector.app.features.spaces.manage.SpaceManageActivity
import im.vector.app.features.terms.ReviewTermsActivity
import im.vector.app.features.widgets.WidgetActivity
import im.vector.app.features.widgets.WidgetArgsBuilder
@ -106,21 +107,31 @@ class DefaultNavigator @Inject constructor(
startActivity(context, intent, buildTask)
}
override fun switchToSpace(context: Context, spaceId: String, roomId: String?, openShareSheet: Boolean) {
override fun switchToSpace(context: Context, spaceId: String, postSwitchSpaceAction: Navigator.PostSwitchSpaceAction) {
if (sessionHolder.getSafeActiveSession()?.getRoomSummary(spaceId) == null) {
fatalError("Trying to open an unknown space $spaceId", vectorPreferences.failFast())
return
}
appStateHandler.setCurrentSpace(spaceId)
if (roomId != null) {
val args = RoomDetailArgs(roomId, eventId = null, openShareSpaceForId = spaceId.takeIf { openShareSheet })
val intent = RoomDetailActivity.newIntent(context, args)
startActivity(context, intent, false)
} else {
// go back to home if we are showing room details?
// This is a bit ugly, but the navigator is supposed to know about the activity stack
if (context is RoomDetailActivity) {
context.finish()
when (postSwitchSpaceAction) {
Navigator.PostSwitchSpaceAction.None -> {
// go back to home if we are showing room details?
// This is a bit ugly, but the navigator is supposed to know about the activity stack
if (context is RoomDetailActivity) {
context.finish()
}
}
Navigator.PostSwitchSpaceAction.OpenAddExistingRooms -> {
startActivity(context, SpaceManageActivity.newIntent(context, spaceId), false)
}
is Navigator.PostSwitchSpaceAction.OpenDefaultRoom -> {
val args = RoomDetailArgs(
postSwitchSpaceAction.roomId,
eventId = null,
openShareSpaceForId = spaceId.takeIf { postSwitchSpaceAction.showShareSheet }
)
val intent = RoomDetailActivity.newIntent(context, args)
startActivity(context, intent, false)
}
}
}
@ -236,7 +247,7 @@ class DefaultNavigator @Inject constructor(
}
override fun switchToSpace(spaceId: String) {
this@DefaultNavigator.switchToSpace(context, spaceId, null, openShareSheet = false)
this@DefaultNavigator.switchToSpace(context, spaceId, Navigator.PostSwitchSpaceAction.None)
}
}
// TODO check if there is already one??

View File

@ -38,7 +38,13 @@ interface Navigator {
fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false)
fun switchToSpace(context: Context, spaceId: String, roomId: String?, openShareSheet: Boolean)
sealed class PostSwitchSpaceAction {
object None : PostSwitchSpaceAction()
data class OpenDefaultRoom(val roomId: String, val showShareSheet: Boolean) : PostSwitchSpaceAction()
object OpenAddExistingRooms: PostSwitchSpaceAction()
}
fun switchToSpace(context: Context, spaceId: String, postSwitchSpaceAction: PostSwitchSpaceAction)
fun openSpacePreview(context: Context, spaceId: String)

View File

@ -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(

View File

@ -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 private 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) }.orEmpty()
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))
}

View File

@ -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
)
/**

View File

@ -36,6 +36,7 @@ import im.vector.app.features.spaces.create.CreateSpaceDetailsFragment
import im.vector.app.features.spaces.create.CreateSpaceEvents
import im.vector.app.features.spaces.create.CreateSpaceState
import im.vector.app.features.spaces.create.CreateSpaceViewModel
import im.vector.app.features.spaces.create.SpaceTopology
import im.vector.app.features.spaces.create.SpaceType
import javax.inject.Inject
@ -61,7 +62,7 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
CreateSpaceState.Step.SetDetails -> {
navigateToFragment(ChooseSpaceTypeFragment::class.java)
}
CreateSpaceState.Step.AddRooms -> {
CreateSpaceState.Step.AddRooms -> {
navigateToFragment(CreateSpaceDefaultRoomsFragment::class.java)
}
CreateSpaceState.Step.ChoosePrivateType -> {
@ -106,6 +107,7 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
setResult(RESULT_OK, Intent().apply {
putExtra(RESULT_DATA_CREATED_SPACE_ID, it.spaceId)
putExtra(RESULT_DATA_DEFAULT_ROOM_ID, it.defaultRoomId)
putExtra(RESULT_DATA_CREATED_SPACE_IS_JUST_ME, it.topology == SpaceTopology.JustMe)
})
finish()
}
@ -155,6 +157,7 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
companion object {
private const val RESULT_DATA_CREATED_SPACE_ID = "RESULT_DATA_CREATED_SPACE_ID"
private const val RESULT_DATA_DEFAULT_ROOM_ID = "RESULT_DATA_DEFAULT_ROOM_ID"
private const val RESULT_DATA_CREATED_SPACE_IS_JUST_ME = "RESULT_DATA_CREATED_SPACE_IS_JUST_ME"
fun newIntent(context: Context): Intent {
return Intent(context, SpaceCreationActivity::class.java).apply {
@ -169,6 +172,10 @@ class SpaceCreationActivity : SimpleFragmentActivity(), CreateSpaceViewModel.Fac
fun getDefaultRoomId(data: Intent?): String? {
return data?.extras?.getString(RESULT_DATA_DEFAULT_ROOM_ID)
}
fun isJustMeSpace(data: Intent?): Boolean {
return data?.extras?.getBoolean(RESULT_DATA_CREATED_SPACE_IS_JUST_ME, false) == true
}
}
override fun create(initialState: CreateSpaceState): CreateSpaceViewModel = viewModelFactory.create(initialState)

View File

@ -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 {

View File

@ -42,8 +42,7 @@ class ChoosePrivateSpaceTypeFragment @Inject constructor(
super.onViewCreated(view, savedInstanceState)
views.justMeButton.setOnClickListener(DebouncedClickListener({
vectorBaseActivity.notImplemented("Organize room as space is not yet implemented")
// sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.JustMe))
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.JustMe))
}))
views.teammatesButton.setOnClickListener(DebouncedClickListener({

View File

@ -24,7 +24,7 @@ sealed class CreateSpaceEvents : VectorViewEvents {
object NavigateToAddRooms : CreateSpaceEvents()
object NavigateToChoosePrivateType : CreateSpaceEvents()
object Dismiss : CreateSpaceEvents()
data class FinishSuccess(val spaceId: String, val defaultRoomId: String?) : CreateSpaceEvents()
data class FinishSuccess(val spaceId: String, val defaultRoomId: String?, val topology: SpaceTopology?) : CreateSpaceEvents()
data class ShowModalError(val errorMessage: String) : CreateSpaceEvents()
object HideModalLoading : CreateSpaceEvents()
}

View File

@ -126,10 +126,11 @@ class CreateSpaceViewModel @AssistedInject constructor(
SpaceTopology.JustMe -> {
setState {
copy(
spaceTopology = SpaceTopology.JustMe
spaceTopology = SpaceTopology.JustMe,
defaultRooms = emptyMap()
)
}
// XXX finish and open the add rooms directly
handleNextFromDefaultRooms()
}
SpaceTopology.MeAndTeammates -> {
setState {
@ -237,14 +238,26 @@ class CreateSpaceViewModel @AssistedInject constructor(
setState {
copy(creationResult = Success(result.spaceId))
}
_viewEvents.post(CreateSpaceEvents.FinishSuccess(result.spaceId, result.childIds.firstOrNull()))
_viewEvents.post(
CreateSpaceEvents.FinishSuccess(
result.spaceId,
result.childIds.firstOrNull(),
state.spaceTopology
)
)
}
is CreateSpaceTaskResult.PartialSuccess -> {
// XXX what can we do here?
setState {
copy(creationResult = Success(result.spaceId))
}
_viewEvents.post(CreateSpaceEvents.FinishSuccess(result.spaceId, result.childIds.firstOrNull()))
_viewEvents.post(
CreateSpaceEvents.FinishSuccess(
result.spaceId,
result.childIds.firstOrNull(),
state.spaceTopology
)
)
}
is CreateSpaceTaskResult.FailedToCreateSpace -> {
setState {

View File

@ -22,6 +22,8 @@ import com.airbnb.epoxy.paging.PagedListEpoxyController
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.utils.createUIHandler
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.list.RoomCategoryItem_
import org.matrix.android.sdk.api.session.room.ResultBoundaries
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.util.toMatrixItem
@ -54,6 +56,26 @@ class AddRoomListController @Inject constructor(
var listener: Listener? = null
var ignoreRooms: List<String>? = null
var initialLoadOccurred = false
fun boundaryChange(boundary: ResultBoundaries) {
val boundaryHasLoadedSomething = boundary.frontLoaded || boundary.zeroItemLoaded
if (initialLoadOccurred != boundaryHasLoadedSomething) {
initialLoadOccurred = boundaryHasLoadedSomething
requestForcedModelBuild()
}
}
var sectionName: String? = null
set(value) {
if (value != field) {
field = value
requestForcedModelBuild()
}
}
var totalSize: Int = 0
var selectedItems: Map<String, Boolean> = emptyMap()
set(value) {
field = value
@ -62,15 +84,29 @@ class AddRoomListController @Inject constructor(
}
override fun addModels(models: List<EpoxyModel<*>>) {
if (ignoreRooms == null) {
super.addModels(models)
val filteredModel = if (ignoreRooms == null) {
models
} else {
super.addModels(
models.filter {
it !is RoomSelectionItem || !ignoreRooms!!.contains(it.matrixItem.id)
models.filter {
it !is RoomSelectionItem || !ignoreRooms!!.contains(it.matrixItem.id)
}
}
val somethingToShow = filteredModel.isNotEmpty() || !initialLoadOccurred
if (somethingToShow || filteredModel.isNotEmpty()) {
add(
RoomCategoryItem_().apply {
id("header")
title(sectionName ?: "")
expanded(true)
}
)
}
super.addModels(filteredModel)
if (!initialLoadOccurred) {
add(
RoomSelectionPlaceHolderItem_().apply { id("loading") }
)
}
}
override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> {

View File

@ -16,6 +16,9 @@
package im.vector.app.features.spaces.manage
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
@ -23,23 +26,30 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.epoxy.EpoxyViewHolder
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentSpaceAddRoomsBinding
import im.vector.app.features.home.room.list.RoomCategoryItem_
import io.reactivex.rxkotlin.subscribeBy
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class SpaceAddRoomFragment @Inject constructor(
private val epoxyController: AddRoomListController,
private val spaceEpoxyController: AddRoomListController,
private val roomEpoxyController: AddRoomListController,
private val viewModelFactory: SpaceAddRoomsViewModel.Factory
) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(),
OnBackPressed, AddRoomListController.Listener, SpaceAddRoomsViewModel.Factory {
@ -79,7 +89,8 @@ class SpaceAddRoomFragment @Inject constructor(
.disposeOnDestroyView()
viewModel.selectionListLiveData.observe(viewLifecycleOwner) {
epoxyController.selectedItems = it
spaceEpoxyController.selectedItems = it
roomEpoxyController.selectedItems = it
saveNeeded = it.values.any { it }
invalidateOptionsMenu()
}
@ -89,7 +100,8 @@ class SpaceAddRoomFragment @Inject constructor(
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::ignoreRooms) {
epoxyController.ignoreRooms = it
spaceEpoxyController.ignoreRooms = it
roomEpoxyController.ignoreRooms = it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::isSaving) {
@ -100,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) {
@ -142,16 +154,71 @@ class SpaceAddRoomFragment @Inject constructor(
override fun onDestroyView() {
views.roomList.cleanup()
epoxyController.listener = null
spaceEpoxyController.listener = null
roomEpoxyController.listener = null
super.onDestroyView()
}
private fun setupRecyclerView() {
views.roomList.configureWith(epoxyController, showDivider = true)
epoxyController.listener = this
viewModel.updatableLivePageResult.livePagedList.observe(viewLifecycleOwner) {
epoxyController.submitList(it)
val concatAdapter = ConcatAdapter()
spaceEpoxyController.sectionName = getString(R.string.spaces_header)
roomEpoxyController.sectionName = getString(R.string.rooms_header)
spaceEpoxyController.listener = this
roomEpoxyController.listener = this
viewModel.updatableLiveSpacePageResult.liveBoundaries.observe(viewLifecycleOwner) {
spaceEpoxyController.boundaryChange(it)
}
viewModel.updatableLiveSpacePageResult.livePagedList.observe(viewLifecycleOwner) {
spaceEpoxyController.totalSize = it.size
spaceEpoxyController.submitList(it)
}
viewModel.updatableLivePageResult.liveBoundaries.observe(viewLifecycleOwner) {
roomEpoxyController.boundaryChange(it)
}
viewModel.updatableLivePageResult.livePagedList.observe(viewLifecycleOwner) {
roomEpoxyController.totalSize = it.size
roomEpoxyController.submitList(it)
}
views.roomList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
views.roomList.addItemDecoration(
object : DividerItemDecoration(context, VERTICAL) {
val decorationDrawable = ContextCompat.getDrawable(requireContext(), R.drawable.divider_horizontal)
override fun getDrawable(): Drawable? {
return decorationDrawable
}
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
val vh = parent.findViewHolderForAdapterPosition(position)
val nextIsSectionOrFinal = parent.findViewHolderForAdapterPosition(position + 1)?.let {
(it as? EpoxyViewHolder)?.model is RoomCategoryItem_
} ?: true
if (vh == null
|| (vh as? EpoxyViewHolder)?.model is RoomCategoryItem_
|| nextIsSectionOrFinal
) {
outRect.setEmpty()
} else {
super.getItemOffsets(outRect, view, parent, state)
}
}
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDraw(c, parent, state)
}
}
)
views.roomList.setHasFixedSize(true)
concatAdapter.addAdapter(roomEpoxyController.adapter)
concatAdapter.addAdapter(spaceEpoxyController.adapter)
views.roomList.adapter = concatAdapter
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {

View File

@ -40,6 +40,7 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomType
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
class AddRoomError(val errorList: Map<String, Throwable>) : Throwable() {
@ -53,11 +54,31 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
private val session: Session
) : VectorViewModel<SpaceAddRoomsState, SpaceAddRoomActions, SpaceAddRoomsViewEvents>(initialState) {
val updatableLivePageResult: UpdatableLivePageResult by lazy {
val updatableLiveSpacePageResult: UpdatableLivePageResult by lazy {
session.getFilteredPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.excludeType = null
this.includeType = listOf(RoomType.SPACE)
this.activeSpaceId = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()
.setPageSize(10)
.setInitialLoadSizeHint(20)
.setEnablePlaceholders(true)
.setPrefetchDistance(10)
.build(),
sortOrder = RoomSortOrder.NAME
)
}
val updatableLivePageResult: UpdatableLivePageResult by lazy {
session.getFilteredPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
this.activeSpaceId = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
@ -116,6 +137,11 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
)
}
updatableLiveSpacePageResult.updateQuery {
it.copy(
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
)
}
setState {
copy(
currentFilter = action.filter

View File

@ -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)
)
}
}
}
}

View File

@ -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)
}
}
}

View File

@ -22,4 +22,5 @@ sealed class SpaceManagedSharedAction : VectorViewModelAction {
object HandleBack : SpaceManagedSharedAction()
object ShowLoading : SpaceManagedSharedAction()
object HideLoading : SpaceManagedSharedAction()
object CreateRoom : SpaceManagedSharedAction()
}

View File

@ -22,4 +22,5 @@ sealed class SpaceManagedSharedViewEvents : VectorViewEvents {
object Finish : SpaceManagedSharedViewEvents()
object ShowLoading : SpaceManagedSharedViewEvents()
object HideLoading : SpaceManagedSharedViewEvents()
object NavigateToCreateRoom : SpaceManagedSharedViewEvents()
}

View File

@ -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>