Фикс отображения нескольких кабинетов.

Дополнительная информация в диалоговом окне о паре.
This commit is contained in:
2024-09-22 23:47:53 +04:00
parent c98d34bd98
commit f929ba2f93
6 changed files with 71 additions and 45 deletions

View File

@@ -32,8 +32,8 @@ android {
applicationId = "ru.n08i40k.polytechnic.next"
minSdk = 26
targetSdk = 35
versionCode = 3
versionName = "1.2"
versionCode = 4
versionName = "1.2.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@@ -44,7 +44,7 @@ class FakeScheduleRepository : ScheduleRepository {
defaultIndex = 1,
name = "Элементы высшей математики",
time = LessonTime(565, 645),
cabinets = arrayListOf("31"),
cabinets = arrayListOf("31", "12"),
teacherNames = arrayListOf("Цацаева Т.Н."),
),
Lesson(

View File

@@ -31,6 +31,36 @@ import ru.n08i40k.polytechnic.next.model.Day
import ru.n08i40k.polytechnic.next.model.Lesson
import ru.n08i40k.polytechnic.next.model.LessonTime
private enum class LessonTimeFormat {
FROM_TO, ONLY_MINUTES_DURATION
}
private fun numWithZero(num: Int): String {
return "0".repeat(if (num <= 9) 1 else 0) + num.toString()
}
@Composable
private fun fmtTime(start: Int, end: Int, format: LessonTimeFormat): ArrayList<String> {
return when (format) {
LessonTimeFormat.FROM_TO -> {
val startHour = numWithZero(start / 60)
val startMinute = numWithZero(start % 60)
val endHour = numWithZero(end / 60)
val endMinute = numWithZero(end % 60)
arrayListOf("$startHour:$startMinute", "$endHour:$endMinute")
}
LessonTimeFormat.ONLY_MINUTES_DURATION -> {
val duration = end - start
arrayListOf("$duration " + stringResource(R.string.minutes))
}
}
}
@Preview(showBackground = true)
@Composable
fun LessonExtraInfo(
lesson: Lesson = FakeScheduleRepository.exampleGroup.days[0]!!.lessons[0]!!,
@@ -38,6 +68,8 @@ fun LessonExtraInfo(
) {
Dialog(onDismissRequest = { mutableExpanded.value = false }) {
Column(modifier = Modifier.padding(5.dp)) {
Text(lesson.name)
if (lesson.teacherNames.isNotEmpty()) {
val teachers = buildString {
append(stringResource(if (lesson.teacherNames.count() > 1) R.string.lesson_teachers else R.string.lesson_teacher))
@@ -61,20 +93,20 @@ fun LessonExtraInfo(
append(minutes)
append(stringResource(R.string.minutes))
}
Text(duration)
if (lesson.cabinets.isNotEmpty()) {
val cabinets = buildString {
append(stringResource(R.string.cabinets))
append(" - ")
append(lesson.cabinets.joinToString(", "))
}
Text(cabinets)
}
}
}
}
private enum class LessonTimeFormat {
FROM_TO, ONLY_MINUTES_DURATION
}
private fun numWithZero(num: Int): String {
return "0".repeat(if (num <= 9) 1 else 0) + num.toString()
}
@Preview(showBackground = true)
@Composable
private fun LessonViewRow(
@@ -105,23 +137,7 @@ private fun LessonViewRow(
Spacer(Modifier.width(7.5.dp))
if (time != null) {
val formattedTime: ArrayList<String> = when (timeFormat) {
LessonTimeFormat.FROM_TO -> {
val startHour = numWithZero(time.start / 60)
val startMinute = numWithZero(time.start % 60)
val endHour = numWithZero(time.end / 60)
val endMinute = numWithZero(time.end % 60)
arrayListOf("$startHour:$startMinute", "$endHour:$endMinute")
}
LessonTimeFormat.ONLY_MINUTES_DURATION -> {
val duration = time.end - time.start
arrayListOf("$duration " + stringResource(R.string.minutes))
}
}
val formattedTime: ArrayList<String> = fmtTime(time.start, time.end, timeFormat)
Column(
modifier = Modifier.fillMaxWidth(0.25f),
@@ -148,8 +164,12 @@ private fun LessonViewRow(
Column(
verticalArrangement = Arrangement.Center
) {
val fraction =
if (cabinets.size == 0) 1F
else if (cabinets.any { it.contains("/") }) 0.9F
else 0.925F
Text(
modifier = Modifier.fillMaxWidth(0.85f),
modifier = Modifier.fillMaxWidth(fraction),
text = name,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
@@ -157,7 +177,7 @@ private fun LessonViewRow(
)
if (!teacherNames.isNullOrEmpty()) {
Text(
modifier = Modifier.fillMaxWidth(0.85f),
modifier = Modifier.fillMaxWidth(fraction),
text = teacherNames,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
@@ -166,15 +186,19 @@ private fun LessonViewRow(
}
}
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
text = cabinets.joinToString(", "),
fontFamily = FontFamily.Monospace,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = contentColor
)
Column(verticalArrangement = Arrangement.Center) {
cabinets.forEach {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
text = it,
fontFamily = FontFamily.Monospace,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = contentColor
)
}
}
}
}

View File

@@ -31,4 +31,5 @@
<string name="change_username">Сменить имя пользователя</string>
<string name="change_group">Сменить группу</string>
<string name="sign_out">Выйти с аккаунта</string>
<string name="cabinets">Кабинеты</string>
</resources>

View File

@@ -31,4 +31,5 @@
<string name="loading">Loading…</string>
<string name="change_group">Change group</string>
<string name="sign_out">Sign out</string>
<string name="cabinets">Cabinets</string>
</resources>