refactored timetable
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../../api/mhsl/customTimetableEvent/add/addCustomTimetableEvent.dart';
|
||||
@@ -18,6 +16,8 @@ import '../../../../../api/webuntis/queries/getRooms/getRoomsCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getSubjects/getSubjectsCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimegridUnits/getTimegridUnitsCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimegridUnits/getTimegridUnitsResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimetable/getTimetableCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
import '../../../../../model/accountData.dart';
|
||||
@@ -25,55 +25,116 @@ import '../../../../../model/accountData.dart';
|
||||
class TimetableDataProvider {
|
||||
static final DateFormat _dateFormat = DateFormat('yyyyMMdd');
|
||||
|
||||
Future<GetTimetableResponse> getWeek(DateTime startDate, DateTime endDate) {
|
||||
final completer = Completer<GetTimetableResponse>();
|
||||
GetTimetableCache(
|
||||
Future<GetTimetableResponse> getWeek(
|
||||
DateTime startDate,
|
||||
DateTime endDate, {
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetTimetableResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetTimetableCache(
|
||||
startdate: int.parse(_dateFormat.format(startDate)),
|
||||
enddate: int.parse(_dateFormat.format(endDate)),
|
||||
onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
},
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
if (!completer.isCompleted) completer.completeError(e);
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getWeek');
|
||||
}
|
||||
|
||||
Future<GetRoomsResponse> getRooms() {
|
||||
final completer = Completer<GetRoomsResponse>();
|
||||
GetRoomsCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
Future<GetRoomsResponse> getRooms({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetRoomsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetRoomsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getRooms');
|
||||
}
|
||||
|
||||
Future<GetSubjectsResponse> getSubjects() {
|
||||
final completer = Completer<GetSubjectsResponse>();
|
||||
GetSubjectsCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
Future<GetSubjectsResponse> getSubjects({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetSubjectsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetSubjectsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getSubjects');
|
||||
}
|
||||
|
||||
Future<GetHolidaysResponse> getSchoolHolidays() {
|
||||
final completer = Completer<GetHolidaysResponse>();
|
||||
GetHolidaysCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
Future<GetHolidaysResponse> getSchoolHolidays({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetHolidaysResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetHolidaysCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getSchoolHolidays');
|
||||
}
|
||||
|
||||
Future<GetCustomTimetableEventResponse> getCustomEvents({bool renew = false}) {
|
||||
final completer = Completer<GetCustomTimetableEventResponse>();
|
||||
GetCustomTimetableEventCache(
|
||||
Future<GetTimegridUnitsResponse> getTimegrid({bool renew = false}) async {
|
||||
GetTimegridUnitsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetTimegridUnitsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getTimegrid');
|
||||
}
|
||||
|
||||
Future<GetCustomTimetableEventResponse> getCustomEvents({
|
||||
bool renew = false,
|
||||
void Function(Object)? onError,
|
||||
}) async {
|
||||
GetCustomTimetableEventResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetCustomTimetableEventCache(
|
||||
GetCustomTimetableEventParams(AccountData().getUserSecret()),
|
||||
renew: renew,
|
||||
onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getCustomEvents');
|
||||
}
|
||||
|
||||
Future<void> addCustomEvent(CustomTimetableEvent event) =>
|
||||
|
||||
Reference in New Issue
Block a user