@@ -53,30 +53,36 @@ class AddToFolderBottomSheet private constructor(private val onDismissListener:
53
53
fun onDismiss ()
54
54
}
55
55
56
+ enum class ThreadType (val value : Int ) {
57
+ INDIVIDUAL (1 ),
58
+ GROUP (2 ),
59
+ OTHER (3 )
60
+ }
61
+
56
62
private val viewModel by viewModel { ConversationListViewModel (isArchived = false ) }
57
63
58
64
companion object {
59
65
private const val ARG_FOLDERS = " argument.folders"
60
66
private const val ARG_THREAD_IDS = " argument.thread.ids"
61
- private const val ARG_ARE_ALL_INDIVIDUAL_CHATS = " argument.are.all.individual.chats"
62
- private const val ARG_ARE_ALL_GROUP_CHATS = " argument.are.all.group.chats"
67
+ private const val ARG_THREAD_TYPES = " argument.thread.types"
63
68
64
69
/* *
65
70
* Shows a bottom sheet that allows a thread to be added to a folder.
66
71
*
67
72
* @param folders list of available folders to add a thread to
68
73
* @param threadIds list of threads that are going to be added
69
- * @param areAllIndividualChats whether the threads are all individual/1:1 chats as opposed to group chats
70
- * @param areAllGroupChats whether the threads are all group chats as opposed to individual/1:1 chats
74
+ * @param threadTypes list of ThreadType of threads present in threadIds
71
75
*/
72
76
@JvmStatic
73
- fun showChatFolderSheet (folders : List <ChatFolderRecord >, threadIds : List <Long >, areAllIndividualChats : Boolean , areAllGroupChats : Boolean , onDismissListener : OnDismissListener ): ComposeBottomSheetDialogFragment {
77
+ fun showChatFolderSheet (folders : List <ChatFolderRecord >, threadIds : List <Long >, threadTypes : List <Int >, onDismissListener : OnDismissListener ): ComposeBottomSheetDialogFragment {
78
+ assert (threadIds.size== threadTypes.size) {
79
+ " ThreadIds and ThreadTypes should have same size"
80
+ }
74
81
return AddToFolderBottomSheet (onDismissListener).apply {
75
82
arguments = bundleOf(
76
83
ARG_FOLDERS to folders,
77
84
ARG_THREAD_IDS to threadIds.toLongArray(),
78
- ARG_ARE_ALL_INDIVIDUAL_CHATS to areAllIndividualChats,
79
- ARG_ARE_ALL_GROUP_CHATS to areAllGroupChats,
85
+ ARG_THREAD_TYPES to threadTypes.toIntArray(),
80
86
)
81
87
}
82
88
}
@@ -86,13 +92,10 @@ class AddToFolderBottomSheet private constructor(private val onDismissListener:
86
92
override fun SheetContent () {
87
93
val folders = requireArguments().getParcelableArrayListCompat(ARG_FOLDERS , ChatFolderRecord ::class .java)?.filter { it.folderType != ChatFolderRecord .FolderType .ALL }
88
94
val threadIds = requireArguments().getLongArray(ARG_THREAD_IDS )?.asList() ? : throw IllegalArgumentException (" At least one ThreadId is expected!" )
89
- val areAllIndividualChats = requireArguments().getBoolean(ARG_ARE_ALL_INDIVIDUAL_CHATS )
90
- val areAllGroupChats = requireArguments().getBoolean(ARG_ARE_ALL_GROUP_CHATS )
91
-
95
+ val threadTypes = requireArguments().getIntArray(ARG_THREAD_TYPES )?.asList() ? : throw IllegalArgumentException (" At least one ThreadId is expected!" )
92
96
AddToChatFolderSheetContent (
93
97
threadIds = threadIds,
94
- areAllIndividualChats = areAllIndividualChats,
95
- areAllGroupChats = areAllGroupChats,
98
+ threadTypes = threadTypes,
96
99
folders = remember { folders ? : emptyList() },
97
100
onClick = { folder, isAlreadyAdded ->
98
101
if (isAlreadyAdded) {
@@ -121,8 +124,7 @@ class AddToFolderBottomSheet private constructor(private val onDismissListener:
121
124
@Composable
122
125
private fun AddToChatFolderSheetContent (
123
126
threadIds : List <Long >,
124
- areAllIndividualChats : Boolean ,
125
- areAllGroupChats : Boolean ,
127
+ threadTypes : List <Int >,
126
128
folders : List <ChatFolderRecord >,
127
129
onClick : (ChatFolderRecord , Boolean ) -> Unit = { _, _ -> },
128
130
onCreate : () -> Unit = {}
@@ -147,11 +149,7 @@ private fun AddToChatFolderSheetContent(
147
149
.background(color = MaterialTheme .colorScheme.surface, shape = RoundedCornerShape (18 .dp))
148
150
) {
149
151
items(folders) { folder ->
150
- val isIncludedViaChatType = (areAllIndividualChats && folder.showIndividualChats) || (areAllGroupChats && folder.showGroupChats)
151
- val isIncludedExplicitly = folder.includedChats.containsAll(threadIds)
152
- val isExcludedExplicitly = folder.excludedChats.containsAll(threadIds)
153
-
154
- val isAlreadyAdded = (isIncludedExplicitly || isIncludedViaChatType) && ! isExcludedExplicitly
152
+ val isAlreadyAdded = isThreadListAlreadyAdded(folder, threadIds, threadTypes)
155
153
156
154
Row (
157
155
verticalAlignment = Alignment .CenterVertically ,
@@ -227,15 +225,36 @@ private fun AddToChatFolderSheetContent(
227
225
}
228
226
}
229
227
228
+ fun isThreadListAlreadyAdded (folder : ChatFolderRecord , threadIds : List <Long >, threadTypes : List <Int >): Boolean {
229
+ val isAnyExcluded = threadIds.any {
230
+ folder.excludedChats.contains(it)
231
+ }
232
+ if (isAnyExcluded) {
233
+ return false
234
+ }
235
+
236
+ if (folder.showIndividualChats) {
237
+ return threadTypes.indices.all { index ->
238
+ threadTypes[index] == AddToFolderBottomSheet .ThreadType .INDIVIDUAL .value || folder.includedChats.contains(threadIds[index])
239
+ }
240
+ }
241
+ if (folder.showGroupChats) {
242
+ return threadTypes.indices.all { index ->
243
+ threadTypes[index] == AddToFolderBottomSheet .ThreadType .GROUP .value || folder.includedChats.contains(threadIds[index])
244
+ }
245
+ }
246
+
247
+ return folder.includedChats.containsAll(threadIds)
248
+ }
249
+
230
250
@SignalPreview
231
251
@Composable
232
252
private fun AddToChatFolderSheetContentPreview () {
233
253
Previews .BottomSheetPreview {
234
254
AddToChatFolderSheetContent (
235
255
folders = listOf (ChatFolderRecord (name = " Friends" ), ChatFolderRecord (name = " Work" )),
236
256
threadIds = listOf (1 ),
237
- areAllIndividualChats = true ,
238
- areAllGroupChats = false
257
+ threadTypes = listOf (0 )
239
258
)
240
259
}
241
260
}
0 commit comments