Skip to content

Commit

Permalink
Fix repeated colors in schedule cards (#907)
Browse files Browse the repository at this point in the history
* Fix repeated colors and simplify to one palette

* [BOT] Applying version.

* Add palettes per theme (dark and light), also comment out teacher section in schedule popup

* Fix test

* Fix remove from original palette

* Add teacherName

---------

Co-authored-by: HugoMigner <[email protected]>
Co-authored-by: Xavier Paquet-Rapold <[email protected]>
Co-authored-by: Xavier Paquet-Rapold <[email protected]>
  • Loading branch information
4 people authored Apr 12, 2024
1 parent b2c70bd commit 59c16dd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
32 changes: 22 additions & 10 deletions lib/core/viewmodels/schedule_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
final Map<String, Color> courseColors = {};

/// The color palette corresponding to the schedule courses.
List<Color> schedulePaletteThemeLight =
AppTheme.schedulePaletteLight.toList();
List<Color> schedulePaletteTheme = [];

/// Get current locale
Locale? get locale => _settingsManager.locale;
Expand Down Expand Up @@ -98,12 +97,13 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
return events;
}

void handleViewChanged(DateTime date, EventController controller) {
void handleViewChanged(DateTime date, EventController controller,
List<Color> scheduleCardsPalette) {
controller.removeWhere((event) => true);
selectedDate = date;
var eventsToAdd = selectedMonthCalendarEvents();
var eventsToAdd = selectedMonthCalendarEvents(scheduleCardsPalette);
if (calendarFormat == CalendarFormat.week) {
eventsToAdd = selectedWeekCalendarEvents();
eventsToAdd = selectedWeekCalendarEvents(scheduleCardsPalette);
}
controller.addAll(eventsToAdd);
}
Expand Down Expand Up @@ -136,12 +136,18 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {

Color getCourseColor(String courseName) {
if (!courseColors.containsKey(courseName)) {
courseColors[courseName] = schedulePaletteThemeLight.removeLast();
courseColors[courseName] = schedulePaletteTheme.removeLast();
}
return courseColors[courseName] ?? Colors.red;
}

List<CalendarEventData> selectedWeekCalendarEvents() {
List<CalendarEventData> selectedWeekCalendarEvents(
List<Color> scheduleCardsPalette) {
if (scheduleCardsPalette.isNotEmpty) {
schedulePaletteTheme = scheduleCardsPalette;
} else {
schedulePaletteTheme = AppTheme.schedulePaletteLight.toList();
}
final List<CalendarEventData> events = [];
final firstDayOfWeek = Utils.getFirstDayOfCurrentWeek(selectedDate,
settings[PreferencesFlag.scheduleStartWeekday] as StartingDayOfWeek);
Expand All @@ -155,7 +161,13 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
return events;
}

List<CalendarEventData> selectedMonthCalendarEvents() {
List<CalendarEventData> selectedMonthCalendarEvents(
List<Color> scheduleCardsPalette) {
if (scheduleCardsPalette.isNotEmpty) {
schedulePaletteTheme = scheduleCardsPalette;
} else {
schedulePaletteTheme = AppTheme.schedulePaletteLight.toList();
}
final List<CalendarEventData> events = [];
final date = selectedDate.datesOfMonths();
for (int i = 0; i < daysInMonth; i++) {
Expand Down Expand Up @@ -198,9 +210,9 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {

if (_coursesActivities.isNotEmpty) {
if (calendarFormat == CalendarFormat.week) {
calendarEvents = selectedWeekCalendarEvents();
calendarEvents = selectedWeekCalendarEvents([]);
} else {
calendarEvents = selectedMonthCalendarEvents();
calendarEvents = selectedMonthCalendarEvents([]);
}
}
}
Expand Down
28 changes: 15 additions & 13 deletions lib/ui/utils/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ class AppTheme {
// Schedule color palettes
static const List<Color> schedulePaletteLight = [
Color(0xfff1c40f),
Color(0xff1abc9c),
Color(0xff2ecc71),
Color(0xff2ecc71),
Color(0xffe67e22),
Color(0xffe91e63),
Color(0xff16a085),
Color(0xff2ecc71),
Color(0xff3498db),
Color(0xff9b59b6),
Color(0xff34495e),
Color(0xffe67e22),
Color(0xffe74c3c)
Color(0xffe74c3c),
];

// schedulePaletteDark, same colors than schedulePaletteLight but darker
static const List<Color> schedulePaletteDark = [
Color(0xfff39c12),
Color(0xff16a085),
Color(0xff27ae60),
Color(0xff2ecc71),
Color(0xff2ecc71),
Color(0xff2980b9),
Color(0xff8e44ad),
Color(0xffb7950b),
Color(0xffa84300),
Color(0xffad1457),
Color(0xff0b5345),
Color(0xff1b5e20),
Color(0xff1e3a56),
Color(0xff6a1b9a),
Color(0xff2c3e50),
Color(0xffd35400),
Color(0xffc0392b)
Color(0xffa84300),
Color(0xff992d22),
];

/// Schedule calendar colors
Expand Down
31 changes: 20 additions & 11 deletions lib/ui/views/schedule_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,20 @@ class _ScheduleViewState extends State<ScheduleView>
final chevronColor = Theme.of(context).brightness == Brightness.light
? AppTheme.primaryDark
: AppTheme.lightThemeBackground;
final scheduleCardsPalette =
Theme.of(context).brightness == Brightness.light
? AppTheme.schedulePaletteLight.toList()
: AppTheme.schedulePaletteDark.toList();

model.handleViewChanged(DateTime.now(), eventController);
model.handleViewChanged(
DateTime.now(), eventController, scheduleCardsPalette);

if (model.calendarFormat == CalendarFormat.month) {
return _buildCalendarViewMonthly(
model, context, eventController, backgroundColor, chevronColor);
return _buildCalendarViewMonthly(model, context, eventController,
backgroundColor, chevronColor, scheduleCardsPalette);
}
return _buildCalendarViewWeekly(model, context, eventController,
backgroundColor, chevronColor, scheduleLineColor);
backgroundColor, chevronColor, scheduleLineColor, scheduleCardsPalette);
}

Widget _buildCalendarViewWeekly(
Expand All @@ -189,13 +194,15 @@ class _ScheduleViewState extends State<ScheduleView>
calendar_view.EventController eventController,
Color backgroundColor,
Color chevronColor,
Color scheduleLineColor) {
Color scheduleLineColor,
List<Color> scheduleCardsPalette) {
return Scaffold(
body: calendar_view.WeekView(
key: weekViewKey,
controller: eventController..addAll(model.selectedWeekCalendarEvents()),
onPageChange: (date, page) =>
model.handleViewChanged(date, eventController),
controller: eventController
..addAll(model.selectedWeekCalendarEvents(scheduleCardsPalette)),
onPageChange: (date, page) => model.handleViewChanged(
date, eventController, scheduleCardsPalette),
backgroundColor: backgroundColor,
headerStyle: calendar_view.HeaderStyle(
decoration: BoxDecoration(
Expand Down Expand Up @@ -259,15 +266,17 @@ class _ScheduleViewState extends State<ScheduleView>
BuildContext context,
calendar_view.EventController eventController,
Color backgroundColor,
Color chevronColor) {
Color chevronColor,
List<Color> scheduleCardsPalette) {
return Scaffold(
body: calendar_view.MonthView(
key: monthViewKey,
controller: eventController..addAll(model.selectedMonthCalendarEvents()),
controller: eventController
..addAll(model.selectedMonthCalendarEvents(scheduleCardsPalette)),
// to provide custom UI for month cells.
cellAspectRatio: 0.78,
onPageChange: (date, page) =>
model.handleViewChanged(date, eventController),
model.handleViewChanged(date, eventController, []),
headerStyle: calendar_view.HeaderStyle(
decoration: BoxDecoration(
color: backgroundColor,
Expand Down

0 comments on commit 59c16dd

Please sign in to comment.