Skip to content

Commit

Permalink
refactor: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Feb 3, 2025
1 parent 8329a95 commit c62f707
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
24 changes: 12 additions & 12 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -603,20 +603,20 @@ class MainViewModel @Inject constructor(

//region Scheduled Drafts
fun rescheduleDraft(scheduleDate: Date) = viewModelScope.launch(ioCoroutineContext) {
val draftResource = this@MainViewModel.draftResource

if (draftResource.isNullOrBlank()) {
snackbarManager.postValue(title = appContext.getString(RCore.string.anErrorHasOccurred))
return@launch
}
draftResource.let { resource ->
if (resource.isNullOrBlank()) {
snackbarManager.postValue(title = appContext.getString(RCore.string.anErrorHasOccurred))
return@launch
}

val apiResponse = ApiRepository.rescheduleDraft(draftResource, scheduleDate)
val apiResponse = ApiRepository.rescheduleDraft(resource, scheduleDate)

if (apiResponse.isSuccess()) {
val scheduledDraftsFolderId = folderController.getFolder(FolderRole.SCHEDULED_DRAFTS)!!.id
refreshFoldersAsync(currentMailbox.value!!, listOf(scheduledDraftsFolderId))
} else {
snackbarManager.postValue(title = appContext.getString(apiResponse.translatedError))
if (apiResponse.isSuccess()) {
val scheduledDraftsFolderId = folderController.getFolder(FolderRole.SCHEDULED_DRAFTS)!!.id
refreshFoldersAsync(currentMailbox.value!!, listOf(scheduledDraftsFolderId))
} else {
snackbarManager.postValue(title = appContext.getString(apiResponse.translatedError))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ open class SelectDateAndTimeForScheduledDraftDialog @Inject constructor(
val hour: Int = timePicker!!.hour
val minute: Int = timePicker!!.minute

selectedDate = selectedDate.setHour(hour)
.setMinute(minute)
selectedDate = selectedDate.setHour(hour).setMinute(minute)

binding.timeField.setText(selectedDate.format(FORMAT_DATE_HOUR_MINUTE))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : ActionsBottomSheetDi
context,
date = Date(lastSelectedScheduleEpoch),
format = FORMAT_DATE_DAY_MONTH,
)
),
)
}
}
Expand Down

0 comments on commit c62f707

Please sign in to comment.