From a64a7f750961bc8b496b19a5933bd00287722f0b Mon Sep 17 00:00:00 2001 From: checkedear <271323618+checkedear@users.noreply.github.com> Date: Mon, 15 Jun 2026 11:39:20 +0200 Subject: [PATCH] feat: omissions --- firka/lib/routing/app_router.dart | 15 + firka/lib/routing/shell_with_nav_bar.dart | 5 + .../ui/components/common_bottom_sheets.dart | 113 ++++ firka/lib/ui/phone/pages/home/home_main.dart | 25 +- .../ui/phone/pages/home/home_omissions.dart | 324 +++++++++++ .../phone/pages/home/home_timetable_mo.dart | 4 +- firka/lib/ui/phone/widgets/info_card.dart | 510 +++++++++--------- firka/lib/ui/phone/widgets/lesson.dart | 12 +- firka/lib/ui/phone/widgets/omission_bar.dart | 87 +++ kreta_api/lib/src/model/omission.dart | 48 +- 10 files changed, 879 insertions(+), 264 deletions(-) create mode 100644 firka/lib/ui/phone/pages/home/home_omissions.dart create mode 100644 firka/lib/ui/phone/widgets/omission_bar.dart diff --git a/firka/lib/routing/app_router.dart b/firka/lib/routing/app_router.dart index 51407e81..7b11a4bd 100644 --- a/firka/lib/routing/app_router.dart +++ b/firka/lib/routing/app_router.dart @@ -1,5 +1,6 @@ import 'dart:collection'; +import 'package:firka/ui/phone/pages/home/home_omissions.dart'; import 'package:flutter/material.dart'; import 'package:firka/core/firka_bundle.dart'; import 'package:firka/app/app_state.dart'; @@ -177,6 +178,20 @@ GoRouter createAppRouter() { ), ], ), + StatefulShellBranch( + routes: [ + GoRoute( + path: '/omissions', + pageBuilder: (context, state) => NoTransitionPage( + key: state.pageKey, + child: DefaultAssetBundle( + bundle: FirkaBundle(), + child: HomeOmissionsScreen(initData), + ), + ), + ), + ], + ), ], ), ], diff --git a/firka/lib/routing/shell_with_nav_bar.dart b/firka/lib/routing/shell_with_nav_bar.dart index d5192d10..0d1b0384 100644 --- a/firka/lib/routing/shell_with_nav_bar.dart +++ b/firka/lib/routing/shell_with_nav_bar.dart @@ -57,6 +57,11 @@ class ShellWithNavBar extends StatelessWidget { Majesticon.calendarSolid, Majesticon.calendarLine, ), + ( + initData.l10n.omissions, + Majesticon.timerSolid, + Majesticon.timerLine, + ), ].indexed.map( (nav) => BottomNavIconWidget( () { diff --git a/firka/lib/ui/components/common_bottom_sheets.dart b/firka/lib/ui/components/common_bottom_sheets.dart index 1a1c0695..6de98f81 100644 --- a/firka/lib/ui/components/common_bottom_sheets.dart +++ b/firka/lib/ui/components/common_bottom_sheets.dart @@ -245,6 +245,119 @@ Future showLessonBottomSheet( ]); } +Future showOmissionBottomSheet( + BuildContext context, + AppInitialization data, + String description, + List omissions, +) async { + showFirkaBottomSheet(context, [ + Text( + omissions.first.date.format(data.l10n, FormatMode.yyyymmdd), + style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary), + ), + SizedBox(height: 2), + Text( + description, + style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textSecondary), + ), + SizedBox(height: 2), + LimitedBox( + maxHeight: 336, + child: ListView.builder( + itemCount: omissions.length, + itemBuilder: (b, i) { + final o = omissions[i]; + return FirkaCard.single( + height: 64, + margin: EdgeInsets.only(bottom: 10), + padding: EdgeInsets.only(left: 14, right: 16), + child: Row( + children: [ + SizedBox( + width: 18, + height: 18, + child: Stack( + alignment: Alignment.center, + children: [ + SvgPicture.asset( + "assets/icons/subtract.svg", + color: appStyle.colors.a15p, + width: 18, + height: 18, + ), + Text( + o.lesson!.classNo?.toString() ?? "-", + style: appStyle.fonts.B_14SB.apply( + color: appStyle.colors.secondary, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + FilledCircle( + diameter: 36, + color: appStyle.colors.a15p, + child: ClassIconWidget( + uid: o.subject.uid, + className: o.subject.name, + category: o.subject.name, + color: appStyle.colors.accent, + size: 24, + ), + ), + SizedBox(width: 12), + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + o.subject.name, + style: appStyle.fonts.B_16SB.apply( + color: appStyle.colors.textPrimary, + ), + overflow: TextOverflow.ellipsis, + ), + Text( + o.teacher, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textSecondary, + ), + overflow: TextOverflow.ellipsis, + ), + ], + ), + ), + SizedBox(width: 8), + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + o.lesson!.start.format(data.l10n, FormatMode.hmm), + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textPrimary, + ), + ), + Text( + o.lesson!.end.format(data.l10n, FormatMode.hmm), + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textPrimary, + ), + ), + ], + ), + ], + ), + ); + }, + ), + ), + ]); +} + Future showTestBottomSheet( BuildContext context, AppInitialization data, diff --git a/firka/lib/ui/phone/pages/home/home_main.dart b/firka/lib/ui/phone/pages/home/home_main.dart index 4ed1e3d7..9c033287 100644 --- a/firka/lib/ui/phone/pages/home/home_main.dart +++ b/firka/lib/ui/phone/pages/home/home_main.dart @@ -45,6 +45,7 @@ class _HomeMainScreen extends FirkaState { List? tests; List? grades; List? homework; + List? omissions; Student? student; Timer? timer; @@ -66,6 +67,7 @@ class _HomeMainScreen extends FirkaState { var testsFetched = 0; var gradesFetched = 0; var homeworkFetched = 0; + var omissionFetched = 0; widget.data.client .getTimeTableStream( @@ -139,6 +141,18 @@ class _HomeMainScreen extends FirkaState { } }); + widget.data.client.getOmissionsStream(cacheOnly: cacheOnly).forEach(( + omission, + ) { + omissionFetched++; + + if (mounted) { + setState(() { + this.omissions = omission.response; + }); + } + }); + widget.data.client.getHomeworkStream(cacheOnly: cacheOnly).forEach(( homework, ) { @@ -161,7 +175,8 @@ class _HomeMainScreen extends FirkaState { studentFetched < r || testsFetched < r || gradesFetched < r || - homeworkFetched < r) { + homeworkFetched < r || + omissionFetched < r) { if (DateTime.now().difference(startTime) > maxWaitTime) { debugPrint('[HomeMain] Data fetch timed out after 30s'); break; @@ -198,6 +213,7 @@ class _HomeMainScreen extends FirkaState { final gradeItems = grades ?? []; final testItems = tests ?? []; final homeworkItems = homework ?? []; + final omissionItems = omissions?.groupList((o) => o.date).values ?? []; final noticeBoardWidgets = <(Widget, DateTime)>[]; for (final item in infoItems) { @@ -216,6 +232,13 @@ class _HomeMainScreen extends FirkaState { noticeBoardWidgets.add((InfoCard.homework(entry), entry.creationDate)); } + for (final omission in omissionItems) { + noticeBoardWidgets.add(( + InfoCard.omission(omission), + omission.first.date, + )); + } + noticeBoardWidgets.sort( (item1, item2) => item2.$2.difference(item1.$2).inMilliseconds, ); diff --git a/firka/lib/ui/phone/pages/home/home_omissions.dart b/firka/lib/ui/phone/pages/home/home_omissions.dart new file mode 100644 index 00000000..47b0f8d3 --- /dev/null +++ b/firka/lib/ui/phone/pages/home/home_omissions.dart @@ -0,0 +1,324 @@ +import 'dart:collection'; + +import 'package:firka/core/extensions.dart'; +import 'package:firka/ui/phone/widgets/info_card.dart'; +import 'package:firka/ui/phone/widgets/omission_bar.dart'; +import 'package:firka_common/firka_common.dart'; +import 'package:kreta_api/kreta_api.dart'; +import 'package:firka/ui/components/firka_card.dart'; +import 'package:firka/ui/components/grade_helpers.dart'; +import 'package:firka/ui/phone/widgets/grade_chart.dart'; +import 'package:firka/ui/phone/widgets/grade_summary_bar.dart'; +import 'package:firka/ui/shared/grade_small_card.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; + +import 'package:firka/api/consts.dart'; +import 'package:firka/core/debug_helper.dart'; +import 'package:firka/core/state/firka_state.dart'; +import 'package:firka/app/app_state.dart'; +import 'package:firka/core/bloc/home_refresh_cubit.dart'; +import 'package:firka/core/settings.dart'; +import 'package:firka/ui/theme/style.dart'; +import 'package:firka/ui/shared/delayed_spinner.dart'; +import 'package:majesticons_flutter/majesticons_flutter.dart'; + +class HomeOmissionsScreen extends StatefulWidget { + final AppInitialization data; + + const HomeOmissionsScreen(this.data, {super.key}); + + @override + State createState() => _HomeOmissionsScreen(); +} + +class _HomeOmissionsScreen extends FirkaState { + ApiResponse>? omissions; + + void _onRefreshRequested(BuildContext context) async { + final cubit = context.read(); + omissions = await widget.data.client.getOmissions(forceCache: false); + if (mounted) { + setState(() {}); + cubit.onRefreshComplete(); + } + } + + @override + void initState() { + super.initState(); + + (() async { + omissions = await widget.data.client.getOmissions(forceCache: false); + if (mounted) setState(() {}); + })(); + } + + @override + Widget build(BuildContext context) { + return BlocListener( + listenWhen: (previous, current) => + current.refreshTrigger != previous.refreshTrigger, + listener: (context, state) { + _onRefreshRequested(context); + }, + child: _buildContent(context), + ); + } + + Widget _buildContent(BuildContext context) { + if (omissions == null) { + return Center(child: DelayedSpinnerWidget()); + } + + final omissionItems = omissions!.response ?? []; + + final overallExcused = omissionItems + .where((o) => o.state == OmissionState.excused) + .length; + + final overallUnexcused = omissionItems + .where((o) => o.state == OmissionState.unexcused) + .length; + + final overallPending = omissionItems + .where((o) => o.state == OmissionState.pending) + .length; + + return Padding( + padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.data.l10n.subjects, + style: appStyle.fonts.H_H2.apply( + color: appStyle.colors.textPrimary, + ), + ), + SizedBox(height: 20), + Row( + spacing: 10, + children: [ + Expanded( + child: FirkaCard.single( + padding: EdgeInsets.symmetric(vertical: 16), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + spacing: 4, + children: [ + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.clipboardCheckSolid, + size: 12.0, + color: appStyle.colors.accent, + ), + Text( + overallExcused.toString(), + style: appStyle.fonts.H_18px.copyWith( + color: appStyle.colors.textPrimary, + ), + ), + ], + ), + Text( + initData.l10n.omission_state_excused, + style: appStyle.fonts.B_16R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ), + ), + Expanded( + child: FirkaCard.single( + padding: EdgeInsets.symmetric(vertical: 16), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + spacing: 4, + children: [ + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.timerSolid, + size: 12.0, + color: appStyle.colors.warningAccent, + ), + Text( + overallPending.toString(), + style: appStyle.fonts.H_18px.copyWith( + color: appStyle.colors.warningAccent, + ), + ), + ], + ), + Text( + initData.l10n.omission_state_pending, + style: appStyle.fonts.B_16R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ), + ), + Expanded( + child: FirkaCard.single( + padding: EdgeInsets.symmetric(vertical: 16), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + spacing: 4, + children: [ + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.restrictedSolid, + size: 12.0, + color: appStyle.colors.errorAccent, + ), + Text( + overallUnexcused.toString(), + style: appStyle.fonts.H_18px.copyWith( + color: appStyle.colors.errorAccent, + ), + ), + ], + ), + Text( + initData.l10n.omission_state_unexcused, + style: appStyle.fonts.B_16R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ), + ), + ], + ), + SizedBox(height: 10), + OmissionBar(omissions: omissions!.response!), + SizedBox(height: 20), + Expanded( + child: ListView( + children: [ + Text( + initData.l10n.subjects, + style: appStyle.fonts.B_16SB.copyWith( + color: appStyle.colors.textPrimary, + ), + ), + SizedBox(height: 10), + ...omissionItems + .fold( + LinkedHashMap>( + equals: (a, b) => a.uid == b.uid, + hashCode: (a) => a.uid.hashCode, + ), + (map, o) => + map + ..putIfAbsent(o.subject, () => []).add(o), + ) + .entries + .map((entry) { + final excused = entry.value + .where((o) => o.state == OmissionState.excused) + .length; + + final unexcused = entry.value + .where((o) => o.state == OmissionState.unexcused) + .length; + + final pending = entry.value + .where((o) => o.state == OmissionState.pending) + .length; + + return FirkaCard.single( + height: 64, + margin: EdgeInsets.only(bottom: 10), + padding: EdgeInsets.symmetric(horizontal: 16), + child: Row( + spacing: 12, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + InfoCard.buildSubject( + appStyle.colors.accent, + entry.key, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + spacing: 2, + children: [ + Text( + entry.key.name, + style: appStyle.fonts.B_16SB.copyWith( + color: appStyle.colors.textPrimary, + ), + overflow: TextOverflow.ellipsis, + ), + Row( + spacing: 4, + children: [ + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.clipboardCheckSolid, + size: 12.0, + color: appStyle.colors.accent, + ), + Text( + excused.toString(), + style: appStyle.fonts.B_14R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + SizedBox(width: 4), + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.timerSolid, + size: 12.0, + color: appStyle.colors.warningAccent, + ), + Text( + pending.toString(), + style: appStyle.fonts.B_14R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + SizedBox(width: 4), + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.restrictedLine, + size: 12.0, + color: appStyle.colors.errorAccent, + ), + Text( + unexcused.toString(), + style: appStyle.fonts.B_14R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ], + ), + ), + ], + ), + ); + }), + ], + ), + ), + ], + ), + ); + } +} diff --git a/firka/lib/ui/phone/pages/home/home_timetable_mo.dart b/firka/lib/ui/phone/pages/home/home_timetable_mo.dart index 0e38b9c7..b2c6643a 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable_mo.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable_mo.dart @@ -230,7 +230,7 @@ class _HomeTimetableMonthlyScreen omission.subject.uid == omittedLesson.subject?.uid; }); - if (omission?.state == "Igazolt") { + if (omission?.state == OmissionState.excused) { body = Center( child: FirkaIconWidget( FirkaIconType.majesticons, @@ -242,7 +242,7 @@ class _HomeTimetableMonthlyScreen break; } - if (omission?.lateForMin != null) { + if (omission?.state == OmissionState.pending) { body = Center( child: FirkaIconWidget( FirkaIconType.majesticons, diff --git a/firka/lib/ui/phone/widgets/info_card.dart b/firka/lib/ui/phone/widgets/info_card.dart index 89c8aec4..52e45e86 100644 --- a/firka/lib/ui/phone/widgets/info_card.dart +++ b/firka/lib/ui/phone/widgets/info_card.dart @@ -1,242 +1,268 @@ -import 'package:firka/app/app_state.dart'; -import 'package:firka/core/extensions.dart'; -import 'package:firka/data/models/homework_cache_model.dart'; -import 'package:firka/ui/components/common_bottom_sheets.dart'; -import 'package:firka/ui/components/firka_card.dart'; -import 'package:firka/ui/components/grade.dart'; -import 'package:firka/ui/components/grade_helpers.dart'; -import 'package:firka/ui/shared/class_icon.dart'; -import 'package:firka/ui/shared/firka_icon.dart'; -import 'package:firka/ui/theme/style.dart'; -import 'package:firka_common/ui/components/filled_circle.dart'; -import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; - -import 'package:kreta_api/kreta_api.dart'; -import 'package:majesticons_flutter/majesticons_flutter.dart'; - -class InfoCard extends StatelessWidget { - final void Function(BuildContext)? onTap; - final Widget icon; - final List texts; - final List right; - - final List textSyles = [ - appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary), - appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary), - ]; - - InfoCard({ - required this.icon, - required this.texts, - this.right = const [], - this.onTap, - super.key, - }); - - static Widget buildSubject(Color color, Subject subject) { - return FilledCircle( - diameter: 32, - color: color.withAlpha(38), - child: ClassIconWidget.subject(subject: subject, color: color, size: 20), - ); - } - - factory InfoCard.test(Test test) { - final color = appStyle.colors.accent; - - return InfoCard( - icon: FilledCircle( - diameter: 36, - color: color.withAlpha(38), - child: FirkaIconWidget( - FirkaIconType.majesticons, - Majesticon.editPen4Solid, - color: color, - size: 24, - ), - ), - texts: [ - test.theme?.firstUpper() ?? test.method.description, - test.subject.name.firstUpper(), - ], - right: [buildSubject(color, test.subject)], - onTap: (context) => showTestBottomSheet(context, initData, test), - ); - } - - factory InfoCard.testDesc(Test test) { - if (test.theme == null) { - return InfoCard.test(test); - } - - final color = appStyle.colors.accent; - - return InfoCard( - icon: FilledCircle( - diameter: 36, - color: color.withAlpha(38), - child: FirkaIconWidget( - FirkaIconType.majesticons, - Majesticon.editPen4Solid, - color: color, - size: 24, - ), - ), - texts: [test.theme!.firstUpper(), test.method.description.firstUpper()], - right: [buildSubject(color, test.subject)], - onTap: (context) => showTestBottomSheet(context, initData, test), - ); - } - - factory InfoCard.messageItem(MessageItem item) { - return InfoCard( - icon: FilledCircle( - diameter: 36, - color: appStyle.colors.accent, - child: Text( - item.author[0], - style: appStyle.fonts.H_H2.apply(color: appStyle.colors.textPrimary), - ), - ), - texts: [item.title, item.author], - onTap: (context) => context.push('/message', extra: item), - ); - } - - factory InfoCard.homework(Homework homework) { - return InfoCard( - icon: FilledCircle( - diameter: 36, - color: appStyle.colors.accent.withAlpha(38), - child: FutureBuilder( - future: isHomeworkDone(initData.isar, homework.uid), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return SizedBox(); - } - final done = snapshot.data!; - return done - ? FirkaIconWidget( - FirkaIconType.majesticonsLocal, - "homeWithMark", - color: appStyle.colors.accent, - size: 24, - ) - : FirkaIconWidget( - FirkaIconType.majesticons, - Majesticon.homeSolid, - color: appStyle.colors.accent, - size: 24, - ); - }, - ), - ), - texts: [initData.l10n.homework, homework.subjectName], - right: [buildSubject(appStyle.colors.accent, homework.subject)], - onTap: (context) => showHomeworkBottomSheet(context, initData, homework), - ); - } - - factory InfoCard.gradeSubj( - Grade grade, { - void Function(BuildContext)? onTap, - }) { - String? value = grade.numericValue == null ? grade.strValue : null; - return InfoCard( - icon: GradeWidget(grade), - texts: [ - (value ?? - grade.topic ?? - grade.mode?.description ?? - grade.type.description!) - .firstUpper(), - grade.subject.name.firstUpper(), - ], - right: [ - buildSubject( - grade.numericValue != null - ? getGradeColor(grade.numericValue!) - : appStyle.colors.accent, - grade.subject, - ), - ], - onTap: - onTap ?? (context) => showGradeBottomSheet(context, initData, grade), - ); - } - - factory InfoCard.gradeGhost( - int gradeValue, - int gradeWeigth, { - void Function(BuildContext)? onTap, - }) { - return InfoCard( - icon: GradeWidget.gradeValue(gradeValue, gradeWeight: gradeWeigth), - texts: ["${initData.l10n.ghost_grade} ($gradeWeigth%)"], - right: [], - onTap: onTap, - ); - } - - factory InfoCard.gradeDesc( - Grade grade, { - void Function(BuildContext)? onTap, - }) { - List texts = [ - (grade.mode?.description ?? grade.type.description!).firstUpper(), - ]; - - if (grade.topic != null) { - texts = [grade.topic!.firstUpper(), ...texts]; - } - - return InfoCard( - icon: GradeWidget(grade), - texts: texts, - right: [buildSubject(appStyle.colors.accent, grade.subject)], - onTap: - onTap ?? (context) => showGradeBottomSheet(context, initData, grade), - ); - } - - @override - Widget build(BuildContext context) { - List children = []; - int i = 0; - for (var text in texts) { - children.add( - Text(text, style: textSyles[i], overflow: TextOverflow.ellipsis), - ); - if (i < textSyles.length) { - i++; - } - } - return GestureDetector( - child: FirkaCard.single( - height: 68, - padding: EdgeInsets.symmetric(horizontal: 16), - margin: EdgeInsets.all(0), - child: Row( - spacing: 12, - children: [ - icon, - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - spacing: 2, - children: children, - ), - ), - ...right, - ], - ), - ), - onTap: () { - if (onTap == null) return; - onTap!.call(context); - }, - ); - } -} +import 'package:firka/app/app_state.dart'; +import 'package:firka/core/extensions.dart'; +import 'package:firka/data/models/homework_cache_model.dart'; +import 'package:firka/ui/components/common_bottom_sheets.dart'; +import 'package:firka/ui/components/firka_card.dart'; +import 'package:firka/ui/components/grade.dart'; +import 'package:firka/ui/components/grade_helpers.dart'; +import 'package:firka/ui/shared/class_icon.dart'; +import 'package:firka/ui/shared/firka_icon.dart'; +import 'package:firka/ui/theme/style.dart'; +import 'package:firka_common/ui/components/filled_circle.dart'; +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:intl/intl.dart'; + +import 'package:kreta_api/kreta_api.dart'; +import 'package:majesticons_flutter/majesticons_flutter.dart'; + +class InfoCard extends StatelessWidget { + final void Function(BuildContext)? onTap; + final Widget icon; + final List texts; + final List right; + + final List textSyles = [ + appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary), + appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary), + ]; + + InfoCard({ + required this.icon, + required this.texts, + this.right = const [], + this.onTap, + super.key, + }); + + static Widget buildSubject(Color color, Subject subject) { + return FilledCircle( + diameter: 32, + color: color.withAlpha(38), + child: ClassIconWidget.subject(subject: subject, color: color, size: 20), + ); + } + + factory InfoCard.test(Test test) { + final color = appStyle.colors.accent; + + return InfoCard( + icon: FilledCircle( + diameter: 36, + color: color.withAlpha(38), + child: FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.editPen4Solid, + color: color, + size: 24, + ), + ), + texts: [ + test.theme?.firstUpper() ?? test.method.description, + test.subject.name.firstUpper(), + ], + right: [buildSubject(color, test.subject)], + onTap: (context) => showTestBottomSheet(context, initData, test), + ); + } + + factory InfoCard.testDesc(Test test) { + if (test.theme == null) { + return InfoCard.test(test); + } + + final color = appStyle.colors.accent; + + return InfoCard( + icon: FilledCircle( + diameter: 36, + color: color.withAlpha(38), + child: FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.editPen4Solid, + color: color, + size: 24, + ), + ), + texts: [test.theme!.firstUpper(), test.method.description.firstUpper()], + right: [buildSubject(color, test.subject)], + onTap: (context) => showTestBottomSheet(context, initData, test), + ); + } + + factory InfoCard.messageItem(MessageItem item) { + return InfoCard( + icon: FilledCircle( + diameter: 36, + color: appStyle.colors.accent, + child: Text( + item.author[0], + style: appStyle.fonts.H_H2.apply(color: appStyle.colors.textPrimary), + ), + ), + texts: [item.title, item.author], + onTap: (context) => context.push('/message', extra: item), + ); + } + + factory InfoCard.omission(List omissions) { + String title = "-"; + for (final state in [ + OmissionState.pending, + OmissionState.unexcused, + OmissionState.excused, + ]) { + final count = omissions.where((o) => o.state == state).length; + title = initData.l10n.omissions_count(state.name, count); + } + return InfoCard( + icon: FilledCircle( + diameter: 36, + color: appStyle.colors.a15p, + child: SizedBox(), + ), + texts: [ + title, + DateFormat.MMMMd(initData.l10n.localeName).format(omissions.first.date), + ], + onTap: (context) => + showOmissionBottomSheet(context, initData, title, omissions), + ); + } + + factory InfoCard.homework(Homework homework) { + return InfoCard( + icon: FilledCircle( + diameter: 36, + color: appStyle.colors.accent.withAlpha(38), + child: FutureBuilder( + future: isHomeworkDone(initData.isar, homework.uid), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return SizedBox(); + } + final done = snapshot.data!; + return done + ? FirkaIconWidget( + FirkaIconType.majesticonsLocal, + "homeWithMark", + color: appStyle.colors.accent, + size: 24, + ) + : FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.homeSolid, + color: appStyle.colors.accent, + size: 24, + ); + }, + ), + ), + texts: [initData.l10n.homework, homework.subjectName], + right: [buildSubject(appStyle.colors.accent, homework.subject)], + onTap: (context) => showHomeworkBottomSheet(context, initData, homework), + ); + } + + factory InfoCard.gradeSubj( + Grade grade, { + void Function(BuildContext)? onTap, + }) { + String? value = grade.numericValue == null ? grade.strValue : null; + return InfoCard( + icon: GradeWidget(grade), + texts: [ + (value ?? + grade.topic ?? + grade.mode?.description ?? + grade.type.description!) + .firstUpper(), + grade.subject.name.firstUpper(), + ], + right: [ + buildSubject( + grade.numericValue != null + ? getGradeColor(grade.numericValue!) + : appStyle.colors.accent, + grade.subject, + ), + ], + onTap: + onTap ?? (context) => showGradeBottomSheet(context, initData, grade), + ); + } + + factory InfoCard.gradeGhost( + int gradeValue, + int gradeWeigth, { + void Function(BuildContext)? onTap, + }) { + return InfoCard( + icon: GradeWidget.gradeValue(gradeValue, gradeWeight: gradeWeigth), + texts: ["${initData.l10n.ghost_grade} ($gradeWeigth%)"], + right: [], + onTap: onTap, + ); + } + + factory InfoCard.gradeDesc( + Grade grade, { + void Function(BuildContext)? onTap, + }) { + List texts = [ + (grade.mode?.description ?? grade.type.description!).firstUpper(), + ]; + + if (grade.topic != null) { + texts = [grade.topic!.firstUpper(), ...texts]; + } + + return InfoCard( + icon: GradeWidget(grade), + texts: texts, + right: [buildSubject(appStyle.colors.accent, grade.subject)], + onTap: + onTap ?? (context) => showGradeBottomSheet(context, initData, grade), + ); + } + + @override + Widget build(BuildContext context) { + List children = []; + int i = 0; + for (var text in texts) { + children.add( + Text(text, style: textSyles[i], overflow: TextOverflow.ellipsis), + ); + if (i < textSyles.length) { + i++; + } + } + return GestureDetector( + child: FirkaCard.single( + height: 68, + padding: EdgeInsets.symmetric(horizontal: 16), + margin: EdgeInsets.all(0), + child: Row( + spacing: 12, + children: [ + icon, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + spacing: 2, + children: children, + ), + ), + ...right, + ], + ), + ), + onTap: () { + if (onTap == null) return; + onTap!.call(context); + }, + ); + } +} diff --git a/firka/lib/ui/phone/widgets/lesson.dart b/firka/lib/ui/phone/widgets/lesson.dart index dd91429f..0f02219f 100644 --- a/firka/lib/ui/phone/widgets/lesson.dart +++ b/firka/lib/ui/phone/widgets/lesson.dart @@ -42,12 +42,10 @@ class LessonWidget extends StatelessWidget { .group("settings") .subGroup("timetable_toast") .boolean("substitution"); - final showLessonNos = - lesson.lessonNumber != null && - data.settings - .group("settings") - .subGroup("timetable_toast") - .boolean("lesson_no"); + final showLessonNos = data.settings + .group("settings") + .subGroup("timetable_toast") + .boolean("lesson_no"); final isDismissed = lesson.type.name == "UresOra"; var accent = appStyle.colors.accent; @@ -115,7 +113,7 @@ class LessonWidget extends StatelessWidget { height: 18, ), Text( - lesson.lessonNumber!.toString(), + lesson.lessonNumber?.toString() ?? "-", style: appStyle.fonts.B_14SB.apply( color: secondary, ), diff --git a/firka/lib/ui/phone/widgets/omission_bar.dart b/firka/lib/ui/phone/widgets/omission_bar.dart new file mode 100644 index 00000000..2a58c52a --- /dev/null +++ b/firka/lib/ui/phone/widgets/omission_bar.dart @@ -0,0 +1,87 @@ +import 'package:firka/app/app_state.dart'; +import 'package:firka/core/extensions.dart'; +import 'package:firka/ui/components/firka_card.dart'; +import 'package:intl/intl.dart'; +import 'package:kreta_api/kreta_api.dart'; +import 'package:firka/ui/components/grade.dart'; +import 'package:firka/ui/components/grade_helpers.dart'; +import 'package:firka/ui/shared/firka_icon.dart'; +import 'package:flutter/material.dart'; +import 'package:majesticons_flutter/majesticons_flutter.dart'; + +import 'package:firka/l10n/app_localizations.dart'; +import 'package:firka/ui/theme/style.dart'; + +class OmissionBar extends StatelessWidget { + final List omissions; + + const OmissionBar({super.key, required this.omissions}); + + @override + Widget build(BuildContext context) { + DateTime now = DateTime.now(); + DateTime start = now.copyWith(month: 9, day: 1); + DateTime startOfTheYear = now.isBefore(start) + ? start.subtract(Duration(days: 365)) + : start; + + Map dayToColor = omissions.fold( + Map.identity(), + (map, o) => map + ..putIfAbsent( + o.date.difference(startOfTheYear).inDays, + () => o.state == OmissionState.excused + ? appStyle.colors.accent + : o.state == OmissionState.unexcused + ? appStyle.colors.errorAccent + : appStyle.colors.warningAccent, + ), + ); + + final bar = ClipRRect( + borderRadius: BorderRadius.circular(8), + child: Row( + children: List.generate(now.difference(startOfTheYear).inDays, (i) { + return Expanded( + child: Container( + height: 12, + color: dayToColor[i] ?? appStyle.colors.a15p, + ), + ); + }), + ), + ); + + return FirkaCard.single( + margin: EdgeInsets.zero, + padding: EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + spacing: 8, + children: [ + bar, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + DateFormat.MMMM( + initData.l10n.localeName, + ).format(startOfTheYear).firstUpper(), + style: appStyle.fonts.B_14R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + Text( + initData.l10n.now, + style: appStyle.fonts.B_14R.copyWith( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ], + ), + ); + } +} diff --git a/kreta_api/lib/src/model/omission.dart b/kreta_api/lib/src/model/omission.dart index fcc4d17a..20061fc3 100644 --- a/kreta_api/lib/src/model/omission.dart +++ b/kreta_api/lib/src/model/omission.dart @@ -4,21 +4,21 @@ import 'subject.dart'; class Omission extends UidObj { final Subject subject; - final Class? c; + final OmittedLesson? lesson; final DateTime date; final String teacher; final NameUidDesc? type; final NameUidDesc? mode; final int? lateForMin; final DateTime createdAt; - final String state; + final OmissionState state; final NameUidDesc? proofType; final UidObj? classGroup; const Omission({ required super.uid, required this.subject, - required this.c, + required this.lesson, required this.date, required this.teacher, this.type, @@ -34,14 +34,14 @@ class Omission extends UidObj { return Omission( uid: json['Uid'], subject: Subject.fromJson(json['Tantargy']), - c: json['Osztaly'] != null ? Class.fromJson(json['Osztaly']) : null, + lesson: json['Ora'] != null ? OmittedLesson.fromJson(json['Ora']) : null, date: json.localDate('Datum')!, teacher: json['RogzitoTanarNeve'], type: json.nameUidDesc('Tipus'), mode: json.nameUidDesc('Mod'), lateForMin: json['KesesPercben'], createdAt: json.localDate('KeszitesDatuma')!, - state: json['IgazolasAllapota'], + state: OmissionState.fromString(json['IgazolasAllapota']), proofType: json.nameUidDesc('IgazolasTipusa'), classGroup: json.uid('OsztalyCsoport'), ); @@ -52,7 +52,7 @@ class Omission extends UidObj { return 'Omission(' 'uid: "$uid", ' 'subject: $subject, ' - 'c: $c, ' + 'c: $lesson, ' 'date: $date, ' 'teacher: "$teacher", ' 'type: $type, ' @@ -66,15 +66,39 @@ class Omission extends UidObj { } } -class Class { +enum OmissionState { + excused("Igazolt"), + unexcused("Igazolatlan"), + pending("Igazolando"), + unknown(""); + + final String key; + const OmissionState(this.key); + + static fromString(String string) { + for (final state in OmissionState.values) { + if (state.key == string) { + return state; + } + } + print("Unknown omission state: ${string}"); + return OmissionState.unknown; + } +} + +class OmittedLesson { final DateTime start; final DateTime end; - final int classNo; + final int? classNo; - const Class({required this.start, required this.end, required this.classNo}); + const OmittedLesson({ + required this.start, + required this.end, + required this.classNo, + }); - factory Class.fromJson(Map json) { - return Class( + factory OmittedLesson.fromJson(Map json) { + return OmittedLesson( start: json.localDate('KezdoDatum')!, end: json.localDate('VegDatum')!, classNo: json['Oraszam'], @@ -83,7 +107,7 @@ class Class { @override String toString() { - return 'Class(' + return 'OmittedLesson(' 'start: "$start", ' 'end: "$end", ' 'classNo: $classNo'