code fixes, added isSameOrAfter for DateTime objects, added check for teacher room and status
This commit is contained in:
parent
20d7b16ede
commit
a0c025b58b
@ -16,4 +16,15 @@ extension IsSameDay on DateTime {
|
||||
TimeOfDay toTimeOfDay() {
|
||||
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);
|
||||
}
|
||||
}
|
@ -246,9 +246,9 @@ class _TimetableState extends State<Timetable> {
|
||||
|
||||
List<GetTimetableResponseObject> _removeDuplicates(TimetableProps data, Duration maxTimeBetweenDouble) {
|
||||
|
||||
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList();
|
||||
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList( );
|
||||
|
||||
if(timetableList.isEmpty){ return timetableList; }
|
||||
if ( timetableList.isEmpty ) return timetableList;
|
||||
|
||||
timetableList.sort((a, b) => _parseWebuntisTimestamp(a.date, a.startTime).compareTo(_parseWebuntisTimestamp(b.date, b.startTime)));
|
||||
|
||||
@ -256,15 +256,38 @@ class _TimetableState extends State<Timetable> {
|
||||
for (var i = 1; i < timetableList.length; i++) {
|
||||
GetTimetableResponseObject currentElement = timetableList.elementAt(i);
|
||||
|
||||
bool isSameSubject() => (currentElement.su.firstOrNull?.id ?? 1) == (previousElement.su.firstOrNull?.id ?? 2);
|
||||
bool isNotSeparated() => _parseWebuntisTimestamp(previousElement.date, previousElement.endTime).add(maxTimeBetweenDouble).add(const Duration(seconds: 1))
|
||||
.isAfter(_parseWebuntisTimestamp(currentElement.date, currentElement.startTime));
|
||||
bool isSameLesson() {
|
||||
int? currentSubjectId = currentElement.su.firstOrNull?.id;
|
||||
int? previousSubjectId = previousElement.su.firstOrNull?.id;
|
||||
|
||||
if(isSameSubject() && isNotSeparated()){
|
||||
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);
|
||||
timetableList.remove( currentElement );
|
||||
i--;
|
||||
}else{
|
||||
} else {
|
||||
previousElement = currentElement;
|
||||
}
|
||||
}
|
||||
@ -274,10 +297,10 @@ class _TimetableState extends State<Timetable> {
|
||||
|
||||
TimetableEvents _buildTableEvents(TimetableProps data) {
|
||||
|
||||
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList();
|
||||
List<GetTimetableResponseObject> timetableList = data.getTimetableResponse.result.toList( );
|
||||
|
||||
if(settings.val().timetableSettings.connectDoubleLessons){
|
||||
timetableList = _removeDuplicates(data, const Duration(minutes: 5));
|
||||
if( settings.val().timetableSettings.connectDoubleLessons ){
|
||||
timetableList = _removeDuplicates( data, const Duration(minutes: 5) );
|
||||
}
|
||||
|
||||
List<Appointment> appointments = timetableList.map((element) {
|
||||
|
@ -8,6 +8,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../model/accountData.dart';
|
||||
import '../../model/timetable/timetableProps.dart';
|
||||
import '../../notification/notifyUpdater.dart';
|
||||
import '../../storage/base/settingsProvider.dart';
|
||||
import '../../theming/appTheme.dart';
|
||||
@ -100,11 +101,12 @@ class _SettingsState extends State<Settings> {
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.calendar_view_day_outlined),
|
||||
title: const Text("Doppelstunden als eine Stunde anzeigen"),
|
||||
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);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user