diff --git a/firka/lib/ui/components/common_bottom_sheets.dart b/firka/lib/ui/components/common_bottom_sheets.dart index f5de1c5a..220e64a0 100644 --- a/firka/lib/ui/components/common_bottom_sheets.dart +++ b/firka/lib/ui/components/common_bottom_sheets.dart @@ -28,6 +28,7 @@ import 'package:firka/ui/phone/widgets/lesson.dart'; import 'package:go_router/go_router.dart'; import 'package:firka/ui/shared/class_icon.dart'; import 'package:firka_common/ui/components/firka_card.dart'; +import 'package:firka/ui/components/stats_table.dart'; import 'package:firka_common/ui/components/grade.dart'; Future showFirkaBottomSheet( @@ -47,34 +48,40 @@ Future showFirkaBottomSheet( Align( alignment: AlignmentGeometry.bottomCenter, child: Container( + width: double.infinity, + constraints: BoxConstraints( + maxHeight: MediaQuery.sizeOf(context).height * 0.85, + ), padding: const EdgeInsets.all(20) - EdgeInsets.only(top: 20), decoration: BoxDecoration( color: appStyle.colors.background, borderRadius: BorderRadius.vertical(top: Radius.circular(24)), ), child: SelectionArea( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Align( - heightFactor: 0, - alignment: Alignment.topCenter, - child: Container( - margin: EdgeInsets.only(top: 18), - width: 40, - height: 4, - foregroundDecoration: ShapeDecoration( - shape: RoundedRectangleBorder( - borderRadius: BorderRadiusGeometry.circular(2), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Align( + heightFactor: 0, + alignment: Alignment.topCenter, + child: Container( + margin: EdgeInsets.only(top: 18), + width: 40, + height: 4, + foregroundDecoration: ShapeDecoration( + shape: RoundedRectangleBorder( + borderRadius: BorderRadiusGeometry.circular(2), + ), + color: appStyle.colors.shadowColor, ), - color: appStyle.colors.shadowColor, ), ), - ), - SizedBox(height: 40), - ...children, - ], + SizedBox(height: 40), + ...children, + ], + ), ), ), ), @@ -84,6 +91,7 @@ Future showFirkaBottomSheet( ); } + Future showLessonBottomSheet( BuildContext context, AppInitialization data, @@ -100,15 +108,43 @@ Future showLessonBottomSheet( final y2k = DateTime(2000, 1); + String fmt(DateTime? dt) => + (dt != null && dt.isAfter(y2k)) + ? dt.format(data.l10n, FormatMode.yyyymmddhhmmss) + : 'N/A'; + if (statsForNerdsEnabled) { - final stats = - "${data.l10n.stats_date}: ${lesson.start.isAfter(y2k) ? lesson.start.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n" - "${data.l10n.stats_created_at}: ${lesson.createdAt.isAfter(y2k) ? lesson.createdAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"; - //"${data.l10n.stats_last_mod}: ${lesson.lastModifiedAt.isAfter(y2k) ? lesson.lastModifiedAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}"; - statsForNerds = Text( - stats, - style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary), - ); + final cg = lesson.classGroup.loadAndGet(); + final subj = lesson.subject.loadAndGet(); + final hw = lesson.homework.loadAndGet(); + final tst = lesson.test.loadAndGet(); + final omission = lesson.omission.loadAndGet(); + + final rows = <(String, String)>[ + ('id (cache key)', lesson.cacheKey.toString()), + ('uid (kréta)', lesson.uid ?? 'N/A'), + ('name', lesson.name), + ('state', lesson.state), + ('type', lesson.type), + ('start', fmt(lesson.start)), + ('end', fmt(lesson.end)), + ('last modified (kréta)', fmt(lesson.createdAt)), + ('room', lesson.roomName ?? 'N/A'), + ('teacher', lesson.teacher ?? 'N/A'), + ('sub. teacher', lesson.substituteTeacher ?? '-'), + ('lesson # (daily)', lesson.dailyNth?.toString() ?? 'N/A'), + ('lesson # (yearly)', lesson.yearlyNth?.toString() ?? 'N/A'), + ('topic', lesson.topic ?? 'N/A'), + ('subject', subj?.name ?? 'N/A'), + ('subject uid', subj?.cacheKey.toString() ?? 'N/A'), + ('class group', cg?.name ?? 'N/A'), + ('class group type', cg?.type ?? 'N/A'), + ('edu. order', cg?.educationalOrderName ?? 'N/A'), + ('homework', hw != null ? 'Yes (id: ${hw.cacheKey})' : 'None'), + ('test', tst != null ? '${tst.method}: ${tst.topic ?? "N/A"}' : 'None'), + ('omission', omission != null ? '${omission.state.name}${omission.lateMins != null ? " (${omission.lateMins}m)" : ""}' : 'None'), + ]; + statsForNerds = StatsForNerdsTable(rows: rows); } showFirkaBottomSheet(context, [ Row( @@ -142,26 +178,28 @@ Future showLessonBottomSheet( size: 26, ), ), - SizedBox(width: 6), - Card( - shadowColor: Colors.transparent, - color: appStyle.colors.a15p, - margin: EdgeInsets.all(0), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - ), - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 6), - child: Text( - lesson.roomName!, - style: appStyle.fonts.B_14R.apply( - color: appStyle.colors.secondary, + if (lesson.roomName != null && lesson.roomName!.isNotEmpty) ...[ + SizedBox(width: 6), + Card( + shadowColor: Colors.transparent, + color: appStyle.colors.a15p, + margin: EdgeInsets.all(0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 6), + child: Text( + lesson.roomName!, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.secondary, + ), + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.center, ), - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, ), ), - ), + ], ], ), SizedBox(height: 20), @@ -179,15 +217,16 @@ Future showLessonBottomSheet( ], ), SizedBox(height: 2), - Text( - lesson.teacher!, - style: appStyle.fonts.B_14R.apply( - color: appStyle.colors.textSecondary, - decoration: lesson.substituteTeacher != null - ? TextDecoration.lineThrough - : TextDecoration.none, + if (lesson.teacher != null && lesson.teacher!.isNotEmpty) + Text( + lesson.teacher!, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textSecondary, + decoration: lesson.substituteTeacher != null + ? TextDecoration.lineThrough + : TextDecoration.none, + ), ), - ), if (lesson.substituteTeacher != null) Text( lesson.substituteTeacher!, @@ -223,11 +262,29 @@ Future showLessonBottomSheet( overflow: TextOverflow.ellipsis, ), ), - ?statsForNerds, ], ), ], ), + if (statsForNerds != null) SizedBox(height: 6), + if (statsForNerds != null) + FirkaCard.single( + margin: EdgeInsets.all(0), + padding: EdgeInsets.all(14), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Debug info', + style: appStyle.fonts.H_14px.apply( + color: appStyle.colors.textPrimary, + ), + ), + SizedBox(height: 10), + statsForNerds, + ], + ), + ), SizedBox(height: 6), if (lesson.test.loadAndGet() != null) InfoCard.testDesc(lesson.test.loadAndGet()!), @@ -253,6 +310,8 @@ Future showLessonBottomSheet( ]); } + + Future showOmissionBottomSheet( BuildContext context, AppInitialization data, diff --git a/firka/lib/ui/components/stats_table.dart b/firka/lib/ui/components/stats_table.dart new file mode 100644 index 00000000..27d38625 --- /dev/null +++ b/firka/lib/ui/components/stats_table.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:firka/ui/theme/style.dart'; + +class StatsForNerdsTable extends StatelessWidget { + final List<(String, String)> rows; + + const StatsForNerdsTable({super.key, required this.rows}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (int i = 0; i < rows.length; i++) ...[ + if (i > 0) + Divider( + height: 1, + thickness: 0.5, + color: appStyle.colors.shadowColor, + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 130, + child: Text( + rows[i].$1, + style: appStyle.fonts.B_12R.apply( + color: appStyle.colors.textSecondary, + ), + ), + ), + SizedBox(width: 8), + Expanded( + child: Text( + rows[i].$2, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textPrimary, + ), + ), + ), + ], + ), + ), + ], + ], + ); + } +} diff --git a/firka/lib/ui/phone/screens/message/message_screen.dart b/firka/lib/ui/phone/screens/message/message_screen.dart index 6f82f37a..5462ced9 100644 --- a/firka/lib/ui/phone/screens/message/message_screen.dart +++ b/firka/lib/ui/phone/screens/message/message_screen.dart @@ -1,6 +1,11 @@ import 'package:firka/core/extensions.dart'; import 'package:firka/app/app_state.dart'; +import 'package:firka/core/settings/settings_repository.dart'; +import 'package:firka/core/settings/settings_schema.dart'; +import 'package:firka/ui/components/stats_table.dart'; import 'package:firka_common/data/models/message_cache_model.dart'; +import 'package:firka_common/data/util.dart'; +import 'package:firka_common/ui/components/firka_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:majesticons_flutter/majesticons_flutter.dart'; @@ -18,6 +23,38 @@ class MessageScreen extends StatelessWidget { @override Widget build(BuildContext context) { + final statsForNerdsEnabled = Settings.statsForNerds.value; + final y2k = DateTime(2000, 1); + String fmt(DateTime? dt) => + (dt != null && dt.isAfter(y2k)) + ? dt.format(data.l10n, FormatMode.yyyymmddhhmmss) + : '-'; + + Widget? statsForNerds; + if (statsForNerdsEnabled) { + final student = message.student.loadAndGet(); + final rows = <(String, String)>[ + ('id (cache key)', message.cacheKey.toString()), + ('uid (kréta)', message.uid ?? '-'), + ('type', message.type ?? '-'), + ('title', message.title), + ('author', message.author), + ('date', fmt(message.createdAt)), + if (message.itemCreatedAt != null) + ('created at', fmt(message.itemCreatedAt)), + if (message.validFrom != null) + ('valid from', fmt(message.validFrom)), + if (message.validTo != null) + ('valid to', fmt(message.validTo)), + ('student', student?.name ?? '-'), + ('student id', student?.cacheKey.toString() ?? '-'), + ('html length', '${message.contentHtml.length} chars'), + if (message.contentText != null && message.contentText!.isNotEmpty) + ('text length', '${message.contentText!.length} chars'), + ]; + statsForNerds = StatsForNerdsTable(rows: rows); + } + return DefaultAssetBundle( bundle: FirkaBundle(), child: Scaffold( @@ -64,115 +101,145 @@ class MessageScreen extends StatelessWidget { ), ], ), - SizedBox(height: 56), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - width: MediaQuery.of(context).size.width * 0.85, - child: Text( - message.title, - textAlign: TextAlign.center, - style: appStyle.fonts.H_H2.apply( - color: appStyle.colors.textPrimary, - ), - ), - ), - ], - ), - SizedBox(height: 8), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - message.createdAt.format( - data.l10n, - FormatMode.yyyymmdd, - ), - textAlign: TextAlign.center, - style: appStyle.fonts.B_16R.apply( - color: appStyle.colors.textSecondary, - ), - ), - ], - ), - SizedBox(height: 56), - Row( - children: [ - Container( - decoration: ShapeDecoration( - color: appStyle.colors.accent, - shape: CircleBorder(eccentricity: 1), - ), - child: SizedBox( - width: 28, - height: 28, - child: Row( + Expanded( + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(height: 36), + Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Padding( - padding: const EdgeInsets.only(bottom: 6), + SizedBox( + width: MediaQuery.of(context).size.width * 0.85, child: Text( - message.author[0], - style: appStyle.fonts.H_18px.copyWith( - fontSize: 20, + message.title, + textAlign: TextAlign.center, + style: appStyle.fonts.H_H2.apply( color: appStyle.colors.textPrimary, ), ), ), ], ), - ), - ), - SizedBox(width: 8), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: - MediaQuery.of(context).size.width / 1.4, - child: Text( - message.author, - style: appStyle.fonts.B_16SB.apply( - color: appStyle.colors.textPrimary, + SizedBox(height: 8), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + message.createdAt.format( + data.l10n, + FormatMode.yyyymmdd, + ), + textAlign: TextAlign.center, + style: appStyle.fonts.B_16R.apply( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + SizedBox(height: 40), + Row( + children: [ + Container( + decoration: ShapeDecoration( + color: appStyle.colors.accent, + shape: CircleBorder(eccentricity: 1), + ), + child: SizedBox( + width: 28, + height: 28, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 6), + child: Text( + message.author.isNotEmpty + ? message.author[0] + : '?', + style: appStyle.fonts.H_18px.copyWith( + fontSize: 20, + color: appStyle.colors.textPrimary, + ), + ), + ), + ], + ), + ), + ), + SizedBox(width: 8), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: MediaQuery.of(context).size.width / 1.4, + child: Text( + message.author, + style: appStyle.fonts.B_16SB.apply( + color: appStyle.colors.textPrimary, + ), + ), + ), + ], + ), + ], + ), + SizedBox(height: 16), + Padding( + padding: const EdgeInsets.all(4), + child: Container( + width: double.infinity, + decoration: BoxDecoration( + color: appStyle.colors.card, + borderRadius: BorderRadius.all( + Radius.circular(16), + ), + ), + child: Padding( + padding: const EdgeInsets.all(12), + child: Html( + data: message.contentHtml + .withoutFontFeatureSettings(), + onLinkTap: (url, map, element) => { + if (url != null) launchUrlString(url), + }, + style: { + "*": Style.fromTextStyle( + appStyle.fonts.B_16R.apply( + color: appStyle.colors.textPrimary, + ), + ), + }, + ), ), ), ), - ], - ), - ], - ), - SizedBox(height: 20), - Flexible( - fit: FlexFit.loose, - child: Padding( - padding: const EdgeInsets.all(4), - child: Container( - decoration: BoxDecoration( - color: appStyle.colors.card, - borderRadius: BorderRadius.all( - Radius.circular(16), - ), - ), - child: Padding( - padding: const EdgeInsets.all(12), - child: SingleChildScrollView( - child: Html( - data: message.contentHtml - .withoutFontFeatureSettings(), - onLinkTap: (url, map, element) => { - if (url != null) launchUrlString(url), - }, - style: { - "*": Style.fromTextStyle( - appStyle.fonts.B_16R.apply( - color: appStyle.colors.textPrimary, - ), + if (statsForNerds != null) ...[ + SizedBox(height: 16), + Padding( + padding: const EdgeInsets.all(4), + child: FirkaCard.single( + margin: EdgeInsets.all(0), + padding: EdgeInsets.all(14), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Debug info', + style: appStyle.fonts.H_14px.apply( + color: appStyle.colors.textPrimary, + ), + ), + SizedBox(height: 10), + statsForNerds, + ], ), - }, + ), ), - ), - ), + ], + SizedBox(height: 24), + ], ), ), ), diff --git a/firka_common/lib/data/models/lesson_cache_model.dart b/firka_common/lib/data/models/lesson_cache_model.dart index b9f439aa..060d992b 100644 --- a/firka_common/lib/data/models/lesson_cache_model.dart +++ b/firka_common/lib/data/models/lesson_cache_model.dart @@ -15,6 +15,7 @@ part 'lesson_cache_model.g.dart'; @collection class LessonCacheModel extends GenericCacheModel { + String? uid; @Index() late DateTime start; late DateTime end; @@ -39,6 +40,7 @@ class LessonCacheModel extends GenericCacheModel { @override void apply(CacheContext ctx) { this + ..uid = ctx.data.uid ..start = ctx.data.start ..end = ctx.data.end ..dailyNth = ctx.data.lessonNumber diff --git a/firka_common/lib/data/models/message_cache_model.dart b/firka_common/lib/data/models/message_cache_model.dart index 6f54af0a..c58d50e4 100644 --- a/firka_common/lib/data/models/message_cache_model.dart +++ b/firka_common/lib/data/models/message_cache_model.dart @@ -8,19 +8,38 @@ part 'message_cache_model.g.dart'; @collection class MessageCacheModel extends GenericCacheModel { + String? uid; late String author; late String title; late String contentHtml; + String? contentText; + DateTime? validFrom; + DateTime? validTo; + DateTime? itemCreatedAt; + String? type; final student = IsarLink(); @override void apply(CacheContext ctx) { this + ..uid = ctx.data.uid ..author = ctx.data.author ..title = ctx.data.title ..createdAt = ctx.data.date ..contentHtml = ctx.data.contentHTML + ..contentText = ctx.data.contentText ..student.value = ctx.cacheManager.findStudent(); + + if (ctx.data is NoticeBoardItem) { + final nb = ctx.data as NoticeBoardItem; + validFrom = nb.validFrom; + validTo = nb.validTo; + type = 'NoticeBoard'; + } else if (ctx.data is InfoBoardItem) { + final ib = ctx.data as InfoBoardItem; + itemCreatedAt = ib.createdAt; + type = ib.type.name; + } } }