Skip to content

Commit

Permalink
Rename and normalise settings keys, fix settings not in export
Browse files Browse the repository at this point in the history
  • Loading branch information
FauconSpartiate committed Oct 1, 2024
1 parent 26e4d2d commit 35f7a45
Show file tree
Hide file tree
Showing 26 changed files with 300 additions and 199 deletions.
2 changes: 1 addition & 1 deletion assets/class_data/lux/classique.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/class_data/lux/general.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/calculations/calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Calculator {

final List<T> result = data.toList();

final int sortDirection = sortDirectionOverride ?? getPreference<int>("sort_direction$sortType");
int sortMode = getPreference<int>("sort_mode$sortType");
final int sortDirection = sortDirectionOverride ?? getPreference<int>("sortDirection$sortType");
int sortMode = getPreference<int>("sortMode$sortType");
if (sortModeOverride != null) sortMode = sortModeOverride;

switch (sortMode) {
Expand Down Expand Up @@ -64,7 +64,7 @@ class Calculator {
return sortDirection * getResult(a)!.compareTo(getResult(b)!);
},
);
case SortMode.coefficient:
case SortMode.weight:
insertionSort(result, compare: (a, b) => sortDirection * a.weight.compareTo(b.weight));
case SortMode.timestamp:
if (result.first is! Test) throw UnimplementedError("Timestamp sorting is only implemented for tests");
Expand Down Expand Up @@ -99,7 +99,7 @@ class Calculator {

if (data.isEmpty || isNullFilled) return null;

final double maxGrade = Manager.years.isNotEmpty ? getCurrentYear().maxGrade : getPreference("max_grade");
final double maxGrade = Manager.years.isNotEmpty ? getCurrentYear().maxGrade : getPreference("maxGrade");

double totalNumerator = 0;
double totalDenominator = 0;
Expand Down Expand Up @@ -130,8 +130,8 @@ class Calculator {
}

static double round(double n, {String? roundingModeOverride, int? roundToOverride, int roundToMultiplier = 1}) {
final String roundingMode = roundingModeOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundingMode : getPreference("rounding_mode"));
int roundTo = roundToOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundTo : getPreference<int>("round_to"));
final String roundingMode = roundingModeOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundingMode : getPreference("roundingMode"));
int roundTo = roundToOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundTo : getPreference<int>("roundTo"));
roundTo *= roundToMultiplier;

final double round = n * roundTo;
Expand Down Expand Up @@ -162,7 +162,7 @@ class Calculator {
static String format(double? n, {bool leadingZero = true, int? roundToOverride, int roundToMultiplier = 1, bool showPlusSign = false}) {
if (n == null || n.isNaN) return "-";

int roundTo = roundToOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundTo : getPreference<int>("round_to"));
int roundTo = roundToOverride ?? (Manager.years.isNotEmpty ? getCurrentYear().roundTo : getPreference<int>("roundTo"));
roundTo *= roundToMultiplier;

String result;
Expand All @@ -174,7 +174,7 @@ class Calculator {

result = n.toStringAsFixed(nbDecimals);

if (leadingZero && getPreference<bool>("leading_zero") && n >= 1 && n < 10) {
if (leadingZero && getPreference<bool>("leadingZero") && n >= 1 && n < 10) {
result = "0$result";
}
if (showPlusSign && n >= 0) {
Expand Down
8 changes: 4 additions & 4 deletions lib/calculations/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class Manager {
static int _currentYear = 0;
static int get currentYear => _currentYear;
static set currentYear(int newValue) {
setPreference<int>("current_year", newValue);
setPreference<int>("currentYear", newValue);
_currentYear = newValue;
}

static int _currentTerm = 0;
static int get currentTerm => _currentTerm;
static set currentTerm(int newValue) {
setPreference<int>("current_term", newValue);
setPreference<int>("currentTerm", newValue);
_currentTerm = newValue;
}

Expand All @@ -34,8 +34,8 @@ class Manager {
static void init() {
Compatibility.upgradeDataVersion();

currentYear = getPreference<int>("current_year");
currentTerm = getPreference<int>("current_term");
currentYear = getPreference<int>("currentYear");
currentTerm = getPreference<int>("currentTerm");

if (years.isNotEmpty) calculate();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/calculations/subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ class Subject extends CalculationObject {
children = childrenList.map((childJson) => Subject.fromJson(childJson as Map<String, dynamic>)..isChild = true).toList();
}

isGroup = json["type"] as bool? ?? false;
isGroup = json["isGroup"] as bool? ?? false;
name = json["name"] as String;
weight = json["coefficient"] as double;
weight = json["weight"] as double;

speakingWeight = json["speakingWeight"] as double? ?? DefaultValues.speakingWeight;
}

Map<String, dynamic> toJson() => {
"name": name,
"coefficient": weight,
"weight": weight,
"speakingWeight": speakingWeight,
"type": isGroup,
"isGroup": isGroup,
"children": children.toList(),
"terms": terms,
};
Expand Down
4 changes: 2 additions & 2 deletions lib/calculations/term.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Term extends CalculationObject {
return Test.fromJson(testJson as Map<String, dynamic>);
}).toList();

weight = json["coefficient"] as double? ?? DefaultValues.coefficient;
weight = json["weight"] as double? ?? DefaultValues.weight;
isExam = json["isExam"] as bool? ?? DefaultValues.isExam;
try {
bonus = json["bonus"] as double;
Expand All @@ -81,7 +81,7 @@ class Term extends CalculationObject {
}

Map<String, dynamic> toJson() => {
"coefficient": weight,
"weight": weight,
"isExam": isExam,
"bonus": bonus,
"tests": tests,
Expand Down
12 changes: 6 additions & 6 deletions lib/calculations/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Test extends CalculationObject {
}

Test.fromJson(Map<String, dynamic> json) {
numerator = json["grade1"] as double?;
denominator = json["grade2"] as double;
numerator = json["numerator"] as double?;
denominator = json["denominator"] as double;
name = json["name"] as String;
weight = json["coefficient"] as double? ?? 1;
weight = json["weight"] as double? ?? 1;
isSpeaking = json["isSpeaking"] as bool? ?? false;
calculate();
if (result == null) numerator = null;
Expand All @@ -65,9 +65,9 @@ class Test extends CalculationObject {

Map<String, dynamic> toJson() => {
"name": name,
"grade1": numerator,
"grade2": denominator,
"coefficient": weight,
"numerator": numerator,
"denominator": denominator,
"weight": weight,
"isSpeaking": isSpeaking,
"timestamp": timestamp,
};
Expand Down
44 changes: 22 additions & 22 deletions lib/calculations/year.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class Year extends CalculationObject {
subjects[newIndex1].isGroup = true;
}

setPreference<int>("sort_mode${SortType.subject}", SortMode.custom);
setPreference<int>("sort_direction${SortType.subject}", SortDirection.ascending);
setPreference<int>("sortMode${SortType.subject}", SortMode.custom);
setPreference<int>("sortDirection${SortType.subject}", SortDirection.ascending);

serialize();
calculate();
Expand Down Expand Up @@ -164,32 +164,32 @@ class Year extends CalculationObject {

name = (json["name"] as String?) ?? "";

validatedSchoolSystem = json["validated_school_system"] as String?;
validatedLuxSystem = json["validated_lux_system"] as String?;
validatedYear = json["validated_year"] as int?;
validatedSection = json["validated_section"] as String?;
validatedVariant = json["validated_variant"] as String?;
validatedSchoolSystem = json["validatedSchoolSystem"] as String?;
validatedLuxSystem = json["validatedLuxSystem"] as String?;
validatedYear = json["validatedYear"] as int?;
validatedSection = json["validatedSection"] as String?;
validatedVariant = json["validatedVariant"] as String?;

termCount = json["term_count"] as int? ?? DefaultValues.termCount;
maxGrade = json["max_grade"] as double? ?? DefaultValues.maxGrade;
roundingMode = json["rounding_mode"] as String? ?? DefaultValues.roundingMode;
roundTo = json["round_to"] as int? ?? DefaultValues.roundTo;
termCount = json["termCount"] as int? ?? DefaultValues.termCount;
maxGrade = json["maxGrade"] as double? ?? DefaultValues.maxGrade;
roundingMode = json["roundingMode"] as String? ?? DefaultValues.roundingMode;
roundTo = json["roundTo"] as int? ?? DefaultValues.roundTo;

hasBeenSortedCustom = (json["has_been_sorted_custom"] as bool?) ?? DefaultValues.hasBeenSortedCustom;
hasBeenSortedCustom = (json["hasBeenSortedCustom"] as bool?) ?? DefaultValues.hasBeenSortedCustom;
}

Map<String, dynamic> toJson() => {
"name": name,
"term_count": termCount,
"max_grade": maxGrade,
"rounding_mode": roundingMode,
"round_to": roundTo,
"validated_school_system": validatedSchoolSystem,
"validated_lux_system": validatedLuxSystem,
"validated_year": validatedYear,
"validated_section": validatedSection,
"validated_variant": validatedVariant,
"has_been_sorted_custom": hasBeenSortedCustom,
"termCount": termCount,
"maxGrade": maxGrade,
"roundingMode": roundingMode,
"roundTo": roundTo,
"validatedSchoolSystem": validatedSchoolSystem,
"validatedLuxSystem": validatedLuxSystem,
"validatedYear": validatedYear,
"validatedSection": validatedSection,
"validatedVariant": validatedVariant,
"hasBeenSortedCustom": hasBeenSortedCustom,
"subjects": subjects,
};
}
14 changes: 7 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "package:graded/calculations/subject.dart";
import "package:graded/localization/generated/l10n.dart";
import "package:graded/localization/material_localization/lb_intl.dart";
import "package:graded/localization/translations.dart";
import "package:graded/misc/default_values.dart";
import "package:graded/misc/enums.dart";
import "package:graded/misc/locale_provider.dart";
import "package:graded/misc/storage.dart";
Expand All @@ -38,11 +39,12 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

await Settings.init();
Manager.init();

String initialRoute = "/";

if (getPreference<bool>("is_first_run")) {
initialRoute = "setup_first";
if (getPreference<bool>("isFirstRun")) {
initialRoute = "/setupFirst";
}

runApp(
Expand Down Expand Up @@ -94,7 +96,7 @@ class _AppContainerState extends State<AppContainer> {
return deviceLocale;
}

initializeDateFormatting("en_GB");
initializeDateFormatting(DefaultValues.language);
return const Locale("en", "GB");
},
locale: provider.locale,
Expand All @@ -105,8 +107,6 @@ class _AppContainerState extends State<AppContainer> {
return createRoute(settings);
},
onGenerateInitialRoutes: (initialRoute) {
Manager.init();

return [
createRoute(RouteSettings(name: initialRoute)),
];
Expand All @@ -122,13 +122,13 @@ Route<dynamic> createRoute(RouteSettings settings) {
Widget route;

switch (settings.name) {
case "setup_first":
case "/setupFirst":
route = const SetupPage(dismissible: false);
case "/setup":
route = const SetupPage();
case "/settings":
route = const SettingsPage();
case "/subject_edit":
case "/subjectEdit":
final CreationType type = (settings.arguments as CreationType?) ?? CreationType.edit;
route = SubjectEditRoute(creationType: type);
case "/subject":
Expand Down
Loading

0 comments on commit 35f7a45

Please sign in to comment.