From 8be8cc9ef792496f87b10d204d169f5822d9c87a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 24 Oct 2019 10:45:53 +0200 Subject: [PATCH] Filter rooms when sharing element --- .../home/room/list/RoomSummaryController.kt | 62 ++++++++++++------- .../features/share/IncomingShareActivity.kt | 18 +++++- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt index 6d786cde5e..0288590833 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt @@ -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, @StringRes titleRes: Int, diff --git a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt index 0d2f9ee040..0ce28f1f4b 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt @@ -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) { 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 } }