1
0
mirror of https://github.com/nextcloud/talk-android synced 2025-03-11 18:10:44 +00:00

WIP filter conversations feature, functionality finished

Signed-off-by: Julius Linus julius.linus@nextcloud.com

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
rapterjet2004 2023-06-13 15:41:04 -05:00 committed by Andy Scherzinger
parent d209083700
commit b4719bcad3
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
3 changed files with 108 additions and 33 deletions
app/src/main
java/com/nextcloud/talk
res/layout

View File

@ -190,6 +190,12 @@ class ConversationsListActivity :
private var conversationsListBottomDialog: ConversationsListBottomDialog? = null
private var searchHelper: MessageSearchHelper? = null
private var searchViewDisposable: Disposable? = null
private var filterState =
mutableMapOf(
NONE to true,
MENTION to false,
UNREAD to false
)
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
@ -760,7 +766,12 @@ class ConversationsListActivity :
}
binding.filterConversationsButton.setOnClickListener {
val newFragment: DialogFragment = FilterConversationFragment.newInstance(adapter!!)
val newFragment: DialogFragment = FilterConversationFragment.newInstance(
adapter!!,
conversationItems,
filterState,
this
)
newFragment.show(supportFragmentManager, FilterConversationFragment.TAG)
}
@ -1462,6 +1473,12 @@ class ConversationsListActivity :
showErrorDialog()
}
fun updateFilterState(none: Boolean, mention: Boolean, unread: Boolean) {
filterState[NONE] = none
filterState[MENTION] = mention
filterState[UNREAD] = unread
}
companion object {
const val TAG = "ConvListController"
const val UNREAD_BUBBLE_DELAY = 2500
@ -1475,5 +1492,8 @@ class ConversationsListActivity :
const val CLIENT_UPGRADE_GPLAY_LINK = "https://play.google.com/store/apps/details?id="
const val HTTP_SERVICE_UNAVAILABLE = 503
const val MAINTENANCE_MODE_HEADER_KEY = "X-Nextcloud-Maintenance-Mode"
const val NONE: String = "none"
const val MENTION: String = "mention"
const val UNREAD: String = "unread"
}
}

View File

@ -2,7 +2,6 @@ package com.nextcloud.talk.ui.dialog
import android.app.Dialog
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -10,9 +9,12 @@ import androidx.fragment.app.DialogFragment
import autodagger.AutoInjector
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.items.ConversationItem
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.conversationlist.ConversationsListActivity
import com.nextcloud.talk.databinding.DialogFilterConversationBinding
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager
import eu.davidea.flexibleadapter.FlexibleAdapter
@ -20,11 +22,18 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class FilterConversationFragment(adapter: FlexibleAdapter<AbstractFlexibleItem<*>>) : DialogFragment() {
class FilterConversationFragment(
adapter: FlexibleAdapter<AbstractFlexibleItem<*>>,
currentConversations: MutableList<AbstractFlexibleItem<*>>,
savedFilterState: MutableMap<String, Boolean>,
conversationsListActivity: ConversationsListActivity
) : DialogFragment() {
lateinit var binding: DialogFilterConversationBinding
private var dialogView: View? = null
private var currentAdapter: FlexibleAdapter<AbstractFlexibleItem<*>> = adapter
private var filterState = mutableMapOf(NONE to true, MENTION to false, UNREAD to false)
private var currentItems = currentConversations
private var filterState = savedFilterState
private var conversationsList = conversationsListActivity
@Inject
lateinit var ncApi: NcApi
@ -58,59 +67,107 @@ class FilterConversationFragment(adapter: FlexibleAdapter<AbstractFlexibleItem<*
binding.root,
)
}.forEach(viewThemeUtils.platform::colorViewBackground)
updateFilters()
}
private fun setUpListeners() {
binding.noFilterButton.setOnClickListener {
Log.i(TAG, "no filter clicked")
filterState[NONE] = !filterState[NONE]!!
if (filterState[NONE]!!) {
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.colorPrimary))
} else
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
filterState[UNREAD] = false
binding.unreadFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
filterState[MENTION] = false
binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
updateFilters()
}
binding.unreadFilterButton.setOnClickListener {
Log.i(TAG, "unread filter clicked")
filterState[UNREAD] = !filterState[UNREAD]!!
if (filterState[UNREAD]!!) {
binding.unreadFilterButton.setBackgroundColor(
resources.getColor(
R.color
.colorPrimary
)
)
} else binding.unreadFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
changeUnreadFilter()
filterState[NONE] = false
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
changeNoneFilter()
}
binding.mentionedFilterButton.setOnClickListener {
Log.i(TAG, "mentioned filter clicked")
filterState[MENTION] = !filterState[MENTION]!!
if (filterState[MENTION]!!) {
binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.colorPrimary))
} else
binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
changeMentionFilter()
filterState[NONE] = false
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
changeNoneFilter()
}
binding.filterButton.setOnClickListener {
Log.i(TAG, "submit clicked")
processSubmit()
dismiss()
}
}
private fun updateFilters() {
changeNoneFilter()
changeUnreadFilter()
changeMentionFilter()
}
private fun changeMentionFilter() {
if (filterState[MENTION]!!) {
binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.colorPrimary))
} else
binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
}
private fun changeUnreadFilter() {
if (filterState[UNREAD]!!) {
binding.unreadFilterButton.setBackgroundColor(
resources.getColor(R.color.colorPrimary)
)
} else binding.unreadFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
}
private fun changeNoneFilter() {
if (filterState[NONE]!!) {
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.colorPrimary))
} else
binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
}
private fun processSubmit() {
var newItems: MutableList<AbstractFlexibleItem<*>> = ArrayList()
if (filterState[NONE]!!) {
currentAdapter.updateDataSet(currentItems, true)
} else {
val items = currentItems
for (i in items) {
val conversation = (i as ConversationItem).model
if (filter(conversation)) {
newItems.add(i)
}
}
currentAdapter.updateDataSet(newItems, true)
}
conversationsList.updateFilterState(
filterState[NONE]!!,
filterState[MENTION]!!,
filterState[UNREAD]!!
)
}
private fun filter(conversation: Conversation): Boolean {
var result = true
for ((k, v) in filterState) {
if (k != NONE && v) {
when (k) {
MENTION -> result = result && conversation.unreadMention
UNREAD -> result = result && (conversation.unreadMessages > 0)
}
}
}
return result
}
companion object {
@JvmStatic
fun newInstance(adapter: FlexibleAdapter<AbstractFlexibleItem<*>>) = FilterConversationFragment(adapter)
fun newInstance(
adapter: FlexibleAdapter<AbstractFlexibleItem<*>>,
currentConversations: MutableList<AbstractFlexibleItem<*>>,
savedFilterState: MutableMap<String, Boolean>,
conversationsListActivity: ConversationsListActivity
) = FilterConversationFragment(adapter, currentConversations, savedFilterState, conversationsListActivity)
val TAG: String = FilterConversationFragment::class.java.simpleName
const val NONE: String = "none"
const val MENTION: String = "mention"

View File

@ -39,7 +39,6 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_half_margin"
android:padding="@dimen/standard_half_padding"
app:backgroundTint="@color/grey_200"
android:text="@string/unread"/>
<com.google.android.material.button.MaterialButton
@ -48,7 +47,6 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_half_margin"
android:padding="@dimen/standard_half_padding"
app:backgroundTint="@color/grey_200"
android:text="@string/mentioned"/>
</com.google.android.flexbox.FlexboxLayout>