mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-19 10:45:13 +01:00
Add clear to search in contacts
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
4cefbc8b37
commit
795bd6449e
@ -143,7 +143,7 @@ class ContactsView(private val bundle: Bundle? = null) : BaseView() {
|
||||
})
|
||||
|
||||
viewModel.apply {
|
||||
searchQueryLiveData.observe(this@ContactsView) { query ->
|
||||
filterLiveData.observe(this@ContactsView) { query ->
|
||||
if (!transitionInProgress) {
|
||||
activity?.clearButton?.isVisible = !query.isNullOrEmpty()
|
||||
}
|
||||
@ -235,7 +235,7 @@ class ContactsView(private val bundle: Bundle? = null) : BaseView() {
|
||||
}
|
||||
|
||||
private fun setSearchQuery(query: CharSequence?) {
|
||||
viewModel.setSearchQuery(query.toString())
|
||||
viewModel.setSearchQuery(query)
|
||||
}
|
||||
|
||||
override fun onFloatingActionButtonClick() {
|
||||
|
@ -40,7 +40,6 @@ import com.nextcloud.talk.newarch.features.contactsflow.ContactsViewOperationSta
|
||||
import com.nextcloud.talk.newarch.features.contactsflow.ParticipantElement
|
||||
import com.nextcloud.talk.newarch.features.conversationslist.ConversationsListView
|
||||
import com.nextcloud.talk.newarch.services.GlobalService
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.koin.core.parameter.parametersOf
|
||||
|
||||
@ -58,13 +57,9 @@ class ContactsViewModel constructor(
|
||||
private val _operationState = MutableLiveData(ContactsViewOperationStateWrapper(ContactsViewOperationState.WAITING, null, null))
|
||||
val operationState: LiveData<ContactsViewOperationStateWrapper> = _operationState.distinctUntilChanged()
|
||||
|
||||
private var searchQuery: MutableLiveData<String?> = MutableLiveData()
|
||||
var searchQueryLiveData: LiveData<String?> = Transformations.switchMap(searchQuery) { searchQuery ->
|
||||
if (initialized) {
|
||||
loadContacts()
|
||||
}
|
||||
liveData<String?> { searchQuery }
|
||||
}
|
||||
private val filterMutableLiveData: MutableLiveData<CharSequence?> = MutableLiveData(null)
|
||||
val filterLiveData: LiveData<CharSequence?> = filterMutableLiveData
|
||||
|
||||
private var conversationToken: String? = null
|
||||
private var groupConversation: Boolean = false
|
||||
private var initialized = false
|
||||
@ -77,8 +72,9 @@ class ContactsViewModel constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setSearchQuery(query: String?) {
|
||||
searchQuery.postValue(query)
|
||||
fun setSearchQuery(query: CharSequence?) {
|
||||
filterMutableLiveData.postValue(query)
|
||||
loadContacts()
|
||||
}
|
||||
|
||||
fun selectParticipant(participant: Participant) {
|
||||
@ -138,7 +134,7 @@ class ContactsViewModel constructor(
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
getContactsUseCase.invoke(viewModelScope, parametersOf(globalService.currentUserLiveData.value, groupConversation, searchQuery.value, conversationToken), object :
|
||||
getContactsUseCase.invoke(viewModelScope, parametersOf(globalService.currentUserLiveData.value, groupConversation, filterLiveData.value, 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)
|
||||
@ -161,7 +157,7 @@ class ContactsViewModel constructor(
|
||||
} as MutableList<ParticipantElement>
|
||||
|
||||
|
||||
if (conversationToken.isNullOrEmpty() && searchQuery.value.isNullOrEmpty()) {
|
||||
if (conversationToken.isNullOrEmpty() && filterLiveData.value.isNullOrEmpty()) {
|
||||
val newGroupElement = ParticipantElement(Pair(context.getString(R.string.nc_new_group), R.drawable.ic_people_group_white_24px), ParticipantElementType.PARTICIPANT_NEW_GROUP.ordinal)
|
||||
participantElementsList.add(0, newGroupElement)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user