Skip to content
Snippets Groups Projects
Commit 2be33a66 authored by doodlezucc's avatar doodlezucc
Browse files

introduce views/lesson providers

parent 91ebf683
No related branches found
No related tags found
No related merge requests found
...@@ -9,11 +9,12 @@ import 'dialogs/error_dialog.dart'; ...@@ -9,11 +9,12 @@ import 'dialogs/error_dialog.dart';
import 'drawer/drawer.dart'; import 'drawer/drawer.dart';
import 'timetable/timetable.dart'; import 'timetable/timetable.dart';
import 'toolbar/toolbar.dart'; import 'toolbar/toolbar.dart';
import 'untis/element_type.dart';
import 'untis/fetch.dart'; import 'untis/fetch.dart';
import 'untis/timetable.dart'; import 'untis/timetable.dart';
import 'user/save_state.dart'; import 'user/save_state.dart';
import 'util/listenable.dart'; import 'util/listenable.dart';
import 'views/mixed_class_view.dart';
import 'views/view.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
...@@ -57,9 +58,11 @@ class MyHomePage extends StatefulWidget { ...@@ -57,9 +58,11 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
TimetableData? timetable; late TimetableView view;
late List<StreamSubscription> _subscriptions; late List<StreamSubscription> _subscriptions;
TimetableData? timetable;
AppContext get appContext => widget.appContext; AppContext get appContext => widget.appContext;
UntisFetch get untis => appContext.untis; UntisFetch get untis => appContext.untis;
...@@ -109,18 +112,11 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -109,18 +112,11 @@ class _MyHomePageState extends State<MyHomePage> {
final profile = await appContext.profile.firstNotNull; final profile = await appContext.profile.firstNotNull;
final selectedClasses = profile.selectedClasses; final selectedClasses = profile.selectedClasses;
final allTimetables = await Future.wait(selectedClasses.map((classId) { view = MixedClassView(classIds: selectedClasses);
final cacheable = untis.timetableOf( final fetchedTimetable = await view.timetableOf(date, untis: untis);
type: ElementType.classGroup,
elementId: classId,
date: date,
);
return Future(() => cacheable.fetched);
}));
setState(() { setState(() {
timetable = TimetableData.mergeAll(allTimetables); timetable = fetchedTimetable;
}); });
} }
......
import '../untis/element_type.dart';
import '../untis/fetch.dart';
import '../untis/timetable.dart';
import 'dart:async';
import 'view.dart';
class MixedClassView extends TimetableView {
final Set<int> classIds;
MixedClassView({required this.classIds});
@override
FutureOr<TimetableData?> timetableOf(
DateTime date, {
required UntisFetch untis,
}) async {
final allTimetables = await Future.wait(classIds.map((classId) {
final cacheable = untis.timetableOf(
type: ElementType.classGroup,
elementId: classId,
date: date,
);
return Future(() => cacheable.fetched);
}));
return TimetableData.mergeAll(allTimetables);
}
}
import 'dart:async';
import '../untis/fetch.dart';
import '../untis/timetable.dart';
abstract class TimetableView {
FutureOr<TimetableData?> timetableOf(
DateTime date, {
required UntisFetch untis,
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment