From bfcc5eb55d97c9c20a3a712dca6ff08dda98bbd1 Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Mon, 21 Jul 2025 08:34:46 +0200 Subject: [PATCH] add timetable page --- firka/assets/images/logos/dave.svg | 15 ++ firka/lib/helpers/extensions.dart | 10 +- firka/lib/l10n | 2 +- .../ui/phone/pages/home/home_timetable.dart | 154 +++++++++++++++++- .../lib/ui/phone/widgets/bottom_tt_icon.dart | 44 +++++ firka/pubspec.yaml | 1 + 6 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 firka/assets/images/logos/dave.svg create mode 100644 firka/lib/ui/phone/widgets/bottom_tt_icon.dart diff --git a/firka/assets/images/logos/dave.svg b/firka/assets/images/logos/dave.svg new file mode 100644 index 00000000..0eaf9eb1 --- /dev/null +++ b/firka/assets/images/logos/dave.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/firka/lib/helpers/extensions.dart b/firka/lib/helpers/extensions.dart index 656c225f..84ea8b7e 100644 --- a/firka/lib/helpers/extensions.dart +++ b/firka/lib/helpers/extensions.dart @@ -34,7 +34,7 @@ extension DurationExtension on Duration { } } -enum FormatMode { yearly, grades, welcome, hmm } +enum FormatMode { yearly, grades, welcome, hmm, da, dd } enum Cycle { morning, day, afternoon, night } @@ -74,9 +74,17 @@ extension DateExtension on DateTime { return DateFormat('h:mm').format(this); case FormatMode.welcome: return DateFormat('EEE, MMM d').format(this); + case FormatMode.da: + return DateFormat('MMMMEEEEd').format(this).substring(0, 2); + case FormatMode.dd: + return DateFormat('dd').format(this); } } + DateTime getMonday() { + return subtract(Duration(days: weekday - 1)); + } + DateTime getMidnight() { return subtract(Duration( hours: hour, diff --git a/firka/lib/l10n b/firka/lib/l10n index d29c9475..5435a1c5 160000 --- a/firka/lib/l10n +++ b/firka/lib/l10n @@ -1 +1 @@ -Subproject commit d29c947552669c8531dba3aaf2f14052c0ae14f3 +Subproject commit 5435a1c50a1f01801b000d7f97b947738cbf8e70 diff --git a/firka/lib/ui/phone/pages/home/home_timetable.dart b/firka/lib/ui/phone/pages/home/home_timetable.dart index 17d97cfe..72823f2a 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable.dart @@ -1,4 +1,14 @@ +import 'package:firka/helpers/api/model/timetable.dart'; +import 'package:firka/helpers/debug_helper.dart'; +import 'package:firka/helpers/extensions.dart'; +import 'package:firka/l10n/app_localizations.dart'; +import 'package:firka/ui/model/style.dart'; +import 'package:firka/ui/phone/widgets/bottom_tt_icon.dart'; +import 'package:firka/ui/widget/delayed_spinner.dart'; +import 'package:firka/ui/widget/firka_icon.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:majesticons_flutter/majesticons_flutter.dart'; import '../../../../main.dart'; @@ -12,10 +22,152 @@ class HomeTimetableScreen extends StatefulWidget { class _HomeTimetableScreen extends State { final AppInitialization data; + List? lessons; + List? dates; + DateTime? active; _HomeTimetableScreen(this.data); + void initState() { + super.initState(); + + var monday = timeNow().getMonday().getMidnight(); + var sunday = monday.add(Duration(days: 6)); + + (() async { + var lessonsResp = await data.client.getTimeTable(monday, sunday); + List dates = List.empty(growable: true); + + if (lessonsResp.response != null) { + lessons = lessonsResp.response; + + for (var i = 0; i < 7; i++) { + var t = monday.add(Duration(days: i)); + + var hasLessons = i < 5 || + lessons!.firstWhereOrNull((lesson) { + return lesson.start.getMidnight().millisecondsSinceEpoch == + t.getMidnight().millisecondsSinceEpoch; + }) != + null; + + if (hasLessons) { + dates.add(t); + } + } + } + + setState(() { + this.dates = dates; + if (timeNow().isAfter(dates.last)) { + active = dates.last; + } else { + active = timeNow().getMidnight(); + } + }); + })(); + } + @override Widget build(BuildContext context) { - return Text("Timetable"); + if (lessons != null && dates != null && active != null) { + List ttWidgets = List.empty(growable: true); + + for (final date in dates!) { + ttWidgets.add(BottomTimeTableNavIconWidget(() { + setState(() { + active = date; + }); + }, date.millisecondsSinceEpoch == active!.millisecondsSinceEpoch, + date)); + } + + return Expanded( + child: Stack( + children: [ + Padding( + padding: const EdgeInsets.only( + top: 16.0, + left: 32.0, + right: 16.0, + ), + child: + Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + AppLocalizations.of(context)!.timetable, + style: appStyle.fonts.H_H2 + .apply(color: appStyle.colors.textPrimary), + ), + Row( + children: [ + Card( + color: appStyle.colors.buttonSecondaryFill, + child: Padding( + padding: const EdgeInsets.all(8), + child: FirkaIconWidget( + FirkaIconType.Majesticons, + Majesticon.tableSolid, + size: 26.0, + color: appStyle.colors.accent, + ), + ), + ), + Card( + color: appStyle.colors.buttonSecondaryFill, + child: Padding( + padding: const EdgeInsets.all(4), + child: FirkaIconWidget( + FirkaIconType.Majesticons, + Majesticon.plusLine, + size: 32.0, + color: appStyle.colors.accent, + ), + ), + ), + Card( + color: appStyle.colors.buttonSecondaryFill, + child: Padding( + padding: const EdgeInsets.all(8), + child: FirkaIconWidget( + FirkaIconType.Majesticons, + Majesticon.settingsCogSolid, + size: 26.0, + color: appStyle.colors.accent, + ), + ), + ) + ], + ), + ], + ), + ]), + ), + Positioned.fill( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SvgPicture.asset("assets/images/logos/dave.svg", + width: 48, height: 48), + SizedBox(height: 12), + Text(AppLocalizations.of(context)!.tt_no_classes_l1), + Text(AppLocalizations.of(context)!.tt_no_classes_l2) + ]), + ), + Padding( + padding: + EdgeInsets.only(top: MediaQuery.of(context).size.height - 250), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: ttWidgets, + ), + ), + ], + )); + } else { + return DelayedSpinnerWidget(); + } } } diff --git a/firka/lib/ui/phone/widgets/bottom_tt_icon.dart b/firka/lib/ui/phone/widgets/bottom_tt_icon.dart new file mode 100644 index 00000000..063aa1b1 --- /dev/null +++ b/firka/lib/ui/phone/widgets/bottom_tt_icon.dart @@ -0,0 +1,44 @@ +import 'package:firka/helpers/extensions.dart'; +import 'package:flutter/material.dart'; + +import '../../model/style.dart'; + +class BottomTimeTableNavIconWidget extends StatelessWidget { + final void Function() onTap; + final bool active; + final DateTime date; + + const BottomTimeTableNavIconWidget(this.onTap, this.active, this.date, + {super.key}); + + @override + Widget build(BuildContext context) { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + onTap(); + }, + child: Card( + color: + active ? appStyle.colors.buttonSecondaryFill : Colors.transparent, + shadowColor: Colors.transparent, + child: SizedBox( + width: 40, + height: 54, + child: Column( + children: [ + SizedBox(height: 6), + Text(date.format(context, FormatMode.da), + style: appStyle.fonts.H_16px + .apply(color: appStyle.colors.textPrimary)), + Text( + date.format(context, FormatMode.dd), + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textSecondary), + ) + ], + )), + ), + ); + } +} diff --git a/firka/pubspec.yaml b/firka/pubspec.yaml index 6a959d7e..eb4a0aaf 100644 --- a/firka/pubspec.yaml +++ b/firka/pubspec.yaml @@ -85,6 +85,7 @@ flutter: uses-material-design: true assets: - assets/images/logos/colored_logo.png + - assets/images/logos/dave.svg - assets/images/carousel/ - assets/majesticons/