Skip to content

Commit

Permalink
Merge branch 'develop' into ui/exam_card
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana authored Oct 16, 2024
2 parents a0cd2a6 + e7e3f55 commit b0f5f01
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 317 deletions.
2 changes: 1 addition & 1 deletion packages/uni_app/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-beta.14+314
1.10.0-beta.25+328
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class NotificationManager {
_localNotificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!;
try {
final permissionGranted = await androidPlugin.requestPermission();
final permissionGranted =
await androidPlugin.requestNotificationsPermission();
if (permissionGranted != true) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,35 @@ class ScheduleFetcherNewApi extends ScheduleFetcher {
/// Fetches the user's lectures from the schedule's HTML page.
@override
Future<List<Lecture>> getLectures(Session session) async {
final endpoints = getEndpoints(session);
final url = getEndpoints(session)[0];
final lectiveYear = getLectiveYear(DateTime.now());

final futures = endpoints.map((baseUrl) async {
final scheduleResponse = await NetworkRouter.getWithCookies(
baseUrl,
{
'pv_num_unico': session.username,
'pv_ano_lectivo': lectiveYear.toString(),
'pv_periodos': '1',
},
session,
);
final scheduleResponse = await NetworkRouter.getWithCookies(
url,
{
'pv_num_unico': session.username,
'pv_ano_lectivo': lectiveYear.toString(),
'pv_periodos': '1',
},
session,
);

final scheduleApiUrl = getScheduleApiUrlFromHtml(scheduleResponse);
final scheduleApiUrl = getScheduleApiUrlFromHtml(scheduleResponse);

if (scheduleApiUrl == null) {
return <Lecture>[];
}
if (scheduleApiUrl == null) {
return <Lecture>[];
}

final scheduleApiResponse = await NetworkRouter.getWithCookies(
scheduleApiUrl,
{},
session,
);
final scheduleApiResponse = await NetworkRouter.getWithCookies(
scheduleApiUrl,
{},
session,
);

return getLecturesFromApiResponse(scheduleApiResponse);
});

final results = await Future.wait(futures);
final results = getLecturesFromApiResponse(scheduleApiResponse);

// TODO(limwa,#1281): Check if handling of lectures in both faculties is correct.
final lectures = results.expand((element) => element).toList()
..sort((l1, l2) => l1.compare(l2));
final lectures = results..sort((l1, l2) => l1.compare(l2));

return lectures;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PreferencesController {
static const String _favoriteRestaurants = 'favorite_restaurants';
static const String _filteredExamsTypes = 'filtered_exam_types';
static final List<String> _defaultFilteredExamTypes = Exam.displayedTypes;
static const String _semesterValue = 'semester_value';
static const String _schoolYearValue = 'school_year_value';

static final _statsToggleStreamController =
StreamController<bool>.broadcast();
Expand Down Expand Up @@ -261,4 +263,26 @@ class PreferencesController {
await prefs.setBool(_usageStatsToggleKey, value);
_statsToggleStreamController.add(value);
}

static Future<void> setSemesterValue(String? value) async {
await prefs.setString(_semesterValue, value ?? '');
if (value == null) {
await prefs.remove(_semesterValue);
}
}

static String? getSemesterValue() {
return prefs.getString(_semesterValue);
}

static Future<void> setSchoolYearValue(String? value) async {
await prefs.setString(_schoolYearValue, value ?? '');
if (value == null) {
await prefs.remove(_schoolYearValue);
}
}

static String? getSchoolYearValue() {
return prefs.getString(_schoolYearValue);
}
}
27 changes: 16 additions & 11 deletions packages/uni_app/lib/controller/parsers/parser_restaurants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:uni/model/entities/meal.dart';
import 'package:uni/model/entities/restaurant.dart';
import 'package:uni/model/utils/day_of_week.dart';

// ignore_for_file: avoid_dynamic_calls

/// Reads restaurants's menu from /feup/pt/CANTINA.EMENTASHOW
List<Restaurant> getRestaurantsFromHtml(Response response) {
final document = parse(response.body);
Expand Down Expand Up @@ -93,23 +91,30 @@ Restaurant getRestaurantFromGSheets(
response.body.indexOf('(') + 1,
response.body.lastIndexOf(')'),
);
final parsedJson = jsonDecode(jsonString);
final parsedJson = jsonDecode(jsonString) as Map<String, dynamic>;

final mealsList = <Meal>[];

final format = DateFormat('d/M/y');
for (final row in parsedJson['table']['rows'] as List<dynamic>) {
final cellList = row['c'];
if ((cellList[1]['v'] == 'Almoço' && isDinner) ||
(cellList[1]['v'] != 'Almoço' && !isDinner)) {

final table = parsedJson['table'] as Map<String, dynamic>;
final rows = table['rows'] as List<dynamic>;

for (final row in rows) {
final cellList = (row as Map<String, dynamic>)['c'] as List<dynamic>;
if (((cellList[1] as Map<String, dynamic>)['v'] == 'Almoço' && isDinner) ||
((cellList[1] as Map<String, dynamic>)['v'] != 'Almoço' && !isDinner)) {
continue;
}

final meal = Meal(
cellList[2]['v'] as String,
cellList[3]['v'] as String,
DayOfWeek.values[format.parseUtc(cellList[0]['f'] as String).weekday - 1],
format.parseUtc(cellList[0]['f'] as String),
(cellList[2] as Map<String, dynamic>)['v'] as String,
(cellList[3] as Map<String, dynamic>)['v'] as String,
DayOfWeek.values[format
.parseUtc((cellList[0] as Map<String, dynamic>)['f'] as String)
.weekday -
1],
format.parseUtc((cellList[0] as Map<String, dynamic>)['f'] as String),
);
mealsList.add(meal);
}
Expand Down
191 changes: 98 additions & 93 deletions packages/uni_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import 'package:uni/view/settings/settings.dart';
import 'package:uni/view/theme.dart';
import 'package:uni/view/theme_notifier.dart';
import 'package:uni/view/transports/transports.dart';
import 'package:upgrader/upgrader.dart';
import 'package:workmanager/workmanager.dart';

SentryEvent? beforeSend(SentryEvent event) {
Expand Down Expand Up @@ -217,100 +218,104 @@ class ApplicationState extends State<Application> {
DeviceOrientation.portraitUp,
]);
return Consumer2<ThemeNotifier, LocaleNotifier>(
builder: (context, themeNotifier, localeNotifier, _) => MaterialApp(
title: 'uni',
builder: (context, themeNotifier, localeNotifier, _) => UpgradeAlert(
navigatorKey: Application.navigatorKey,
theme: applicationLightTheme,
darkTheme: applicationDarkTheme,
themeMode: themeNotifier.getTheme(),
locale: localeNotifier.getLocale().localeCode,
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
initialRoute: widget.initialRoute,
navigatorObservers: navigatorObservers,
onGenerateRoute: (settings) {
final transitions = {
'/${NavigationItem.navLogin.route}':
PageTransition.makePageTransition(
page: const LoginPageView(),
settings: settings,
),
'/${NavigationItem.navPersonalArea.route}':
PageTransition.makePageTransition(
page: const HomePageView(),
settings: settings,
),
'/${NavigationItem.navSchedule.route}':
PageTransition.makePageTransition(
page: SchedulePage(),
settings: settings,
),
'/${NavigationItem.navExams.route}':
PageTransition.makePageTransition(
page: const ExamsPageView(),
settings: settings,
),
'/${NavigationItem.navStops.route}':
PageTransition.makePageTransition(
page: const BusStopNextArrivalsPage(),
settings: settings,
),
'/${NavigationItem.navCourseUnits.route}':
PageTransition.makePageTransition(
page: const CourseUnitsPageView(),
settings: settings,
),
'/${NavigationItem.navLocations.route}':
PageTransition.makePageTransition(
page: const LocationsPage(),
settings: settings,
),
'/${NavigationItem.navRestaurants.route}':
PageTransition.makePageTransition(
page: const RestaurantPageView(),
settings: settings,
),
'/${NavigationItem.navCalendar.route}':
PageTransition.makePageTransition(
page: const CalendarPageView(),
settings: settings,
),
'/${NavigationItem.navLibrary.route}':
PageTransition.makePageTransition(
page: const LibraryPage(),
settings: settings,
),
'/${NavigationItem.navFaculty.route}':
PageTransition.makePageTransition(
page: const FacultyPageView(),
settings: settings,
),
'/${NavigationItem.navAcademicPath.route}':
PageTransition.makePageTransition(
page: const AcademicPathPageView(),
settings: settings,
),
'/${NavigationItem.navTransports.route}':
PageTransition.makePageTransition(
page: const TransportsPageView(),
settings: settings,
),
'/${NavigationItem.navProfile.route}':
MaterialPageRoute<ProfilePageView>(
builder: (__) => const ProfilePageView(),
),
'/${NavigationItem.navSettings.route}':
MaterialPageRoute<SettingsPage>(
builder: (_) => const SettingsPage(),
),
};
return transitions[settings.name];
},
showIgnore: false,
child: MaterialApp(
title: 'uni',
navigatorKey: Application.navigatorKey,
theme: applicationLightTheme,
darkTheme: applicationDarkTheme,
themeMode: themeNotifier.getTheme(),
locale: localeNotifier.getLocale().localeCode,
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
initialRoute: widget.initialRoute,
navigatorObservers: navigatorObservers,
onGenerateRoute: (settings) {
final transitions = {
'/${NavigationItem.navLogin.route}':
PageTransition.makePageTransition(
page: const LoginPageView(),
settings: settings,
),
'/${NavigationItem.navPersonalArea.route}':
PageTransition.makePageTransition(
page: const HomePageView(),
settings: settings,
),
'/${NavigationItem.navSchedule.route}':
PageTransition.makePageTransition(
page: SchedulePage(),
settings: settings,
),
'/${NavigationItem.navExams.route}':
PageTransition.makePageTransition(
page: const ExamsPageView(),
settings: settings,
),
'/${NavigationItem.navStops.route}':
PageTransition.makePageTransition(
page: const BusStopNextArrivalsPage(),
settings: settings,
),
'/${NavigationItem.navCourseUnits.route}':
PageTransition.makePageTransition(
page: const CourseUnitsPageView(),
settings: settings,
),
'/${NavigationItem.navLocations.route}':
PageTransition.makePageTransition(
page: const LocationsPage(),
settings: settings,
),
'/${NavigationItem.navRestaurants.route}':
PageTransition.makePageTransition(
page: const RestaurantPageView(),
settings: settings,
),
'/${NavigationItem.navCalendar.route}':
PageTransition.makePageTransition(
page: const CalendarPageView(),
settings: settings,
),
'/${NavigationItem.navLibrary.route}':
PageTransition.makePageTransition(
page: const LibraryPage(),
settings: settings,
),
'/${NavigationItem.navFaculty.route}':
PageTransition.makePageTransition(
page: const FacultyPageView(),
settings: settings,
),
'/${NavigationItem.navAcademicPath.route}':
PageTransition.makePageTransition(
page: const AcademicPathPageView(),
settings: settings,
),
'/${NavigationItem.navTransports.route}':
PageTransition.makePageTransition(
page: const TransportsPageView(),
settings: settings,
),
'/${NavigationItem.navProfile.route}':
MaterialPageRoute<ProfilePageView>(
builder: (__) => const ProfilePageView(),
),
'/${NavigationItem.navSettings.route}':
MaterialPageRoute<SettingsPage>(
builder: (_) => const SettingsPage(),
),
};
return transitions[settings.name];
},
),
),
);
}
Expand Down
Loading

0 comments on commit b0f5f01

Please sign in to comment.