Skip to content

Commit

Permalink
bunch of project structure improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
user5522 committed Dec 23, 2023
1 parent 816b91a commit 8551669
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 240 deletions.
2 changes: 1 addition & 1 deletion lib/components/settings/customize_timetable.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// All the settings that allow for customizing the timetable.
class CustomizeTimetableOptions extends ConsumerWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Screen to manage the period of the timetable.
/// Changes the start time and end time of the timetable.
Expand Down
4 changes: 2 additions & 2 deletions lib/components/settings/timetable_features.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/components/settings/screens/timetable_period_screen.dart';

/// All the settings for changing some timetable features.
Expand All @@ -27,7 +27,7 @@ class TimetableFeaturesOptions extends ConsumerWidget {
),
);
},
title: const Text("Time Period Config"),
title: const Text("Time Period Configuration"),
),
SwitchListTile(
title: const Text("Rotation Weeks"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:timetable/components/subject_management/subject_configs/time_con
import 'package:timetable/components/widgets/list_tile_group.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Day, Time & Rotation Week config part of the Subject creation screen.
class TimeDayRotationWeekConfig extends ConsumerWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:timetable/components/widgets/bottom_sheets/rotation_week_modal_bottom_sheet.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';

/// Rotation Week config part of the Subject creation screen.
class RotationWeekConfig extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Time config part of the Subject creation screen.
class TimeConfig extends ConsumerWidget {
Expand Down
4 changes: 2 additions & 2 deletions lib/components/subject_management/subject_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:timetable/constants/basic_subject.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/models/overlapping_subjects.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/overlapping_subjects.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/provider/subjects.dart';

/// The Subject creation/modification screen.
Expand Down
1 change: 1 addition & 0 deletions lib/components/timetable_views/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:timetable/components/widgets/day_view_subject_builder.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/constants/grid_properties.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';
import 'package:timetable/db/database.dart';

/// Timetable view that shows each day's subjects in a single screen.
Expand Down
113 changes: 47 additions & 66 deletions lib/components/timetable_views/grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import 'package:timetable/components/widgets/grid_view_overlapping_subjects_buil
import 'package:timetable/components/widgets/time_column.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/constants/grid_properties.dart';
import 'package:timetable/helpers/overlapping_subjects.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/models/overlapping_subjects.dart';
import 'package:timetable/provider/overlapping_subjects.dart';
import 'package:timetable/components/widgets/grid_view_subject_builder.dart';
import 'package:timetable/components/widgets/subject_container_builder.dart';
import 'package:timetable/components/widgets/tile.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/helpers/rotation_weeks.dart';
import 'package:timetable/provider/settings.dart';

/// Timetable view that shows All the days' subjects in a grid form.
class TimetableGridView extends HookConsumerWidget {
Expand Down Expand Up @@ -92,6 +94,7 @@ class TimetableGridView extends HookConsumerWidget {
final overlappingSubjects = ref.watch(overlappingSubjectsProvider);
final customStartTime = ref.watch(settingsProvider).customStartTime;

// subjects' containers
final List<List<Tile?>> grid = List.generate(
totalDays,
(columnIndex) => List.generate(
Expand All @@ -105,85 +108,63 @@ class TimetableGridView extends HookConsumerWidget {
),
);

// overlapping subjects
for (int j = 0; j < subjects.length; j++) {
for (int i = 0; i < subjects.length; i++) {
if (i != j) {
final bool sameDay = (subjects[i].day.index == subjects[j].day.index);
final bool subjectsInSameDay = (subjects[i].day == subjects[j].day);
final bool subjectsOverlapInTime =
((subjects[i].startTime.hour <= subjects[j].startTime.hour &&
subjects[i].endTime.hour > subjects[j].startTime.hour) ||
(subjects[j].startTime.hour <= subjects[i].startTime.hour &&
subjects[j].endTime.hour > subjects[i].startTime.hour));

if (sameDay && subjectsOverlapInTime) {
if (subjectsInSameDay && subjectsOverlapInTime) {
overlappingSubjects.add([subjects[i], subjects[j]]);
}

if (overlappingSubjects.isNotEmpty &&
overlappingSubjects.any((e) => e.length == 2)) {
overlappingSubjects.removeWhere(
(elem) => elem.any(
(e) {
if (rotationWeek.value == RotationWeeks.a) {
return e.rotationWeek == RotationWeeks.b;
} else if (rotationWeek.value == RotationWeeks.b) {
return e.rotationWeek == RotationWeeks.a;
} else {
return false;
}
},
),
);

for (final subjects in overlappingSubjects) {
SubjectData getSubjectWithEarlierStartTime() {
if (subjects[0].startTime.hour < subjects[1].startTime.hour) {
return subjects[0];
} else {
return subjects[1];
}
}

SubjectData getSubjectWithLaterEndTime() {
if (subjects[0].endTime.hour > subjects[1].endTime.hour) {
return subjects[0];
} else {
return subjects[1];
}
}

var day = subjects[0].day.index;
var earlierStartTimeHour =
getSubjectWithEarlierStartTime().startTime.hour;
var laterEndTimeHour = getSubjectWithLaterEndTime().endTime.hour;
var start = getSubjectWithEarlierStartTime().startTime.hour -
getCustomStartTime(customStartTime, ref).hour;
var end = getSubjectWithLaterEndTime().endTime.hour -
getCustomStartTime(customStartTime, ref).hour;
var column = grid[day];

column.replaceRange(
start,
end,
List.generate(end - start, (_) => null),
);

column[start] = Tile(
height: end - start,
child: OverlappingSubjBuilder(
subjects: subjects,
earlierStartTimeHour: earlierStartTimeHour,
laterEndTimeHour: laterEndTimeHour,
),
);
}
}
}
}
}

for (final subject in subjects.where(
(e) => !overlappingSubjects.any((elem) => elem.contains(e)),
if (overlappingSubjects.isNotEmpty &&
overlappingSubjects.any((e) => e.length == 2)) {
getFilteredByRotationWeeksOverlappingSubjects(
overlappingSubjects,
rotationWeek,
);
}

for (final subjects in overlappingSubjects) {
var day = subjects[0].day.index;
var earlierStartTimeHour = getEarliestSubject(subjects).startTime.hour;
var laterEndTimeHour = getLatestSubject(subjects).endTime.hour;

var startTime = getEarliestSubject(subjects).startTime.hour -
getCustomStartTime(customStartTime, ref).hour;
var endTime = getLatestSubject(subjects).endTime.hour -
getCustomStartTime(customStartTime, ref).hour;
var column = grid[day];

column.replaceRange(
startTime,
endTime,
List.generate(endTime - startTime, (_) => null),
);

column[startTime] = Tile(
height: endTime - startTime,
child: OverlappingSubjBuilder(
subjects: subjects,
earlierStartTimeHour: earlierStartTimeHour,
laterEndTimeHour: laterEndTimeHour,
),
);
}

// normal subjects
for (final subject in filterOverlappingSubjects(
subjects,
overlappingSubjects,
)) {
var day = subject.day.index;
var start = subject.startTime.hour -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';

/// Bottom Sheet Modal Widget used to select a subject's rotation week.
class RotationWeekModalBottomSheet extends StatelessWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/widgets/day_view_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Top navigation bar in the day view that allows to switch between days quickly.
class DayViewNavigationBar extends ConsumerWidget {
Expand Down
4 changes: 2 additions & 2 deletions lib/components/widgets/day_view_subject_builder.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/components/subject_management/subject_screen.dart';

/// Subject builder for the day view.
Expand Down
2 changes: 1 addition & 1 deletion lib/components/widgets/days_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/constants/grid_properties.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Widget that appears at the top of the timetable grid view screen and shows the week's days.
class DaysRow extends ConsumerWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:non_uniform_border/non_uniform_border.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/constants/grid_properties.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/components/subject_management/subject_screen.dart';

/// Overlapping Subjects Builder for the grid view.
Expand Down
4 changes: 2 additions & 2 deletions lib/components/widgets/grid_view_subject_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:non_uniform_border/non_uniform_border.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/components/subject_management/subject_screen.dart';
import 'package:timetable/constants/grid_properties.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/components/widgets/navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';
import 'package:timetable/screens/settings_screen.dart';
import 'package:timetable/screens/timetable_screen.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/components/widgets/navigation_bar_toggle.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Toggles the navbar.
class NavbarToggle extends HookConsumerWidget {
Expand Down
1 change: 1 addition & 0 deletions lib/components/widgets/rotation_week_toggle.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/helpers/rotation_weeks.dart';

/// Toggles between all rotation weeks.
class RotationWeekToggle extends HookWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/widgets/time_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/grid_properties.dart';
import 'package:timetable/constants/time.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Widget that appears at the left side of the timetable grid view screen and shows the timetable time period.
class TimeColumn extends ConsumerWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/custom_times.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Returns the custom start time set by the user if customTimePeriod is true,
/// otherwise returns the default start time. (8:00)
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/grid_properties.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/models/settings.dart';
import 'package:timetable/provider/settings.dart';

/// Width of the time column.
const double timeColumnWidth = 22.5;
Expand Down
Loading

0 comments on commit 8551669

Please sign in to comment.