Skip to content

Commit

Permalink
Show will send immediately warning if scheduled send is in the past.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Feb 1, 2023
1 parent b4c5726 commit 4ad233c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.fragment.app.FragmentManager
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointForward
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import org.thoughtcrime.securesms.R
Expand Down Expand Up @@ -64,15 +65,14 @@ class ScheduleMessageTimePickerBottomSheet : FixedRoundedCornerBottomSheetDialog
scheduledMinute = scheduledLocalDateTime.minute

binding.scheduleSend.setOnClickListener {
dismiss()
val messageId = arguments?.getLong(KEY_MESSAGE_ID)
if (messageId == null) {
findListener<ScheduleCallback>()?.onScheduleSend(getSelectedTimestamp())
if (getSelectedTimestamp() < System.currentTimeMillis()) {
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.ScheduleMessageTimePickerBottomSheet__select_time_in_past_dialog_warning)
.setPositiveButton(R.string.ScheduleMessageTimePickerBottomSheet__select_time_in_past_dialog_positive_button) { _, _ -> scheduleMessageSend() }
.setNegativeButton(android.R.string.cancel, null)
.show()
} else {
val selectedTime = getSelectedTimestamp()
if (selectedTime != arguments?.getLong(KEY_INITIAL_TIME)) {
findListener<RescheduleCallback>()?.onReschedule(selectedTime, messageId)
}
scheduleMessageSend()
}
}

Expand Down Expand Up @@ -166,6 +166,19 @@ class ScheduleMessageTimePickerBottomSheet : FixedRoundedCornerBottomSheetDialog
binding.timeText.text = scheduledTime.formatHours(requireContext())
}

private fun scheduleMessageSend() {
dismissAllowingStateLoss()
val messageId = arguments?.getLong(KEY_MESSAGE_ID)
if (messageId == null) {
findListener<ScheduleCallback>()?.onScheduleSend(getSelectedTimestamp())
} else {
val selectedTime = getSelectedTimestamp()
if (selectedTime != arguments?.getLong(KEY_INITIAL_TIME)) {
findListener<RescheduleCallback>()?.onReschedule(selectedTime, messageId)
}
}
}

interface ScheduleCallback {
fun onScheduleSend(scheduledTime: Long)
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,12 @@
<string name="ScheduleMessageTimePickerBottomSheet__dialog_title">Schedule message</string>
<!-- Text for confirmation button when scheduling messages that allows the user to confirm and schedule the sending time -->
<string name="ScheduleMessageTimePickerBottomSheet__schedule_send">Schedule send</string>

<!-- Disclaimer in message scheduling dialog. %1$s replaced with a GMT offset (e.g. GMT-05:00), and %2$s is replaced with the time zone name (e.g. Eastern Standard Time) -->
<string name="ScheduleMessageTimePickerBottomSheet__timezone_disclaimer">All times in (%1$s) %2$s</string>
<!-- Warning dialog message text shown when select time for scheduled send is in the past resulting in an immediate send if scheduled. -->
<string name="ScheduleMessageTimePickerBottomSheet__select_time_in_past_dialog_warning">Selected time is in the past. This will send the message immediately.</string>
<!-- Positive button text for warning dialog shown when scheduled send is in the past -->
<string name="ScheduleMessageTimePickerBottomSheet__select_time_in_past_dialog_positive_button">Send immediately</string>

<!-- Context menu option to send a scheduled message now -->
<string name="ScheduledMessagesBottomSheet_menu_send_now">Send now</string>
Expand Down

0 comments on commit 4ad233c

Please sign in to comment.