Should be working

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2024-11-20 10:54:46 -06:00
parent 8228f770b9
commit 6067f04b12
No known key found for this signature in database
GPG key ID: 3AA5FDFED7944099
3 changed files with 80 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import android.content.Intent
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.widget.doOnTextChanged
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import autodagger.AutoInjector import autodagger.AutoInjector
import com.google.android.material.snackbar.Snackbar 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.data.OpenConversation
import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel
import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys
import com.vanniktech.ui.showKeyboardAndFocus
import javax.inject.Inject import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
@ -40,6 +42,8 @@ class ListOpenConversationsActivity : BaseActivity() {
lateinit var adapter: OpenConversationsAdapter lateinit var adapter: OpenConversationsAdapter
var searching = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
@ -52,15 +56,34 @@ class ListOpenConversationsActivity : BaseActivity() {
setupActionBar() setupActionBar()
setContentView(binding.root) setContentView(binding.root)
setupSystemColors() setupSystemColors()
viewThemeUtils.platform.colorEditText(binding.searchEdit)
val user = currentUserProvider.currentUser.blockingGet() val user = currentUserProvider.currentUser.blockingGet()
adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) } adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) }
binding.openConversationsRecyclerView.adapter = adapter binding.openConversationsRecyclerView.adapter = adapter
binding.searchOpenConversations.setOnClickListener {
searching = !searching
handleSearchUI(searching)
}
binding.searchEdit.doOnTextChanged { text, _, _, count ->
adapter.filter(text.toString())
}
initObservers() 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) { private fun adapterOnClick(conversation: OpenConversation) {
val bundle = Bundle() val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.roomToken) bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.roomToken)
@ -105,7 +128,12 @@ class ListOpenConversationsActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.openConversationsToolbar) setSupportActionBar(binding.openConversationsToolbar)
binding.openConversationsToolbar.setNavigationOnClickListener { binding.openConversationsToolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed() if (searching) {
handleSearchUI(false)
searching = false
} else {
onBackPressedDispatcher.onBackPressed()
}
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -21,6 +21,8 @@ import com.nextcloud.talk.openconversations.data.OpenConversation
class OpenConversationsAdapter(val user: User, private val onClick: (OpenConversation) -> Unit) : class OpenConversationsAdapter(val user: User, private val onClick: (OpenConversation) -> Unit) :
ListAdapter<OpenConversation, OpenConversationsAdapter.OpenConversationsViewHolder>(ConversationsCallback) { ListAdapter<OpenConversation, OpenConversationsAdapter.OpenConversationsViewHolder>(ConversationsCallback) {
private var originalList: List<OpenConversation> = emptyList()
private var isFiltering = false
inner class OpenConversationsViewHolder(val itemBinding: RvItemOpenConversationBinding) : inner class OpenConversationsViewHolder(val itemBinding: RvItemOpenConversationBinding) :
RecyclerView.ViewHolder(itemBinding.root) { RecyclerView.ViewHolder(itemBinding.root) {
@ -68,6 +70,36 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers
val conversation = getItem(position) val conversation = getItem(position)
holder.bindItem(conversation) holder.bindItem(conversation)
} }
fun filter(text: String) {
if (text == "") {
submitList(originalList)
isFiltering = false
return
}
isFiltering = true
val newList = mutableListOf<OpenConversation>()
for (conversation in originalList) {
if (conversation.displayName.contains(text)) {
newList.add(conversation)
}
}
if (newList.isNotEmpty()) {
submitList(newList)
}
}
override fun onCurrentListChanged(
previousList: MutableList<OpenConversation>,
currentList: MutableList<OpenConversation>
) {
if (!isFiltering) {
originalList = currentList
}
super.onCurrentListChanged(previousList, currentList)
}
} }
object ConversationsCallback : DiffUtil.ItemCallback<OpenConversation>() { object ConversationsCallback : DiffUtil.ItemCallback<OpenConversation>() {

View file

@ -16,6 +16,7 @@
android:id="@+id/open_conversations_appbar" android:id="@+id/open_conversations_appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/open_conversations_toolbar" android:id="@+id/open_conversations_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -26,7 +27,24 @@
app:layout_scrollFlags="scroll|enterAlways" app:layout_scrollFlags="scroll|enterAlways"
app:navigationIconTint="@color/fontAppbar" app:navigationIconTint="@color/fontAppbar"
app:popupTheme="@style/appActionBarPopupMenu" app:popupTheme="@style/appActionBarPopupMenu"
app:titleTextColor="@color/fontAppbar" /> app:titleTextColor="@color/fontAppbar" >
<ImageView
android:id="@+id/search_open_conversations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/search_icon"
android:layout_gravity="end"
android:layout_marginHorizontal="@dimen/standard_margin"
android:src="@drawable/ic_search_white_24dp" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/search_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView