mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Filter rooms when sharing element
This commit is contained in:
parent
b17b54d218
commit
8be8cc9ef7
2 changed files with 54 additions and 26 deletions
|
@ -20,6 +20,8 @@ import androidx.annotation.StringRes
|
|||
import com.airbnb.epoxy.EpoxyController
|
||||
import im.vector.matrix.android.api.session.room.model.Membership
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.epoxy.noResultItem
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.room.filtered.FilteredRoomFooterItem
|
||||
import im.vector.riotx.features.home.room.filtered.filteredRoomFooterItem
|
||||
|
@ -47,24 +49,28 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
|
|||
|
||||
override fun buildModels() {
|
||||
val nonNullViewState = viewState ?: return
|
||||
if (nonNullViewState.displayMode == RoomListFragment.DisplayMode.FILTERED) {
|
||||
buildFilteredRooms(nonNullViewState)
|
||||
} else {
|
||||
val roomSummaries = nonNullViewState.asyncFilteredRooms()
|
||||
roomSummaries?.forEach { (category, summaries) ->
|
||||
if (summaries.isEmpty()) {
|
||||
return@forEach
|
||||
} else {
|
||||
val isExpanded = nonNullViewState.isCategoryExpanded(category)
|
||||
buildRoomCategory(nonNullViewState, summaries, category.titleRes, nonNullViewState.isCategoryExpanded(category)) {
|
||||
listener?.onToggleRoomCategory(category)
|
||||
}
|
||||
if (isExpanded) {
|
||||
buildRoomModels(summaries,
|
||||
nonNullViewState.joiningRoomsIds,
|
||||
nonNullViewState.joiningErrorRoomsIds,
|
||||
nonNullViewState.rejectingRoomsIds,
|
||||
nonNullViewState.rejectingErrorRoomsIds)
|
||||
when (nonNullViewState.displayMode) {
|
||||
RoomListFragment.DisplayMode.FILTERED,
|
||||
RoomListFragment.DisplayMode.SHARE -> {
|
||||
buildFilteredRooms(nonNullViewState)
|
||||
}
|
||||
else -> {
|
||||
val roomSummaries = nonNullViewState.asyncFilteredRooms()
|
||||
roomSummaries?.forEach { (category, summaries) ->
|
||||
if (summaries.isEmpty()) {
|
||||
return@forEach
|
||||
} else {
|
||||
val isExpanded = nonNullViewState.isCategoryExpanded(category)
|
||||
buildRoomCategory(nonNullViewState, summaries, category.titleRes, nonNullViewState.isCategoryExpanded(category)) {
|
||||
listener?.onToggleRoomCategory(category)
|
||||
}
|
||||
if (isExpanded) {
|
||||
buildRoomModels(summaries,
|
||||
nonNullViewState.joiningRoomsIds,
|
||||
nonNullViewState.joiningErrorRoomsIds,
|
||||
nonNullViewState.rejectingRoomsIds,
|
||||
nonNullViewState.rejectingErrorRoomsIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,12 +86,15 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
|
|||
.filter { it.membership == Membership.JOIN && roomListNameFilter.test(it) }
|
||||
|
||||
buildRoomModels(filteredSummaries,
|
||||
viewState.joiningRoomsIds,
|
||||
viewState.joiningErrorRoomsIds,
|
||||
viewState.rejectingRoomsIds,
|
||||
viewState.rejectingErrorRoomsIds)
|
||||
viewState.joiningRoomsIds,
|
||||
viewState.joiningErrorRoomsIds,
|
||||
viewState.rejectingRoomsIds,
|
||||
viewState.rejectingErrorRoomsIds)
|
||||
|
||||
addFilterFooter(viewState)
|
||||
when {
|
||||
viewState.displayMode == RoomListFragment.DisplayMode.FILTERED -> addFilterFooter(viewState)
|
||||
filteredSummaries.isEmpty() -> addEmptyFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFilterFooter(viewState: RoomListViewState) {
|
||||
|
@ -96,6 +105,13 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
|
|||
}
|
||||
}
|
||||
|
||||
private fun addEmptyFooter() {
|
||||
noResultItem {
|
||||
id("no_result")
|
||||
text(stringProvider.getString(R.string.no_result_placeholder))
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildRoomCategory(viewState: RoomListViewState,
|
||||
summaries: List<RoomSummary>,
|
||||
@StringRes titleRes: Int,
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.ClipDescription
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import com.kbeanie.multipicker.utils.IntentUtils
|
||||
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
||||
import im.vector.riotx.R
|
||||
|
@ -39,7 +40,7 @@ class IncomingShareActivity :
|
|||
VectorBaseActivity(), AttachmentsHelper.Callback {
|
||||
|
||||
@Inject lateinit var sessionHolder: ActiveSessionHolder
|
||||
private lateinit var roomListFragment: RoomListFragment
|
||||
private var roomListFragment: RoomListFragment? = null
|
||||
private lateinit var attachmentsHelper: AttachmentsHelper
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
|
@ -77,12 +78,23 @@ class IncomingShareActivity :
|
|||
} else {
|
||||
cannotManageShare()
|
||||
}
|
||||
|
||||
incomingShareSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
roomListFragment?.filterRoomsWith(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
|
||||
val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Attachments(attachments))
|
||||
roomListFragment = RoomListFragment.newInstance(roomListParams)
|
||||
replaceFragment(roomListFragment, R.id.shareRoomListFragmentContainer)
|
||||
.also { replaceFragment(it, R.id.shareRoomListFragmentContainer) }
|
||||
}
|
||||
|
||||
override fun onAttachmentsProcessFailed() {
|
||||
|
@ -102,7 +114,7 @@ class IncomingShareActivity :
|
|||
} else {
|
||||
val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Text(sharedText))
|
||||
roomListFragment = RoomListFragment.newInstance(roomListParams)
|
||||
replaceFragment(roomListFragment, R.id.shareRoomListFragmentContainer)
|
||||
.also { replaceFragment(it, R.id.shareRoomListFragmentContainer) }
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue