From 38135f845e53bda17a14303d54989b03907daafd Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 14:53:54 +0100 Subject: [PATCH 1/6] use field parameter "searchTerm" Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); From e2dc525bf1a52aeefb2b6485df5abd32b59abdd0 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 15:01:13 +0100 Subject: [PATCH 2/6] implement search in open conversations Signed-off-by: sowjanyakch --- .../openconversations/ListOpenConversationsActivity.kt | 5 ++++- .../data/OpenConversationsRepository.kt | 2 +- .../data/OpenConversationsRepositoryImpl.kt | 5 +++-- .../viewmodels/OpenConversationsViewModel.kt | 10 +++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) 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..002b2d1e6 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,7 +70,8 @@ class ListOpenConversationsActivity : BaseActivity() { handleSearchUI(searching) } binding.editText.doOnTextChanged { text, _, _, count -> - adapter.filter(text.toString()) + openConversationsViewModel.updateSearchTerm(text.toString()) + openConversationsViewModel.fetchConversations() } initObservers() @@ -83,6 +85,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/data/OpenConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt index 4e9fb7a15..149edbc34 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..0eff93bf3 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..8a5fc436e 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 From 0035e03cd25d808370dae38993c1f51110dfc213 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 15:04:49 +0100 Subject: [PATCH 3/6] remove unused code Signed-off-by: sowjanyakch --- .../adapters/OpenConversationsAdapter.kt | 29 ------------------- 1 file changed, 29 deletions(-) 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() { From 9068a42f10876d2a954b06c11dd9ff9a3727c5ff Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 15:21:58 +0100 Subject: [PATCH 4/6] configured editText to occupy single line Signed-off-by: sowjanyakch --- app/src/main/res/layout/activity_open_conversations.xml | 1 + 1 file changed, 1 insertion(+) 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"/> From 298cf3a249cf150f76230a4113d4ac452dd1c45a Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 15:35:43 +0100 Subject: [PATCH 5/6] ktlintFormat Signed-off-by: sowjanyakch --- .../talk/openconversations/data/OpenConversationsRepository.kt | 2 +- .../openconversations/data/OpenConversationsRepositoryImpl.kt | 2 +- .../openconversations/viewmodels/OpenConversationsViewModel.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 149edbc34..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(searchTerm:String): 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 0eff93bf3..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,7 +21,7 @@ class OpenConversationsRepositoryImpl(private val ncApi: NcApi, currentUserProvi val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)) - override fun fetchConversations(searchTerm:String): Observable> { + override fun fetchConversations(searchTerm: String): Observable> { val roomOverall = ncApi.getOpenConversations( credentials, ApiUtils.getUrlForOpenConversations(apiVersion, currentUser.baseUrl!!), 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 8a5fc436e..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 @@ -38,7 +38,7 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope fun fetchConversations() { _viewState.value = FetchConversationsStartState - repository.fetchConversations(_searchTerm.value?: "") + repository.fetchConversations(_searchTerm.value ?: "") .subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) ?.subscribe(FetchConversationsObserver()) From 006cfae6f18c8e62cfbd2a16ec1d24cedcff47bf Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 19 Dec 2024 16:29:55 +0100 Subject: [PATCH 6/6] sort conversations only if text is present Signed-off-by: sowjanyakch --- .../openconversations/ListOpenConversationsActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 002b2d1e6..10380f941 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -70,10 +70,11 @@ class ListOpenConversationsActivity : BaseActivity() { handleSearchUI(searching) } binding.editText.doOnTextChanged { text, _, _, count -> - openConversationsViewModel.updateSearchTerm(text.toString()) - openConversationsViewModel.fetchConversations() + if (!text.isNullOrBlank()) { + openConversationsViewModel.updateSearchTerm(text.toString()) + openConversationsViewModel.fetchConversations() + } } - initObservers() }