finished new live card during lesson part

This commit is contained in:
Kima 2024-05-01 22:24:19 +02:00
parent d84a9892c8
commit 6ba105f08c
5 changed files with 380 additions and 114 deletions

View File

@ -17,16 +17,26 @@ import 'package:provider/provider.dart';
import 'lesson_tile.i18n.dart'; import 'lesson_tile.i18n.dart';
class LessonTile extends StatelessWidget { class LessonTile extends StatelessWidget {
const LessonTile(this.lesson, const LessonTile(
{super.key, this.lesson, {
super.key,
this.onTap, this.onTap,
this.swapDesc = false, this.swapDesc = false,
this.subjectPageView = false}); this.subjectPageView = false,
this.swapRoom = false,
this.currentLessonIndicator = true,
this.padding,
this.contentPadding,
});
final Lesson lesson; final Lesson lesson;
final bool swapDesc; final bool swapDesc;
final void Function()? onTap; final void Function()? onTap;
final bool subjectPageView; final bool subjectPageView;
final bool swapRoom;
final bool currentLessonIndicator;
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry? contentPadding;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -128,7 +138,7 @@ class LessonTile extends StatelessWidget {
// } // }
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 4.0, top: 7.0), padding: padding ?? const EdgeInsets.only(bottom: 4.0, top: 7.0),
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
borderRadius: BorderRadius.circular(12.0), borderRadius: BorderRadius.circular(12.0),
@ -149,7 +159,8 @@ class LessonTile extends StatelessWidget {
onTap: onTap, onTap: onTap,
// onLongPress: kDebugMode ? () => log(jsonEncode(lesson.json)) : null, // onLongPress: kDebugMode ? () => log(jsonEncode(lesson.json)) : null,
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
contentPadding: const EdgeInsets.symmetric(horizontal: 4.0), contentPadding: contentPadding ??
const EdgeInsets.symmetric(horizontal: 4.0),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)), borderRadius: BorderRadius.circular(12.0)),
title: !subjectPageView title: !subjectPageView
@ -222,7 +233,37 @@ class LessonTile extends StatelessWidget {
// const SizedBox( // const SizedBox(
// height: 10.0, // height: 10.0,
// ), // ),
if (cleanDesc != '') if (swapRoom)
Container(
width: lesson.room.length > 20 ? 111 : null,
padding: const EdgeInsets.symmetric(
horizontal: 5.5, vertical: 3.0),
decoration: BoxDecoration(
color: fill
? accent.withOpacity(.15)
: Theme.of(context)
.colorScheme
.secondary
.withOpacity(.15),
borderRadius: BorderRadius.circular(10.0),
),
child: Text(
lesson.room,
overflow: TextOverflow.ellipsis,
style: TextStyle(
height: 1.1,
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: fill
? accent.withOpacity(0.9)
: Theme.of(context)
.colorScheme
.secondary
.withOpacity(.9),
),
),
),
if (cleanDesc != '' && !swapRoom)
Text( Text(
cleanDesc, cleanDesc,
maxLines: 1, maxLines: 1,
@ -288,6 +329,7 @@ class LessonTile extends StatelessWidget {
// ), // ),
// Current lesson indicator // Current lesson indicator
if (currentLessonIndicator)
Transform.translate( Transform.translate(
offset: const Offset(-22.0, -1.0), offset: const Offset(-22.0, -1.0),
child: Container( child: Container(
@ -310,7 +352,8 @@ class LessonTile extends StatelessWidget {
) )
], ],
), ),
margin: const EdgeInsets.symmetric(vertical: 4.0), margin:
const EdgeInsets.symmetric(vertical: 4.0),
width: 4.0, width: 4.0,
height: double.infinity, height: double.infinity,
), ),
@ -342,6 +385,7 @@ class LessonTile extends StatelessWidget {
// ), // ),
// ), // ),
// ), // ),
if (!swapRoom)
Container( Container(
width: lesson.room.length > 20 ? 111 : null, width: lesson.room.length > 20 ? 111 : null,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View File

@ -212,6 +212,10 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
// currentState = LiveCardState.empty; // currentState = LiveCardState.empty;
// } // }
// TODO: REMOVE IN PRODUCTION BUILD!!!
print(_liveCard.currentState);
_liveCard.currentState = LiveCardState.morning;
return Scaffold( return Scaffold(
body: Stack( body: Stack(
children: [ children: [
@ -321,8 +325,11 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
// expandedHeight: _liveCardAnimation.value * 238.0, // expandedHeight: _liveCardAnimation.value * 238.0,
expandedHeight: _liveCardAnimation.value * expandedHeight: _liveCardAnimation.value *
(_liveCard.currentState == LiveCardState.morning (_liveCard.currentState == LiveCardState.morning
? 280.0 ? 274.0
: 238.0), : (_liveCard.currentState ==
LiveCardState.duringLesson
? 288.0
: 238.0)),
// Live Card // Live Card
flexibleSpace: FlexibleSpaceBar( flexibleSpace: FlexibleSpaceBar(
@ -330,12 +337,17 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 24.0, left: 24.0,
right: 24.0, right: 24.0,
top: (_liveCard.currentState == top: ((_liveCard.currentState ==
LiveCardState.morning LiveCardState.morning ||
_liveCard.currentState ==
LiveCardState.duringLesson)
? 0.0 ? 0.0
: 62.0) + : 62.0) +
MediaQuery.of(context).padding.top, MediaQuery.of(context).padding.top,
bottom: 52.0, bottom: _liveCard.currentState ==
LiveCardState.morning
? 44.0
: 52.0,
), ),
child: Transform.scale( child: Transform.scale(
scale: _liveCardAnimation.value, scale: _liveCardAnimation.value,

View File

@ -1,8 +1,17 @@
// ignore_for_file: unnecessary_null_comparison
import 'package:animations/animations.dart'; import 'package:animations/animations.dart';
import 'package:refilc/api/providers/user_provider.dart'; import 'package:refilc/api/providers/user_provider.dart';
import 'package:refilc/helpers/subject.dart'; import 'package:refilc/helpers/subject.dart';
import 'package:refilc/icons/filc_icons.dart'; import 'package:refilc/icons/filc_icons.dart';
import 'package:refilc/models/settings.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/progress_bar.dart';
// import 'package:refilc_kreta_api/models/category.dart'; // import 'package:refilc_kreta_api/models/category.dart';
// import 'package:refilc_kreta_api/models/lesson.dart'; // import 'package:refilc_kreta_api/models/lesson.dart';
// import 'package:refilc_kreta_api/models/subject.dart'; // import 'package:refilc_kreta_api/models/subject.dart';
@ -60,28 +69,31 @@ class LiveCardStateA extends State<LiveCard> {
Duration bellDelay = liveCard.delay; Duration bellDelay = liveCard.delay;
// test // test
// liveCard.currentState = LiveCardState.morning; // TODO: REMOVE IN PRODUCTION BUILD!!!
// liveCard.nextLesson = Lesson( liveCard.currentState = LiveCardState.morning;
// date: DateTime.now().add(Duration( liveCard.nextLesson = Lesson(
// minutes: 30, date: DateTime.now().add(Duration(
// )), minutes: 30,
// subject: GradeSubject( )),
// category: Category(id: 'asd'), id: 'asd', name: 'Matematika'), subject: GradeSubject(
// lessonIndex: 'lessonIndex', category: Category(id: 'asd'), id: 'asd', name: 'Matematika'),
// teacher: Teacher(id: 'id', name: 'name'), lessonIndex: '1',
// start: DateTime.now().add(Duration( teacher: Teacher(id: 'id', name: 'name'),
// minutes: 30, start: DateTime.now().subtract(Duration(
// )), minutes: 30,
// end: DateTime.now().add(Duration( )),
// minutes: 30 + 45, end: DateTime.now().add(Duration(
// )), minutes: 15,
// homeworkId: 'homeworkId', )),
// id: 'id', homeworkId: 'homeworkId',
// description: 'description', id: 'id',
// room: 'ABC69', description: 'description',
// groupName: 'groupName', room: 'ABC69',
// name: 'name', groupName: 'groupName',
// ); name: 'name',
);
// liveCard.nextLesson = liveCard.currentLesson;
// final dt = DateTime(2024, 3, 22, 17, 12, 1, 1, 1); // final dt = DateTime(2024, 3, 22, 17, 12, 1, 1, 1);
@ -323,41 +335,234 @@ class LiveCardStateA extends State<LiveCard> {
final showMinutes = maxTime - elapsedTime > 60; final showMinutes = maxTime - elapsedTime > 60;
// child = LiveCardWidget(
// key: const Key('livecard.duringLesson'),
// liveCardState: liveCard.currentState,
// leading: liveCard.currentLesson!.lessonIndex +
// (RegExp(r'\d').hasMatch(liveCard.currentLesson!.lessonIndex)
// ? "."
// : ""),
// title: liveCard.currentLesson!.subject.renamedTo ??
// liveCard.currentLesson!.subject.name.capital(),
// titleItalic: liveCard.currentLesson!.subject.isRenamed &&
// settingsProvider.renamedSubjectsEnabled &&
// settingsProvider.renamedSubjectsItalics,
// subtitle: liveCard.currentLesson!.room,
// icon: SubjectIcon.resolveVariant(
// subject: liveCard.currentLesson!.subject, context: context),
// description: liveCard.currentLesson!.description != ""
// ? Text(liveCard.currentLesson!.description)
// : null,
// nextSubject: liveCard.nextLesson?.subject.renamedTo ??
// liveCard.nextLesson?.subject.name.capital(),
// nextSubjectItalic: liveCard.nextLesson?.subject.isRenamed == true &&
// settingsProvider.renamedSubjectsEnabled &&
// settingsProvider.renamedSubjectsItalics,
// nextRoom: liveCard.nextLesson?.room,
// 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 titleItalic = liveCard.currentLesson!.subject.isRenamed &&
// settingsProvider.renamedSubjectsEnabled &&
// settingsProvider.renamedSubjectsItalics;
var nextSubject = liveCard.nextLesson?.subject.renamedTo ??
liveCard.nextLesson?.subject.name.capital();
var nextSubjectItalic =
liveCard.nextLesson?.subject.isRenamed == true &&
settingsProvider.renamedSubjectsEnabled &&
settingsProvider.renamedSubjectsItalics;
var progressMax = showMinutes ? maxTime / 60 : maxTime;
var progressCurrent = showMinutes ? elapsedTime / 60 : elapsedTime;
var progressAccuracy =
showMinutes ? ProgressAccuracy.minutes : ProgressAccuracy.seconds;
child = LiveCardWidget( child = LiveCardWidget(
key: const Key('livecard.duringLesson'), key: const Key('livecard.duringLesson'),
leading: liveCard.currentLesson!.lessonIndex + children: liveCard.currentLesson != null
(RegExp(r'\d').hasMatch(liveCard.currentLesson!.lessonIndex) ? [
? "." SplittedPanel(
: ""), hasShadow: false,
title: liveCard.currentLesson!.subject.renamedTo ?? padding: EdgeInsets.zero,
liveCard.currentLesson!.subject.name.capital(), cardPadding: EdgeInsets.zero,
titleItalic: liveCard.currentLesson!.subject.isRenamed && spacing: 8.0,
settingsProvider.renamedSubjectsEnabled && children: [
settingsProvider.renamedSubjectsItalics, SplittedPanel(
subtitle: liveCard.currentLesson!.room, hasShadow: false,
icon: SubjectIcon.resolveVariant( isTransparent: true,
subject: liveCard.currentLesson!.subject, context: context), padding: EdgeInsets.zero,
description: liveCard.currentLesson!.description != "" cardPadding: const EdgeInsets.symmetric(
? Text(liveCard.currentLesson!.description) horizontal: 12.0,
: null, vertical: 0.0,
nextSubject: liveCard.nextLesson?.subject.renamedTo ?? ),
liveCard.nextLesson?.subject.name.capital(), spacing: 0.0,
nextSubjectItalic: liveCard.nextLesson?.subject.isRenamed == true && children: [
settingsProvider.renamedSubjectsEnabled && LessonTile(
settingsProvider.renamedSubjectsItalics, liveCard.currentLesson!,
nextRoom: liveCard.nextLesson?.room, swapRoom: true,
progressMax: showMinutes ? maxTime / 60 : maxTime, currentLessonIndicator: false,
progressCurrent: showMinutes ? elapsedTime / 60 : elapsedTime, padding:
progressAccuracy: const EdgeInsets.only(top: 8.0, bottom: 4.0),
showMinutes ? ProgressAccuracy.minutes : ProgressAccuracy.seconds, contentPadding: EdgeInsets.zero,
onProgressTap: () { ),
if (!(nextSubject == null &&
progressCurrent == null &&
progressMax == null))
Row(
children: [
const SizedBox(
width: 5.0,
),
if (progressCurrent != null &&
progressMax != null)
GestureDetector(
onTap: () {
showDialog( showDialog(
barrierColor: Colors.black, barrierColor: Colors.black,
context: context, context: context,
builder: (context) => builder: (context) => HeadsUpCountdown(
HeadsUpCountdown(maxTime: maxTime, elapsedTime: elapsedTime), 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
? [
Container(
width: (liveCard.nextLesson?.room
.length ??
0) >
20
? 111
: null,
padding: const EdgeInsets.symmetric(
horizontal: 5.5, vertical: 3.0),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondary
.withOpacity(.15),
borderRadius:
BorderRadius.circular(10.0),
),
child: Text(
liveCard.nextLesson!.room,
overflow: TextOverflow.ellipsis,
style: TextStyle(
height: 1.1,
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.colorScheme
.secondary
.withOpacity(.9),
),
),
),
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; break;
case LiveCardState.duringBreak: case LiveCardState.duringBreak:

View File

@ -23,6 +23,7 @@ extension Localization on String {
"s": "sec(s)", "s": "sec(s)",
// v5 // v5
"first_lesson_soon": "Your first lesson starts soon!", "first_lesson_soon": "Your first lesson starts soon!",
"go_home": "You've no more lessons today",
}, },
"hu_hu": { "hu_hu": {
"next": "Következő", "next": "Következő",
@ -44,6 +45,7 @@ extension Localization on String {
"s": "másodperc", "s": "másodperc",
// v5 // v5
"first_lesson_soon": "Hamarosan kezdődik az első órád!", "first_lesson_soon": "Hamarosan kezdődik az első órád!",
"go_home": "Ma már nincs több órád",
}, },
"de_de": { "de_de": {
"next": "Nächste", "next": "Nächste",
@ -65,6 +67,7 @@ extension Localization on String {
"s": "Sekunde", "s": "Sekunde",
// v5 // v5
"first_lesson_soon": "Ihre erste Unterrichtsstunde beginnt bald!", "first_lesson_soon": "Ihre erste Unterrichtsstunde beginnt bald!",
"go_home": "Sie haben heute keinen Unterricht mehr",
}, },
}; };

View File

@ -1,9 +1,11 @@
import 'package:refilc/api/providers/live_card_provider.dart';
import 'package:refilc/models/settings.dart'; import 'package:refilc/models/settings.dart';
import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_mobile_ui/common/progress_bar.dart'; import 'package:refilc_mobile_ui/common/progress_bar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:refilc_mobile_ui/pages/home/live_card/live_card.dart';
import 'live_card.i18n.dart'; import 'live_card.i18n.dart';
enum ProgressAccuracy { minutes, seconds } enum ProgressAccuracy { minutes, seconds }