Skip to content

Commit

Permalink
Replace hidden today with a proper button on the TopBar (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
costular authored Oct 11, 2024
1 parent 71c86e3 commit 98f781d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.costular.atomtasks.agenda.ui

import androidx.compose.foundation.clickable
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -11,7 +11,10 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.CalendarMonth
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -34,6 +37,7 @@ import com.kizitonwose.calendar.compose.weekcalendar.WeekCalendarState
import com.kizitonwose.calendar.compose.weekcalendar.rememberWeekCalendarState
import java.time.LocalDate
import kotlinx.coroutines.launch
import com.costular.atomtasks.core.ui.R.string as S

private const val DaysToShow = 365L

Expand All @@ -42,6 +46,7 @@ private const val DaysToShow = 365L
internal fun AgendaHeader(
modifier: Modifier = Modifier,
selectedDay: Day,
shouldShowTodayAction: Boolean,
onSelectDate: (LocalDate) -> Unit,
onSelectToday: () -> Unit,
onClickCalendar: () -> Unit,
Expand All @@ -64,27 +69,31 @@ internal fun AgendaHeader(
) {
val selectedDayText = DateUtils.dayAsText(selectedDay.date)

Row(
verticalAlignment = Alignment.CenterVertically,
ScreenHeader(
text = selectedDayText,
modifier = Modifier
.weight(1f)
.clickable(onClick = {
coroutineScope.launch {
weekCalendarState.animateScrollToWeek(LocalDate.now())
}
onSelectToday()
}),
) {
ScreenHeader(
text = selectedDayText,
modifier = Modifier
.testTag(TestTagHeader)
.padding(
top = AppTheme.dimens.spacingLarge,
bottom = AppTheme.dimens.spacingLarge,
start = AppTheme.dimens.spacingLarge,
),
)
.testTag(TestTagHeader)
.padding(
top = AppTheme.dimens.spacingLarge,
bottom = AppTheme.dimens.spacingLarge,
start = AppTheme.dimens.spacingLarge,
),
)

AnimatedVisibility(visible = shouldShowTodayAction) {
TextButton(onClick = {
coroutineScope.launch {
weekCalendarState.animateScrollToWeek(LocalDate.now())
}
onSelectToday()
}) {
Text(
text = stringResource(S.today),
style = MaterialTheme.typography.titleMedium
.copy(color = MaterialTheme.colorScheme.onSurface)
)
}
}

IconButton(
Expand Down Expand Up @@ -136,6 +145,7 @@ private fun HeaderCollapsedPreview() {
AtomTheme {
AgendaHeader(
selectedDay = LocalDate.now().asDay(),
shouldShowTodayAction = true,
onSelectDate = {},
onSelectToday = {},
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ fun AgendaScreen(
AgendaHeader(
selectedDay = state.selectedDay,
onSelectDate = onSelectDate,
modifier = Modifier.fillMaxWidth(),
// Start using date provider instead of fixed date
shouldShowTodayAction = state.selectedDay.date != LocalDate.now(),
onSelectToday = onSelectToday,
onClickCalendar = onClickOpenCalendarView,
modifier = Modifier.fillMaxWidth(),
)

TasksContent(
Expand Down

0 comments on commit 98f781d

Please sign in to comment.