@@ -21,6 +21,8 @@ import android.content.Context
21
21
import android.content.res.ColorStateList
22
22
import android.graphics.Canvas
23
23
import android.os.Build
24
+ import android.text.Spannable
25
+ import android.text.TextUtils.TruncateAt
24
26
import android.view.HapticFeedbackConstants
25
27
import android.view.LayoutInflater
26
28
import android.view.View
@@ -46,13 +48,13 @@ import com.infomaniak.mail.R
46
48
import com.infomaniak.mail.data.LocalSettings
47
49
import com.infomaniak.mail.data.LocalSettings.SwipeAction
48
50
import com.infomaniak.mail.data.LocalSettings.ThreadDensity
49
- import com.infomaniak.mail.data.LocalSettings.ThreadDensity.COMPACT
50
- import com.infomaniak.mail.data.LocalSettings.ThreadDensity.LARGE
51
51
import com.infomaniak.mail.data.models.Folder.FolderRole
52
52
import com.infomaniak.mail.data.models.correspondent.Recipient
53
53
import com.infomaniak.mail.data.models.thread.Thread
54
54
import com.infomaniak.mail.databinding.*
55
55
import com.infomaniak.mail.ui.main.folder.ThreadListAdapter.ThreadListViewHolder
56
+ import com.infomaniak.mail.ui.main.thread.SubjectFormatter
57
+ import com.infomaniak.mail.ui.main.thread.SubjectFormatter.TagColor
56
58
import com.infomaniak.mail.utils.RealmChangesBinding
57
59
import com.infomaniak.mail.utils.Utils.runCatchingRealm
58
60
import com.infomaniak.mail.utils.extensions.*
@@ -94,6 +96,7 @@ class ThreadListAdapter @Inject constructor(
94
96
private var folderRole: FolderRole ? = null
95
97
private var onSwipeFinished: (() -> Unit )? = null
96
98
private var multiSelection: MultiSelectionListener <Thread >? = null
99
+ private var isFolderNameVisible: Boolean = false
97
100
98
101
// region Tablet mode
99
102
private var openedThreadPosition: Int? = null
@@ -108,10 +111,12 @@ class ThreadListAdapter @Inject constructor(
108
111
folderRole : FolderRole ? ,
109
112
onSwipeFinished : (() -> Unit )? = null,
110
113
multiSelection : MultiSelectionListener <Thread >? = null,
114
+ isFolderNameVisible : Boolean = false,
111
115
) {
112
116
this .folderRole = folderRole
113
117
this .onSwipeFinished = onSwipeFinished
114
118
this .multiSelection = multiSelection
119
+ this .isFolderNameVisible = isFolderNameVisible
115
120
}
116
121
117
122
override fun onAttachedToRecyclerView (recyclerView : RecyclerView ) {
@@ -188,6 +193,8 @@ class ThreadListAdapter @Inject constructor(
188
193
setupThreadDensityDependentUi()
189
194
displayAvatar(thread)
190
195
196
+ displayFolderName(thread)
197
+
191
198
with (thread) {
192
199
expeditor.text = formatRecipientNames(computeDisplayedRecipients())
193
200
mailSubject.text = context.formatSubject(subject)
@@ -226,6 +233,37 @@ class ThreadListAdapter @Inject constructor(
226
233
updateSelectedUi(thread)
227
234
}
228
235
236
+ private fun CardviewThreadItemBinding.displayFolderName (thread : Thread ) {
237
+ val isCompactMode = localSettings.threadDensity == ThreadDensity .COMPACT
238
+
239
+ fun setFolderNameVisibility (isVisible : Boolean ) {
240
+ folderNameExpandMode.isVisible = ! isCompactMode && isVisible
241
+ folderNameCompactMode.isVisible = isCompactMode && isVisible
242
+ }
243
+
244
+ val folderNameView = if (isCompactMode) folderNameCompactMode else folderNameExpandMode
245
+
246
+ if (shouldDisplayFolderName(thread.folderName)) {
247
+ folderNameView.text = computeFolderName(thread)
248
+ setFolderNameVisibility(isVisible = true )
249
+ } else {
250
+ setFolderNameVisibility(isVisible = false )
251
+ }
252
+ }
253
+
254
+ private fun shouldDisplayFolderName (folderName : String ) = isFolderNameVisible && folderName.isNotEmpty()
255
+
256
+ private fun CardviewThreadItemBinding.computeFolderName (thread : Thread ): Spannable {
257
+ return context.postfixWithTag(
258
+ tag = thread.folderName,
259
+ tagColor = TagColor (R .color.folderTagBackground, R .color.folderTagTextColor),
260
+ ellipsizeConfiguration = SubjectFormatter .EllipsizeConfiguration (
261
+ maxWidth = context.resources.getDimension(R .dimen.folderNameTagMaxSize),
262
+ truncateAt = TruncateAt .END ,
263
+ ),
264
+ )
265
+ }
266
+
229
267
private fun CardviewThreadItemBinding.onThreadClickWithAbilityToOpenMultiSelection (
230
268
thread : Thread ,
231
269
listener : MultiSelectionListener <Thread >,
@@ -302,27 +340,27 @@ class ThreadListAdapter @Inject constructor(
302
340
303
341
multiSelection?.let {
304
342
with (localSettings) {
305
- expeditorAvatar.isVisible = ! isMultiSelected && threadDensity == LARGE
343
+ expeditorAvatar.isVisible = ! isMultiSelected && threadDensity == ThreadDensity . LARGE
306
344
checkMarkLayout.isVisible = it.isEnabled
307
345
checkedState.isVisible = isMultiSelected
308
- uncheckedState.isVisible = ! isMultiSelected && threadDensity != LARGE
346
+ uncheckedState.isVisible = ! isMultiSelected && threadDensity != ThreadDensity . LARGE
309
347
}
310
348
}
311
349
}
312
350
313
351
private fun CardviewThreadItemBinding.setupThreadDensityDependentUi () = with (localSettings) {
314
- val margin = if (threadDensity == COMPACT ) threadMarginCompact else threadMarginOther
352
+ val margin = if (threadDensity == ThreadDensity . COMPACT ) threadMarginCompact else threadMarginOther
315
353
threadCard.setMarginsRelative(top = margin, bottom = margin)
316
354
317
- expeditorAvatar.isVisible = threadDensity == LARGE
318
- mailBodyPreview.isGone = threadDensity == COMPACT
355
+ expeditorAvatar.isVisible = threadDensity == ThreadDensity . LARGE
356
+ mailBodyPreview.isGone = threadDensity == ThreadDensity . COMPACT
319
357
320
358
checkMarkBackground.reshapeToDensity()
321
359
uncheckedState.reshapeToDensity()
322
360
}
323
361
324
362
private fun ImageView.reshapeToDensity () {
325
- val checkMarkSize = if (localSettings.threadDensity == LARGE ) checkMarkSizeLarge else checkMarkSizeOther
363
+ val checkMarkSize = if (localSettings.threadDensity == ThreadDensity . LARGE ) checkMarkSizeLarge else checkMarkSizeOther
326
364
layoutParams.apply {
327
365
width = checkMarkSize
328
366
height = checkMarkSize
@@ -542,7 +580,7 @@ class ThreadListAdapter @Inject constructor(
542
580
add(folderRole)
543
581
}
544
582
545
- if (threadDensity == COMPACT ) {
583
+ if (threadDensity == ThreadDensity . COMPACT ) {
546
584
if (multiSelection?.selectedItems?.let (threads::containsAll) == false ) {
547
585
multiSelection?.selectedItems?.removeAll { ! threads.contains(it) }
548
586
}
0 commit comments