Skip to content

Commit

Permalink
refactor: Remove unused values in SelectDateAndTimeForScheduledDraftD…
Browse files Browse the repository at this point in the history
…ialog

Simplify some of the logic by removing unnecessary logic
  • Loading branch information
LunarX committed Feb 18, 2025
1 parent 559956e commit 71ec610
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ package com.infomaniak.mail.ui.alertDialogs

import android.content.Context
import android.text.format.DateFormat
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import com.google.android.material.datepicker.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.infomaniak.lib.core.utils.*
import com.infomaniak.mail.R
import com.infomaniak.mail.data.LocalSettings
import com.infomaniak.mail.databinding.DialogSelectDateAndTimeForScheduledDraftBinding
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
Expand All @@ -53,9 +51,6 @@ open class SelectDateAndTimeForScheduledDraftDialog @Inject constructor(

private lateinit var selectedDate: Date

@Inject
lateinit var localSettings: LocalSettings

private fun initDialog() = with(binding) {
MaterialAlertDialogBuilder(context)
.setView(root)
Expand All @@ -69,11 +64,18 @@ open class SelectDateAndTimeForScheduledDraftDialog @Inject constructor(
onAbort = null
}

fun show(title: String, onSchedule: (Long) -> Unit, onAbort: (() -> Unit)? = null) {
showDialogWithBasicInfo(title, R.string.buttonScheduleTitle)
fun show(onSchedule: (Long) -> Unit, onAbort: (() -> Unit)? = null) {
showDialogWithBasicInfo()
setupListeners(onSchedule, onAbort)
}

private fun showDialogWithBasicInfo() {
alertDialog.show()

selectDate(Date().roundUpToNextTenMinutes())
positiveButton.setText(R.string.buttonScheduleTitle)
}

private fun setupListeners(onSchedule: (Long) -> Unit, onAbort: (() -> Unit)?) = with(alertDialog) {

binding.dateField.setOnClickListener {
Expand Down Expand Up @@ -169,21 +171,6 @@ open class SelectDateAndTimeForScheduledDraftDialog @Inject constructor(
datePicker.show(super.activity.supportFragmentManager, null)
}

private fun showDialogWithBasicInfo(
title: String? = null,
@StringRes positiveButtonText: Int? = null,
@StringRes negativeButtonText: Int? = null,
) {
alertDialog.show()

selectDate(Date().roundUpToNextTenMinutes())

title?.let(binding.dialogTitle::setText)

positiveButtonText?.let(positiveButton::setText)
negativeButtonText?.let(negativeButton::setText)
}

companion object {
const val MIN_SCHEDULE_DELAY_MINUTES = 5
const val MAX_SCHEDULE_DELAY_YEARS = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ class ThreadFragment : Fragment() {

getBackNavigationResult(OPEN_DATE_AND_TIME_SCHEDULE_DIALOG) { _: Boolean ->
dateAndTimeScheduleDialog.show(
title = getString(R.string.datePickerTitle),
onSchedule = { timestamp ->
localSettings.lastSelectedScheduleEpoch = timestamp
mainViewModel.rescheduleDraft(Date(timestamp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ class NewMessageFragment : Fragment() {

getBackNavigationResult(OPEN_DATE_AND_TIME_SCHEDULE_DIALOG) { _: Boolean ->
dateAndTimeScheduleDialog.show(
title = getString(R.string.datePickerTitle),
onSchedule = { timestamp ->
localSettings.lastSelectedScheduleEpoch = timestamp
scheduleDraft(timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marginStandard"
tools:text="@string/datePickerTitle" />
android:text="@string/datePickerTitle" />

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 71ec610

Please sign in to comment.