Skip to content

Commit

Permalink
refactor: Rename dateAndTimeScheduleDialog related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Jan 30, 2025
1 parent f550fe9 commit 5e24d75
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
10 changes: 4 additions & 6 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,10 @@ class MainViewModel @Inject constructor(
val mergedContactsLive: LiveData<MergedContactDictionary> = avatarMergedContactData.mergedContactLiveData
//endregion

//region Schedule draft
//region Scheduled Draft
var draftResource: String? = null

val showOrCloseSelectDateAndTimeForScheduleDialog = SingleLiveEvent<Unit>()

fun showSelectDateAndTimeForScheduleDialog() = showOrCloseSelectDateAndTimeForScheduleDialog.postValue(Unit)
val dateAndTimeScheduledDialogTrigger = SingleLiveEvent<Unit>()
fun showDateAndTimeScheduleDialog() = dateAndTimeScheduledDialogTrigger.postValue(Unit)
//endregion

//region Share Thread URL
Expand Down Expand Up @@ -638,7 +636,7 @@ class MainViewModel @Inject constructor(
}
//endregion

//region Schedule draft
//region Scheduled Draft
private fun getScheduleDraft(draftResource: String, onSuccess: () -> Unit) = viewModelScope.launch(ioCoroutineContext) {
val apiResponse = ApiRepository.getDraft(draftResource)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : ActionsBottomSheetDi
} else {
customScheduleItem.setClosingOnClickListener {
if (navigationArgs.isAlreadyScheduled) {
mainViewModel.showSelectDateAndTimeForScheduleDialog()
mainViewModel.showDateAndTimeScheduleDialog()
} else {
newMessageViewModel.showSelectDateAndTimeForScheduleDialog()
newMessageViewModel.showDateAndTimeScheduleDialog()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ThreadFragment : Fragment() {
lateinit var snackbarManager: SnackbarManager

@Inject
lateinit var selectDateAndTimeForScheduledDraftDialog: SelectDateAndTimeForScheduledDraftDialog
lateinit var dateAndTimeScheduleDialog: SelectDateAndTimeForScheduledDraftDialog

@Inject
lateinit var confirmScheduledDraftModificationDialog: ConfirmScheduledDraftModificationDialog
Expand Down Expand Up @@ -169,7 +169,7 @@ class ThreadFragment : Fragment() {

observeMessageOfUserToBlock()

observeSelectDateAndTimeForScheduleDialogState()
observeDateAndTimeScheduleDialogState()
}

private fun observeReportDisplayProblemResult() {
Expand All @@ -188,12 +188,12 @@ class ThreadFragment : Fragment() {
}
}

private fun observeSelectDateAndTimeForScheduleDialogState() {
mainViewModel.showOrCloseSelectDateAndTimeForScheduleDialog.observe(viewLifecycleOwner) {
selectDateAndTimeForScheduledDraftDialog.show(
private fun observeDateAndTimeScheduleDialogState() {
mainViewModel.dateAndTimeScheduledDialogTrigger.observe(viewLifecycleOwner) {
dateAndTimeScheduleDialog.show(
title = getString(R.string.datePickerTitle),
onPositiveButtonClicked = {
val scheduleDate = selectDateAndTimeForScheduledDraftDialog.selectedDate.time
val scheduleDate = dateAndTimeScheduleDialog.selectedDate.time
localSettings.lastSelectedScheduleDate = scheduleDate

mainViewModel.draftResource?.let { draftResource ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class NewMessageFragment : Fragment() {
lateinit var snackbarManager: SnackbarManager

@Inject
lateinit var selectDateAndTimeForScheduledDraftDialog: SelectDateAndTimeForScheduledDraftDialog
lateinit var dateAndTimeScheduleDialog: SelectDateAndTimeForScheduledDraftDialog

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return FragmentNewMessageBinding.inflate(inflater, container, false).also { _binding = it }.root
Expand Down Expand Up @@ -218,23 +218,17 @@ class NewMessageFragment : Fragment() {
}

private fun observeSelectDateAndTimeForScheduleDialogState() {
newMessageViewModel.showOrCloseSelectDateAndTimeForScheduleDialog.observe(viewLifecycleOwner) { showDialog ->
if (showDialog) {
selectDateAndTimeForScheduledDraftDialog.show(
title = getString(R.string.datePickerTitle),
onPositiveButtonClicked = {
val scheduleDate = selectDateAndTimeForScheduledDraftDialog.selectedDate.time
localSettings.lastSelectedScheduleDate = scheduleDate

newMessageViewModel.setScheduleDate(Date(scheduleDate))

tryToSendEmail(scheduled = true)
},
onNegativeButtonClicked = { safeNavigate(resId = R.id.scheduleSendBottomSheetDialog) },
)
} else {
selectDateAndTimeForScheduledDraftDialog.resetLoadingAndDismiss()
}
newMessageViewModel.dateAndTimeScheduledDialogTrigger.observe(viewLifecycleOwner) {
dateAndTimeScheduleDialog.show(
title = getString(R.string.datePickerTitle),
onPositiveButtonClicked = {
val scheduleDate = dateAndTimeScheduleDialog.selectedDate.time
localSettings.lastSelectedScheduleDate = scheduleDate
newMessageViewModel.setScheduleDate(Date(scheduleDate))
tryToSendEmail(scheduled = true)
},
onNegativeButtonClicked = { safeNavigate(resId = R.id.scheduleSendBottomSheetDialog) },
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ class NewMessageViewModel @Inject constructor(

val editorBodyInitializer = SingleLiveEvent<BodyContentPayload>()

val showOrCloseSelectDateAndTimeForScheduleDialog = SingleLiveEvent<Boolean>()

fun showSelectDateAndTimeForScheduleDialog() = showOrCloseSelectDateAndTimeForScheduleDialog.postValue(true)
//region Scheduled Draft
val dateAndTimeScheduledDialogTrigger = SingleLiveEvent<Unit>()
fun showDateAndTimeScheduleDialog() = dateAndTimeScheduledDialogTrigger.postValue(Unit)
//endregion

// 1. Navigating to AiPropositionFragment causes NewMessageFragment to export its body to `subjectAndBodyChannel`.
// 2. Inserting the AI proposition navigates back to NewMessageFragment.
Expand Down

0 comments on commit 5e24d75

Please sign in to comment.