@@ -19,8 +19,11 @@ package com.infomaniak.mail.ui.main.thread
19
19
20
20
import android.content.Context
21
21
import android.content.res.Resources
22
+ import android.graphics.Paint
22
23
import android.text.StaticLayout
24
+ import android.text.TextPaint
23
25
import android.text.TextUtils
26
+ import androidx.core.content.res.ResourcesCompat
24
27
import com.infomaniak.mail.MatomoMail.trackExternalEvent
25
28
import com.infomaniak.mail.R
26
29
import com.infomaniak.mail.data.models.thread.Thread
@@ -31,7 +34,7 @@ import com.infomaniak.mail.utils.extensions.formatSubject
31
34
import com.infomaniak.mail.utils.extensions.postfixWithTag
32
35
import javax.inject.Inject
33
36
import javax.inject.Singleton
34
- import com.infomaniak.lib.core.R as CoreR
37
+ import com.infomaniak.lib.core.R as RCore
35
38
36
39
@Singleton
37
40
class SubjectFormatter @Inject constructor(private val context : Context ) {
@@ -97,20 +100,20 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
97
100
private fun postFixWithFolder (
98
101
previousContent : CharSequence ,
99
102
folderName : String ,
100
- ellipsizeTag : EllipsizeConfiguration
103
+ ellipsizeConfiguration : EllipsizeConfiguration
101
104
) = context.postfixWithTag(
102
105
previousContent,
103
106
folderName,
104
- TagColor (R .color.folderNameBackground , R .color.folderNameTextColor ),
105
- ellipsizeTag
107
+ TagColor (R .color.tagBackground , R .color.tagTextColor ),
108
+ ellipsizeConfiguration
106
109
)
107
110
108
111
private fun getFolderName (thread : Thread ) = if (thread.messages.size > 1 ) " " else thread.folderName
109
112
110
113
private fun getEllipsizeConfiguration (previousContent : CharSequence , tag : String ): EllipsizeConfiguration {
111
- val paddingsInPixels = (context.resources.getDimension(CoreR .dimen.marginStandard ) * 2 ).toInt()
114
+ val paddingsInPixels = (context.resources.getDimension(R .dimen.threadHorizontalMargin ) * 2 ).toInt()
112
115
val width = Resources .getSystem().displayMetrics.widthPixels - paddingsInPixels
113
- val tagsTextPaint = RoundedBackgroundSpan . getTagsPaint(context)
116
+ val tagsTextPaint = getTagsPaint(context)
114
117
115
118
val layoutBeforeAddingTag = StaticLayout .Builder .obtain(
116
119
previousContent,
@@ -120,13 +123,20 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
120
123
width
121
124
).build()
122
125
123
- val fullString = " $previousContent $tag "
124
- val layoutAfterAddingTag = StaticLayout .Builder .obtain(fullString, 0 , fullString.length, tagsTextPaint, width).build()
126
+ // Colors are not used but here, we just need to compute the tag layouts
127
+ val stringAfterAddingTag = context.postfixWithTag(
128
+ previousContent,
129
+ tag,
130
+ TagColor (RCore .color.black, RCore .color.black)
131
+ )
132
+
133
+ val layoutAfterAddingTag =
134
+ StaticLayout .Builder .obtain(stringAfterAddingTag, 0 , stringAfterAddingTag.length, tagsTextPaint, width).build()
125
135
126
136
val positionLastChar = layoutBeforeAddingTag.getPrimaryHorizontal(previousContent.length).toInt()
127
137
val linesCountDifferent = layoutAfterAddingTag.lineCount != layoutBeforeAddingTag.lineCount
128
- val maxWidth = if (layoutAfterAddingTag.lineCount != layoutBeforeAddingTag.lineCount ) width else width - positionLastChar
129
- return EllipsizeConfiguration (maxWidth, TextUtils .TruncateAt .MIDDLE , linesCountDifferent)
138
+ val maxWidth = if (linesCountDifferent ) width else width - positionLastChar
139
+ return EllipsizeConfiguration (maxWidth, TextUtils .TruncateAt .MIDDLE , linesCountDifferent, tagsTextPaint )
130
140
}
131
141
132
142
data class SubjectData (
@@ -139,6 +149,15 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
139
149
data class EllipsizeConfiguration (
140
150
val maxWidth : Int ,
141
151
val truncateAt : TextUtils .TruncateAt = TextUtils .TruncateAt .MIDDLE ,
142
- val withNewLine : Boolean = false
152
+ val withNewLine : Boolean = false ,
153
+ val tagTextPaint : TextPaint
143
154
)
155
+
156
+ companion object {
157
+
158
+ fun getTagsPaint (context : Context ) = TextPaint (Paint .ANTI_ALIAS_FLAG ).apply {
159
+ textSize = context.resources.getDimension(R .dimen.tagTextSize)
160
+ typeface = ResourcesCompat .getFont(context, R .font.tag_font)
161
+ }
162
+ }
144
163
}
0 commit comments