claude refactor

This commit is contained in:
2026-05-04 13:54:39 +02:00
parent 9973f12733
commit 551c1bf1fa
125 changed files with 4484 additions and 2544 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import 'getHolidays.dart';
import 'getHolidaysResponse.dart';
class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
GetHolidaysCache({onUpdate, renew}) : super(RequestCache.cacheDay, onUpdate, renew: renew) {
GetHolidaysCache({void Function(GetHolidaysResponse)? onUpdate, bool? renew}) : super(RequestCache.cacheDay, onUpdate, renew: renew) {
start('state-holidays');
}
@@ -8,7 +8,7 @@ import 'getChatResponse.dart';
class GetChatCache extends RequestCache<GetChatResponse> {
String chatToken;
GetChatCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
GetChatCache({required void Function(GetChatResponse) onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
start('nc-chat-$chatToken');
}
@@ -86,7 +86,7 @@ class GetChatResponseObject {
}
Map<String, RichObjectString>? _fromJson(json) {
Map<String, RichObjectString>? _fromJson(dynamic json) {
if(json is Map<String, dynamic>) {
var data = <String, RichObjectString>{};
for (var element in json.keys) {
@@ -7,7 +7,7 @@ import 'getParticipantsResponse.dart';
class GetParticipantsCache extends RequestCache<GetParticipantsResponse> {
String chatToken;
GetParticipantsCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
GetParticipantsCache({required void Function(GetParticipantsResponse) onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
start('nc-chat-participants-$chatToken');
}
@@ -7,7 +7,7 @@ import 'getRoomParams.dart';
import 'getRoomResponse.dart';
class GetRoomCache extends RequestCache<GetRoomResponse> {
GetRoomCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
GetRoomCache({void Function(GetRoomResponse)? onUpdate, bool? renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
start('nc-rooms');
}
@@ -9,7 +9,7 @@ import 'listFilesResponse.dart';
class ListFilesCache extends RequestCache<ListFilesResponse> {
String path;
ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
ListFilesCache({required void Function(ListFilesResponse) onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
var bytes = utf8.encode('MarianumMobile-$path');
var cacheName = md5.convert(bytes).toString();
start('wd-folder-$cacheName');
@@ -5,7 +5,7 @@ import 'getBreakersResponse.dart';
class GetBreakersCache extends RequestCache<GetBreakersResponse> {
GetBreakersCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
GetBreakersCache({void Function(GetBreakersResponse)? onUpdate, bool? renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
start('breakers');
}
+11 -12
View File
@@ -13,8 +13,8 @@ abstract class RequestCache<T extends ApiResponse?> {
static String collection = 'MarianumMobile';
int maxCacheTime;
Function(T) onUpdate;
Function(Exception) onError;
void Function(T)? onUpdate;
void Function(Exception) onError;
bool? renew;
RequestCache(this.maxCacheTime, this.onUpdate, {this.onError = ignore, this.renew = false});
@@ -22,24 +22,23 @@ abstract class RequestCache<T extends ApiResponse?> {
static void ignore(Exception e) {}
Future<void> start(String document) async {
var tableData = await Localstore.instance.collection(collection).doc(document).get();
if(tableData != null) {
onUpdate(onLocalData(tableData['json']));
final tableData = await Localstore.instance.collection(collection).doc(document).get();
if (tableData != null) {
onUpdate?.call(onLocalData(tableData['json']));
}
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
if(renew == null || !renew!) return;
if (DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
if (renew == null || !renew!) return;
}
try {
var newValue = await onLoad();
onUpdate(newValue);
final newValue = await onLoad();
onUpdate?.call(newValue);
Localstore.instance.collection(collection).doc(document).set({
'json': jsonEncode(newValue),
'lastupdate': DateTime.now().millisecondsSinceEpoch
'lastupdate': DateTime.now().millisecondsSinceEpoch,
});
} on Exception catch(e) {
} on Exception catch (e) {
onError(e);
}
}
@@ -5,7 +5,7 @@ import 'getHolidays.dart';
import 'getHolidaysResponse.dart';
class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
GetHolidaysCache({onUpdate}) : super(RequestCache.cacheDay, onUpdate) {
GetHolidaysCache({void Function(GetHolidaysResponse)? onUpdate}) : super(RequestCache.cacheDay, onUpdate) {
start('wu-holidays');
}
@@ -5,7 +5,7 @@ import 'getRooms.dart';
import 'getRoomsResponse.dart';
class GetRoomsCache extends RequestCache<GetRoomsResponse> {
GetRoomsCache({onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
GetRoomsCache({void Function(GetRoomsResponse)? onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
start('wu-rooms');
}
@@ -5,7 +5,7 @@ import 'getSubjects.dart';
import 'getSubjectsResponse.dart';
class GetSubjectsCache extends RequestCache<GetSubjectsResponse> {
GetSubjectsCache({onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
GetSubjectsCache({void Function(GetSubjectsResponse)? onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
start('wu-subjects');
}
@@ -10,7 +10,12 @@ class GetTimetableCache extends RequestCache<GetTimetableResponse> {
int startdate;
int enddate;
GetTimetableCache({required onUpdate, onError, required this.startdate, required this.enddate}) : super(RequestCache.cacheMinute, onUpdate, onError: onError) {
GetTimetableCache({
required void Function(GetTimetableResponse) onUpdate,
void Function(Exception)? onError,
required this.startdate,
required this.enddate,
}) : super(RequestCache.cacheMinute, onUpdate, onError: onError ?? RequestCache.ignore) {
start('wu-timetable-$startdate-$enddate');
}