Skip to content

Commit 818f3d8

Browse files
committed
refactor: Use nullable lastSelectedScheduleEpoch inside the bottom sheet
1 parent b77ba3c commit 818f3d8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/src/main/java/com/infomaniak/mail/ui/bottomSheetDialogs/ScheduleSendBottomSheetDialog.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : BottomSheetDialogFra
4545
private val navigationArgs: ScheduleSendBottomSheetDialogArgs by navArgs()
4646
private var binding: BottomSheetScheduleSendBinding by safeBinding()
4747

48-
// Navigation args does not support nullable primitive types, so we use 0L
49-
// as a replacement (corresponding to Thursday 1 January 1970 00:00:00 UT).
50-
private var lastSelectedScheduleEpoch: Long = 0L
48+
private var lastSelectedScheduleEpoch: Long? = null
5149

5250
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
5351
return BottomSheetScheduleSendBinding.inflate(inflater, container, false).also { binding = it }.root
@@ -56,7 +54,9 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : BottomSheetDialogFra
5654
override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) {
5755
super.onViewCreated(view, savedInstanceState)
5856

59-
lastSelectedScheduleEpoch = navigationArgs.lastSelectedScheduleEpoch
57+
// Navigation args does not support nullable primitive types, so we use 0L
58+
// as a replacement (corresponding to Thursday 1 January 1970 00:00:00 UT).
59+
lastSelectedScheduleEpoch = navigationArgs.lastSelectedScheduleEpoch.takeIf { it != 0L }
6060

6161
computeLastScheduleItem()
6262
setLastScheduleClickListener()
@@ -72,15 +72,17 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : BottomSheetDialogFra
7272
}
7373

7474
private fun computeLastScheduleItem() = with(binding) {
75-
if (Date(lastSelectedScheduleEpoch).isAtLeastXMinutesInTheFuture(MIN_SELECTABLE_DATE_MINUTES)) {
75+
val lastSelectedDate = lastSelectedScheduleEpoch?.let { Date(it) }
76+
77+
if (lastSelectedDate?.isAtLeastXMinutesInTheFuture(MIN_SELECTABLE_DATE_MINUTES) == true) {
7678
lastScheduleItem.isVisible = true
77-
lastScheduleItem.setDescription(context.dayOfWeekDateWithoutYear(date = Date(lastSelectedScheduleEpoch)))
79+
lastScheduleItem.setDescription(context.dayOfWeekDateWithoutYear(date = lastSelectedDate))
7880
}
7981
}
8082

8183
private fun setLastScheduleClickListener() {
8284
binding.lastScheduleItem.setOnClickListener {
83-
if (lastSelectedScheduleEpoch != 0L) {
85+
if (lastSelectedScheduleEpoch != null) {
8486
trackScheduleSendEvent("lastSelectedSchedule")
8587
setBackNavigationResult(SCHEDULE_DRAFT_RESULT, lastSelectedScheduleEpoch)
8688
}

0 commit comments

Comments
 (0)