Skip to content

Commit e69546c

Browse files
committed
Create a container for icons
wip Reorganize subject formatting methods Code review
1 parent 23a5413 commit e69546c

File tree

15 files changed

+200
-218
lines changed

15 files changed

+200
-218
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import okhttp3.OkHttpClient
4646
import javax.inject.Inject
4747

4848
class ThreadController @Inject constructor(
49+
private val context: Context,
4950
private val mailboxContentRealm: RealmDatabase.MailboxContent,
5051
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
5152
) {
@@ -81,7 +82,6 @@ class ThreadController @Inject constructor(
8182
* @return A list of search threads. The search only returns messages from spam or trash if we explicitly selected those folders
8283
*/
8384
suspend fun initAndGetSearchFolderThreads(
84-
context: Context,
8585
remoteThreads: List<Thread>,
8686
folderRole: FolderRole?,
8787
): List<Thread> = withContext(ioDispatcher) {
@@ -115,12 +115,14 @@ class ThreadController @Inject constructor(
115115
val searchFolder = FolderController.getOrCreateSearchFolder(realm = this)
116116
remoteThreads.map { remoteThread ->
117117
ensureActive()
118+
val firstMessageFolderId = remoteThread.messages.single().folderId
118119
if (remoteThread.messages.size == 1) {
119-
val folderId = remoteThread.messages.first().folderId
120-
getFolder(folderId, this@writeBlocking)?.let { folder -> remoteThread.folderName = folder.getLocalizedName(context) }
120+
getFolder(firstMessageFolderId, this@writeBlocking)?.let { folder ->
121+
remoteThread.folderName = folder.getLocalizedName(context)
122+
}
121123
}
122124
remoteThread.isFromSearch = true
123-
remoteThread.folderId = remoteThread.messages.first().folderId
125+
remoteThread.folderId = firstMessageFolderId
124126

125127
keepOldMessagesAndAddToSearchFolder(remoteThread, searchFolder)
126128

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.content.Context
2121
import android.content.res.ColorStateList
2222
import android.graphics.Canvas
2323
import android.os.Build
24+
import android.text.TextUtils
2425
import android.view.HapticFeedbackConstants
2526
import android.view.LayoutInflater
2627
import android.view.View
@@ -53,7 +54,7 @@ import com.infomaniak.mail.data.models.correspondent.Recipient
5354
import com.infomaniak.mail.data.models.thread.Thread
5455
import com.infomaniak.mail.databinding.*
5556
import com.infomaniak.mail.ui.main.folder.ThreadListAdapter.ThreadListViewHolder
56-
import com.infomaniak.mail.ui.main.thread.SubjectFormatter.getFolderName
57+
import com.infomaniak.mail.ui.main.thread.SubjectFormatter
5758
import com.infomaniak.mail.utils.RealmChangesBinding
5859
import com.infomaniak.mail.utils.Utils.runCatchingRealm
5960
import com.infomaniak.mail.utils.extensions.*
@@ -87,7 +88,6 @@ class ThreadListAdapter @Inject constructor(
8788
private var swipingIsAuthorized: Boolean = true
8889
private var displaySeeAllButton = false // TODO: Manage this for intelligent mailbox
8990
private var isLoadMoreDisplayed = false
90-
private var isFolderNameVisible: Boolean = false
9191

9292
var onThreadClicked: ((thread: Thread) -> Unit)? = null
9393
var onFlushClicked: ((dialogTitle: String) -> Unit)? = null
@@ -96,6 +96,7 @@ class ThreadListAdapter @Inject constructor(
9696
private var folderRole: FolderRole? = null
9797
private var onSwipeFinished: (() -> Unit)? = null
9898
private var multiSelection: MultiSelectionListener<Thread>? = null
99+
private var isFolderNameVisible: Boolean = false
99100

100101
//region Tablet mode
101102
private var openedThreadPosition: Int? = null
@@ -189,10 +190,18 @@ class ThreadListAdapter @Inject constructor(
189190
private fun shouldDisplayFolderName(folderName: String) = isFolderNameVisible && folderName.isNotEmpty()
190191

191192
private fun CardviewThreadItemBinding.displayThread(thread: Thread, position: Int) {
192-
val folderName = getFolderName(thread)
193-
if (shouldDisplayFolderName(folderName)) {
193+
if (shouldDisplayFolderName(thread.folderName)) {
194194
folderNameView.isVisible = true
195-
folderNameView.text = folderName
195+
folderNameView.text = context.postfixWithTag(
196+
tag = thread.folderName,
197+
tagColor = TagColor(R.color.folderNameBackground, R.color.folderNameTextColor),
198+
ellipsizeConfiguration = SubjectFormatter.EllipsizeConfiguration(
199+
maxWidth = context.resources.getDimension(R.dimen.subjectTagMaxSize).toInt(),
200+
truncateAt = TextUtils.TruncateAt.END
201+
),
202+
)
203+
} else {
204+
folderNameView.isVisible = false
196205
}
197206

198207
refreshCachedSelectedPosition(thread.uid, position) // If item changed position, update cached position.

app/src/main/java/com/infomaniak/mail/ui/main/search/SearchViewModel.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,8 @@ class SearchViewModel @Inject constructor(
209209

210210
suspend fun ApiResponse<ThreadResult>.initSearchFolderThreads() {
211211
runCatching {
212-
data?.threads?.let {
213-
threadController.initAndGetSearchFolderThreads(
214-
context,
215-
remoteThreads = it,
216-
folderRole = folder?.role
217-
)
212+
data?.threads?.let { threads ->
213+
threadController.initAndGetSearchFolderThreads(remoteThreads = threads, folderRole = folder?.role)
218214
}
219215
}.getOrElse { exception ->
220216
exception.printStackTrace()

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
*/
1818
package com.infomaniak.mail.ui.main.thread
1919

20+
import android.content.Context
2021
import android.graphics.Canvas
2122
import android.graphics.Paint
2223
import android.graphics.Paint.FontMetricsInt
2324
import android.graphics.RectF
2425
import android.graphics.Typeface
26+
import android.text.TextPaint
2527
import android.text.style.LineHeightSpan
2628
import android.text.style.ReplacementSpan
29+
import androidx.core.content.res.ResourcesCompat
30+
import com.infomaniak.mail.R
2731

2832
/**
2933
* A span to create a rounded background on a text.
@@ -36,6 +40,7 @@ class RoundedBackgroundSpan(
3640
private val textColor: Int,
3741
private val textTypeface: Typeface,
3842
private val fontSize: Float,
43+
private val cornerRadius: Float = CORNER_RADIUS
3944
) : ReplacementSpan(), LineHeightSpan {
4045

4146
override fun getSize(paint: Paint, text: CharSequence?, start: Int, end: Int, fm: FontMetricsInt?): Int {
@@ -65,7 +70,7 @@ class RoundedBackgroundSpan(
6570
)
6671

6772
paint.color = backgroundColor
68-
canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, paint)
73+
canvas.drawRoundRect(rect, cornerRadius, cornerRadius, paint)
6974

7075
paint.setGivenTextStyle()
7176
canvas.drawText(
@@ -98,5 +103,11 @@ class RoundedBackgroundSpan(
98103
private const val PADDING = 16
99104
private const val VERTICAL_OFFSET = 4
100105
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+
}
101112
}
102113
}

0 commit comments

Comments
 (0)