mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-19 10:45:13 +01:00
Updates to various things
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
ba97ece139
commit
9a8eacecb8
@ -71,15 +71,11 @@ class ContactsViewModel constructor(
|
||||
selectedParticipantsLiveData.postValue(selectedParticipants)
|
||||
}
|
||||
|
||||
fun loadContacts() {
|
||||
private fun loadContacts() {
|
||||
getContactsUseCase.invoke(viewModelScope, parametersOf(globalService.currentUserLiveData.value, groupConversation, searchQuery, conversationToken), object :
|
||||
UseCaseResponse<List<Participant>> {
|
||||
override suspend fun onSuccess(result: List<Participant>) {
|
||||
val sortPriority = mapOf("users" to 0, "groups" to 1, "emails" to 2, "circles" to 0)
|
||||
val typeComparator = Comparator<Participant> { o1, o2 ->
|
||||
sortPriority[o2.source]?.let { sortPriority[o1.source]?.compareTo(it) }
|
||||
0
|
||||
}
|
||||
|
||||
val sortedList = result.sortedWith(compareBy({
|
||||
sortPriority[it.source]
|
||||
|
@ -147,7 +147,7 @@ class ConversationsListView : BaseView() {
|
||||
}
|
||||
|
||||
private fun setSearchQuery(query: CharSequence?) {
|
||||
viewModel.filterLiveData.value = query
|
||||
viewModel.filterLiveData.postValue(query)
|
||||
}
|
||||
|
||||
private fun onElementClick(page: Page, holder: Presenter.Holder, element: Element<Conversation>) {
|
||||
|
@ -24,6 +24,8 @@ package com.nextcloud.talk.newarch.features.search
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.widget.SearchView
|
||||
import androidx.databinding.adapters.SearchViewBindingAdapter
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
@ -33,7 +35,7 @@ import kotlinx.coroutines.launch
|
||||
class DebouncingTextWatcher(
|
||||
lifecycle: Lifecycle,
|
||||
private val onDebouncingTextWatcherChange: (CharSequence?) -> Unit
|
||||
) : TextWatcher {
|
||||
) : TextWatcher, SearchView.OnQueryTextListener() {
|
||||
private var debouncePeriod: Long = 500
|
||||
|
||||
private val coroutineScope = lifecycle.coroutineScope
|
||||
@ -48,11 +50,25 @@ class DebouncingTextWatcher(
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
textChanged(s)
|
||||
}
|
||||
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
// do nothing, we already handle it in onQueryTextChange
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
textChanged(newText)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun textChanged(charSequence: CharSequence?) {
|
||||
searchJob?.cancel()
|
||||
searchJob = coroutineScope.launch {
|
||||
s.let {
|
||||
charSequence.let {
|
||||
delay(debouncePeriod)
|
||||
onDebouncingTextWatcherChange(s)
|
||||
onDebouncingTextWatcherChange(charSequence)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
android:animateLayoutChanges="true"
|
||||
android:icon="@drawable/ic_search_white_24dp"
|
||||
android:title="@string/nc_search"
|
||||
android:visible="false"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user