Skip to content

Commit 26031ff

Browse files
committed
Code review
1 parent 3d5fe71 commit 26031ff

File tree

9 files changed

+63
-49
lines changed

9 files changed

+63
-49
lines changed

app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/ThreadController.kt

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.infomaniak.mail.data.cache.mailboxContent
2020
import android.content.Context
2121
import com.infomaniak.mail.data.api.ApiRepository
2222
import com.infomaniak.mail.data.cache.RealmDatabase
23-
import com.infomaniak.mail.data.cache.mailboxContent.FolderController.Companion.getFolder
2423
import com.infomaniak.mail.data.models.Folder
2524
import com.infomaniak.mail.data.models.Folder.FolderRole
2625
import com.infomaniak.mail.data.models.message.Message
@@ -115,16 +114,15 @@ class ThreadController @Inject constructor(
115114
val searchFolder = FolderController.getOrCreateSearchFolder(realm = this)
116115
remoteThreads.map { remoteThread ->
117116
ensureActive()
118-
val firstMessageFolderId = remoteThread.messages.single().folderId
119-
if (remoteThread.messages.size == 1) {
120-
getFolder(firstMessageFolderId, this@writeBlocking)?.let { folder ->
121-
remoteThread.folderName = folder.getLocalizedName(context)
122-
}
123-
}
117+
124118
remoteThread.isFromSearch = true
125119

126120
val folderId = if (remoteThread.messages.count() == 1) {
127-
remoteThread.messages.single().folderId
121+
val firstMessageFolderId = remoteThread.messages.single().folderId
122+
FolderController.getFolder(firstMessageFolderId, this@writeBlocking)?.let { folder ->
123+
remoteThread.folderName = folder.getLocalizedName(context)
124+
}
125+
firstMessageFolderId
128126
} else {
129127
filterFolder!!.id
130128
}

app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListAdapter.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ class ThreadListAdapter @Inject constructor(
190190
private fun shouldDisplayFolderName(folderName: String) = isFolderNameVisible && folderName.isNotEmpty()
191191

192192
private fun CardviewThreadItemBinding.displayThread(thread: Thread, position: Int) {
193-
resetFolderNameVisibility()
194-
displayFolderName(thread)
195193

196194
refreshCachedSelectedPosition(thread.uid, position) // If item changed position, update cached position.
197195
setupThreadDensityDependentUi()
198196
displayAvatar(thread)
199197

198+
displayFolderName(thread)
199+
200200
with(thread) {
201201
expeditor.text = formatRecipientNames(computeDisplayedRecipients())
202202
mailSubject.text = context.formatSubject(subject)
@@ -236,15 +236,18 @@ class ThreadListAdapter @Inject constructor(
236236
}
237237

238238
private fun CardviewThreadItemBinding.displayFolderName(thread: Thread) {
239+
resetFolderNameVisibility()
240+
239241
val folderNameView = if (localSettings.threadDensity == COMPACT) folderNameCompactMode else folderNameExpandMode
240242
if (shouldDisplayFolderName(thread.folderName)) {
241243
folderNameView.isVisible = true
242244
folderNameView.text = context.postfixWithTag(
243245
tag = thread.folderName,
244-
tagColor = TagColor(R.color.folderNameBackground, R.color.folderNameTextColor),
246+
tagColor = TagColor(R.color.tagBackground, R.color.tagTextColor),
245247
ellipsizeConfiguration = SubjectFormatter.EllipsizeConfiguration(
246-
maxWidth = context.resources.getDimension(R.dimen.subjectTagMaxSize).toInt(),
247-
truncateAt = TextUtils.TruncateAt.END
248+
maxWidth = context.resources.getDimension(R.dimen.folderNameTagMaxSize).toInt(),
249+
truncateAt = TextUtils.TruncateAt.END,
250+
tagTextPaint = SubjectFormatter.getTagsPaint(context)
248251
),
249252
)
250253
} else {

app/src/main/java/com/infomaniak/mail/ui/main/thread/RoundedBackgroundSpan.kt

+2-12
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,14 @@ import androidx.core.content.res.ResourcesCompat
3030
import com.infomaniak.mail.R
3131

3232
/**
33-
* A span to create a rounded background on a text.
34-
*
35-
* If radius is set, it generates a rounded background.
36-
* If radius is null, it generates a circle background.
33+
* A span to create a rounded background with the specified radius on a text.
3734
*/
3835
class RoundedBackgroundSpan(
3936
private val backgroundColor: Int,
4037
private val textColor: Int,
4138
private val textTypeface: Typeface,
4239
private val fontSize: Float,
43-
private val cornerRadius: Float = CORNER_RADIUS
40+
private val cornerRadius: Float
4441
) : ReplacementSpan(), LineHeightSpan {
4542

4643
override fun getSize(paint: Paint, text: CharSequence?, start: Int, end: Int, fm: FontMetricsInt?): Int {
@@ -102,12 +99,5 @@ class RoundedBackgroundSpan(
10299
private const val LEFT_MARGIN = 4
103100
private const val PADDING = 16
104101
private const val VERTICAL_OFFSET = 4
105-
private const val CORNER_RADIUS = 10f
106-
107-
fun getTagsPaint(context: Context) = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
108-
color = ResourcesCompat.getColor(context.resources, R.color.folderNameTextColor, null)
109-
textSize = context.resources.getDimension(R.dimen.externalTagTextSize)
110-
typeface = ResourcesCompat.getFont(context, R.font.tag_font)
111-
}
112102
}
113103
}

app/src/main/java/com/infomaniak/mail/ui/main/thread/SubjectFormatter.kt

+30-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ package com.infomaniak.mail.ui.main.thread
1919

2020
import android.content.Context
2121
import android.content.res.Resources
22+
import android.graphics.Paint
2223
import android.text.StaticLayout
24+
import android.text.TextPaint
2325
import android.text.TextUtils
26+
import androidx.core.content.res.ResourcesCompat
2427
import com.infomaniak.mail.MatomoMail.trackExternalEvent
2528
import com.infomaniak.mail.R
2629
import com.infomaniak.mail.data.models.thread.Thread
@@ -31,7 +34,7 @@ import com.infomaniak.mail.utils.extensions.formatSubject
3134
import com.infomaniak.mail.utils.extensions.postfixWithTag
3235
import javax.inject.Inject
3336
import javax.inject.Singleton
34-
import com.infomaniak.lib.core.R as CoreR
37+
import com.infomaniak.lib.core.R as RCore
3538

3639
@Singleton
3740
class SubjectFormatter @Inject constructor(private val context: Context) {
@@ -97,20 +100,20 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
97100
private fun postFixWithFolder(
98101
previousContent: CharSequence,
99102
folderName: String,
100-
ellipsizeTag: EllipsizeConfiguration
103+
ellipsizeConfiguration: EllipsizeConfiguration
101104
) = context.postfixWithTag(
102105
previousContent,
103106
folderName,
104-
TagColor(R.color.folderNameBackground, R.color.folderNameTextColor),
105-
ellipsizeTag
107+
TagColor(R.color.tagBackground, R.color.tagTextColor),
108+
ellipsizeConfiguration
106109
)
107110

108111
private fun getFolderName(thread: Thread) = if (thread.messages.size > 1) "" else thread.folderName
109112

110113
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()
112115
val width = Resources.getSystem().displayMetrics.widthPixels - paddingsInPixels
113-
val tagsTextPaint = RoundedBackgroundSpan.getTagsPaint(context)
116+
val tagsTextPaint = getTagsPaint(context)
114117

115118
val layoutBeforeAddingTag = StaticLayout.Builder.obtain(
116119
previousContent,
@@ -120,13 +123,20 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
120123
width
121124
).build()
122125

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()
125135

126136
val positionLastChar = layoutBeforeAddingTag.getPrimaryHorizontal(previousContent.length).toInt()
127137
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)
130140
}
131141

132142
data class SubjectData(
@@ -139,6 +149,15 @@ class SubjectFormatter @Inject constructor(private val context: Context) {
139149
data class EllipsizeConfiguration(
140150
val maxWidth: Int,
141151
val truncateAt: TextUtils.TruncateAt = TextUtils.TruncateAt.MIDDLE,
142-
val withNewLine: Boolean = false
152+
val withNewLine: Boolean = false,
153+
val tagTextPaint: TextPaint
143154
)
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+
}
144163
}

app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import com.infomaniak.mail.ui.main.folder.ThreadListAdapter
8383
import com.infomaniak.mail.ui.main.thread.MessageWebViewClient
8484
import com.infomaniak.mail.ui.main.thread.RoundedBackgroundSpan
8585
import com.infomaniak.mail.ui.main.thread.SubjectFormatter
86+
import com.infomaniak.mail.ui.main.thread.SubjectFormatter.Companion.getTagsPaint
8687
import com.infomaniak.mail.ui.main.thread.ThreadFragment.HeaderState
8788
import com.infomaniak.mail.utils.*
8889
import com.infomaniak.mail.utils.Utils
@@ -516,7 +517,7 @@ fun Context.postfixWithTag(
516517

517518
fun getConfiguredTag(): CharSequence {
518519
return if (ellipsizeConfiguration != null) {
519-
val textPaint = RoundedBackgroundSpan.getTagsPaint(this)
520+
val textPaint = getTagsPaint(this)
520521
with(ellipsizeConfiguration) {
521522
val tagNameLayout =
522523
StaticLayout.Builder.obtain(tag, 0, tag.length, textPaint, maxWidth)
@@ -555,14 +556,14 @@ private fun Spannable.setTagSpan(
555556
val backgroundColor = context.getColor(backgroundColorRes)
556557
val textColor = context.getColor(textColorRes)
557558
val textTypeface = ResourcesCompat.getFont(context, R.font.tag_font)!!
558-
val textSize = context.resources.getDimensionPixelSize(R.dimen.externalTagTextSize).toFloat()
559+
val textSize = context.resources.getDimensionPixelSize(R.dimen.tagTextSize).toFloat()
559560
setSpan(
560561
RoundedBackgroundSpan(
561562
backgroundColor = backgroundColor,
562563
textColor = textColor,
563564
textTypeface = textTypeface,
564565
fontSize = textSize,
565-
cornerRadius = context.resources.getDimension(R.dimen.subjectTagRadius)
566+
cornerRadius = context.resources.getDimension(R.dimen.tagRadius)
566567
),
567568
startIndex,
568569
endIndex,

app/src/main/res/layout/cardview_thread_item.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
app:layout_constraintHorizontal_chainStyle="packed"
239239
app:layout_constraintStart_toEndOf="@id/mailSubject"
240240
app:layout_constraintTop_toTopOf="@id/mailSubject"
241-
tools:background="@color/grey_background"
241+
tools:background="@color/tagBackground"
242242
tools:gravity="center"
243243
tools:text="Folder name"
244244
tools:visibility="visible" />

app/src/main/res/values-night/colors.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
<color name="calendarHeaderBackground">@color/orca</color>
8989

9090
<!-- Thread -->
91-
<color name="folderNameTextColor">@color/shark</color>
92-
<color name="folderNameBackground">@color/orca</color>
91+
<color name="tagTextColor">@color/shark</color>
92+
<color name="tagBackground">@color/orca</color>
9393

9494
<!-- Swipe actions -->
9595
<color name="swipeDelete">@color/redDestructiveAction</color>

app/src/main/res/values/colors.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
<color name="manyAvatarsAdditionalPeopleBackground">@color/iconColorSecondaryText</color>
166166

167167
<!-- Thread -->
168-
<color name="folderNameTextColor">@color/elephant</color>
169-
<color name="folderNameBackground">@color/polar_bear</color>
168+
<color name="tagTextColor">@color/elephant</color>
169+
<color name="tagBackground">@color/polar_bear</color>
170170

171171
<!-- Swipe actions -->
172172
<color name="swipeDelete">@color/redDestructiveAction</color>

app/src/main/res/values/dimens.xml

+8-5
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
<dimen name="noMailTextViewSize">300dp</dimen>
3939
<dimen name="searchViewHeight">38dp</dimen>
4040
<dimen name="smallCornerRadius">6dp</dimen>
41-
<dimen name="subjectTagRadius">4dp</dimen>
42-
<dimen name="subjectTagMaxSize">150dp</dimen>
4341
<dimen name="userAvatarSizeLarge">40dp</dimen>
4442
<dimen name="messageDividerHeight">6dp</dimen>
4543
<dimen name="smallIconSize">12dp</dimen>
@@ -52,6 +50,7 @@
5250
<dimen name="textButtonPrimaryHeight">56dp</dimen>
5351
<dimen name="textButtonPrimaryMediumHeight">40dp</dimen>
5452
<dimen name="mediumButtonHorizontalMargin">20dp</dimen>
53+
<dimen name="threadHorizontalMargin">@dimen/marginStandard</dimen>
5554

5655
<!-- Menu Drawer -->
5756
<dimen name="decoratedItemViewHeight">48dp</dimen>
@@ -61,12 +60,16 @@
6160
<dimen name="decoratedItemConstraintMarginStart">@dimen/marginStandardSmall</dimen>
6261
<dimen name="decoratedItemTextMarginStart">@dimen/marginStandardSmall</dimen>
6362

63+
<!-- Tag -->
64+
<dimen name="tagRadius">4dp</dimen>
65+
<dimen name="tagTextSize">12sp</dimen>
66+
67+
<!-- Search folder name tag -->
68+
<dimen name="folderNameTagMaxSize">150dp</dimen>
69+
6470
<!-- Settings -->
6571
<dimen name="dividerHorizontalPadding">16dp</dimen>
6672

67-
<!-- External tag -->
68-
<dimen name="externalTagTextSize">12sp</dimen>
69-
7073
<!-- AI -->
7174
<dimen name="scrimOpacity">0.32</dimen>
7275
<integer name="aiPromptAnimationDuration">300</integer>

0 commit comments

Comments
 (0)