Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove unused values in SelectDateAndTimeForScheduledDraftDialog #2171

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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