From 316f26ec82944f6defbdb2296f0aaae5614747a4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 30 Oct 2020 09:06:48 +0100 Subject: [PATCH] Search: Add "No more results" item (iso Element Web) --- .../detail/search/SearchResultController.kt | 60 +++++++++++-------- vector/src/main/res/values/strings.xml | 1 + 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt index c6789e1ac9..a2a9e6ae7d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt @@ -20,6 +20,7 @@ import android.graphics.Typeface import android.text.Spannable import android.text.SpannableString import android.text.style.StyleSpan +import com.airbnb.epoxy.EpoxyModel import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.epoxy.VisibilityState import im.vector.app.R @@ -28,7 +29,7 @@ import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.epoxy.loadingItem import im.vector.app.core.epoxy.noResultItem import im.vector.app.core.resources.StringProvider -import im.vector.app.core.ui.list.genericItemHeader +import im.vector.app.core.ui.list.GenericItemHeader_ import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.Content @@ -60,6 +61,8 @@ class SearchResultController @Inject constructor( override fun buildModels(data: SearchViewState?) { data ?: return + val searchItems = buildSearchResultItems(data) + if (data.hasMoreResult) { loadingItem { // Always use a different id, because we can be notified several times of visibility state changed @@ -70,24 +73,30 @@ class SearchResultController @Inject constructor( } } } - } - - val hasItems = buildSearchResultItems(data) - if (!hasItems && !data.hasMoreResult) { - // All returned result returned by the server has been filtered out and there is no more result - noResultItem { - id("noResult") - text(stringProvider.getString(R.string.no_result_placeholder)) + } else { + if (searchItems.isEmpty()) { + // All returned results by the server has been filtered out and there is no more result + noResultItem { + id("noResult") + text(stringProvider.getString(R.string.no_result_placeholder)) + } + } else { + noResultItem { + id("noMoreResult") + text(stringProvider.getString(R.string.no_more_results)) + } } } + + searchItems.forEach { add(it) } } /** * @return true if some item has been added */ - private fun buildSearchResultItems(data: SearchViewState): Boolean { + private fun buildSearchResultItems(data: SearchViewState): List> { var lastDate: Calendar? = null - var hasItems = false + val result = mutableListOf>() data.searchResult.forEach { eventAndSender -> val event = eventAndSender.event @@ -101,26 +110,25 @@ class SearchResultController @Inject constructor( timeInMillis = eventAndSender.event.originServerTs ?: System.currentTimeMillis() } if (lastDate?.get(Calendar.DAY_OF_YEAR) != eventDate.get(Calendar.DAY_OF_YEAR)) { - genericItemHeader { - id(eventDate.hashCode()) - text(dateFormatter.format(eventDate.timeInMillis, DateFormatKind.EDIT_HISTORY_HEADER)) - } + GenericItemHeader_() + .id(eventDate.hashCode()) + .text(dateFormatter.format(eventDate.timeInMillis, DateFormatKind.EDIT_HISTORY_HEADER)) + .let { result.add(it) } } lastDate = eventDate - searchResultItem { - id(eventAndSender.event.eventId) - avatarRenderer(avatarRenderer) - formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE)) - spannable(spannable) - sender(eventAndSender.sender - ?: eventAndSender.event.senderId?.let { session.getUser(it) }?.toMatrixItem()) - listener { listener?.onItemClicked(eventAndSender.event) } - } - hasItems = true + SearchResultItem_() + .id(eventAndSender.event.eventId) + .avatarRenderer(avatarRenderer) + .formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE)) + .spannable(spannable) + .sender(eventAndSender.sender + ?: eventAndSender.event.senderId?.let { session.getUser(it) }?.toMatrixItem()) + .listener { listener?.onItemClicked(eventAndSender.event) } + .let { result.add(it) } } - return hasItems + return result } /** diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 16ebca5f20..b4c42b276b 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -173,6 +173,7 @@ No conversations You didn’t allow Element to access your local contacts No results + No more results No identity server configured.