Merge pull request 'added connected double lessons with own setting' (#49) from develop-connectedDoubleLessons into develop
Reviewed-on: #49
This commit is contained in:
commit
3e3e2579f0
@ -16,4 +16,15 @@ extension IsSameDay on DateTime {
|
|||||||
TimeOfDay toTimeOfDay() {
|
TimeOfDay toTimeOfDay() {
|
||||||
return TimeOfDay(hour: hour, minute: minute);
|
return TimeOfDay(hour: hour, minute: minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSameDateTime(DateTime other) {
|
||||||
|
bool isSameDay = this.isSameDay(other);
|
||||||
|
bool isSameTimeOfDay = (toTimeOfDay() == other.toTimeOfDay());
|
||||||
|
|
||||||
|
return isSameDay && isSameTimeOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSameOrAfter(DateTime other) {
|
||||||
|
return isSameDateTime(other) || isAfter(other);
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,9 @@ part 'timetableSettings.g.dart';
|
|||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class TimetableSettings {
|
class TimetableSettings {
|
||||||
TimetableSettings();
|
bool connectDoubleLessons;
|
||||||
|
|
||||||
|
TimetableSettings({required this.connectDoubleLessons});
|
||||||
|
|
||||||
factory TimetableSettings.fromJson(Map<String, dynamic> json) => _$TimetableSettingsFromJson(json);
|
factory TimetableSettings.fromJson(Map<String, dynamic> json) => _$TimetableSettingsFromJson(json);
|
||||||
Map<String, dynamic> toJson() => _$TimetableSettingsToJson(this);
|
Map<String, dynamic> toJson() => _$TimetableSettingsToJson(this);
|
||||||
|
@ -7,7 +7,11 @@ part of 'timetableSettings.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
TimetableSettings _$TimetableSettingsFromJson(Map<String, dynamic> json) =>
|
TimetableSettings _$TimetableSettingsFromJson(Map<String, dynamic> json) =>
|
||||||
TimetableSettings();
|
TimetableSettings(
|
||||||
|
connectDoubleLessons: json['connectDoubleLessons'] as bool,
|
||||||
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$TimetableSettingsToJson(TimetableSettings instance) =>
|
Map<String, dynamic> _$TimetableSettingsToJson(TimetableSettings instance) =>
|
||||||
<String, dynamic>{};
|
<String, dynamic>{
|
||||||
|
'connectDoubleLessons': instance.connectDoubleLessons,
|
||||||
|
};
|
||||||
|
@ -244,9 +244,66 @@ class _TimetableState extends State<Timetable> {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<GetTimetableResponseObject> _removeDuplicates(TimetableProps data, Duration maxTimeBetweenDouble) {
|
||||||
|
|
||||||
|
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList();
|
||||||
|
|
||||||
|
if(timetableList.isEmpty) return timetableList;
|
||||||
|
|
||||||
|
timetableList.sort((a, b) => _parseWebuntisTimestamp(a.date, a.startTime).compareTo(_parseWebuntisTimestamp(b.date, b.startTime)));
|
||||||
|
|
||||||
|
GetTimetableResponseObject previousElement = timetableList.first;
|
||||||
|
for(var i = 1; i < timetableList.length; i++) {
|
||||||
|
GetTimetableResponseObject currentElement = timetableList.elementAt(i);
|
||||||
|
|
||||||
|
bool isSameLesson() {
|
||||||
|
int? currentSubjectId = currentElement.su.firstOrNull?.id;
|
||||||
|
int? previousSubjectId = previousElement.su.firstOrNull?.id;
|
||||||
|
|
||||||
|
if(currentSubjectId == null || previousSubjectId == null || currentSubjectId != previousSubjectId) return false;
|
||||||
|
|
||||||
|
int? currentRoomId = currentElement.ro.firstOrNull?.id;
|
||||||
|
int? previousRoomId = previousElement.ro.firstOrNull?.id;
|
||||||
|
|
||||||
|
if(currentRoomId != previousRoomId) return false;
|
||||||
|
|
||||||
|
int? currentTeacherId = currentElement.te.firstOrNull?.id;
|
||||||
|
int? previousTeacherId = previousElement.te.firstOrNull?.id;
|
||||||
|
|
||||||
|
if(currentTeacherId != previousTeacherId) return false;
|
||||||
|
|
||||||
|
String? currentStatusCode = currentElement.code;
|
||||||
|
String? previousStatusCode = previousElement.code;
|
||||||
|
|
||||||
|
if(currentStatusCode != previousStatusCode) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNotSeparated() => _parseWebuntisTimestamp(previousElement.date, previousElement.endTime).add(maxTimeBetweenDouble)
|
||||||
|
.isSameOrAfter(_parseWebuntisTimestamp(currentElement.date, currentElement.startTime));
|
||||||
|
|
||||||
|
if(isSameLesson() && isNotSeparated()) {
|
||||||
|
previousElement.endTime = currentElement.endTime;
|
||||||
|
timetableList.remove(currentElement);
|
||||||
|
i--;
|
||||||
|
} else {
|
||||||
|
previousElement = currentElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return timetableList;
|
||||||
|
}
|
||||||
|
|
||||||
TimetableEvents _buildTableEvents(TimetableProps data) {
|
TimetableEvents _buildTableEvents(TimetableProps data) {
|
||||||
|
|
||||||
List<Appointment> appointments = data.getTimetableResponse.result.map((element) {
|
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList();
|
||||||
|
|
||||||
|
if(settings.val().timetableSettings.connectDoubleLessons) {
|
||||||
|
timetableList = _removeDuplicates(data, const Duration(minutes: 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Appointment> appointments = timetableList.map((element) {
|
||||||
|
|
||||||
GetRoomsResponse rooms = data.getRoomsResponse;
|
GetRoomsResponse rooms = data.getRoomsResponse;
|
||||||
GetSubjectsResponse subjects = data.getSubjectsResponse;
|
GetSubjectsResponse subjects = data.getSubjectsResponse;
|
||||||
|
@ -23,7 +23,9 @@ class DefaultSettings {
|
|||||||
askedForPreferredGradeSystem: false,
|
askedForPreferredGradeSystem: false,
|
||||||
inputs: []
|
inputs: []
|
||||||
),
|
),
|
||||||
timetableSettings: TimetableSettings(),
|
timetableSettings: TimetableSettings(
|
||||||
|
connectDoubleLessons: false,
|
||||||
|
),
|
||||||
talkSettings: TalkSettings(
|
talkSettings: TalkSettings(
|
||||||
sortFavoritesToTop: true,
|
sortFavoritesToTop: true,
|
||||||
sortUnreadToTop: false,
|
sortUnreadToTop: false,
|
||||||
|
@ -8,6 +8,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../../model/accountData.dart';
|
import '../../model/accountData.dart';
|
||||||
|
import '../../model/timetable/timetableProps.dart';
|
||||||
import '../../notification/notifyUpdater.dart';
|
import '../../notification/notifyUpdater.dart';
|
||||||
import '../../storage/base/settingsProvider.dart';
|
import '../../storage/base/settingsProvider.dart';
|
||||||
import '../../theming/appTheme.dart';
|
import '../../theming/appTheme.dart';
|
||||||
@ -98,6 +99,20 @@ class _SettingsState extends State<Settings> {
|
|||||||
|
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.calendar_view_day_outlined),
|
||||||
|
title: const Text('Doppelstunden zusammenhängend anzeigen'),
|
||||||
|
trailing: Checkbox(
|
||||||
|
value: settings.val().timetableSettings.connectDoubleLessons,
|
||||||
|
onChanged: (e) {
|
||||||
|
settings.val(write: true).timetableSettings.connectDoubleLessons = e!;
|
||||||
|
Provider.of<TimetableProps>(context, listen: false).run(renew: false);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const Divider(),
|
||||||
|
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.star_border),
|
leading: const Icon(Icons.star_border),
|
||||||
title: const Text('Favoriten im Talk nach oben sortieren'),
|
title: const Text('Favoriten im Talk nach oben sortieren'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user