|
@@ -2,7 +2,6 @@ package com.nextcloud.talk.ui.dialog
|
|
|
|
|
|
import android.app.Dialog
|
|
import android.app.Dialog
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
-import android.util.Log
|
|
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
@@ -10,9 +9,12 @@ import androidx.fragment.app.DialogFragment
|
|
import autodagger.AutoInjector
|
|
import autodagger.AutoInjector
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import com.nextcloud.talk.R
|
|
import com.nextcloud.talk.R
|
|
|
|
+import com.nextcloud.talk.adapters.items.ConversationItem
|
|
import com.nextcloud.talk.api.NcApi
|
|
import com.nextcloud.talk.api.NcApi
|
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
|
|
|
+import com.nextcloud.talk.conversationlist.ConversationsListActivity
|
|
import com.nextcloud.talk.databinding.DialogFilterConversationBinding
|
|
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.ui.theme.ViewThemeUtils
|
|
import com.nextcloud.talk.users.UserManager
|
|
import com.nextcloud.talk.users.UserManager
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
@@ -20,11 +22,18 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
|
import javax.inject.Inject
|
|
import javax.inject.Inject
|
|
|
|
|
|
@AutoInjector(NextcloudTalkApplication::class)
|
|
@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
|
|
lateinit var binding: DialogFilterConversationBinding
|
|
private var dialogView: View? = null
|
|
private var dialogView: View? = null
|
|
private var currentAdapter: FlexibleAdapter<AbstractFlexibleItem<*>> = adapter
|
|
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
|
|
@Inject
|
|
lateinit var ncApi: NcApi
|
|
lateinit var ncApi: NcApi
|
|
@@ -58,59 +67,107 @@ class FilterConversationFragment(adapter: FlexibleAdapter<AbstractFlexibleItem<*
|
|
binding.root,
|
|
binding.root,
|
|
)
|
|
)
|
|
}.forEach(viewThemeUtils.platform::colorViewBackground)
|
|
}.forEach(viewThemeUtils.platform::colorViewBackground)
|
|
|
|
+ updateFilters()
|
|
}
|
|
}
|
|
|
|
|
|
private fun setUpListeners() {
|
|
private fun setUpListeners() {
|
|
binding.noFilterButton.setOnClickListener {
|
|
binding.noFilterButton.setOnClickListener {
|
|
- Log.i(TAG, "no filter clicked")
|
|
|
|
filterState[NONE] = !filterState[NONE]!!
|
|
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
|
|
filterState[UNREAD] = false
|
|
- binding.unreadFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
|
|
|
|
filterState[MENTION] = false
|
|
filterState[MENTION] = false
|
|
- binding.mentionedFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
|
|
|
|
|
|
+ updateFilters()
|
|
}
|
|
}
|
|
|
|
|
|
binding.unreadFilterButton.setOnClickListener {
|
|
binding.unreadFilterButton.setOnClickListener {
|
|
- Log.i(TAG, "unread filter clicked")
|
|
|
|
filterState[UNREAD] = !filterState[UNREAD]!!
|
|
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
|
|
filterState[NONE] = false
|
|
- binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
|
|
|
|
|
|
+ changeNoneFilter()
|
|
}
|
|
}
|
|
|
|
|
|
binding.mentionedFilterButton.setOnClickListener {
|
|
binding.mentionedFilterButton.setOnClickListener {
|
|
- Log.i(TAG, "mentioned filter clicked")
|
|
|
|
filterState[MENTION] = !filterState[MENTION]!!
|
|
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
|
|
filterState[NONE] = false
|
|
- binding.noFilterButton.setBackgroundColor(resources.getColor(R.color.grey_200))
|
|
|
|
|
|
+ changeNoneFilter()
|
|
}
|
|
}
|
|
|
|
|
|
binding.filterButton.setOnClickListener {
|
|
binding.filterButton.setOnClickListener {
|
|
- Log.i(TAG, "submit clicked")
|
|
|
|
|
|
+ processSubmit()
|
|
dismiss()
|
|
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 {
|
|
companion object {
|
|
@JvmStatic
|
|
@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
|
|
val TAG: String = FilterConversationFragment::class.java.simpleName
|
|
const val NONE: String = "none"
|
|
const val NONE: String = "none"
|
|
const val MENTION: String = "mention"
|
|
const val MENTION: String = "mention"
|