Skip to content
Merged

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.2.1" apply false
id "com.android.application" version "8.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

Expand Down
1 change: 1 addition & 0 deletions assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"auto_complete_colors": "Auto Complete Colors",
"auto_complete_colors_description": "auto assigns colors from previously made subjects that have matching names",
"default_tb_view": "Default View",
"week_start_day": "Initial Day",
"view": "View",
"grid": "Grid",
"default_subject_duration": "Default Subject Duration",
Expand Down
1 change: 1 addition & 0 deletions assets/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"auto_complete_colors": "Saisie Automatique des Couleurs",
"auto_complete_colors_description": "attribue automatiquement les couleurs des matières créés précédemment qui portent des noms correspondants",
"default_tb_view": "Vue par défaut",
"week_start_day": "Jour initial",
"view": "Vue",
"grid": "Grille",
"default_subject_duration": "Durée par défaut d'une matière",
Expand Down
6 changes: 3 additions & 3 deletions lib/core/constants/basic_subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const basicSubject = Subject(
location: "",
color: Colors.black,
startTime: TimeOfDay(hour: 8, minute: 0),
endTime: TimeOfDay(hour: 18, minute: 0),
day: Days.monday,
rotationWeek: RotationWeeks.all,
endTime: TimeOfDay(hour: 9, minute: 0),
day: Day.sunday,
rotationWeek: RotationWeeks.none,
note: "",
timetable: "1",
);
34 changes: 14 additions & 20 deletions lib/core/constants/days.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
/// The week's days.
enum Days {
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday,
}
enum Day {
sunday('sunday', 7),
monday('monday', 1),
tuesday('tuesday', 2),
wednesday('wednesday', 3),
thursday('thursday', 4),
friday('friday', 5),
saturday('saturday', 6);

/// The week's days as a list of strings.
List<String> days = [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
];
final String name;
final int isoValue;
const Day(this.name, this.isoValue);

const List<Days> daysList = Days.values;
String get shortened => name.substring(0, 3);
String get initial => name[0];
}
8 changes: 0 additions & 8 deletions lib/core/constants/grid_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import 'package:timetable/features/settings/providers/settings.dart';
/// Width of the time column.
const double timeColumnWidth = 22.5;

/// Number of columns in the grid view of the timetable.
int columns(WidgetRef ref) {
final hideSunday = ref.watch(settingsProvider).hideSunday;

if (!hideSunday) return 7;
return 6;
}

/// Number of rows in the grid view based on the custom start time and custom end time (if customTimePeriod is true),
/// otherwise uses the default time period. (8:00 -> 18:00)
/// if hour difference is 0, there will be 24 rows
Expand Down
12 changes: 8 additions & 4 deletions lib/core/constants/rotation_weeks.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/// Basic Rotation Weeks definition.
enum RotationWeeks {
all,
none,
a,
b,
none("all"),
a("A"),
b("B");

final String name;
const RotationWeeks(this.name);

String get displayName => name == "all" ? "" : name;
}
9 changes: 6 additions & 3 deletions lib/core/constants/theme_options.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// Theme options.
enum ThemeOption {
dark,
light,
auto,
dark("dark"),
light("light"),
auto("system");

final String name;
const ThemeOption(this.name);
}
11 changes: 9 additions & 2 deletions lib/core/constants/timetable_views.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import 'package:easy_localization/easy_localization.dart';

/// Timetable Views
enum TbViews {
grid,
day,
grid("grid"),
day("day");

final String name;
const TbViews(this.name);

String get label => name.tr();
}
30 changes: 15 additions & 15 deletions lib/core/db/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/core/db/services/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Future<void> restoreData(
note: drift.Value(element["note"]),
color: Color(element["color"]),
rotationWeek: RotationWeeks.values[element["rotationWeek"]],
day: Days.values[element["day"]],
day: Day.values[element["day"]],
startTime: TimeOfDay(
hour: element["startTimeHour"],
minute: element["startTimeMinute"]),
Expand Down
2 changes: 1 addition & 1 deletion lib/core/db/tables/subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Subjects extends Table {
// to maintain the Color type instead of using int.
IntColumn get color => integer().map(const ColorConverter())();
IntColumn get rotationWeek => intEnum<RotationWeeks>()();
IntColumn get day => intEnum<Days>()();
IntColumn get day => intEnum<Day>()();
TextColumn get startTime => text().map(const TimeOfDayConverter())();
TextColumn get endTime => text().map(const TimeOfDayConverter())();
// added in v3
Expand Down
7 changes: 7 additions & 0 deletions lib/core/models/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Settings {
final TbViews defaultTimetableView;
final Color appThemeColor;
final Duration defaultSubjectDuration;
final int weekStartDay;

// settings defaults
Settings({
Expand All @@ -41,6 +42,7 @@ class Settings {
this.defaultTimetableView = TbViews.grid,
this.appThemeColor = Colors.deepPurple,
this.defaultSubjectDuration = const Duration(minutes: 60),
this.weekStartDay = 1,
});

Settings copyWith({
Expand All @@ -61,6 +63,7 @@ class Settings {
TbViews? defaultTimetableView,
Color? appThemeColor,
Duration? defaultSubjectDuration,
int? weekStartDay,
}) =>
Settings(
customTimePeriod: customTimePeriod ?? this.customTimePeriod,
Expand All @@ -82,6 +85,7 @@ class Settings {
appThemeColor: appThemeColor ?? this.appThemeColor,
defaultSubjectDuration:
defaultSubjectDuration ?? this.defaultSubjectDuration,
weekStartDay: weekStartDay ?? this.weekStartDay,
);

Map<String, dynamic> toJson() => {
Expand All @@ -104,6 +108,7 @@ class Settings {
'defaultTimetableView': defaultTimetableView.name,
'appThemeColorValue': appThemeColor.toInt(),
'defaultSubjectDuration': defaultSubjectDuration.inMinutes,
'weekStartDay': weekStartDay,
};

factory Settings.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -147,6 +152,8 @@ class Settings {
defaultSubjectDuration: json['defaultSubjectDuration'] != null
? Duration(minutes: json['defaultSubjectDuration'] as int)
: null,
weekStartDay:
json['weekStartDay'] != null ? json['weekStartDay'] as int : null,
);
}
}
45 changes: 45 additions & 0 deletions lib/core/services/day.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/core/constants/days.dart';
import 'package:timetable/features/settings/providers/settings.dart';

/// Service to provide the current day's index and ordered days.
class DaysService {
const DaysService(this.ref);
final Ref ref;

List<Day> get orderedDays {
final settings = ref.watch(settingsProvider);
var days = Day.values;

var rotatedDays = [
...days.sublist(settings.weekStartDay),
...days.sublist(0, settings.weekStartDay),
];

if (settings.hideSunday) {
rotatedDays = rotatedDays.where((day) => day != Day.sunday).toList();
}

return rotatedDays;
}

int get currentDayIndex {
final settings = ref.watch(settingsProvider);
final now = DateTime.now();
final currentIsoWeekday = now.weekday;

var dayIndex = currentIsoWeekday - 1;

dayIndex = (dayIndex - settings.weekStartDay) % Day.values.length;
if (dayIndex < 0) dayIndex += Day.values.length;

if (settings.hideSunday) {
if (currentIsoWeekday == 7) return -1;
if (currentIsoWeekday > settings.weekStartDay) {
dayIndex -= 1;
}
}

return dayIndex;
}
}
File renamed without changes.
7 changes: 5 additions & 2 deletions lib/core/utils/overlapping_subjects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ void filterOverlappingSubjectsByRotationWeeks(
return e.rotationWeek == RotationWeeks.b;
case RotationWeeks.b:
return e.rotationWeek == RotationWeeks.a;
case RotationWeeks.all:
return false;
case RotationWeeks.none:
return false;
}
Expand Down Expand Up @@ -141,3 +139,8 @@ List<List<Subject>> findOverlappingSubjects(List<Subject> subjects) {

return overlappingSubjects.where((e) => e.length > 1).toList();
}

/// checks if 2 subjects overlap in hours
bool overlaps(Subject a, Subject b) {
return a.startTime.hour < b.endTime.hour && b.startTime.hour < a.endTime.hour;
}
Loading