@@ -25,6 +25,7 @@ import android.text.method.LinkMovementMethod
25
25
import android.view.LayoutInflater
26
26
import android.view.View
27
27
import android.view.ViewGroup
28
+ import androidx.annotation.IdRes
28
29
import androidx.core.graphics.ColorUtils
29
30
import androidx.core.view.isGone
30
31
import androidx.core.view.isVisible
@@ -61,8 +62,14 @@ import com.infomaniak.mail.ui.MainViewModel
61
62
import com.infomaniak.mail.ui.alertDialogs.*
62
63
import com.infomaniak.mail.ui.main.folder.TwoPaneFragment
63
64
import com.infomaniak.mail.ui.main.folder.TwoPaneViewModel
65
+ import com.infomaniak.mail.ui.main.folder.TwoPaneViewModel.NavData
64
66
import com.infomaniak.mail.ui.main.thread.ThreadAdapter.ContextMenuType
65
67
import com.infomaniak.mail.ui.main.thread.ThreadViewModel.OpenThreadResult
68
+ import com.infomaniak.mail.ui.main.thread.actions.AttachmentActionsBottomSheetDialogArgs
69
+ import com.infomaniak.mail.ui.main.thread.actions.MessageActionsBottomSheetDialogArgs
70
+ import com.infomaniak.mail.ui.main.thread.actions.ReplyBottomSheetDialogArgs
71
+ import com.infomaniak.mail.ui.main.thread.actions.ThreadActionsBottomSheetDialogArgs
72
+ import com.infomaniak.mail.ui.main.thread.calendar.AttendeesBottomSheetDialogArgs
66
73
import com.infomaniak.mail.utils.*
67
74
import com.infomaniak.mail.utils.ExternalUtils.findExternalRecipients
68
75
import com.infomaniak.mail.utils.UiUtils.dividerDrawable
@@ -186,7 +193,12 @@ class ThreadFragment : Fragment() {
186
193
private fun setupAdapter () = with (binding.messagesList) {
187
194
adapter = ThreadAdapter (
188
195
shouldLoadDistantResources = shouldLoadDistantResources(),
189
- onContactClicked = twoPaneViewModel::navigateToDetailContact,
196
+ onContactClicked = {
197
+ safeNavigate(
198
+ resId = R .id.detailedContactBottomSheetDialog,
199
+ args = DetailedContactBottomSheetDialogArgs (it).toBundle(),
200
+ )
201
+ },
190
202
onDraftClicked = { message ->
191
203
trackNewMessageEvent(OPEN_FROM_DRAFT_NAME )
192
204
twoPaneViewModel.navigateToNewMessage(
@@ -201,7 +213,12 @@ class ThreadFragment : Fragment() {
201
213
mainViewModel.currentMailbox.value?.let { mailbox -> threadViewModel.deleteDraft(message, mailbox) }
202
214
},
203
215
onAttachmentClicked = { attachment ->
204
- attachment.resource?.let (twoPaneViewModel::navigateToAttachmentActions)
216
+ attachment.resource?.let { resource ->
217
+ safeNavigate(
218
+ resId = R .id.attachmentActionsBottomSheetDialog,
219
+ args = AttachmentActionsBottomSheetDialogArgs (resource).toBundle(),
220
+ )
221
+ }
205
222
},
206
223
onDownloadAllClicked = { message ->
207
224
trackAttachmentActionsEvent(" downloadAll" )
@@ -215,8 +232,13 @@ class ThreadFragment : Fragment() {
215
232
message.navigateToActionsBottomSheet()
216
233
},
217
234
onAllExpandedMessagesLoaded = ::scrollToFirstUnseenMessage,
235
+ navigateToAttendeeBottomSheet = { attendees ->
236
+ safeNavigate(
237
+ resId = R .id.attendeesBottomSheetDialog,
238
+ args = AttendeesBottomSheetDialogArgs (attendees.toTypedArray()).toBundle(),
239
+ )
240
+ },
218
241
navigateToNewMessageActivity = { twoPaneViewModel.navigateToNewMessage(mailToUri = it) },
219
- navigateToAttendeeBottomSheet = { attendees -> twoPaneViewModel.navigateToAttendees(attendees.toTypedArray()) },
220
242
promptLink = { data, type ->
221
243
// When adding a phone number to contacts, Google decodes this value in case it's url-encoded. But I could not
222
244
// reproduce this issue when manually creating a url-encoded href. If this is triggered, fix it by also
@@ -316,22 +338,25 @@ class ThreadFragment : Fragment() {
316
338
threadViewModel.failedMessagesUids.observe(viewLifecycleOwner, threadAdapter::updateFailedMessages)
317
339
}
318
340
319
- private fun observeQuickActionBarClicks () = with (twoPaneViewModel) {
341
+ private fun observeQuickActionBarClicks () {
320
342
threadViewModel.quickActionBarClicks.observe(viewLifecycleOwner) { (threadUid, lastMessageToReplyTo, menuId) ->
321
343
when (menuId) {
322
344
R .id.quickActionReply -> replyTo(lastMessageToReplyTo)
323
345
R .id.quickActionForward -> {
324
- navigateToNewMessage(
346
+ twoPaneViewModel. navigateToNewMessage(
325
347
draftMode = DraftMode .FORWARD ,
326
348
previousMessageUid = lastMessageToReplyTo.uid,
327
349
shouldLoadDistantResources = shouldLoadDistantResources(lastMessageToReplyTo.uid),
328
350
)
329
351
}
330
352
R .id.quickActionMenu -> {
331
- navigateToThreadActions(
332
- threadUid = threadUid,
333
- shouldLoadDistantResources = shouldLoadDistantResources(lastMessageToReplyTo.uid),
334
- messageUidToReplyTo = lastMessageToReplyTo.uid,
353
+ safeNavigate(
354
+ resId = R .id.threadActionsBottomSheetDialog,
355
+ args = ThreadActionsBottomSheetDialogArgs (
356
+ threadUid = threadUid,
357
+ shouldLoadDistantResources = shouldLoadDistantResources(lastMessageToReplyTo.uid),
358
+ messageUidToReplyTo = lastMessageToReplyTo.uid,
359
+ ).toBundle(),
335
360
)
336
361
}
337
362
}
@@ -450,26 +475,33 @@ class ThreadFragment : Fragment() {
450
475
scheduleDownloadManager(url, name)
451
476
}
452
477
453
- private fun replyTo (message : Message ) = with (twoPaneViewModel) {
478
+ private fun replyTo (message : Message ) {
454
479
455
480
val shouldLoadDistantResources = shouldLoadDistantResources(message.uid)
456
481
457
482
if (message.getRecipientsForReplyTo(replyAll = true ).second.isEmpty()) {
458
- navigateToNewMessage(
483
+ twoPaneViewModel. navigateToNewMessage(
459
484
draftMode = DraftMode .REPLY ,
460
485
previousMessageUid = message.uid,
461
486
shouldLoadDistantResources = shouldLoadDistantResources,
462
487
)
463
488
} else {
464
- navigateToReply(message.uid, shouldLoadDistantResources)
489
+ safeNavigate(
490
+ resId = R .id.replyBottomSheetDialog,
491
+ args = ReplyBottomSheetDialogArgs (message.uid, shouldLoadDistantResources).toBundle(),
492
+ )
465
493
}
466
494
}
467
495
468
496
private fun Message.navigateToActionsBottomSheet () {
469
- twoPaneViewModel.navigateToMessageAction(
470
- messageUid = uid,
471
- isThemeTheSame = threadAdapter.isThemeTheSameMap[uid] ? : return ,
472
- shouldLoadDistantResources = shouldLoadDistantResources(uid),
497
+ safeNavigate(
498
+ resId = R .id.messageActionsBottomSheetDialog,
499
+ args = MessageActionsBottomSheetDialogArgs (
500
+ messageUid = uid,
501
+ threadUid = twoPaneViewModel.currentThreadUid.value ? : return ,
502
+ isThemeTheSame = threadAdapter.isThemeTheSameMap[uid] ? : return ,
503
+ shouldLoadDistantResources = shouldLoadDistantResources(uid),
504
+ ).toBundle(),
473
505
)
474
506
}
475
507
@@ -548,6 +580,10 @@ class ThreadFragment : Fragment() {
548
580
549
581
fun getAnchor (): View ? = _binding ?.quickActionBar
550
582
583
+ private fun safeNavigate (@IdRes resId : Int , args : Bundle ) {
584
+ twoPaneViewModel.navArgs.value = NavData (resId, args)
585
+ }
586
+
551
587
enum class HeaderState {
552
588
ELEVATED ,
553
589
LOWERED ,
0 commit comments