Skip to content

Commit

Permalink
refactor: Remove unused values in SelectDateAndTimeForScheduledDraftD…
Browse files Browse the repository at this point in the history
…ialog (#2171)
  • Loading branch information
LunarX authored Feb 19, 2025
2 parents e8a1615 + 637de8c commit cf245cb
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 com.infomaniak.mail.utils.date.DateFormatUtils.formatTime
import dagger.hilt.android.qualifiers.ActivityContext
Expand All @@ -54,9 +52,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 @@ -70,11 +65,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 @@ -170,21 +172,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 @@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marginStandard"
tools:text="@string/datePickerTitle" />
android:text="@string/datePickerTitle" />

<com.infomaniak.lib.core.views.EndIconTextInputLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit cf245cb

Please sign in to comment.