Skip to content

Commit

Permalink
minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneh-s committed Jan 9, 2025
1 parent 9d3e327 commit bcdc613
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.canopas.yourspace.ui.flow.journey.timeline

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand Down Expand Up @@ -135,6 +136,17 @@ private fun TimelineContent(modifier: Modifier) {
color = AppTheme.colorScheme.textPrimary,
modifier = Modifier.weight(1f)
)

if (!state.isToday) {
Text(
stringResource(R.string.today),
style = AppTheme.appTypography.header4,
color = AppTheme.colorScheme.primary,
modifier = Modifier.clickable {
viewModel.resetToToday()
}
)
}
}
key(state.selectedTimeTo) {
HorizontalDatePicker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class JourneyTimelineViewModel @Inject constructor(
val today = Calendar.getInstance()
today.set(Calendar.HOUR_OF_DAY, 0)
today.set(Calendar.MINUTE, 0)
today.set(Calendar.SECOND, 0)
today.set(Calendar.MILLISECOND, 0)

return today.timeInMillis == calendar.timeInMillis
}
Expand Down Expand Up @@ -265,6 +263,16 @@ class JourneyTimelineViewModel @Inject constructor(
loadLocations()
}

fun resetToToday() {
_state.value = _state.value.copy(
selectedTimeFrom = getTodayStartTimestamp(),
selectedTimeTo = getTodayEndTimestamp(),
groupedLocation = emptyMap(),
isToday = true
)
loadLocations()
}

fun dismissDatePicker() {
_state.value = _state.value.copy(showDatePicker = false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import javax.inject.Inject
class CalendarViewModel @Inject constructor() : ViewModel() {
private val _state = MutableStateFlow(
CalendarViewState(
selectedDate = LocalDate.now().withDayOfMonth(1),
selectedDate = LocalDate.now().atStartOfDay().toLocalDate(),
weekStartDate = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
)
)
Expand All @@ -35,7 +35,7 @@ class CalendarViewModel @Inject constructor() : ViewModel() {

private fun setContainsToday() {
val today = LocalDate.now()
val endOfWeek = state.value.weekStartDate.plusDays(6)
val endOfWeek = state.value.weekStartDate
val containsToday = today.isAfter(state.value.weekStartDate) && today.isBefore(endOfWeek)
_state.update { it.copy(containsToday = containsToday) }
}
Expand Down

This file was deleted.

0 comments on commit bcdc613

Please sign in to comment.