@@ -21,6 +21,8 @@ import android.content.Context
2121import android.content.res.ColorStateList
2222import android.graphics.Canvas
2323import android.os.Build
24+ import android.text.Spannable
25+ import android.text.TextUtils.TruncateAt
2426import android.view.HapticFeedbackConstants
2527import android.view.LayoutInflater
2628import android.view.View
@@ -46,13 +48,13 @@ import com.infomaniak.mail.R
4648import com.infomaniak.mail.data.LocalSettings
4749import com.infomaniak.mail.data.LocalSettings.SwipeAction
4850import com.infomaniak.mail.data.LocalSettings.ThreadDensity
49- import com.infomaniak.mail.data.LocalSettings.ThreadDensity.COMPACT
50- import com.infomaniak.mail.data.LocalSettings.ThreadDensity.LARGE
5151import com.infomaniak.mail.data.models.Folder.FolderRole
5252import com.infomaniak.mail.data.models.correspondent.Recipient
5353import com.infomaniak.mail.data.models.thread.Thread
5454import com.infomaniak.mail.databinding.*
5555import 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
5658import com.infomaniak.mail.utils.RealmChangesBinding
5759import com.infomaniak.mail.utils.Utils.runCatchingRealm
5860import com.infomaniak.mail.utils.extensions.*
@@ -94,6 +96,7 @@ class ThreadListAdapter @Inject constructor(
9496 private var folderRole: FolderRole ? = null
9597 private var onSwipeFinished: (() -> Unit )? = null
9698 private var multiSelection: MultiSelectionListener <Thread >? = null
99+ private var isFolderNameVisible: Boolean = false
97100
98101 // region Tablet mode
99102 private var openedThreadPosition: Int? = null
@@ -108,10 +111,12 @@ class ThreadListAdapter @Inject constructor(
108111 folderRole : FolderRole ? ,
109112 onSwipeFinished : (() -> Unit )? = null,
110113 multiSelection : MultiSelectionListener <Thread >? = null,
114+ isFolderNameVisible : Boolean = false,
111115 ) {
112116 this .folderRole = folderRole
113117 this .onSwipeFinished = onSwipeFinished
114118 this .multiSelection = multiSelection
119+ this .isFolderNameVisible = isFolderNameVisible
115120 }
116121
117122 override fun onAttachedToRecyclerView (recyclerView : RecyclerView ) {
@@ -188,6 +193,8 @@ class ThreadListAdapter @Inject constructor(
188193 setupThreadDensityDependentUi()
189194 displayAvatar(thread)
190195
196+ displayFolderName(thread)
197+
191198 with (thread) {
192199 expeditor.text = formatRecipientNames(computeDisplayedRecipients())
193200 mailSubject.text = context.formatSubject(subject)
@@ -226,6 +233,37 @@ class ThreadListAdapter @Inject constructor(
226233 updateSelectedUi(thread)
227234 }
228235
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+
229267 private fun CardviewThreadItemBinding.onThreadClickWithAbilityToOpenMultiSelection (
230268 thread : Thread ,
231269 listener : MultiSelectionListener <Thread >,
@@ -302,27 +340,27 @@ class ThreadListAdapter @Inject constructor(
302340
303341 multiSelection?.let {
304342 with (localSettings) {
305- expeditorAvatar.isVisible = ! isMultiSelected && threadDensity == LARGE
343+ expeditorAvatar.isVisible = ! isMultiSelected && threadDensity == ThreadDensity . LARGE
306344 checkMarkLayout.isVisible = it.isEnabled
307345 checkedState.isVisible = isMultiSelected
308- uncheckedState.isVisible = ! isMultiSelected && threadDensity != LARGE
346+ uncheckedState.isVisible = ! isMultiSelected && threadDensity != ThreadDensity . LARGE
309347 }
310348 }
311349 }
312350
313351 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
315353 threadCard.setMarginsRelative(top = margin, bottom = margin)
316354
317- expeditorAvatar.isVisible = threadDensity == LARGE
318- mailBodyPreview.isGone = threadDensity == COMPACT
355+ expeditorAvatar.isVisible = threadDensity == ThreadDensity . LARGE
356+ mailBodyPreview.isGone = threadDensity == ThreadDensity . COMPACT
319357
320358 checkMarkBackground.reshapeToDensity()
321359 uncheckedState.reshapeToDensity()
322360 }
323361
324362 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
326364 layoutParams.apply {
327365 width = checkMarkSize
328366 height = checkMarkSize
@@ -542,7 +580,7 @@ class ThreadListAdapter @Inject constructor(
542580 add(folderRole)
543581 }
544582
545- if (threadDensity == COMPACT ) {
583+ if (threadDensity == ThreadDensity . COMPACT ) {
546584 if (multiSelection?.selectedItems?.let (threads::containsAll) == false ) {
547585 multiSelection?.selectedItems?.removeAll { ! threads.contains(it) }
548586 }
0 commit comments