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, ),