Skip to content

Commit

Permalink
refactor: Rename for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBourdin88 committed Nov 22, 2024
1 parent 71252af commit a7184a0
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ object ApiRepository : ApiRepositoryCore() {
return callApi(url = ApiRoutes.shareLink(mailboxUuid, folderId, mailId), method = POST)
}

fun getDownloadedAttachment(mailboxUuid: String, folderId: String, shortUid: Int): Response {
fun getDownloadedMessage(mailboxUuid: String, folderId: String, shortUid: Int): Response {
val request = Request.Builder().url(ApiRoutes.downloadMessage(mailboxUuid, folderId, shortUid))
.headers(HttpUtils.getHeaders(null))
.get()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ class MainViewModel @Inject constructor(
val message = messageController.getMessage(messageUid) ?: return@launch
val mailbox = currentMailbox.value ?: return@launch

val response = ApiRepository.getDownloadedAttachment(mailbox.uuid, message.folderId, message.shortUid)
val response = ApiRepository.getDownloadedMessage(mailbox.uuid, message.folderId, message.shortUid)

if (!response.isSuccessful || response.body == null) {
reportDisplayProblemTrigger.postValue(Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.infomaniak.mail.ui.MainActivity
import com.infomaniak.mail.ui.MainViewModel
import com.infomaniak.mail.ui.main.search.SearchFragment
import com.infomaniak.mail.ui.main.thread.ThreadFragment
import com.infomaniak.mail.ui.main.thread.actions.DownloadThreadsProgressDialog.Companion.DOWNLOAD_THREADS_RESULT
import com.infomaniak.mail.ui.main.thread.actions.DownloadMessagesProgressDialog
import com.infomaniak.mail.utils.extensions.*
import javax.inject.Inject

Expand Down Expand Up @@ -121,7 +121,7 @@ abstract class TwoPaneFragment : Fragment() {

private fun observeThreadNavigation() = with(twoPaneViewModel) {
getBackNavigationResult(AttachmentExtensions.DOWNLOAD_ATTACHMENT_RESULT, ::startActivity)
getBackNavigationResult(DOWNLOAD_THREADS_RESULT, ::startActivity)
getBackNavigationResult(DownloadMessagesProgressDialog.DOWNLOAD_MESSAGES_RESULT, ::startActivity)

newMessageArgs.observe(viewLifecycleOwner) {
safeNavigateToNewMessageActivity(args = it.toBundle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import com.infomaniak.mail.utils.KDriveUtils.canSaveOnKDrive
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class DownloadThreadsProgressDialog : DownloadProgressDialog() {
private val downloadThreadsViewModel: DownloadThreadsViewModel by viewModels()
private val navigationArgs: DownloadThreadsProgressDialogArgs by navArgs()
class DownloadMessagesProgressDialog : DownloadProgressDialog() {
private val downloadThreadsViewModel: DownloadMessagesViewModel by viewModels()
private val navigationArgs: DownloadMessagesProgressDialogArgs by navArgs()
override val dialogTitle: String? by lazy { getDialogTitleFromArgs() }
override val dialogIconDrawableRes: Int? by lazy { null }

Expand All @@ -45,7 +45,7 @@ class DownloadThreadsProgressDialog : DownloadProgressDialog() {
popBackStackWithError()
} else {
ArrayList(threadUris).openKDriveOrPlayStore(requireContext())?.let { openKDriveIntent ->
setBackNavigationResult(DOWNLOAD_THREADS_RESULT, openKDriveIntent)
setBackNavigationResult(DOWNLOAD_MESSAGES_RESULT, openKDriveIntent)
} ?: run { findNavController().popBackStack() }
}
}
Expand Down Expand Up @@ -75,6 +75,6 @@ class DownloadThreadsProgressDialog : DownloadProgressDialog() {
}

companion object {
const val DOWNLOAD_THREADS_RESULT = "download_threads_result"
const val DOWNLOAD_MESSAGES_RESULT = "download_messages_result"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import java.io.File
import javax.inject.Inject

@HiltViewModel
class DownloadThreadsViewModel @Inject constructor(
class DownloadMessagesViewModel @Inject constructor(
application: Application,
private val savedStateHandle: SavedStateHandle,
private val messageController: MessageController,
Expand All @@ -48,7 +48,7 @@ class DownloadThreadsViewModel @Inject constructor(
private val ioCoroutineContext = viewModelScope.coroutineContext(ioDispatcher)

private val messageLocalUids
inline get() = savedStateHandle.get<Array<String>>(DownloadThreadsProgressDialogArgs::messageUids.name)!!
inline get() = savedStateHandle.get<Array<String>>(DownloadMessagesProgressDialogArgs::messageUids.name)!!

fun downloadThreads(currentMailbox: Mailbox?) = liveData(ioCoroutineContext) {
val downloadedThreadUris: List<Uri>? = runCatching {
Expand All @@ -58,7 +58,7 @@ class DownloadThreadsViewModel @Inject constructor(

messageLocalUids.forEach { messageUid ->
val message = messageController.getMessage(messageUid) ?: return@runCatching null
val response = ApiRepository.getDownloadedAttachment(mailbox.uuid, message.folderId, message.shortUid)
val response = ApiRepository.getDownloadedMessage(mailbox.uuid, message.folderId, message.shortUid)

if (!response.isSuccessful || response.body == null) return@runCatching null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MessageActionsBottomSheetDialog : MailActionsBottomSheetDialog() {

override fun onSaveKDrive() {
trackBottomSheetThreadActionsEvent(ACTION_SAVE_KDRIVE_NAME)
navigateToDownloadThreadsProgressDialog(
navigateToDownloadMessagesProgressDialog(
listOf(messageUid),
mainViewModel.getSubject(threadUid),
MessageActionsBottomSheetDialog::class.java.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.infomaniak.mail.ui.main.folder.ThreadListMultiSelection
import com.infomaniak.mail.ui.main.folder.ThreadListMultiSelection.Companion.getReadIconAndShortText
import com.infomaniak.mail.utils.extensions.animatedNavigation
import com.infomaniak.mail.utils.extensions.deleteWithConfirmationPopup
import com.infomaniak.mail.utils.extensions.navigateToDownloadThreadsProgressDialog
import com.infomaniak.mail.utils.extensions.navigateToDownloadMessagesProgressDialog
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand Down Expand Up @@ -120,7 +120,7 @@ class MultiSelectBottomSheetDialog : ActionsBottomSheetDialog() {
}
binding.saveKDrive.setClosingOnClickListener(shouldCloseMultiSelection = true) {
trackMultiSelectActionEvent(ACTION_SAVE_KDRIVE_NAME, selectedThreadsCount, isFromBottomSheet = true)
navigateToDownloadThreadsProgressDialog(
navigateToDownloadMessagesProgressDialog(
messageUids = mainViewModel.getMessagesUidsFromThreadUids(selectedThreadsUids),
nameFirstMessage = selectedThreads.firstOrNull()?.subject,
MultiSelectBottomSheetDialog::class.java.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ThreadActionsBottomSheetDialog : MailActionsBottomSheetDialog() {

override fun onSaveKDrive() {
trackBottomSheetThreadActionsEvent(ACTION_SAVE_KDRIVE_NAME)
navigateToDownloadThreadsProgressDialog(
navigateToDownloadMessagesProgressDialog(
messageUids = thread.messages.map { it.uid },
nameFirstMessage = thread.subject,
ThreadActionsBottomSheetDialog::class.java.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.infomaniak.mail.ui.login.LoginActivity
import com.infomaniak.mail.ui.login.LoginActivityArgs
import com.infomaniak.mail.ui.login.NoMailboxActivity
import com.infomaniak.mail.ui.main.thread.actions.AttachmentActionsBottomSheetDialog
import com.infomaniak.mail.ui.main.thread.actions.DownloadThreadsProgressDialogArgs
import com.infomaniak.mail.ui.main.thread.actions.DownloadMessagesProgressDialogArgs
import com.infomaniak.mail.ui.newMessage.NewMessageActivityArgs
import com.infomaniak.mail.ui.noValidMailboxes.NoValidMailboxesActivity
import com.infomaniak.mail.utils.AccountUtils
Expand Down Expand Up @@ -91,14 +91,14 @@ fun Fragment.navigateToDownloadProgressDialog(
)
}

fun Fragment.navigateToDownloadThreadsProgressDialog(
fun Fragment.navigateToDownloadMessagesProgressDialog(
messageUids: List<String>,
nameFirstMessage: String?,
currentClassName: String
) {
safeNavigate(
resId = R.id.downloadThreadsProgressDialog,
args = DownloadThreadsProgressDialogArgs(
resId = R.id.downloadMessagesProgressDialog,
args = DownloadMessagesProgressDialogArgs(
messageUids = messageUids.toTypedArray(),
nameFirstMessage = nameFirstMessage
).toBundle(),
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/navigation/main_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@
</dialog>

<dialog
android:id="@+id/downloadThreadsProgressDialog"
android:name="com.infomaniak.mail.ui.main.thread.actions.DownloadThreadsProgressDialog"
android:label="DownloadThreadsProgressDialog"
android:id="@+id/downloadMessagesProgressDialog"
android:name="com.infomaniak.mail.ui.main.thread.actions.DownloadMessagesProgressDialog"
android:label="DownloadMessagesProgressDialog"
tools:layout="@layout/dialog_download_progress">
<argument
android:name="messageUids"
Expand Down

0 comments on commit a7184a0

Please sign in to comment.