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

Дополнительная информация в диалоговом окне о паре.
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" applicationId = "ru.n08i40k.polytechnic.next"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 3 versionCode = 4
versionName = "1.2" versionName = "1.2.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {

View File

@@ -44,7 +44,7 @@ class FakeScheduleRepository : ScheduleRepository {
defaultIndex = 1, defaultIndex = 1,
name = "Элементы высшей математики", name = "Элементы высшей математики",
time = LessonTime(565, 645), time = LessonTime(565, 645),
cabinets = arrayListOf("31"), cabinets = arrayListOf("31", "12"),
teacherNames = arrayListOf("Цацаева Т.Н."), teacherNames = arrayListOf("Цацаева Т.Н."),
), ),
Lesson( 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.Lesson
import ru.n08i40k.polytechnic.next.model.LessonTime 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 @Composable
fun LessonExtraInfo( fun LessonExtraInfo(
lesson: Lesson = FakeScheduleRepository.exampleGroup.days[0]!!.lessons[0]!!, lesson: Lesson = FakeScheduleRepository.exampleGroup.days[0]!!.lessons[0]!!,
@@ -38,6 +68,8 @@ fun LessonExtraInfo(
) { ) {
Dialog(onDismissRequest = { mutableExpanded.value = false }) { Dialog(onDismissRequest = { mutableExpanded.value = false }) {
Column(modifier = Modifier.padding(5.dp)) { Column(modifier = Modifier.padding(5.dp)) {
Text(lesson.name)
if (lesson.teacherNames.isNotEmpty()) { if (lesson.teacherNames.isNotEmpty()) {
val teachers = buildString { val teachers = buildString {
append(stringResource(if (lesson.teacherNames.count() > 1) R.string.lesson_teachers else R.string.lesson_teacher)) append(stringResource(if (lesson.teacherNames.count() > 1) R.string.lesson_teachers else R.string.lesson_teacher))
@@ -61,18 +93,18 @@ fun LessonExtraInfo(
append(minutes) append(minutes)
append(stringResource(R.string.minutes)) append(stringResource(R.string.minutes))
} }
Text(duration) 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) @Preview(showBackground = true)
@@ -105,23 +137,7 @@ private fun LessonViewRow(
Spacer(Modifier.width(7.5.dp)) Spacer(Modifier.width(7.5.dp))
if (time != null) { if (time != null) {
val formattedTime: ArrayList<String> = when (timeFormat) { val formattedTime: ArrayList<String> = fmtTime(time.start, time.end, 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))
}
}
Column( Column(
modifier = Modifier.fillMaxWidth(0.25f), modifier = Modifier.fillMaxWidth(0.25f),
@@ -148,8 +164,12 @@ private fun LessonViewRow(
Column( Column(
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
val fraction =
if (cabinets.size == 0) 1F
else if (cabinets.any { it.contains("/") }) 0.9F
else 0.925F
Text( Text(
modifier = Modifier.fillMaxWidth(0.85f), modifier = Modifier.fillMaxWidth(fraction),
text = name, text = name,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
@@ -157,7 +177,7 @@ private fun LessonViewRow(
) )
if (!teacherNames.isNullOrEmpty()) { if (!teacherNames.isNullOrEmpty()) {
Text( Text(
modifier = Modifier.fillMaxWidth(0.85f), modifier = Modifier.fillMaxWidth(fraction),
text = teacherNames, text = teacherNames,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
@@ -166,16 +186,20 @@ private fun LessonViewRow(
} }
} }
Column(verticalArrangement = Arrangement.Center) {
cabinets.forEach {
Text( Text(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End, textAlign = TextAlign.End,
text = cabinets.joinToString(", "), text = it,
fontFamily = FontFamily.Monospace, fontFamily = FontFamily.Monospace,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
maxLines = 1, maxLines = 1,
color = contentColor color = contentColor
) )
} }
}
}
} }
@Preview(showBackground = true) @Preview(showBackground = true)

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
[versions] [versions]
accompanistSwiperefresh = "0.36.0" accompanistSwiperefresh = "0.36.0"
agp = "8.6.0" agp = "8.6.1"
firebaseBom = "33.3.0" firebaseBom = "33.3.0"
hiltAndroid = "2.51.1" hiltAndroid = "2.51.1"
hiltAndroidCompiler = "2.51.1" hiltAndroidCompiler = "2.51.1"
@@ -11,13 +11,13 @@ junit = "4.13.2"
junitVersion = "1.2.1" junitVersion = "1.2.1"
espressoCore = "3.6.1" espressoCore = "3.6.1"
kotlinxSerializationJson = "1.7.2" kotlinxSerializationJson = "1.7.2"
lifecycleRuntimeKtx = "2.8.5" lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.2" activityCompose = "1.9.2"
composeBom = "2024.09.01" composeBom = "2024.09.02"
protobufLite = "3.0.1" protobufLite = "3.0.1"
volley = "1.2.1" volley = "1.2.1"
datastore = "1.1.1" datastore = "1.1.1"
navigationCompose = "2.8.0" navigationCompose = "2.8.1"
firebaseCrashlytics = "19.1.0" firebaseCrashlytics = "19.1.0"
googleFirebaseCrashlytics = "3.0.2" googleFirebaseCrashlytics = "3.0.2"
@@ -40,7 +40,7 @@ androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version = "1.7.1" } androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version = "1.7.2" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }