From f929ba2f935ee3488706301b5d2dfa376a46e65e Mon Sep 17 00:00:00 2001 From: n08i40k Date: Sun, 22 Sep 2024 23:47:53 +0400 Subject: [PATCH] 1.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Фикс отображения нескольких кабинетов. Дополнительная информация в диалоговом окне о паре. --- app/build.gradle.kts | 4 +- .../schedule/impl/FakeScheduleRepository.kt | 2 +- .../next/ui/main/schedule/LessonView.kt | 98 ++++++++++++------- app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + gradle/libs.versions.toml | 10 +- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5e5bffb..396ae31 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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 { diff --git a/app/src/main/java/ru/n08i40k/polytechnic/next/data/schedule/impl/FakeScheduleRepository.kt b/app/src/main/java/ru/n08i40k/polytechnic/next/data/schedule/impl/FakeScheduleRepository.kt index 1ccb7db..37b8e3d 100644 --- a/app/src/main/java/ru/n08i40k/polytechnic/next/data/schedule/impl/FakeScheduleRepository.kt +++ b/app/src/main/java/ru/n08i40k/polytechnic/next/data/schedule/impl/FakeScheduleRepository.kt @@ -44,7 +44,7 @@ class FakeScheduleRepository : ScheduleRepository { defaultIndex = 1, name = "Элементы высшей математики", time = LessonTime(565, 645), - cabinets = arrayListOf("31"), + cabinets = arrayListOf("31", "12"), teacherNames = arrayListOf("Цацаева Т.Н."), ), Lesson( diff --git a/app/src/main/java/ru/n08i40k/polytechnic/next/ui/main/schedule/LessonView.kt b/app/src/main/java/ru/n08i40k/polytechnic/next/ui/main/schedule/LessonView.kt index 40123ed..6a82b80 100644 --- a/app/src/main/java/ru/n08i40k/polytechnic/next/ui/main/schedule/LessonView.kt +++ b/app/src/main/java/ru/n08i40k/polytechnic/next/ui/main/schedule/LessonView.kt @@ -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 { + 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 = 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 = 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 + ) + } + } } } diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 3c738be..1ad036a 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -31,4 +31,5 @@ Сменить имя пользователя Сменить группу Выйти с аккаунта + Кабинеты \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f6a808c..55ab8fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,4 +31,5 @@ Loading… Change group Sign out + Cabinets \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a3f9f6b..363cb4c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] accompanistSwiperefresh = "0.36.0" -agp = "8.6.0" +agp = "8.6.1" firebaseBom = "33.3.0" hiltAndroid = "2.51.1" hiltAndroidCompiler = "2.51.1" @@ -11,13 +11,13 @@ junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" kotlinxSerializationJson = "1.7.2" -lifecycleRuntimeKtx = "2.8.5" +lifecycleRuntimeKtx = "2.8.6" activityCompose = "1.9.2" -composeBom = "2024.09.01" +composeBom = "2024.09.02" protobufLite = "3.0.1" volley = "1.2.1" datastore = "1.1.1" -navigationCompose = "2.8.0" +navigationCompose = "2.8.1" firebaseCrashlytics = "19.1.0" 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-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } 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-material3 = { group = "androidx.compose.material3", name = "material3" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }