mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Search: Add "No more results" item (iso Element Web)
This commit is contained in:
parent
225a5d4e59
commit
316f26ec82
2 changed files with 35 additions and 26 deletions
|
@ -20,6 +20,7 @@ import android.graphics.Typeface
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
|
import com.airbnb.epoxy.EpoxyModel
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import com.airbnb.epoxy.VisibilityState
|
import com.airbnb.epoxy.VisibilityState
|
||||||
import im.vector.app.R
|
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.loadingItem
|
||||||
import im.vector.app.core.epoxy.noResultItem
|
import im.vector.app.core.epoxy.noResultItem
|
||||||
import im.vector.app.core.resources.StringProvider
|
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 im.vector.app.features.home.AvatarRenderer
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.Content
|
import org.matrix.android.sdk.api.session.events.model.Content
|
||||||
|
@ -60,6 +61,8 @@ class SearchResultController @Inject constructor(
|
||||||
override fun buildModels(data: SearchViewState?) {
|
override fun buildModels(data: SearchViewState?) {
|
||||||
data ?: return
|
data ?: return
|
||||||
|
|
||||||
|
val searchItems = buildSearchResultItems(data)
|
||||||
|
|
||||||
if (data.hasMoreResult) {
|
if (data.hasMoreResult) {
|
||||||
loadingItem {
|
loadingItem {
|
||||||
// Always use a different id, because we can be notified several times of visibility state changed
|
// Always use a different id, because we can be notified several times of visibility state changed
|
||||||
|
@ -70,24 +73,30 @@ class SearchResultController @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if (searchItems.isEmpty()) {
|
||||||
val hasItems = buildSearchResultItems(data)
|
// All returned results by the server has been filtered out and there is no more result
|
||||||
if (!hasItems && !data.hasMoreResult) {
|
noResultItem {
|
||||||
// All returned result returned by the server has been filtered out and there is no more result
|
id("noResult")
|
||||||
noResultItem {
|
text(stringProvider.getString(R.string.no_result_placeholder))
|
||||||
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
|
* @return true if some item has been added
|
||||||
*/
|
*/
|
||||||
private fun buildSearchResultItems(data: SearchViewState): Boolean {
|
private fun buildSearchResultItems(data: SearchViewState): List<EpoxyModel<*>> {
|
||||||
var lastDate: Calendar? = null
|
var lastDate: Calendar? = null
|
||||||
var hasItems = false
|
val result = mutableListOf<EpoxyModel<*>>()
|
||||||
|
|
||||||
data.searchResult.forEach { eventAndSender ->
|
data.searchResult.forEach { eventAndSender ->
|
||||||
val event = eventAndSender.event
|
val event = eventAndSender.event
|
||||||
|
@ -101,26 +110,25 @@ class SearchResultController @Inject constructor(
|
||||||
timeInMillis = eventAndSender.event.originServerTs ?: System.currentTimeMillis()
|
timeInMillis = eventAndSender.event.originServerTs ?: System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
if (lastDate?.get(Calendar.DAY_OF_YEAR) != eventDate.get(Calendar.DAY_OF_YEAR)) {
|
if (lastDate?.get(Calendar.DAY_OF_YEAR) != eventDate.get(Calendar.DAY_OF_YEAR)) {
|
||||||
genericItemHeader {
|
GenericItemHeader_()
|
||||||
id(eventDate.hashCode())
|
.id(eventDate.hashCode())
|
||||||
text(dateFormatter.format(eventDate.timeInMillis, DateFormatKind.EDIT_HISTORY_HEADER))
|
.text(dateFormatter.format(eventDate.timeInMillis, DateFormatKind.EDIT_HISTORY_HEADER))
|
||||||
}
|
.let { result.add(it) }
|
||||||
}
|
}
|
||||||
lastDate = eventDate
|
lastDate = eventDate
|
||||||
|
|
||||||
searchResultItem {
|
SearchResultItem_()
|
||||||
id(eventAndSender.event.eventId)
|
.id(eventAndSender.event.eventId)
|
||||||
avatarRenderer(avatarRenderer)
|
.avatarRenderer(avatarRenderer)
|
||||||
formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE))
|
.formattedDate(dateFormatter.format(event.originServerTs, DateFormatKind.MESSAGE_SIMPLE))
|
||||||
spannable(spannable)
|
.spannable(spannable)
|
||||||
sender(eventAndSender.sender
|
.sender(eventAndSender.sender
|
||||||
?: eventAndSender.event.senderId?.let { session.getUser(it) }?.toMatrixItem())
|
?: eventAndSender.event.senderId?.let { session.getUser(it) }?.toMatrixItem())
|
||||||
listener { listener?.onItemClicked(eventAndSender.event) }
|
.listener { listener?.onItemClicked(eventAndSender.event) }
|
||||||
}
|
.let { result.add(it) }
|
||||||
hasItems = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasItems
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -173,6 +173,7 @@
|
||||||
<string name="no_conversation_placeholder">No conversations</string>
|
<string name="no_conversation_placeholder">No conversations</string>
|
||||||
<string name="no_contact_access_placeholder">You didn’t allow Element to access your local contacts</string>
|
<string name="no_contact_access_placeholder">You didn’t allow Element to access your local contacts</string>
|
||||||
<string name="no_result_placeholder">No results</string>
|
<string name="no_result_placeholder">No results</string>
|
||||||
|
<string name="no_more_results">No more results</string>
|
||||||
<string name="people_no_identity_server">No identity server configured.</string>
|
<string name="people_no_identity_server">No identity server configured.</string>
|
||||||
|
|
||||||
<!-- Rooms fragment -->
|
<!-- Rooms fragment -->
|
||||||
|
|
Loading…
Reference in a new issue