Skip to content

Commit

Permalink
Implement share action
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBourdin88 committed Jul 9, 2024
1 parent 57c414e commit 125f477
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/infomaniak/mail/MatomoMail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object MatomoMail : MatomoCore {
const val ACTION_FAVORITE_NAME = "favorite"
const val ACTION_SPAM_NAME = "spam"
const val ACTION_PRINT_NAME = "print"
const val ACTION_SHARE_LINK_NAME = "shareLink"
const val ACTION_POSTPONE_NAME = "postpone"
const val ADD_MAILBOX_NAME = "addMailbox"
const val DISCOVER_LATER = "discoverLater"
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
package com.infomaniak.mail.ui

import android.app.Activity
import android.app.Application
import android.content.Context
import androidx.lifecycle.*
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.utils.ApiErrorCode.Companion.translateError
Expand Down Expand Up @@ -1061,6 +1063,19 @@ class MainViewModel @Inject constructor(
return messageController.getMessageCountInThreadForFolder(threadUid, folderId, mailboxContentRealm()) == 1L
}

fun shareThreadUrl(messageUid: String, activityContext: Context) {
val message = messageController.getMessage(messageUid) ?: return

viewModelScope.launch(ioCoroutineContext) {
val mailboxUuid = currentMailbox.value?.uuid!!
val response = ApiRepository.getShareLink(mailboxUuid, message.folderId, message.shortUid)

if (response.isSuccess() && response.data != null) {
response.data!!.url?.let { activityContext.shareString(it) }
}
}
}

companion object {
private val TAG: String = MainViewModel::class.java.simpleName
private val DEFAULT_SELECTED_FOLDER = FolderRole.INBOX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ abstract class MailActionsBottomSheetDialog : ActionsBottomSheetDialog() {
override fun onFavorite() = Unit
override fun onReportJunk() = Unit
override fun onPrint() = Unit
override fun onShare() = Unit
override fun onReportDisplayProblem() = Unit
//endregion
}
Expand All @@ -70,6 +71,7 @@ abstract class MailActionsBottomSheetDialog : ActionsBottomSheetDialog() {
postpone.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onPostpone() }
favorite.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onFavorite() }
reportJunk.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onReportJunk() }
share.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onShare() }
print.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onPrint() }
reportDisplayProblem.setClosingOnClickListener(shouldCloseMultiSelection) { onClickListener.onReportDisplayProblem() }

Expand Down Expand Up @@ -124,6 +126,7 @@ abstract class MailActionsBottomSheetDialog : ActionsBottomSheetDialog() {
fun onFavorite()
fun onReportJunk()
fun onPrint()
fun onShare()
fun onReportDisplayProblem()

fun onReply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import com.infomaniak.mail.MatomoMail.ACTION_POSTPONE_NAME
import com.infomaniak.mail.MatomoMail.ACTION_PRINT_NAME
import com.infomaniak.mail.MatomoMail.ACTION_REPLY_ALL_NAME
import com.infomaniak.mail.MatomoMail.ACTION_REPLY_NAME
import com.infomaniak.mail.MatomoMail.ACTION_SHARE_LINK_NAME
import com.infomaniak.mail.MatomoMail.trackBottomSheetMessageActionsEvent
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
import com.infomaniak.mail.R
import com.infomaniak.mail.data.models.Folder.FolderRole
import com.infomaniak.mail.data.models.draft.Draft.DraftMode
Expand Down Expand Up @@ -162,6 +164,13 @@ class MessageActionsBottomSheetDialog : MailActionsBottomSheetDialog() {
)
}

override fun onShare() {
activity?.let {
trackBottomSheetThreadActionsEvent(ACTION_SHARE_LINK_NAME)
mainViewModel.shareThreadUrl(message.uid, activityContext = it)
}
}

override fun onReportDisplayProblem() {
notYetImplemented()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.infomaniak.mail.MatomoMail.ACTION_POSTPONE_NAME
import com.infomaniak.mail.MatomoMail.ACTION_PRINT_NAME
import com.infomaniak.mail.MatomoMail.ACTION_REPLY_ALL_NAME
import com.infomaniak.mail.MatomoMail.ACTION_REPLY_NAME
import com.infomaniak.mail.MatomoMail.ACTION_SHARE_LINK_NAME
import com.infomaniak.mail.MatomoMail.ACTION_SPAM_NAME
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
import com.infomaniak.mail.R
Expand Down Expand Up @@ -189,6 +190,13 @@ class ThreadActionsBottomSheetDialog : MailActionsBottomSheetDialog() {
notYetImplemented()
}

override fun onShare() {
activity?.let {
trackBottomSheetThreadActionsEvent(ACTION_SHARE_LINK_NAME)
mainViewModel.shareThreadUrl(messageUidToReply, activityContext = it)
}
}

override fun onReportDisplayProblem() {
notYetImplemented()
}
Expand Down

0 comments on commit 125f477

Please sign in to comment.