1
1
/*
2
2
* Infomaniak Mail - Android
3
- * Copyright (C) 2023 Infomaniak Network SA
3
+ * Copyright (C) 2023-2024 Infomaniak Network SA
4
4
*
5
5
* This program is free software: you can redistribute it and/or modify
6
6
* it under the terms of the GNU General Public License as published by
@@ -25,7 +25,6 @@ import androidx.fragment.app.activityViewModels
25
25
import androidx.fragment.app.viewModels
26
26
import androidx.navigation.fragment.findNavController
27
27
import com.infomaniak.lib.core.utils.context
28
- import com.infomaniak.lib.core.utils.hasSupportedApplications
29
28
import com.infomaniak.lib.core.utils.safeBinding
30
29
import com.infomaniak.lib.core.utils.safeNavigate
31
30
import com.infomaniak.mail.MatomoMail.trackAttachmentActionsEvent
@@ -34,14 +33,13 @@ import com.infomaniak.mail.data.models.Attachment
34
33
import com.infomaniak.mail.databinding.BottomSheetAttachmentActionsBinding
35
34
import com.infomaniak.mail.ui.MainViewModel
36
35
import com.infomaniak.mail.utils.AttachmentIntentUtils.AttachmentIntentType
37
- import com.infomaniak.mail.utils.AttachmentIntentUtils.AttachmentIntentType.OPEN_WITH
38
36
import com.infomaniak.mail.utils.AttachmentIntentUtils.AttachmentIntentType.SAVE_TO_DRIVE
39
- import com.infomaniak.mail.utils.AttachmentIntentUtils.getIntentOrGoToPlaystore
40
- import com.infomaniak.mail.utils.AttachmentIntentUtils.openWithIntent
37
+ import com.infomaniak.mail.utils.AttachmentIntentUtils.createDownloadDialogNavArgs
38
+ import com.infomaniak.mail.utils.AttachmentIntentUtils.executeIntent
39
+ import com.infomaniak.mail.utils.AttachmentIntentUtils.openAttachment
41
40
import com.infomaniak.mail.utils.PermissionUtils
42
41
import dagger.hilt.android.AndroidEntryPoint
43
42
import javax.inject.Inject
44
- import com.infomaniak.lib.core.R as RCore
45
43
46
44
@AndroidEntryPoint
47
45
class AttachmentActionsBottomSheetDialog : ActionsBottomSheetDialog () {
@@ -71,45 +69,37 @@ class AttachmentActionsBottomSheetDialog : ActionsBottomSheetDialog() {
71
69
}
72
70
73
71
private fun setupListeners (attachment : Attachment ) = with (binding) {
72
+
73
+ fun navigateToDownloadProgressDialog (attachmentIntentType : AttachmentIntentType ) {
74
+ safeNavigate(
75
+ resId = R .id.downloadAttachmentProgressDialog,
76
+ args = attachment.createDownloadDialogNavArgs(attachmentIntentType),
77
+ currentClassName = AttachmentActionsBottomSheetDialog ::class .java.name,
78
+ )
79
+ }
80
+
74
81
openWithItem.setClosingOnClickListener {
75
82
trackAttachmentActionsEvent(" open" )
76
- if ( attachment.openWithIntent(context).hasSupportedApplications(context)) {
77
- attachment.executeIntent( OPEN_WITH )
78
- } else {
79
- mainViewModel.snackBarManager.setValue(getString( RCore .string.errorNoSupportingAppFound))
80
- }
83
+ attachment.openAttachment(
84
+ context,
85
+ navigateToDownloadProgressDialog = { navigateToDownloadProgressDialog(it) },
86
+ showSnackBar = { snackBarErrorMessage -> mainViewModel.snackBarManager.setValue(snackBarErrorMessage) }
87
+ )
81
88
}
82
89
kDriveItem.setClosingOnClickListener {
83
90
trackAttachmentActionsEvent(" saveToKDrive" )
84
- attachment.executeIntent(SAVE_TO_DRIVE )
91
+ attachment.executeIntent(
92
+ context,
93
+ SAVE_TO_DRIVE ,
94
+ navigateToDownloadProgressDialog = { navigateToDownloadProgressDialog(it) },
95
+ )
85
96
}
86
97
deviceItem.setOnClickListener {
87
98
trackAttachmentActionsEvent(" download" )
88
99
scheduleDownloadManager(attachment.downloadUrl, attachment.name)
89
100
}
90
101
}
91
102
92
- private fun Attachment.executeIntent (intentType : AttachmentIntentType ) {
93
- if (hasUsableCache(requireContext()) || isInlineCachedFile(requireContext())) {
94
- getIntentOrGoToPlaystore(requireContext(), intentType)?.let (::startActivity)
95
- } else {
96
- navigateToDownloadProgressDialog(intentType)
97
- }
98
- }
99
-
100
- private fun Attachment.navigateToDownloadProgressDialog (intentType : AttachmentIntentType ) {
101
- safeNavigate(
102
- resId = R .id.downloadAttachmentProgressDialog,
103
- args = DownloadAttachmentProgressDialogArgs (
104
- attachmentResource = resource!! ,
105
- attachmentName = name,
106
- attachmentType = getFileTypeFromMimeType(),
107
- intentType = intentType,
108
- ).toBundle(),
109
- currentClassName = AttachmentActionsBottomSheetDialog ::class .java.name,
110
- )
111
- }
112
-
113
103
private fun scheduleDownloadManager (downloadUrl : String , filename : String ) {
114
104
if (permissionUtils.hasDownloadManagerPermission) {
115
105
scheduleDownloadAndPopBack(downloadUrl, filename)
0 commit comments