From bcdc6135a87b7c8ab59b38604292611f5fd9870a Mon Sep 17 00:00:00 2001 From: Sneh Date: Thu, 9 Jan 2025 14:17:08 +0530 Subject: [PATCH] minor changes. --- .../journey/timeline/JourneyTimelineScreen.kt | 12 +++ .../timeline/JourneyTimelineViewModel.kt | 12 ++- .../timeline/component/CalendarViewModel.kt | 4 +- .../timeline/component/CalenderDataSource.kt | 78 ------------------- 4 files changed, 24 insertions(+), 82 deletions(-) delete mode 100644 app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalenderDataSource.kt diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineScreen.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineScreen.kt index 2ec8fdf1..5e6718e0 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineScreen.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineScreen.kt @@ -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 @@ -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( diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineViewModel.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineViewModel.kt index d0ed5412..29513b75 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineViewModel.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/JourneyTimelineViewModel.kt @@ -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 } @@ -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) } diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalendarViewModel.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalendarViewModel.kt index 5a37abb5..dd2fdf53 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalendarViewModel.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalendarViewModel.kt @@ -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)) ) ) @@ -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) } } diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalenderDataSource.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalenderDataSource.kt deleted file mode 100644 index a9233fd9..00000000 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/journey/timeline/component/CalenderDataSource.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.canopas.yourspace.ui.flow.journey.timeline.component - -import java.time.LocalDate -import java.time.format.DateTimeFormatter -import java.time.temporal.ChronoUnit -import java.util.stream.Collectors -import java.util.stream.Stream - -class CalendarDataSource { - - val today: LocalDate - get() = LocalDate.now() - - fun getData( - currentList: List, - lastSelectedDate: LocalDate, - isScrollUp: Boolean - ): CalendarUiModel { - val startDate: LocalDate - val endDate: LocalDate - - if (isScrollUp) { - startDate = currentList.first().minusDays(30) - endDate = currentList.first().minusDays(1) - } else { - startDate = currentList.last().plusDays(1) - endDate = currentList.last().plusDays(30) - } - - val additionalDates = getDatesBetween(startDate, endDate) - val combinedDates = if (isScrollUp) { - additionalDates + currentList - } else { - currentList + additionalDates - } - - return toUiModel(combinedDates, lastSelectedDate) - } - - fun getDatesBetween(startDate: LocalDate, endDate: LocalDate): List { - val numOfDays = ChronoUnit.DAYS.between(startDate, endDate) + 1 - return Stream.iterate(startDate) { date -> date.plusDays(1) } - .limit(numOfDays) - .collect(Collectors.toList()) - } - - private fun toUiModel( - dateList: List, - lastSelectedDate: LocalDate - ): CalendarUiModel { - return CalendarUiModel( - selectedDate = toItemUiModel(lastSelectedDate, true), - visibleDates = dateList.map { - toItemUiModel(it, it.isEqual(lastSelectedDate)) - } - ) - } - - private fun toItemUiModel(date: LocalDate, isSelectedDate: Boolean) = CalendarUiModel.Date( - isSelected = isSelectedDate, - isToday = date.isEqual(today), - date = date - ) -} - -data class CalendarUiModel( - val selectedDate: Date, - val visibleDates: List -) { - - data class Date( - val date: LocalDate, - val isSelected: Boolean, - val isToday: Boolean - ) { - val day: String = date.format(DateTimeFormatter.ofPattern("EE")) - } -}