diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 78605a7fc..a404d973a 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -494,7 +494,8 @@ public interface NcApi { Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /listed-room */ @GET - Observable getOpenConversations(@Header("Authorization") String authorization, @Url String url); + Observable getOpenConversations(@Header("Authorization") String authorization, @Url String url, + @Query("searchTerm") String searchTerm); @GET Observable status(@Header("Authorization") String authorization, @Url String url); diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt index 187e7ab4f..10380f941 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -25,6 +25,7 @@ import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.openconversations.adapters.OpenConversationsAdapter import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel import com.nextcloud.talk.utils.bundle.BundleKeys +import com.vanniktech.ui.hideKeyboardAndFocus import com.vanniktech.ui.showKeyboardAndFocus import javax.inject.Inject @@ -69,9 +70,11 @@ class ListOpenConversationsActivity : BaseActivity() { handleSearchUI(searching) } binding.editText.doOnTextChanged { text, _, _, count -> - adapter.filter(text.toString()) + if (!text.isNullOrBlank()) { + openConversationsViewModel.updateSearchTerm(text.toString()) + openConversationsViewModel.fetchConversations() + } } - initObservers() } @@ -83,6 +86,7 @@ class ListOpenConversationsActivity : BaseActivity() { } else { binding.searchOpenConversations.visibility = View.VISIBLE binding.textInputLayout.visibility = View.GONE + binding.editText.hideKeyboardAndFocus() } } diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt index 89da0c002..88416a849 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt @@ -26,8 +26,6 @@ class OpenConversationsAdapter( private val onClick: (Conversation) -> Unit ) : ListAdapter(ConversationsCallback) { - private var originalList: List = emptyList() - private var isFiltering = false inner class OpenConversationsViewHolder(val itemBinding: RvItemOpenConversationBinding) : RecyclerView.ViewHolder(itemBinding.root) { @@ -78,33 +76,6 @@ class OpenConversationsAdapter( val conversation = getItem(position) holder.bindItem(conversation) } - - fun filter(text: String) { - if (text == "") { - submitList(originalList) - isFiltering = false - return - } - - isFiltering = true - val newList = mutableListOf() - for (conversation in originalList) { - if (conversation.displayName.contains(text, true) || conversation.description!!.contains(text, true)) { - newList.add(conversation) - } - } - - if (newList.isNotEmpty()) { - submitList(newList) - } - } - - override fun onCurrentListChanged(previousList: MutableList, currentList: MutableList) { - if (!isFiltering) { - originalList = currentList - } - super.onCurrentListChanged(previousList, currentList) - } } object ConversationsCallback : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt index 4e9fb7a15..884282326 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt @@ -11,5 +11,5 @@ import io.reactivex.Observable interface OpenConversationsRepository { - fun fetchConversations(): Observable> + fun fetchConversations(searchTerm: String): Observable> } diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt index 3dbaf4dbb..6bfdddbe7 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt @@ -21,10 +21,11 @@ class OpenConversationsRepositoryImpl(private val ncApi: NcApi, currentUserProvi val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)) - override fun fetchConversations(): Observable> { + override fun fetchConversations(searchTerm: String): Observable> { val roomOverall = ncApi.getOpenConversations( credentials, - ApiUtils.getUrlForOpenConversations(apiVersion, currentUser.baseUrl!!) + ApiUtils.getUrlForOpenConversations(apiVersion, currentUser.baseUrl!!), + searchTerm ) return roomOverall.map { it.ocs?.data!! } } diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt b/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt index cfe387a26..92501de8b 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt @@ -32,14 +32,22 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope val viewState: LiveData get() = _viewState + private val _searchTerm: MutableLiveData = MutableLiveData("") + val searchTerm: LiveData + get() = _searchTerm + fun fetchConversations() { _viewState.value = FetchConversationsStartState - repository.fetchConversations() + repository.fetchConversations(_searchTerm.value ?: "") .subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) ?.subscribe(FetchConversationsObserver()) } + fun updateSearchTerm(newTerm: String) { + _searchTerm.value = newTerm + } + inner class FetchConversationsObserver : Observer> { override fun onSubscribe(d: Disposable) { // unused atm diff --git a/app/src/main/res/layout/activity_open_conversations.xml b/app/src/main/res/layout/activity_open_conversations.xml index 13ebaf2a0..79822f130 100644 --- a/app/src/main/res/layout/activity_open_conversations.xml +++ b/app/src/main/res/layout/activity_open_conversations.xml @@ -57,6 +57,7 @@ android:layout_height="wrap_content" android:hint="@string/nc_search" android:textColorHint="@color/low_emphasis_text" + android:singleLine="true" android:textColor = "@color/high_emphasis_text"/>