Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/request-dep-widget-bus-stop-card
Browse files Browse the repository at this point in the history
  • Loading branch information
rubuy-74 authored Sep 21, 2023
2 parents a1752e9 + 6e3ec96 commit 01be81f
Show file tree
Hide file tree
Showing 78 changed files with 3,153 additions and 409 deletions.
10 changes: 10 additions & 0 deletions uni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ But you can also watch for changes in `.dart` files and automatically run the `b
dart run build_runner watch
```

## Translation files

Intl package allows the internationalization of the app, currently supporting Portuguese ('pt_PT') and English ('en_EN). This package creates `.arb` files (one for each language), mapping a key to the correspondent translated string.
In order to access those translations through getters, you must add the translations you want to the `.arb` files and run:
```
dart pub global run intl_utils:generate
```
This will generate `.dart` files with the getters you need to access the translations.
You must include `'package:uni/generated/l10n.dart'` and, depending on the locale of the application, `S.of(context).{key_of_translation}` will get you the translated string.

## Project structure

### Overview
Expand Down
1 change: 1 addition & 0 deletions uni/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ analyzer:
exclude:
- "**.g.dart"
- "**.mocks.dart"
- "**generated/**"

# Custom linter rules. A list of all rules can be found at
# https://dart-lang.github.io/linter/lints/options/options.html
Expand Down
2 changes: 1 addition & 1 deletion uni/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.62+180
1.5.64+182
3 changes: 2 additions & 1 deletion uni/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -204,6 +204,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
19 changes: 19 additions & 0 deletions uni/lib/controller/local_storage/app_shared_preferences.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';
import 'dart:io';

import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';
import 'package:uni/model/entities/app_locale.dart';
import 'package:uni/model/entities/exam.dart';
import 'package:uni/utils/favorite_widget_type.dart';

Expand All @@ -21,6 +23,7 @@ class AppSharedPreferences {
static const String tuitionNotificationsToggleKey =
'tuition_notification_toogle';
static const String themeMode = 'theme_mode';
static const String locale = 'app_locale';
static const int keyLength = 32;
static const int ivLength = 16;
static final iv = encrypt.IV.fromLength(ivLength);
Expand Down Expand Up @@ -117,6 +120,22 @@ class AppSharedPreferences {
return prefs.setInt(themeMode, (themeIndex + 1) % 3);
}

static Future<void> setLocale(AppLocale appLocale) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(locale, appLocale.name);
}

static Future<AppLocale> getLocale() async {
final prefs = await SharedPreferences.getInstance();
final appLocale =
prefs.getString(locale) ?? Platform.localeName.substring(0, 2);

return AppLocale.values.firstWhere(
(e) => e.toString() == 'AppLocale.$appLocale',
orElse: () => AppLocale.en,
);
}

/// Deletes the user's student number and password.
static Future<void> removePersistentUserInfo() async {
final prefs = await SharedPreferences.getInstance();
Expand Down
45 changes: 22 additions & 23 deletions uni/lib/controller/parsers/parser_course_units.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,36 @@ List<CourseUnit> parseCourseUnitsAndCourseAverage(
final codeName = row.children[2].children[0].innerHtml;
final name = row.children[3].children[0].innerHtml;
final ects = row.children[5].innerHtml.replaceAll(',', '.');
String? grade;
String? status;

var yearIncrement = -1;
for (var i = 0;; i += 2) {
if (row.children.length <= 6 + i) {
break;
}
yearIncrement++;
grade = row.children[6 + i].innerHtml.replaceAll('&nbsp;', ' ').trim();
status = row.children[7 + i].innerHtml.replaceAll('&nbsp;', ' ').trim();
if (status != '') {
break;
final status =
row.children[7 + i].innerHtml.replaceAll('&nbsp;', ' ').trim();
final grade =
row.children[6 + i].innerHtml.replaceAll('&nbsp;', ' ').trim();

if (status.isEmpty) {
continue;
}
}
if (yearIncrement < 0) {
continue;
}

final courseUnit = CourseUnit(
schoolYear:
'${firstSchoolYear + yearIncrement}/${firstSchoolYear + yearIncrement + 1}',
occurrId: int.parse(occurId),
abbreviation: codeName,
status: status,
grade: grade,
ects: double.parse(ects),
name: name,
curricularYear: int.parse(year),
semesterCode: semester,
);
courseUnits.add(courseUnit);
final courseUnit = CourseUnit(
schoolYear:
'${firstSchoolYear + yearIncrement}/${firstSchoolYear + yearIncrement + 1}',
occurrId: int.parse(occurId),
abbreviation: codeName,
status: status,
grade: grade,
ects: double.parse(ects),
name: name,
curricularYear: int.parse(year),
semesterCode: semester,
);
courseUnits.add(courseUnit);
}
}

return courseUnits;
Expand Down
67 changes: 67 additions & 0 deletions uni/lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that looks up messages for specific locales by
// delegating to the appropriate library.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:implementation_imports, file_names, unnecessary_new
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
// ignore_for_file:argument_type_not_assignable, invalid_assignment
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
// ignore_for_file:comment_references

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';

import 'messages_en.dart' as messages_en;
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),
};

MessageLookupByLibrary? _findExact(String localeName) {
switch (localeName) {
case 'en':
return messages_en.messages;
case 'pt_PT':
return messages_pt_pt.messages;
default:
return null;
}
}

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

bool _messagesExistFor(String locale) {
try {
return _findExact(locale) != null;
} catch (e) {
return false;
}
}

MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
var actualLocale =
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
Loading

0 comments on commit 01be81f

Please sign in to comment.