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: Use nullable lastSelectedScheduleEpoch inside the bottom sheet #2186

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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 @@ -45,9 +45,7 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : BottomSheetDialogFra
private val navigationArgs: ScheduleSendBottomSheetDialogArgs by navArgs()
private var binding: BottomSheetScheduleSendBinding by safeBinding()

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

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

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

computeLastScheduleItem()
setLastScheduleClickListener()
Expand All @@ -72,15 +72,17 @@ class ScheduleSendBottomSheetDialog @Inject constructor() : BottomSheetDialogFra
}

private fun computeLastScheduleItem() = with(binding) {
if (Date(lastSelectedScheduleEpoch).isAtLeastXMinutesInTheFuture(MIN_SELECTABLE_DATE_MINUTES)) {
val lastSelectedDate = lastSelectedScheduleEpoch?.let { Date(it) }

if (lastSelectedDate?.isAtLeastXMinutesInTheFuture(MIN_SELECTABLE_DATE_MINUTES) == true) {
lastScheduleItem.isVisible = true
lastScheduleItem.setDescription(context.dayOfWeekDateWithoutYear(date = Date(lastSelectedScheduleEpoch)))
lastScheduleItem.setDescription(context.dayOfWeekDateWithoutYear(date = lastSelectedDate))
}
}

private fun setLastScheduleClickListener() {
binding.lastScheduleItem.setOnClickListener {
if (lastSelectedScheduleEpoch != 0L) {
if (lastSelectedScheduleEpoch != null) {
trackScheduleSendEvent("lastSelectedSchedule")
setBackNavigationResult(SCHEDULE_DRAFT_RESULT, lastSelectedScheduleEpoch)
}
Expand Down
Loading