Skip to content

Commit d535d4c

Browse files
Merge pull request #1723 from Infomaniak/fix-print
Fix print feature not working on SuperCollapsedBlock Message
2 parents fae22aa + 4f676d2 commit d535d4c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ class PrintMailFragment : Fragment() {
5959
setupAdapter()
6060

6161
messagesLive.observe(viewLifecycleOwner) { (items, _) ->
62-
threadAdapter.submitList(items.filter { it is Message && it.uid == navigationArgs.messageUid })
62+
threadAdapter.submitList(listOf(items.single { it is Message && it.uid == navigationArgs.messageUid }))
6363
}
6464

6565
navigationArgs.openThreadUid?.let {
66-
reassignThreadLive(it)
67-
reassignMessagesLive(it)
66+
reassignMessagesLive(it, withSuperCollapsedBlock = false)
6867
}
6968
}
7069

@@ -79,11 +78,12 @@ class PrintMailFragment : Fragment() {
7978
}
8079

8180
private fun startPrintingView() {
82-
threadViewModel.threadLive.value?.subject?.let { subject ->
83-
printMailViewModel.startPrintingService(requireActivity(), subject, getWebViewToPrint()) {
84-
findNavController().popBackStack()
85-
}
86-
}
81+
printMailViewModel.startPrintingService(
82+
activityContext = requireActivity(),
83+
subject = (threadAdapter.items.single() as Message).subject,
84+
webView = getWebViewToPrint(),
85+
onFinish = findNavController()::popBackStack,
86+
)
8787
}
8888

8989
private fun getWebViewToPrint(): WebView = with(binding.messagesList[0]) { findViewById(R.id.bodyWebView) }

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,19 @@ class ThreadViewModel @Inject constructor(
114114
}
115115
}
116116

117-
fun reassignMessagesLive(threadUid: String) {
117+
fun reassignMessagesLive(threadUid: String, withSuperCollapsedBlock: Boolean = true) {
118118
messagesLiveJob?.cancel()
119119
messagesLiveJob = viewModelScope.launch(ioCoroutineContext) {
120120
messageController.getSortedAndNotDeletedMessagesAsync(threadUid)
121-
?.map { mapRealmMessagesResult(it.list, threadUid) }
121+
?.map { mapRealmMessagesResult(it.list, threadUid, withSuperCollapsedBlock) }
122122
?.collect(messagesLive::postValue)
123123
}
124124
}
125125

126126
private suspend fun mapRealmMessagesResult(
127127
messages: RealmResults<Message>,
128128
threadUid: String,
129+
withSuperCollapsedBlock: Boolean,
129130
): Pair<ThreadAdapterItems, MessagesWithoutHeavyData> {
130131

131132
superCollapsedBlock = superCollapsedBlock ?: SuperCollapsedBlock()
@@ -134,7 +135,8 @@ class ThreadViewModel @Inject constructor(
134135
val messagesToFetch = mutableListOf<Message>()
135136
val thread = messages.firstOrNull()?.threads?.firstOrNull { it.uid == threadUid } ?: return items to messagesToFetch
136137
val firstIndexAfterBlock = computeFirstIndexAfterBlock(thread, messages)
137-
superCollapsedBlock!!.shouldBeDisplayed = shouldBlockBeDisplayed(messages.count(), firstIndexAfterBlock)
138+
superCollapsedBlock!!.shouldBeDisplayed =
139+
shouldBlockBeDisplayed(messages.count(), firstIndexAfterBlock, withSuperCollapsedBlock)
138140

139141
suspend fun addMessage(message: Message) {
140142
splitBody(message).let {
@@ -219,9 +221,9 @@ class ThreadViewModel @Inject constructor(
219221
* - If there's any unread Message in between, it will be displayed (hence, all following Messages will be displayed too).
220222
* After all these Messages are displayed, if there's at least 2 remaining Messages, they're gonna be collapsed in the Block.
221223
*/
222-
private fun shouldBlockBeDisplayed(messagesCount: Int, firstIndexAfterBlock: Int): Boolean {
223-
224-
return superCollapsedBlock?.shouldBeDisplayed == true && // If the Block was hidden for any reason, we mustn't ever display it again
224+
private fun shouldBlockBeDisplayed(messagesCount: Int, firstIndexAfterBlock: Int, withSuperCollapsedBlock: Boolean): Boolean {
225+
return withSuperCollapsedBlock && // When we want to print a mail, we need the full list of Messages
226+
superCollapsedBlock?.shouldBeDisplayed == true && // If the Block was hidden for any reason, we mustn't ever display it again
225227
superCollapsedBlock?.hasBeenClicked == false && // Block hasn't been expanded by the user
226228
messagesCount >= SUPER_COLLAPSED_BLOCK_MINIMUM_MESSAGES_LIMIT && // At least 5 Messages in the Thread
227229
firstIndexAfterBlock >= SUPER_COLLAPSED_BLOCK_FIRST_INDEX_LIMIT // At least 2 Messages in the Block

0 commit comments

Comments
 (0)