impr: week field

- remove Sunday
- make current day rounded
- show names of days of a week
This commit is contained in:
Sweetbread 2025-04-24 22:03:49 +03:00
parent 0c57d0b7e7
commit 0cad16ac74
Signed by: Sweetbread
GPG Key ID: 17A5CB9A7DD85319
3 changed files with 84 additions and 26 deletions

View File

@ -18,10 +18,10 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.LinearProgressIndicator
@ -42,6 +42,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
@ -49,8 +50,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.kizitonwose.calendar.compose.WeekCalendar
import com.kizitonwose.calendar.compose.weekcalendar.rememberWeekCalendarState
import com.kizitonwose.calendar.core.WeekDay
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -65,6 +66,7 @@ import ru.sweetbread.unn.ScheduleUnit
import ru.sweetbread.unn.getScheduleDay
import ru.sweetbread.unn.ui.theme.UNNTheme
import splitties.resources.appStr
import splitties.resources.appStrArray
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
@ -75,35 +77,75 @@ import java.util.Calendar
@Composable
fun Schedule() {
val state = rememberWeekCalendarState(
firstDayOfWeek = DayOfWeek.MONDAY // TODO: set start and end weeks to September and July of current year
var selectedDate by remember { mutableStateOf(LocalDate.now()) }
val calendarState = rememberWeekCalendarState(
startDate = LocalDate.now(),
firstVisibleWeekDate = LocalDate.now(),
firstDayOfWeek = DayOfWeek.MONDAY
)
Column {
var curDate by remember { mutableStateOf(LocalDate.now()) }
WeekCalendar(
state = state,
dayContent = {
Box(
modifier = Modifier
.padding(vertical = 16.dp)
.aspectRatio(1f) // This is important for square sizing!
.offset(2.dp)
.background(if (it.date == curDate) MaterialTheme.colorScheme.inversePrimary else MaterialTheme.colorScheme.surfaceContainer)
.clickable(
onClick = { curDate = it.date },
enabled = curDate != it.date
),
contentAlignment = Alignment.Center,
) {
Text(
text = it.date.dayOfMonth.toString(),
fontWeight = if (it.date == LocalDate.now()) FontWeight.Bold else null
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp),
horizontalArrangement = Arrangement.SpaceEvenly
) {
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 = curDate)
}
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
)
}
}
}

View File

@ -21,4 +21,12 @@
<string name="noData">Нет данных</string>
<string name="news">Новости</string>
<string name="schedule">Расписание</string>
<string-array name="short_weekdays">
<item>Пн</item>
<item>Вт</item>
<item>Ср</item>
<item>Чт</item>
<item>Пт</item>
<item>Сб</item>
</string-array>
</resources>

View File

@ -23,5 +23,13 @@
<string name="noData">No Data</string>
<string name="news">News</string>
<string name="schedule">Schedule</string>
<string-array name="short_weekdays">
<item>Mn</item>
<item>Tu</item>
<item>We</item>
<item>Th</item>
<item>Fr</item>
<item>Sa</item>
</string-array>
<!-- <string name="login_failed">"Login failed"</string>-->
</resources>