impr: week field
- remove Sunday - make current day rounded - show names of days of a week
This commit is contained in:
parent
0c57d0b7e7
commit
0cad16ac74
@ -18,10 +18,10 @@ import androidx.compose.foundation.layout.Row
|
|||||||
import androidx.compose.foundation.layout.aspectRatio
|
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.offset
|
|
||||||
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
|
||||||
@ -42,6 +42,7 @@ 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
|
||||||
@ -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.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.kizitonwose.calendar.compose.WeekCalendar
|
|
||||||
import com.kizitonwose.calendar.compose.weekcalendar.rememberWeekCalendarState
|
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
|
||||||
@ -65,6 +66,7 @@ import ru.sweetbread.unn.ScheduleUnit
|
|||||||
import ru.sweetbread.unn.getScheduleDay
|
import ru.sweetbread.unn.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.DayOfWeek
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@ -75,36 +77,76 @@ import java.util.Calendar
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Schedule() {
|
fun Schedule() {
|
||||||
val state = rememberWeekCalendarState(
|
var selectedDate by remember { mutableStateOf(LocalDate.now()) }
|
||||||
firstDayOfWeek = DayOfWeek.MONDAY // TODO: set start and end weeks to September and July of current year
|
val calendarState = rememberWeekCalendarState(
|
||||||
|
startDate = LocalDate.now(),
|
||||||
|
firstVisibleWeekDate = LocalDate.now(),
|
||||||
|
firstDayOfWeek = DayOfWeek.MONDAY
|
||||||
)
|
)
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
var curDate by remember { mutableStateOf(LocalDate.now()) }
|
Row(
|
||||||
WeekCalendar(
|
|
||||||
state = state,
|
|
||||||
dayContent = {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(vertical = 16.dp)
|
.fillMaxWidth()
|
||||||
.aspectRatio(1f) // This is important for square sizing!
|
.padding(horizontal = 8.dp),
|
||||||
.offset(2.dp)
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
.background(if (it.date == curDate) MaterialTheme.colorScheme.inversePrimary else MaterialTheme.colorScheme.surfaceContainer)
|
) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(
|
.clickable(
|
||||||
onClick = { curDate = it.date },
|
onClick = onClick,
|
||||||
enabled = curDate != it.date
|
enabled = !isSelected
|
||||||
),
|
),
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column (
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = it.date.dayOfMonth.toString(),
|
text = day.date.dayOfMonth.toString(),
|
||||||
fontWeight = if (it.date == LocalDate.now()) FontWeight.Bold else null
|
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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
ScheduleDay(date = curDate)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -21,4 +21,12 @@
|
|||||||
<string name="noData">Нет данных</string>
|
<string name="noData">Нет данных</string>
|
||||||
<string name="news">Новости</string>
|
<string name="news">Новости</string>
|
||||||
<string name="schedule">Расписание</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>
|
</resources>
|
@ -23,5 +23,13 @@
|
|||||||
<string name="noData">No Data</string>
|
<string name="noData">No Data</string>
|
||||||
<string name="news">News</string>
|
<string name="news">News</string>
|
||||||
<string name="schedule">Schedule</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>-->
|
<!-- <string name="login_failed">"Login failed"</string>-->
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user