forked from firka/firka
add timetable page
This commit is contained in:
15
firka/assets/images/logos/dave.svg
Normal file
15
firka/assets/images/logos/dave.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 18 KiB |
@@ -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,
|
||||
|
||||
Submodule firka/lib/l10n updated: d29c947552...5435a1c50a
@@ -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<HomeTimetableScreen> {
|
||||
final AppInitialization data;
|
||||
List<Lesson>? lessons;
|
||||
List<DateTime>? 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<DateTime> 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<Widget> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
firka/lib/ui/phone/widgets/bottom_tt_icon.dart
Normal file
44
firka/lib/ui/phone/widgets/bottom_tt_icon.dart
Normal file
@@ -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),
|
||||
)
|
||||
],
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user