Skip to content

Commit

Permalink
irregular periods, period sorting, week start fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasslos committed Oct 15, 2023
1 parent 34f6d8f commit 1d45a9a
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 152 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ android {
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
//TODO: Change versionCode and versionName if there is a new version
versionCode 1309
versionName "v1.3.9"
versionCode 1310
versionName "v1.3.10"
}

signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/rpc_request/rpc_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuthParams with _$AuthParams {
isGoogle: true,
),
'clientTime': DateTime.now().millisecondsSinceEpoch,
}
},
};
}

Expand Down
3 changes: 1 addition & 2 deletions lib/core/session/custom_subject_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class CustomSubjectColorsNotifier
prefs.getString('$_userId.custom_subject_colors');
if (customSubjectColors != null) {
state = Map.unmodifiable({
for (var e in jsonDecode(customSubjectColors) as List)
e['subjectId'] as int: CustomSubjectColor.fromJson(e)
for (var e in jsonDecode(customSubjectColors) as List) e['subjectId'] as int: CustomSubjectColor.fromJson(e),
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/session/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SessionsNotifier extends StateNotifier<List<Session>> {
set currentlyUsedSession(Session session) {
state = List.unmodifiable([
session,
...[...state]..remove(session)
...[...state]..remove(session),
]);
saveToSharedPrefs();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/untis/models/user_data/user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class UserData with _$UserData {
{for (var e in json['masterData']['holidays'] ?? []) e['id'] as int: Holiday.fromJson(e)},
{for (var e in json['masterData']['klassen']) e['id'] as int: Klasse.fromJson(e)},
{for (var e in json['masterData']['rooms']) e['id'] as int: Room.fromJson(e)},
{for (var e in json['masterData']['subjects']) e['id'] as int: Subject.fromJson(e)
{
for (var e in json['masterData']['subjects']) e['id'] as int: Subject.fromJson(e),
},
{
for (var e in json['masterData']['teachers'])
e['id'] as int: Teacher.fromJson(e)
for (var e in json['masterData']['teachers']) e['id'] as int: Teacher.fromJson(e),
},
(json['masterData']['timeGrid']['days'].first['units'] as List<dynamic>)
.map((e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/untis/requests/request_app_shared_secret.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Future<String> requestAppSharedSecret(
var response = await rpcRequest(
method: 'getAppSharedSecret',
params: [
AppSharedSecretParams(username: username, password: password).toJson()
AppSharedSecretParams(username: username, password: password).toJson(),
],
serverUrl: Uri.parse(apiBaseUrl),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/untis/requests/request_timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Future<Map<DateTime, List<TimeTablePeriod>>> requestTimeTable(
'masterDataTimestamp': userData.timeStamp,
'timetableTimestamp': 0,
'timetableTimestamps': [],
...authParams.toJson()
...authParams.toJson(),
}
],
serverUrl: Uri.parse(apiBaseUrl),
Expand Down
2 changes: 1 addition & 1 deletion lib/core/untis/requests/request_user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Future<UserData> requestUserData(
'elementId': 0,
'deviceOs': 'AND',
'deviceOsVersion': '',
...authParams.toJson()
...authParams.toJson(),
}
],
serverUrl: Uri.parse(apiBaseUrl),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/screens/filter_screen/filter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class _FilterScreenState extends ConsumerState<FilterScreen> {
Text('Fehler beim Laden des Stundenplans', style: TextStyle(fontSize: 20)),
SizedBox(height: 16),
Text('Die möglichen Filter werden aus Stunden aus den letzten zwei und den nächsten zwei Wochen erstellt. '
'Mindestens eine dieser Wochen konnte nicht richtig geladen werden, zum Beispiel, weil der Untis-Server überlastet ist. Versuche, alle Wochen neu zu laden oder die App zu schließen und zu öffnen, um es erneut zu versuchen. Wenn das Problem weiter auftritt, kannst du dich gerne an mich wenden.')
'Mindestens eine dieser Wochen konnte nicht richtig geladen werden, zum Beispiel, weil der Untis-Server überlastet ist. Versuche, alle Wochen neu zu laden oder die App zu schließen und zu öffnen, um es erneut zu versuchen. Wenn das Problem weiter auftritt, kannst du dich gerne an mich wenden.'),
],
),
),
Expand Down
30 changes: 23 additions & 7 deletions lib/ui/screens/home_screen/widgets/period_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,28 @@ import 'package:your_schedule/ui/screens/home_screen/widgets/timetable_period_wi
// Das vereinfacht den Code und macht ihn ohne Funktionseinbußen verständlicher.
Iterable<List<List<TimeTablePeriod>>> periodsToTimeTableGrid(
List<TimeTablePeriod> periods,
Map<int, Subject> subjects,
) sync* {
// Das Raster ist eine Liste von Spalten, jede Spalte ist eine Liste von "Zeilen", die eigentlich nur Stunden sind.
List<List<TimeTablePeriod>> grid = [];
DateTime? lastEndTime;

periods.sort(
(a, b) => !a.startTime.isAtSameMomentAs(b.startTime)
? a.startTime.compareTo(b.startTime)
: a.endTime.compareTo(b.endTime),
);
periods.sort((a, b) {
var startCompare = a.startTime.compareTo(b.startTime);
if (startCompare != 0) {
return startCompare;
}
var endCompare = a.endTime.compareTo(b.endTime);
if (endCompare != 0) {
return endCompare;
}
Subject? aSubject = subjects[a.subject?.id ?? -1];
Subject? bSubject = subjects[b.subject?.id ?? -1];
if (aSubject != null && bSubject != null) {
return aSubject.name.compareTo(bSubject.name);
}
return 0;
});

// Wir gehen jede Stunde in der Reihenfolge ihrer Startzeit durch.
for (TimeTablePeriod period in periods) {
Expand Down Expand Up @@ -94,6 +106,9 @@ class PeriodLayout extends ConsumerWidget {
return CustomMultiChildLayout(
delegate: _PeriodLayoutDelegate(
periods: periods,
subjects: ref.watch(
selectedSessionProvider.select((value) => value.userData!.subjects),
),
startOfDay: startOfDay,
endOfDay: endOfDay,
),
Expand All @@ -114,19 +129,20 @@ class PeriodLayout extends ConsumerWidget {

class _PeriodLayoutDelegate extends MultiChildLayoutDelegate {
final List<TimeTablePeriod> periods;
final Map<int, Subject> subjects;
final TimeOfDay startOfDay;
final TimeOfDay endOfDay;

_PeriodLayoutDelegate({
required this.periods,
required this.subjects,
required this.startOfDay,
required this.endOfDay,
});

@override
void performLayout(Size size) {
for (List<List<TimeTablePeriod>> gridPart
in periodsToTimeTableGrid(periods)) {
for (List<List<TimeTablePeriod>> gridPart in periodsToTimeTableGrid(periods, subjects)) {
/// Als erstes berechnen wir den Offset für jede Stunde.
double columnWidth = size.width / gridPart.length;

Expand Down

0 comments on commit 1d45a9a

Please sign in to comment.