From e211d64ffbc8cc6f905f067394bfb3fc1c660036 Mon Sep 17 00:00:00 2001 From: checkedear <271323618+checkedear@users.noreply.github.com> Date: Thu, 11 Jun 2026 13:29:20 +0200 Subject: [PATCH] feat: shorten teacher's name --- firka/lib/core/extensions.dart | 22 ++++++++++++++++++++++ firka/lib/ui/phone/widgets/lesson.dart | 2 +- firka/lib/ui/phone/widgets/lesson_big.dart | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/firka/lib/core/extensions.dart b/firka/lib/core/extensions.dart index 42fa8e26..6c7f90ae 100644 --- a/firka/lib/core/extensions.dart +++ b/firka/lib/core/extensions.dart @@ -294,4 +294,26 @@ extension StringExtension on String { if (length == 1) this[0].toUpperCase(); return this[0].toUpperCase() + substring(1, length); } + + String shortenName([int start = 0]) { + if (length <= 16 || start >= length) { + return this; + } + + int index = indexOf(" ", start); + if (index == -1) { + return this; + } + + String string = substring(start, index); + if (string.endsWith(".")) { + return this; + } + + return replaceRange( + start, + index, + "${string[0]}.", + ).shortenName(index - string.length + 2 + 1); + } } diff --git a/firka/lib/ui/phone/widgets/lesson.dart b/firka/lib/ui/phone/widgets/lesson.dart index 12910890..dd91429f 100644 --- a/firka/lib/ui/phone/widgets/lesson.dart +++ b/firka/lib/ui/phone/widgets/lesson.dart @@ -166,7 +166,7 @@ class LessonWidget extends StatelessWidget { ), showSubstitutions ? Text( - lesson.substituteTeacher!, + lesson.substituteTeacher!.shortenName(), style: appStyle.fonts.B_14R.apply( color: appStyle.colors.textSecondary, ), diff --git a/firka/lib/ui/phone/widgets/lesson_big.dart b/firka/lib/ui/phone/widgets/lesson_big.dart index 5d5698ab..605cce4f 100644 --- a/firka/lib/ui/phone/widgets/lesson_big.dart +++ b/firka/lib/ui/phone/widgets/lesson_big.dart @@ -204,7 +204,7 @@ class LessonBigWidget extends StatelessWidget { ), if (isSubstituted) Text( - lesson.substituteTeacher!, + lesson.substituteTeacher!.shortenName(), style: appStyle.fonts.B_14R.apply( color: appStyle.colors.textSecondary, ),