From 6067f04b12fd7314b9d357f1bf33e037701eb3c8 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Wed, 20 Nov 2024 10:54:46 -0600 Subject: [PATCH] Should be working Signed-off-by: rapterjet2004 --- .../ListOpenConversationsActivity.kt | 30 ++++++++++++++++- .../adapters/OpenConversationsAdapter.kt | 32 +++++++++++++++++++ .../layout/activity_open_conversations.xml | 20 +++++++++++- 3 files changed, 80 insertions(+), 2 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 ac57ffe55..77ef599e1 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -10,6 +10,7 @@ import android.content.Intent import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View +import androidx.core.widget.doOnTextChanged import androidx.lifecycle.ViewModelProvider import autodagger.AutoInjector import com.google.android.material.snackbar.Snackbar @@ -23,6 +24,7 @@ import com.nextcloud.talk.openconversations.adapters.OpenConversationsAdapter import com.nextcloud.talk.openconversations.data.OpenConversation import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel import com.nextcloud.talk.utils.bundle.BundleKeys +import com.vanniktech.ui.showKeyboardAndFocus import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) @@ -40,6 +42,8 @@ class ListOpenConversationsActivity : BaseActivity() { lateinit var adapter: OpenConversationsAdapter + var searching = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -52,15 +56,34 @@ class ListOpenConversationsActivity : BaseActivity() { setupActionBar() setContentView(binding.root) setupSystemColors() + viewThemeUtils.platform.colorEditText(binding.searchEdit) val user = currentUserProvider.currentUser.blockingGet() adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) } binding.openConversationsRecyclerView.adapter = adapter + binding.searchOpenConversations.setOnClickListener { + searching = !searching + handleSearchUI(searching) + } + binding.searchEdit.doOnTextChanged { text, _, _, count -> + adapter.filter(text.toString()) + } initObservers() } + private fun handleSearchUI(show: Boolean) { + if (show) { + binding.searchOpenConversations.visibility = View.GONE + binding.searchEdit.visibility = View.VISIBLE + binding.searchEdit.showKeyboardAndFocus() + } else { + binding.searchOpenConversations.visibility = View.VISIBLE + binding.searchEdit.visibility = View.GONE + } + } + private fun adapterOnClick(conversation: OpenConversation) { val bundle = Bundle() bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.roomToken) @@ -105,7 +128,12 @@ class ListOpenConversationsActivity : BaseActivity() { private fun setupActionBar() { setSupportActionBar(binding.openConversationsToolbar) binding.openConversationsToolbar.setNavigationOnClickListener { - onBackPressedDispatcher.onBackPressed() + if (searching) { + handleSearchUI(false) + searching = false + } else { + onBackPressedDispatcher.onBackPressed() + } } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) 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 2fdc128cc..93ede4f59 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 @@ -21,6 +21,8 @@ import com.nextcloud.talk.openconversations.data.OpenConversation class OpenConversationsAdapter(val user: User, private val onClick: (OpenConversation) -> Unit) : ListAdapter(ConversationsCallback) { + private var originalList: List = emptyList() + private var isFiltering = false inner class OpenConversationsViewHolder(val itemBinding: RvItemOpenConversationBinding) : RecyclerView.ViewHolder(itemBinding.root) { @@ -68,6 +70,36 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers 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)) { + 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/res/layout/activity_open_conversations.xml b/app/src/main/res/layout/activity_open_conversations.xml index a13e48734..06bae2172 100644 --- a/app/src/main/res/layout/activity_open_conversations.xml +++ b/app/src/main/res/layout/activity_open_conversations.xml @@ -16,6 +16,7 @@ android:id="@+id/open_conversations_appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> + + app:titleTextColor="@color/fontAppbar" > + + + + +