From 15d550f55a2a9a1ade9c78d88fa85a99f5c36ec8 Mon Sep 17 00:00:00 2001 From: Pupsi28 Date: Sun, 17 Mar 2024 14:30:10 +0100 Subject: [PATCH 1/4] changed custom event color to darker orange shade --- lib/view/pages/timetable/timetable.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index 53cc8c7..d0c9614 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -289,7 +289,7 @@ class _TimetableState extends State { location: customEvent.description, subject: customEvent.title, recurrenceRule: customEvent.rrule, - color: Colors.deepOrange, + color: Colors.deepOrange.shade800, startTimeZone: '', endTimeZone: '', ); From a2f1ccae7b7b7d97ecc02eb373b3bdb443ff5295 Mon Sep 17 00:00:00 2001 From: Pupsi28 Date: Sun, 17 Mar 2024 17:01:18 +0100 Subject: [PATCH 2/4] option to change custom timetable event colors --- .../customTimetableEvent.dart | 3 +- .../customTimetableEvent.g.dart | 2 + .../customTimetableEventEditDialog.dart | 33 ++++++++++++++++ .../timetable/custonTimetableColors.dart | 39 +++++++++++++++++++ lib/view/pages/timetable/timetable.dart | 3 +- 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 lib/view/pages/timetable/custonTimetableColors.dart diff --git a/lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart b/lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart index c6b668a..1a8efe5 100644 --- a/lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart +++ b/lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart @@ -13,6 +13,7 @@ class CustomTimetableEvent { DateTime startDate; @JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson) DateTime endDate; + String? color; String rrule; @JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson) DateTime createdAt; @@ -20,7 +21,7 @@ class CustomTimetableEvent { DateTime updatedAt; CustomTimetableEvent({required this.id, required this.title, required this.description, required this.startDate, - required this.endDate, required this.rrule, required this.createdAt, required this.updatedAt}); + required this.endDate, required this.color, required this.rrule, required this.createdAt, required this.updatedAt}); factory CustomTimetableEvent.fromJson(Map json) => _$CustomTimetableEventFromJson(json); Map toJson() => _$CustomTimetableEventToJson(this); diff --git a/lib/api/mhsl/customTimetableEvent/customTimetableEvent.g.dart b/lib/api/mhsl/customTimetableEvent/customTimetableEvent.g.dart index 2d6416a..433f7e6 100644 --- a/lib/api/mhsl/customTimetableEvent/customTimetableEvent.g.dart +++ b/lib/api/mhsl/customTimetableEvent/customTimetableEvent.g.dart @@ -14,6 +14,7 @@ CustomTimetableEvent _$CustomTimetableEventFromJson( description: json['description'] as String, startDate: MhslApi.dateTimeFromJson(json['startDate'] as String), endDate: MhslApi.dateTimeFromJson(json['endDate'] as String), + color: json['color'] as String?, rrule: json['rrule'] as String, createdAt: MhslApi.dateTimeFromJson(json['createdAt'] as String), updatedAt: MhslApi.dateTimeFromJson(json['updatedAt'] as String), @@ -27,6 +28,7 @@ Map _$CustomTimetableEventToJson( 'description': instance.description, 'startDate': MhslApi.dateTimeToJson(instance.startDate), 'endDate': MhslApi.dateTimeToJson(instance.endDate), + 'color': instance.color, 'rrule': instance.rrule, 'createdAt': MhslApi.dateTimeToJson(instance.createdAt), 'updatedAt': MhslApi.dateTimeToJson(instance.updatedAt), diff --git a/lib/view/pages/timetable/customTimetableEventEditDialog.dart b/lib/view/pages/timetable/customTimetableEventEditDialog.dart index f1b3791..4d925ce 100644 --- a/lib/view/pages/timetable/customTimetableEventEditDialog.dart +++ b/lib/view/pages/timetable/customTimetableEventEditDialog.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:jiffy/jiffy.dart'; import 'package:marianum_mobile/extensions/dateTime.dart'; +import 'package:marianum_mobile/view/pages/timetable/custonTimetableColors.dart'; import 'package:provider/provider.dart'; import 'package:rrule_generator/rrule_generator.dart'; import 'package:time_range_picker/time_range_picker.dart'; @@ -32,6 +33,10 @@ class _AddCustomTimetableEventDialogState extends State element.name == widget.existingEvent?.color, + orElse: () => CustomTimetableColors.orange + ); late bool isEditingExisting = widget.existingEvent != null; @@ -77,6 +82,7 @@ class _AddCustomTimetableEventDialogState extends State( + value: _customTimetableColor, + icon: const Icon(Icons.arrow_drop_down), + items: CustomTimetableColors.values.map((e) => DropdownMenuItem( + value: e, + enabled: e != _customTimetableColor, + child: Row( + children: [ + Icon(Icons.circle, color: TimetableColors.getDisplayOptions(e).color), + const SizedBox(width: 10), + Text(TimetableColors.getDisplayOptions(e).displayName), + ], + ), + )).toList(), + onChanged: (e) { + setState(() { + _customTimetableColor = e!; + }); + }, + ), + ), + const Divider(), RRuleGenerator( config: RRuleGeneratorConfig( headerEnabled: true, @@ -156,6 +188,7 @@ class _AddCustomTimetableEventDialogState extends State element.name == color)).color; + } +} + +class ColorModeDisplay { + final Color color; + final String displayName; + + ColorModeDisplay({required this.color, required this.displayName}); +} \ No newline at end of file diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index d0c9614..415513f 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:marianum_mobile/extensions/dateTime.dart'; +import 'package:marianum_mobile/view/pages/timetable/custonTimetableColors.dart'; import 'package:provider/provider.dart'; import 'package:syncfusion_flutter_calendar/calendar.dart'; @@ -289,7 +290,7 @@ class _TimetableState extends State { location: customEvent.description, subject: customEvent.title, recurrenceRule: customEvent.rrule, - color: Colors.deepOrange.shade800, + color: TimetableColors.getColorFromString(customEvent.color ?? CustomTimetableColors.orange.name), startTimeZone: '', endTimeZone: '', ); From e40760a07af373d4d39fe36a3ebdc2128e858785 Mon Sep 17 00:00:00 2001 From: Pupsi28 Date: Sun, 17 Mar 2024 17:08:43 +0100 Subject: [PATCH 3/4] added fallback option for non existing colors --- lib/view/pages/timetable/custonTimetableColors.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view/pages/timetable/custonTimetableColors.dart b/lib/view/pages/timetable/custonTimetableColors.dart index 17cc807..bd21695 100644 --- a/lib/view/pages/timetable/custonTimetableColors.dart +++ b/lib/view/pages/timetable/custonTimetableColors.dart @@ -27,7 +27,7 @@ class TimetableColors { } static Color getColorFromString(String color){ - return getDisplayOptions(CustomTimetableColors.values.firstWhere((element) => element.name == color)).color; + return getDisplayOptions(CustomTimetableColors.values.firstWhere((element) => element.name == color, orElse: () => CustomTimetableColors.orange)).color; } } From 90154880d0ea1c58833d798e36d04a881d7045d8 Mon Sep 17 00:00:00 2001 From: Pupsi28 Date: Sun, 17 Mar 2024 17:38:48 +0100 Subject: [PATCH 4/4] resolved pr comments --- ...imetableColors.dart => customTimetableColors.dart} | 11 +++++++---- .../timetable/customTimetableEventEditDialog.dart | 4 ++-- lib/view/pages/timetable/timetable.dart | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) rename lib/view/pages/timetable/{custonTimetableColors.dart => customTimetableColors.dart} (75%) diff --git a/lib/view/pages/timetable/custonTimetableColors.dart b/lib/view/pages/timetable/customTimetableColors.dart similarity index 75% rename from lib/view/pages/timetable/custonTimetableColors.dart rename to lib/view/pages/timetable/customTimetableColors.dart index bd21695..060bf0c 100644 --- a/lib/view/pages/timetable/custonTimetableColors.dart +++ b/lib/view/pages/timetable/customTimetableColors.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:marianum_mobile/theming/darkAppTheme.dart'; -enum CustomTimetableColors{ +import '../../../theming/darkAppTheme.dart'; + +enum CustomTimetableColors { orange, red, green, @@ -9,6 +10,8 @@ enum CustomTimetableColors{ } class TimetableColors { + static const CustomTimetableColors defaultColor = CustomTimetableColors.orange; + static ColorModeDisplay getDisplayOptions(CustomTimetableColors color) { switch(color) { case CustomTimetableColors.green: @@ -26,8 +29,8 @@ class TimetableColors { } } - static Color getColorFromString(String color){ - return getDisplayOptions(CustomTimetableColors.values.firstWhere((element) => element.name == color, orElse: () => CustomTimetableColors.orange)).color; + static Color getColorFromString(String color) { + return getDisplayOptions(CustomTimetableColors.values.firstWhere((element) => element.name == color, orElse: () => TimetableColors.defaultColor)).color; } } diff --git a/lib/view/pages/timetable/customTimetableEventEditDialog.dart b/lib/view/pages/timetable/customTimetableEventEditDialog.dart index 4d925ce..c25fd82 100644 --- a/lib/view/pages/timetable/customTimetableEventEditDialog.dart +++ b/lib/view/pages/timetable/customTimetableEventEditDialog.dart @@ -4,7 +4,6 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:jiffy/jiffy.dart'; import 'package:marianum_mobile/extensions/dateTime.dart'; -import 'package:marianum_mobile/view/pages/timetable/custonTimetableColors.dart'; import 'package:provider/provider.dart'; import 'package:rrule_generator/rrule_generator.dart'; import 'package:time_range_picker/time_range_picker.dart'; @@ -17,6 +16,7 @@ import '../../../api/mhsl/customTimetableEvent/update/updateCustomTimetableEvent import '../../../model/accountData.dart'; import '../../../model/timetable/timetableProps.dart'; import '../../../widget/infoDialog.dart'; +import 'customTimetableColors.dart'; class CustomTimetableEventEditDialog extends StatefulWidget { final CustomTimetableEvent? existingEvent; @@ -35,7 +35,7 @@ class _AddCustomTimetableEventDialogState extends State element.name == widget.existingEvent?.color, - orElse: () => CustomTimetableColors.orange + orElse: () => TimetableColors.defaultColor ); late bool isEditingExisting = widget.existingEvent != null; diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index 415513f..c7068fb 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:marianum_mobile/extensions/dateTime.dart'; -import 'package:marianum_mobile/view/pages/timetable/custonTimetableColors.dart'; import 'package:provider/provider.dart'; import 'package:syncfusion_flutter_calendar/calendar.dart'; @@ -18,6 +17,7 @@ import '../../../widget/placeholderView.dart'; import 'appointmenetComponent.dart'; import 'appointmentDetails.dart'; import 'arbitraryAppointment.dart'; +import 'customTimetableColors.dart'; import 'customTimetableEventEditDialog.dart'; import 'timeRegionComponent.dart'; import 'timetableEvents.dart'; @@ -290,7 +290,7 @@ class _TimetableState extends State { location: customEvent.description, subject: customEvent.title, recurrenceRule: customEvent.rrule, - color: TimetableColors.getColorFromString(customEvent.color ?? CustomTimetableColors.orange.name), + color: TimetableColors.getColorFromString(customEvent.color ?? TimetableColors.defaultColor.name), startTimeZone: '', endTimeZone: '', );