From 93d56fec285aa10f0ddbbe063eadb666b2eef313 Mon Sep 17 00:00:00 2001 From: Kima Date: Thu, 2 May 2024 20:28:35 +0200 Subject: [PATCH] finished the entire new live card thingie --- refilc/lib/ui/widgets/lesson/lesson_tile.dart | 4 +- .../lib/pages/home/home_page.dart | 14 +- .../lib/pages/home/live_card/live_card.dart | 446 +++++++++++++++--- .../home/live_card/live_card_widget.dart | 2 - 4 files changed, 394 insertions(+), 72 deletions(-) diff --git a/refilc/lib/ui/widgets/lesson/lesson_tile.dart b/refilc/lib/ui/widgets/lesson/lesson_tile.dart index 272d480..43a494b 100644 --- a/refilc/lib/ui/widgets/lesson/lesson_tile.dart +++ b/refilc/lib/ui/widgets/lesson/lesson_tile.dart @@ -27,6 +27,7 @@ class LessonTile extends StatelessWidget { this.currentLessonIndicator = true, this.padding, this.contentPadding, + this.showSubTiles = false, }); final Lesson lesson; @@ -37,6 +38,7 @@ class LessonTile extends StatelessWidget { final bool currentLessonIndicator; final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? contentPadding; + final bool showSubTiles; @override Widget build(BuildContext context) { @@ -446,7 +448,7 @@ class LessonTile extends StatelessWidget { ), // Homework & Exams - ...subtiles, + if (showSubTiles) ...subtiles, ], ), ), diff --git a/refilc_mobile_ui/lib/pages/home/home_page.dart b/refilc_mobile_ui/lib/pages/home/home_page.dart index 5f45065..449e521 100644 --- a/refilc_mobile_ui/lib/pages/home/home_page.dart +++ b/refilc_mobile_ui/lib/pages/home/home_page.dart @@ -213,8 +213,8 @@ class HomePageState extends State with TickerProviderStateMixin { // } // TODO: REMOVE IN PRODUCTION BUILD!!! - print(_liveCard.currentState); - _liveCard.currentState = LiveCardState.morning; + // print(_liveCard.currentState); + // _liveCard.currentState = LiveCardState.duringBreak; return Scaffold( body: Stack( @@ -326,8 +326,10 @@ class HomePageState extends State with TickerProviderStateMixin { expandedHeight: _liveCardAnimation.value * (_liveCard.currentState == LiveCardState.morning ? 274.0 - : (_liveCard.currentState == - LiveCardState.duringLesson + : ((_liveCard.currentState == + LiveCardState.duringLesson || + _liveCard.currentState == + LiveCardState.duringBreak) ? 288.0 : 238.0)), @@ -340,7 +342,9 @@ class HomePageState extends State with TickerProviderStateMixin { top: ((_liveCard.currentState == LiveCardState.morning || _liveCard.currentState == - LiveCardState.duringLesson) + LiveCardState.duringLesson || + _liveCard.currentState == + LiveCardState.duringBreak) ? 0.0 : 62.0) + MediaQuery.of(context).padding.top, diff --git a/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart b/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart index 2b52bbf..d6dbcf5 100644 --- a/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart +++ b/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart @@ -3,15 +3,12 @@ import 'package:animations/animations.dart'; import 'package:refilc/api/providers/user_provider.dart'; import 'package:refilc/helpers/subject.dart'; -import 'package:refilc/icons/filc_icons.dart'; import 'package:refilc/models/settings.dart'; import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc/ui/widgets/lesson/lesson_tile.dart'; -import 'package:refilc_kreta_api/models/category.dart'; -import 'package:refilc_kreta_api/models/lesson.dart'; -import 'package:refilc_kreta_api/models/subject.dart'; -import 'package:refilc_kreta_api/models/teacher.dart'; +import 'package:refilc_mobile_ui/common/panel/panel.dart'; import 'package:refilc_mobile_ui/common/progress_bar.dart'; +import 'package:refilc_mobile_ui/common/round_border_icon.dart'; // import 'package:refilc_kreta_api/models/category.dart'; // import 'package:refilc_kreta_api/models/lesson.dart'; // import 'package:refilc_kreta_api/models/subject.dart'; @@ -70,30 +67,30 @@ class LiveCardStateA extends State { // test // TODO: REMOVE IN PRODUCTION BUILD!!! - liveCard.currentState = LiveCardState.morning; - liveCard.nextLesson = Lesson( - date: DateTime.now().add(Duration( - minutes: 30, - )), - subject: GradeSubject( - category: Category(id: 'asd'), id: 'asd', name: 'Matematika'), - lessonIndex: '1', - teacher: Teacher(id: 'id', name: 'name'), - start: DateTime.now().subtract(Duration( - minutes: 30, - )), - end: DateTime.now().add(Duration( - minutes: 15, - )), - homeworkId: 'homeworkId', - id: 'id', - description: 'description', - room: 'ABC69', - groupName: 'groupName', - name: 'name', - ); + // liveCard.currentState = LiveCardState.duringBreak; + // liveCard.nextLesson = Lesson( + // date: DateTime.now().add(Duration( + // minutes: 30, + // )), + // subject: GradeSubject( + // category: Category(id: 'asd'), id: 'asd', name: 'Matematika'), + // lessonIndex: '1', + // teacher: Teacher(id: 'id', name: 'name'), + // start: DateTime.now().subtract(Duration( + // minutes: 30, + // )), + // end: DateTime.now().add(Duration( + // minutes: 15, + // )), + // homeworkId: 'homeworkId', + // id: 'id', + // description: 'description', + // room: 'ABC69', + // groupName: 'groupName', + // name: 'name', + // ); - // liveCard.nextLesson = liveCard.currentLesson; + // liveCard.prevLesson = liveCard.nextLesson; // final dt = DateTime(2024, 3, 22, 17, 12, 1, 1, 1); @@ -304,7 +301,7 @@ class LiveCardStateA extends State { width: 10, ), Text( - '${DateFormat('H:mm').format(liveCard.nextLesson!.start)}-${DateFormat('H:mm').format(liveCard.nextLesson!.end)}', + '${DateFormat('H:mm').format(liveCard.nextLesson!.start)} - ${DateFormat('H:mm').format(liveCard.nextLesson!.end)}', style: const TextStyle( fontSize: 12.5, fontWeight: FontWeight.w500, @@ -546,7 +543,7 @@ class LiveCardStateA extends State { width: 10, ), Text( - '${DateFormat('H:mm').format(liveCard.nextLesson!.start)}-${DateFormat('H:mm').format(liveCard.nextLesson!.end)}', + '${DateFormat('H:mm').format(liveCard.nextLesson!.start)} - ${DateFormat('H:mm').format(liveCard.nextLesson!.end)}', style: const TextStyle( fontSize: 12.5, fontWeight: FontWeight.w500, @@ -566,12 +563,17 @@ class LiveCardStateA extends State { ); break; case LiveCardState.duringBreak: - final iconFloorMap = { - "to room": FeatherIcons.chevronsRight, - "up floor": FilcIcons.upstairs, - "down floor": FilcIcons.downstairs, - "ground floor": FilcIcons.downstairs, - }; + if (liveCard.prevLesson == null || liveCard.nextLesson == null) { + child = Container(); + break; + } + + // final iconFloorMap = { + // "to room": FeatherIcons.chevronsRight, + // "up floor": FilcIcons.upstairs, + // "down floor": FilcIcons.downstairs, + // "ground floor": FilcIcons.downstairs, + // }; final diff = liveCard.getFloorDifference(); @@ -587,36 +589,352 @@ class LiveCardStateA extends State { final showMinutes = maxTime - elapsedTime > 60; + // child = LiveCardWidget( + // key: const Key('livecard.duringBreak'), + // title: "break".i18n, + // icon: iconFloorMap[diff], + // description: liveCard.nextLesson!.room != liveCard.prevLesson!.room + // ? Text("go $diff".i18n.fill([ + // diff != "to room" + // ? (liveCard.nextLesson!.getFloor() ?? 0) + // : liveCard.nextLesson!.room + // ])) + // : Text("stay".i18n), + // nextSubject: liveCard.nextLesson?.subject.renamedTo ?? + // liveCard.nextLesson?.subject.name.capital(), + // nextSubjectItalic: liveCard.nextLesson?.subject.isRenamed == true && + // settingsProvider.renamedSubjectsItalics, + // nextRoom: diff != "to room" ? liveCard.nextLesson?.room : null, + // progressMax: showMinutes ? maxTime / 60 : maxTime, + // progressCurrent: showMinutes ? elapsedTime / 60 : elapsedTime, + // progressAccuracy: + // showMinutes ? ProgressAccuracy.minutes : ProgressAccuracy.seconds, + // onProgressTap: () { + // showDialog( + // barrierColor: Colors.black, + // context: context, + // builder: (context) => HeadsUpCountdown( + // maxTime: maxTime, + // elapsedTime: elapsedTime, + // ), + // ); + // }, + // ); + + var nextSubject = liveCard.nextLesson?.subject.renamedTo ?? + liveCard.nextLesson?.subject.name.capital(); + var nextSubjectItalic = + liveCard.nextLesson?.subject.isRenamed == true && + settingsProvider.renamedSubjectsItalics; + // var nextRoom = diff != "to room" ? liveCard.nextLesson?.room : null; + var progressMax = showMinutes ? maxTime / 60 : maxTime; + var progressCurrent = showMinutes ? elapsedTime / 60 : elapsedTime; + var progressAccuracy = + showMinutes ? ProgressAccuracy.minutes : ProgressAccuracy.seconds; + + // Lesson breakLesson = Lesson( + // date: DateTime.now(), + // start: liveCard.prevLesson!.end, + // end: liveCard.nextLesson!.start, + // name: 'break'.i18n, + // description: 'Menj a XY terembe...', + // ); + child = LiveCardWidget( key: const Key('livecard.duringBreak'), - title: "break".i18n, - icon: iconFloorMap[diff], - description: liveCard.nextLesson!.room != liveCard.prevLesson!.room - ? Text("go $diff".i18n.fill([ - diff != "to room" - ? (liveCard.nextLesson!.getFloor() ?? 0) - : liveCard.nextLesson!.room - ])) - : Text("stay".i18n), - nextSubject: liveCard.nextLesson?.subject.renamedTo ?? - liveCard.nextLesson?.subject.name.capital(), - nextSubjectItalic: liveCard.nextLesson?.subject.isRenamed == true && - settingsProvider.renamedSubjectsItalics, - nextRoom: diff != "to room" ? liveCard.nextLesson?.room : null, - progressMax: showMinutes ? maxTime / 60 : maxTime, - progressCurrent: showMinutes ? elapsedTime / 60 : elapsedTime, - progressAccuracy: - showMinutes ? ProgressAccuracy.minutes : ProgressAccuracy.seconds, - onProgressTap: () { - showDialog( - barrierColor: Colors.black, - context: context, - builder: (context) => HeadsUpCountdown( - maxTime: maxTime, - elapsedTime: elapsedTime, - ), - ); - }, + children: liveCard.nextLesson != null + ? [ + SplittedPanel( + hasShadow: false, + padding: EdgeInsets.zero, + cardPadding: EdgeInsets.zero, + spacing: 8.0, + children: [ + SplittedPanel( + hasShadow: false, + isTransparent: true, + padding: EdgeInsets.zero, + cardPadding: const EdgeInsets.symmetric( + horizontal: 12.0, + vertical: 0.0, + ), + spacing: 0.0, + children: [ + // LessonTile( + // liveCard.currentLesson!, + // swapRoom: true, + // currentLessonIndicator: false, + // padding: + // const EdgeInsets.only(top: 8.0, bottom: 4.0), + // contentPadding: EdgeInsets.zero, + // ), + Padding( + padding: + const EdgeInsets.only(top: 8.0, bottom: 4.0), + child: Material( + color: Colors.transparent, + borderRadius: BorderRadius.circular(12.0), + child: Visibility( + visible: + liveCard.nextLesson!.subject.id != '' || + liveCard.nextLesson!.isEmpty, + replacement: Padding( + padding: const EdgeInsets.only(top: 6.0), + child: PanelTitle( + title: Text(liveCard.nextLesson!.name)), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + minVerticalPadding: 0.0, + dense: true, + // onLongPress: kDebugMode ? () => log(jsonEncode(lesson.json)) : null, + visualDensity: VisualDensity.compact, + contentPadding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(12.0)), + title: Text( + "break".i18n, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.5, + color: AppColors.of(context) + .text + .withOpacity(!liveCard + .nextLesson!.isEmpty + ? 1.0 + : 0.5), + fontStyle: liveCard.nextLesson! + .subject.isRenamed && + settingsProvider + .renamedSubjectsItalics + ? FontStyle.italic + : null), + ), + + subtitle: DefaultTextStyle( + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + fontWeight: FontWeight.w400, + fontSize: 15.0, + height: 1.0, + color: AppColors.of(context) + .text + .withOpacity(.75), + ), + maxLines: !(nextSubject == null && + progressCurrent == null && + progressMax == null) + ? 1 + : 2, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: liveCard.nextLesson!.room != + liveCard.prevLesson!.room + ? Text("go $diff".i18n.fill([ + diff != "to room" + ? (liveCard.nextLesson! + .getFloor() ?? + 0) + : liveCard.nextLesson!.room + ])) + : Text("stay".i18n), + ), + + // subtitle: description != "" + // ? Text( + // description, + // style: const TextStyle( + // fontWeight: FontWeight.w500, + // fontSize: 14.0, + // ), + // maxLines: 1, + // softWrap: false, + // overflow: TextOverflow.ellipsis, + // ) + // : null, + minLeadingWidth: 34.0, + leading: AspectRatio( + aspectRatio: 1, + child: Center( + child: Stack( + children: [ + RoundBorderIcon( + color: + AppColors.of(context).text, + width: 1.0, + icon: const SizedBox( + width: 25, + height: 25, + child: Center( + child: Icon( + Icons.local_cafe, + size: 20.0, + ), + ), + ), + ), + ], + ), + ), + ), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + width: 10, + ), + Stack( + alignment: Alignment.center, + children: [ + // xix alignment hack :p + const Opacity( + opacity: 0, + child: Text("EE:EE")), + Text( + "${DateFormat("H:mm").format(liveCard.prevLesson!.end)}\n${DateFormat("H:mm").format(liveCard.nextLesson!.start)}", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.w500, + color: AppColors.of(context) + .text + .withOpacity(.9), + ), + ), + ], + ), + ], + ), + ), + ], + ), + ), + ), + ), + if (!(nextSubject == null && + progressCurrent == null && + progressMax == null)) + Row( + children: [ + const SizedBox( + width: 5.0, + ), + if (progressCurrent != null && + progressMax != null) + GestureDetector( + onTap: () { + showDialog( + barrierColor: Colors.black, + context: context, + builder: (context) => HeadsUpCountdown( + maxTime: maxTime, + elapsedTime: elapsedTime), + ); + }, + child: Container( + color: Colors.transparent, + child: Text( + "remaining ${progressAccuracy == ProgressAccuracy.minutes ? 'min' : 'sec'}" + .plural( + (progressMax - progressCurrent) + .round()), + maxLines: 1, + style: TextStyle( + fontWeight: FontWeight.w500, + color: AppColors.of(context) + .text + .withOpacity(.75), + height: 1.1, + ), + ), + ), + ) + ], + ), + if (progressCurrent != null && progressMax != null) + Padding( + padding: + const EdgeInsets.only(top: 4.0, bottom: 12.0), + child: ProgressBar( + value: progressCurrent / progressMax), + ) + ], + ), + SplittedPanel( + hasShadow: false, + isTransparent: true, + padding: EdgeInsets.zero, + cardPadding: const EdgeInsets.symmetric( + horizontal: 18.0, + vertical: 11.0, + ), + spacing: 0.0, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Icon( + liveCard.nextLesson == null + ? Icons.home_outlined + : SubjectIcon.resolveVariant( + context: context, + subject: + liveCard.nextLesson!.subject, + ), + size: 23.0, + ), + const SizedBox(width: 12.0), + Text( + (liveCard.nextLesson?.subject + .isRenamed ?? + false + ? liveCard + .nextLesson?.subject.renamedTo + : liveCard + .nextLesson?.subject.name) ?? + 'go_home'.i18n, + style: TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.w600, + fontStyle: nextSubjectItalic + ? FontStyle.italic + : null, + ), + ), + ], + ), + Row( + children: liveCard.nextLesson != null + ? [ + const SizedBox( + width: 10, + ), + Text( + '${DateFormat('H:mm').format(liveCard.nextLesson!.start)} - ${DateFormat('H:mm').format(liveCard.nextLesson!.end)}', + style: const TextStyle( + fontSize: 12.5, + fontWeight: FontWeight.w500, + ), + ), + ] + : [], + ), + ], + ), + ], + ), + ], + ), + ] + : null, ); break; case LiveCardState.afternoon: diff --git a/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart b/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart index 306c15b..07f3933 100644 --- a/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart +++ b/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart @@ -1,11 +1,9 @@ -import 'package:refilc/api/providers/live_card_provider.dart'; import 'package:refilc/models/settings.dart'; import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc_mobile_ui/common/progress_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:provider/provider.dart'; -import 'package:refilc_mobile_ui/pages/home/live_card/live_card.dart'; import 'live_card.i18n.dart'; enum ProgressAccuracy { minutes, seconds }