Skip to content

Commit

Permalink
Changing uc link to open in app page (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Feb 29, 2024
2 parents a219124 + 2d0c6c2 commit fc08b02
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 41 deletions.
13 changes: 6 additions & 7 deletions uni/lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';
Expand All @@ -21,8 +20,8 @@ import 'messages_pt_PT.dart' as messages_pt_pt;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new SynchronousFuture(null),
'pt_PT': () => new SynchronousFuture(null),
'en': () => new Future.value(null),
'pt_PT': () => new Future.value(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
Expand All @@ -37,18 +36,18 @@ MessageLookupByLibrary? _findExact(String localeName) {
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) {
Future<bool> initializeMessages(String localeName) async {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new SynchronousFuture(false);
return new Future.value(false);
}
var lib = _deferredLibraries[availableLocale];
lib == null ? new SynchronousFuture(false) : lib();
await (lib == null ? new Future.value(false) : lib());
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new SynchronousFuture(true);
return new Future.value(true);
}

bool _messagesExistFor(String locale) {
Expand Down
12 changes: 6 additions & 6 deletions uni/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -20,12 +19,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static String m0(time) => "last refresh at ${time}";
static m0(time) => "last refresh at ${time}";

static String m1(time) =>
static m1(time) =>
"${Intl.plural(time, zero: 'Refreshed ${time} minutes ago', one: 'Refreshed ${time} minute ago', other: 'Refreshed ${time} minutes ago')}";

static String m2(title) => "${Intl.select(title, {
static m2(title) => "${Intl.select(title, {
'horario': 'Schedule',
'exames': 'Exams',
'area': 'Personal Area',
Expand All @@ -42,7 +41,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
static _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("About us"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Academic services"),
Expand Down Expand Up @@ -276,6 +275,7 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Terms and Conditions"),
"theme": MessageLookupByLibrary.simpleMessage("Theme"),
"title": MessageLookupByLibrary.simpleMessage("Title"),
"uc_info": MessageLookupByLibrary.simpleMessage("Open UC page in app"),
"unavailable": MessageLookupByLibrary.simpleMessage("Unavailable"),
"valid_email":
MessageLookupByLibrary.simpleMessage("Please enter a valid email"),
Expand Down
13 changes: 7 additions & 6 deletions uni/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -20,12 +19,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt_PT';

static String m0(time) => "última atualização às ${time}";
static m0(time) => "última atualização às ${time}";

static String m1(time) =>
static m1(time) =>
"${Intl.plural(time, zero: 'Atualizado há ${time} minutos', one: 'Atualizado há ${time} minuto', other: 'Atualizado há ${time} minutos')}";

static String m2(title) => "${Intl.select(title, {
static m2(title) => "${Intl.select(title, {
'horario': 'Horário',
'exames': 'Exames',
'area': 'Área Pessoal',
Expand All @@ -42,7 +41,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
static _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("Sobre nós"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Serviços académicos"),
Expand Down Expand Up @@ -278,6 +277,8 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Termos e Condições"),
"theme": MessageLookupByLibrary.simpleMessage("Tema"),
"title": MessageLookupByLibrary.simpleMessage("Título"),
"uc_info":
MessageLookupByLibrary.simpleMessage("Abrir página da UC na app"),
"unavailable": MessageLookupByLibrary.simpleMessage("Indisponível"),
"valid_email": MessageLookupByLibrary.simpleMessage(
"Por favor insere um email válido"),
Expand Down
12 changes: 11 additions & 1 deletion uni/lib/generated/l10n.dart

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

2 changes: 2 additions & 0 deletions uni/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@
"@terms": {},
"title": "Title",
"@title": {},
"uc_info": "Open UC page",
"@uc_info": {},
"unavailable": "Unavailable",
"@unavailable": {},
"valid_email": "Please enter a valid email",
Expand Down
2 changes: 2 additions & 0 deletions uni/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@
"@terms": {},
"title": "Título",
"@title": {},
"uc_info": "Abrir página da UC",
"@uc_info": {},
"unavailable": "Indisponível",
"@unavailable": {},
"valid_email": "Por favor insere um email válido",
Expand Down
52 changes: 35 additions & 17 deletions uni/lib/view/schedule/widgets/schedule_slot.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/networking/url_launcher.dart';
import 'package:provider/provider.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/providers/startup/profile_provider.dart';
import 'package:uni/view/common_widgets/row_container.dart';
import 'package:uni/view/course_unit_info/course_unit_info.dart';

class ScheduleSlot extends StatelessWidget {
const ScheduleSlot({
Expand All @@ -16,6 +20,7 @@ class ScheduleSlot extends StatelessWidget {
this.classNumber,
super.key,
});

final String subject;
final String rooms;
final DateTime begin;
Expand Down Expand Up @@ -68,6 +73,8 @@ class ScheduleSlot extends StatelessWidget {
rooms,
style: Theme.of(context).textTheme.bodyMedium,
);
final courseUnit = _correspondingCourseUnit(context);

return [
ScheduleTimeWidget(
begin: DateFormat('HH:mm').format(begin),
Expand All @@ -80,9 +87,10 @@ class ScheduleSlot extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SubjectButtonWidget(
occurrId: occurrId,
),
if (courseUnit != null)
SubjectButtonWidget(
courseUnit: courseUnit,
),
subjectTextField,
typeClassTextField,
],
Expand All @@ -100,21 +108,27 @@ class ScheduleSlot extends StatelessWidget {
roomTextField,
];
}

CourseUnit? _correspondingCourseUnit(BuildContext context) {
final courseUnits = context.read<ProfileProvider>().state!.courseUnits;
return courseUnits.firstWhereOrNull(
(courseUnit) => courseUnit.occurrId == occurrId,
);
}
}

class SubjectButtonWidget extends StatelessWidget {
const SubjectButtonWidget({required this.occurrId, super.key});
final int occurrId;
const SubjectButtonWidget({required this.courseUnit, super.key});

String toUcLink(int occurrId) {
const faculty = 'feup'; // should not be hardcoded
return '${NetworkRouter.getBaseUrl(faculty)}'
'UCURR_GERAL.FICHA_UC_VIEW?pv_ocorrencia_id=$occurrId';
}
final CourseUnit courseUnit;

Future<void> _launchURL(BuildContext context) async {
final url = toUcLink(occurrId);
await launchUrlWithToast(context, url);
void _launchUcPage(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute<CourseUnitDetailPageView>(
builder: (context) => CourseUnitDetailPageView(courseUnit),
),
);
}

@override
Expand All @@ -131,8 +145,8 @@ class SubjectButtonWidget extends StatelessWidget {
iconSize: 18,
color: Colors.grey,
alignment: Alignment.centerRight,
tooltip: 'Abrir página da UC no browser',
onPressed: () => _launchURL(context),
tooltip: S.of(context).uc_info,
onPressed: () => _launchUcPage(context),
),
],
);
Expand All @@ -145,6 +159,7 @@ class ScheduleTeacherClassInfoWidget extends StatelessWidget {
this.classNumber,
super.key,
});

final String? classNumber;
final String teacher;

Expand All @@ -160,6 +175,7 @@ class ScheduleTeacherClassInfoWidget extends StatelessWidget {

class ScheduleTimeWidget extends StatelessWidget {
const ScheduleTimeWidget({required this.begin, required this.end, super.key});

final String begin;
final String end;

Expand All @@ -181,6 +197,7 @@ class ScheduleTimeTextField extends StatelessWidget {
required this.context,
super.key,
});

final String time;
final BuildContext context;

Expand All @@ -201,6 +218,7 @@ class TextFieldWidget extends StatelessWidget {
required this.alignment,
super.key,
});

final String text;
final TextStyle? style;
final TextAlign alignment;
Expand Down
5 changes: 5 additions & 0 deletions uni/test/test_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/app_locale.dart';
import 'package:uni/model/entities/profile.dart';
import 'package:uni/model/providers/startup/profile_provider.dart';
import 'package:uni/view/locale_notifier.dart';

Future<void> initTestEnvironment() async {
Expand All @@ -23,6 +25,9 @@ Widget testableWidget(
ChangeNotifierProvider<LocaleNotifier>(
create: (_) => LocaleNotifier(AppLocale.pt),
),
ChangeNotifierProvider(
create: (_) => ProfileProvider()..setState(Profile()),
),
...providers,
],
child: _wrapWidget(widget),
Expand Down
10 changes: 6 additions & 4 deletions uni/test/unit/view/Pages/exams_page_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void main() async {
final providers = [ChangeNotifierProvider(create: (_) => examProvider)];

await tester.pumpWidget(testableWidget(widget, providers: providers));
await tester.pump();
await tester.pumpAndSettle();

debugDumpApp();

expect(find.byKey(Key(firstExam.toString())), findsOneWidget);
expect(find.byKey(Key('$firstExam-exam')), findsOneWidget);
Expand Down Expand Up @@ -93,7 +95,7 @@ void main() async {
final providers = [ChangeNotifierProvider(create: (_) => examProvider)];

await tester.pumpWidget(testableWidget(widget, providers: providers));
await tester.pump();
await tester.pumpAndSettle();

expect(
find.byKey(Key(examList.map((ex) => ex.toString()).join())),
Expand Down Expand Up @@ -139,7 +141,7 @@ void main() async {
final providers = [ChangeNotifierProvider(create: (_) => examProvider)];

await tester.pumpWidget(testableWidget(widget, providers: providers));
await tester.pump();
await tester.pumpAndSettle();

expect(find.byKey(Key(firstExam.toString())), findsOneWidget);
expect(find.byKey(Key(secondExam.toString())), findsOneWidget);
Expand Down Expand Up @@ -208,7 +210,7 @@ void main() async {
final providers = [ChangeNotifierProvider(create: (_) => examProvider)];

await tester.pumpWidget(testableWidget(widget, providers: providers));
await tester.pump();
await tester.pumpAndSettle();

expect(find.byKey(Key(firstDayKey)), findsOneWidget);
expect(find.byKey(Key(secondDayKey)), findsOneWidget);
Expand Down

0 comments on commit fc08b02

Please sign in to comment.