fix: delete Sunday in week calendar
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2025 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
||||||
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@@ -132,8 +132,6 @@ dependencies {
|
|||||||
implementation(libs.splitties.base)
|
implementation(libs.splitties.base)
|
||||||
implementation(libs.splitties.room)
|
implementation(libs.splitties.room)
|
||||||
|
|
||||||
implementation(libs.compose)
|
|
||||||
|
|
||||||
implementation(libs.sentry)
|
implementation(libs.sentry)
|
||||||
|
|
||||||
implementation(libs.androidx.room.runtime)
|
implementation(libs.androidx.room.runtime)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2025 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
||||||
|
|
||||||
package ru.sweetbread.unn.ui.composes
|
package ru.sweetbread.unn.ui.composes
|
||||||
|
|
||||||
@@ -9,16 +9,13 @@ import androidx.compose.foundation.Canvas
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
@@ -39,7 +36,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -47,8 +43,6 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.kizitonwose.calendar.compose.weekcalendar.rememberWeekCalendarState
|
|
||||||
import com.kizitonwose.calendar.core.WeekDay
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -63,8 +57,6 @@ import ru.sweetbread.unn.api.ScheduleUnit
|
|||||||
import ru.sweetbread.unn.api.getScheduleDay
|
import ru.sweetbread.unn.api.getScheduleDay
|
||||||
import ru.sweetbread.unn.ui.theme.UNNTheme
|
import ru.sweetbread.unn.ui.theme.UNNTheme
|
||||||
import splitties.resources.appStr
|
import splitties.resources.appStr
|
||||||
import splitties.resources.appStrArray
|
|
||||||
import java.time.DayOfWeek
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
@@ -75,77 +67,20 @@ import java.util.Calendar
|
|||||||
@Composable
|
@Composable
|
||||||
fun Schedule() {
|
fun Schedule() {
|
||||||
var selectedDate by remember { mutableStateOf(LocalDate.now()) }
|
var selectedDate by remember { mutableStateOf(LocalDate.now()) }
|
||||||
val calendarState = rememberWeekCalendarState(
|
|
||||||
startDate = LocalDate.now(),
|
|
||||||
firstVisibleWeekDate = LocalDate.now(),
|
|
||||||
firstDayOfWeek = DayOfWeek.MONDAY
|
|
||||||
)
|
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
Row(
|
BoundedWeekPicker(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 8.dp),
|
.padding(vertical = 8.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
selectedDate = selectedDate,
|
||||||
) {
|
onDateSelected = { selectedDate = it }
|
||||||
calendarState.firstVisibleWeek.days
|
)
|
||||||
.filter { it.date.dayOfWeek != DayOfWeek.SUNDAY }
|
|
||||||
.forEach { day ->
|
|
||||||
DayItem (
|
|
||||||
Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.aspectRatio(1f)
|
|
||||||
.padding(2.dp),
|
|
||||||
day = day,
|
|
||||||
isSelected = day.date == selectedDate,
|
|
||||||
onClick = { selectedDate = day.date }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScheduleDay(date = selectedDate)
|
ScheduleDay(date = selectedDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun DayItem(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
day: WeekDay,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
|
||||||
val isToday = day.date == LocalDate.now()
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = modifier
|
|
||||||
.background(
|
|
||||||
color = if (isSelected) MaterialTheme.colorScheme.inversePrimary
|
|
||||||
else MaterialTheme.colorScheme.surfaceContainer,
|
|
||||||
shape = if (isToday) CircleShape else RectangleShape
|
|
||||||
)
|
|
||||||
.clickable(
|
|
||||||
onClick = onClick,
|
|
||||||
enabled = !isSelected
|
|
||||||
),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Column (
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = day.date.dayOfMonth.toString(),
|
|
||||||
fontWeight = if (isToday) FontWeight.Bold else null,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = appStrArray(R.array.short_weekdays)[day.date.dayOfWeek.value-1],
|
|
||||||
fontWeight = if (isToday) FontWeight.Bold else null,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ScheduleDay(modifier: Modifier = Modifier, date: LocalDate) {
|
fun ScheduleDay(modifier: Modifier = Modifier, date: LocalDate) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
||||||
|
package ru.sweetbread.unn.ui.composes
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import java.time.DayOfWeek
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.format.TextStyle
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BoundedWeekPicker(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
selectedDate: LocalDate,
|
||||||
|
onDateSelected: (LocalDate) -> Unit,
|
||||||
|
baseDate: LocalDate = LocalDate.now()
|
||||||
|
) {
|
||||||
|
val rangeStart = remember(baseDate) {
|
||||||
|
baseDate
|
||||||
|
.with(DayOfWeek.MONDAY)
|
||||||
|
.minusWeeks(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
val pageCount = 2 /* prev */ + 1 /* cur */ + 5 /* next */
|
||||||
|
|
||||||
|
fun pageIndexForDate(date: LocalDate): Int {
|
||||||
|
val weekStart = date.with(DayOfWeek.MONDAY)
|
||||||
|
return ChronoUnit.WEEKS.between(rangeStart, weekStart)
|
||||||
|
.toInt()
|
||||||
|
.coerceIn(0, pageCount - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
val initialPage = remember(selectedDate) { pageIndexForDate(selectedDate) }
|
||||||
|
|
||||||
|
val pagerState = rememberPagerState(
|
||||||
|
initialPage = initialPage,
|
||||||
|
pageCount = { pageCount }
|
||||||
|
)
|
||||||
|
|
||||||
|
LaunchedEffect(selectedDate) {
|
||||||
|
val targetPage = pageIndexForDate(selectedDate)
|
||||||
|
if (targetPage != pagerState.currentPage) {
|
||||||
|
pagerState.scrollToPage(targetPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalPager(
|
||||||
|
state = pagerState,
|
||||||
|
modifier = modifier,
|
||||||
|
beyondViewportPageCount = 1,
|
||||||
|
pageSpacing = 0.dp
|
||||||
|
) { page ->
|
||||||
|
val weekStart = rangeStart.plusWeeks(page.toLong())
|
||||||
|
val days = List(6) { weekStart.plusDays(it.toLong()) }
|
||||||
|
|
||||||
|
WeekPage(
|
||||||
|
days = days,
|
||||||
|
selectedDate = selectedDate,
|
||||||
|
onDateSelected = onDateSelected
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun WeekPage(
|
||||||
|
days: List<LocalDate>,
|
||||||
|
selectedDate: LocalDate,
|
||||||
|
onDateSelected: (LocalDate) -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
|
days.forEach { date ->
|
||||||
|
DayItem(
|
||||||
|
date = date,
|
||||||
|
isSelected = date == selectedDate,
|
||||||
|
onClick = { onDateSelected(date) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DayItem(
|
||||||
|
date: LocalDate,
|
||||||
|
isSelected: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
val backgroundColor = if (isSelected) MaterialTheme.colorScheme.primary else Color.Transparent
|
||||||
|
val contentColor = if (isSelected) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.onSurface
|
||||||
|
val fontWeight = if (date == LocalDate.now()) FontWeight.ExtraBold else FontWeight.Normal
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.size(56.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(backgroundColor)
|
||||||
|
.clickable(onClick = onClick),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
Text(
|
||||||
|
text = date.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault()),
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = contentColor,
|
||||||
|
fontWeight = fontWeight
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = date.dayOfMonth.toString(),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = contentColor,
|
||||||
|
fontWeight = fontWeight
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.7.3"
|
agp = "8.7.3"
|
||||||
calendar = "2.6.2"
|
|
||||||
coilCompose = "2.7.0"
|
coilCompose = "2.7.0"
|
||||||
compose = "1.8.0"
|
compose = "1.8.0"
|
||||||
coreSplashscreen = "1.0.1"
|
coreSplashscreen = "1.0.1"
|
||||||
@@ -35,7 +34,6 @@ androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref =
|
|||||||
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomRuntime" }
|
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomRuntime" }
|
||||||
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomRuntime" }
|
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomRuntime" }
|
||||||
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
|
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
|
||||||
compose = { module = "com.kizitonwose.calendar:compose", version.ref = "calendar" }
|
|
||||||
desugar_jdk_libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar_jdk_libs" }
|
desugar_jdk_libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar_jdk_libs" }
|
||||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||||
|
|||||||
Reference in New Issue
Block a user