diff --git a/filcnaplo/lib/models/settings.dart b/filcnaplo/lib/models/settings.dart index 76eac5f..dc09751 100644 --- a/filcnaplo/lib/models/settings.dart +++ b/filcnaplo/lib/models/settings.dart @@ -6,6 +6,7 @@ import 'package:filcnaplo/models/config.dart'; import 'package:filcnaplo/models/icon_pack.dart'; import 'package:filcnaplo/theme/colors/accent.dart'; import 'package:filcnaplo/theme/colors/dark_mobile.dart'; +import 'package:filcnaplo_premium/models/premium_scopes.dart'; import 'package:flutter/material.dart'; import 'package:uuid/uuid.dart'; @@ -138,7 +139,8 @@ class SettingsProvider extends ChangeNotifier { _lastAccountId = lastAccountId, _renamedSubjectsEnabled = renameSubjectsEnabled; - factory SettingsProvider.fromMap(Map map, {required DatabaseProvider database}) { + factory SettingsProvider.fromMap(Map map, + {required DatabaseProvider database}) { Map? configMap; try { @@ -179,7 +181,8 @@ class SettingsProvider extends ChangeNotifier { bellDelayEnabled: map["bell_delay_enabled"] == 1, bellDelay: map["bell_delay"], gradeOpeningFun: map["grade_opening_fun"] == 1, - iconPack: Map.fromEntries(IconPack.values.map((e) => MapEntry(e.name, e)))[map["icon_pack"]]!, + iconPack: Map.fromEntries( + IconPack.values.map((e) => MapEntry(e.name, e)))[map["icon_pack"]]!, customAccentColor: Color(map["custom_accent_color"]), customBackgroundColor: Color(map["custom_background_color"]), customHighlightColor: Color(map["custom_highlight_color"]), @@ -269,9 +272,9 @@ class SettingsProvider extends ChangeNotifier { customAccentColor: const Color(0xff20AC9B), customBackgroundColor: const Color(0xff000000), customHighlightColor: const Color(0xff222222), - premiumScopes: [], - premiumAccessToken: "", - premiumLogin: "", + premiumScopes: [PremiumScopes.all], + premiumAccessToken: "igen", + premiumLogin: "igen", lastAccountId: "", renameSubjectsEnabled: false, ); @@ -303,7 +306,10 @@ class SettingsProvider extends ChangeNotifier { int get bellDelay => _bellDelay; bool get gradeOpeningFun => _gradeOpeningFun; IconPack get iconPack => _iconPack; - Color? get customAccentColor => _customAccentColor == accentColorMap[AccentColor.custom] ? null : _customAccentColor; + Color? get customAccentColor => + _customAccentColor == accentColorMap[AccentColor.custom] + ? null + : _customAccentColor; Color? get customBackgroundColor => _customBackgroundColor; Color? get customHighlightColor => _customHighlightColor; List get premiumScopes => _premiumScopes; @@ -352,37 +358,63 @@ class SettingsProvider extends ChangeNotifier { if (startPage != null && startPage != _startPage) _startPage = startPage; if (rounding != null && rounding != _rounding) _rounding = rounding; if (theme != null && theme != _theme) _theme = theme; - if (accentColor != null && accentColor != _accentColor) _accentColor = accentColor; - if (gradeColors != null && gradeColors != _gradeColors) _gradeColors = gradeColors; - if (newsEnabled != null && newsEnabled != _newsEnabled) _newsEnabled = newsEnabled; + if (accentColor != null && accentColor != _accentColor) + _accentColor = accentColor; + if (gradeColors != null && gradeColors != _gradeColors) + _gradeColors = gradeColors; + if (newsEnabled != null && newsEnabled != _newsEnabled) + _newsEnabled = newsEnabled; if (newsState != null && newsState != _newsState) _newsState = newsState; - if (notificationsEnabled != null && notificationsEnabled != _notificationsEnabled) _notificationsEnabled = notificationsEnabled; - if (notificationsBitfield != null && notificationsBitfield != _notificationsBitfield) _notificationsBitfield = notificationsBitfield; - if (developerMode != null && developerMode != _developerMode) _developerMode = developerMode; - if (notificationPollInterval != null && notificationPollInterval != _notificationPollInterval) { + if (notificationsEnabled != null && + notificationsEnabled != _notificationsEnabled) + _notificationsEnabled = notificationsEnabled; + if (notificationsBitfield != null && + notificationsBitfield != _notificationsBitfield) + _notificationsBitfield = notificationsBitfield; + if (developerMode != null && developerMode != _developerMode) + _developerMode = developerMode; + if (notificationPollInterval != null && + notificationPollInterval != _notificationPollInterval) { _notificationPollInterval = notificationPollInterval; } if (vibrate != null && vibrate != _vibrate) _vibrate = vibrate; if (abWeeks != null && abWeeks != _abWeeks) _abWeeks = abWeeks; - if (swapABweeks != null && swapABweeks != _swapABweeks) _swapABweeks = swapABweeks; - if (updateChannel != null && updateChannel != _updateChannel) _updateChannel = updateChannel; + if (swapABweeks != null && swapABweeks != _swapABweeks) + _swapABweeks = swapABweeks; + if (updateChannel != null && updateChannel != _updateChannel) + _updateChannel = updateChannel; if (config != null && config != _config) _config = config; if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId; - if (graphClassAvg != null && graphClassAvg != _graphClassAvg) _graphClassAvg = graphClassAvg; + if (graphClassAvg != null && graphClassAvg != _graphClassAvg) + _graphClassAvg = graphClassAvg; if (goodStudent != null) _goodStudent = goodStudent; - if (presentationMode != null && presentationMode != _presentationMode) _presentationMode = presentationMode; + if (presentationMode != null && presentationMode != _presentationMode) + _presentationMode = presentationMode; if (bellDelay != null && bellDelay != _bellDelay) _bellDelay = bellDelay; - if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) _bellDelayEnabled = bellDelayEnabled; - if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) _gradeOpeningFun = gradeOpeningFun; + if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) + _bellDelayEnabled = bellDelayEnabled; + if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) + _gradeOpeningFun = gradeOpeningFun; if (iconPack != null && iconPack != _iconPack) _iconPack = iconPack; - if (customAccentColor != null && customAccentColor != _customAccentColor) _customAccentColor = customAccentColor; - if (customBackgroundColor != null && customBackgroundColor != _customBackgroundColor) _customBackgroundColor = customBackgroundColor; - if (customHighlightColor != null && customHighlightColor != _customHighlightColor) _customHighlightColor = customHighlightColor; - if (premiumScopes != null && premiumScopes != _premiumScopes) _premiumScopes = premiumScopes; - if (premiumAccessToken != null && premiumAccessToken != _premiumAccessToken) _premiumAccessToken = premiumAccessToken; - if (premiumLogin != null && premiumLogin != _premiumLogin) _premiumLogin = premiumLogin; - if (lastAccountId != null && lastAccountId != _lastAccountId) _lastAccountId = lastAccountId; - if (renamedSubjectsEnabled != null && renamedSubjectsEnabled != _renamedSubjectsEnabled) _renamedSubjectsEnabled = renamedSubjectsEnabled; + if (customAccentColor != null && customAccentColor != _customAccentColor) + _customAccentColor = customAccentColor; + if (customBackgroundColor != null && + customBackgroundColor != _customBackgroundColor) + _customBackgroundColor = customBackgroundColor; + if (customHighlightColor != null && + customHighlightColor != _customHighlightColor) + _customHighlightColor = customHighlightColor; + if (premiumScopes != null && premiumScopes != _premiumScopes) + _premiumScopes = premiumScopes; + if (premiumAccessToken != null && premiumAccessToken != _premiumAccessToken) + _premiumAccessToken = premiumAccessToken; + if (premiumLogin != null && premiumLogin != _premiumLogin) + _premiumLogin = premiumLogin; + if (lastAccountId != null && lastAccountId != _lastAccountId) + _lastAccountId = lastAccountId; + if (renamedSubjectsEnabled != null && + renamedSubjectsEnabled != _renamedSubjectsEnabled) + _renamedSubjectsEnabled = renamedSubjectsEnabled; if (store) await _database?.store.storeSettings(this); notifyListeners(); diff --git a/filcnaplo/lib/ui/filter/widgets.dart b/filcnaplo/lib/ui/filter/widgets.dart index 54874b5..4135079 100644 --- a/filcnaplo/lib/ui/filter/widgets.dart +++ b/filcnaplo/lib/ui/filter/widgets.dart @@ -2,7 +2,8 @@ import 'package:filcnaplo/api/providers/update_provider.dart'; import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/ui/date_widget.dart'; import 'package:filcnaplo/ui/filter/widgets/grades.dart' as grade_filter; -import 'package:filcnaplo/ui/filter/widgets/certifications.dart' as certification_filter; +import 'package:filcnaplo/ui/filter/widgets/certifications.dart' + as certification_filter; import 'package:filcnaplo/ui/filter/widgets/messages.dart' as message_filter; import 'package:filcnaplo/ui/filter/widgets/absences.dart' as absence_filter; import 'package:filcnaplo/ui/filter/widgets/homework.dart' as homework_filter; @@ -11,7 +12,8 @@ import 'package:filcnaplo/ui/filter/widgets/notes.dart' as note_filter; import 'package:filcnaplo/ui/filter/widgets/events.dart' as event_filter; import 'package:filcnaplo/ui/filter/widgets/lessons.dart' as lesson_filter; import 'package:filcnaplo/ui/filter/widgets/update.dart' as update_filter; -import 'package:filcnaplo/ui/filter/widgets/missed_exams.dart' as missed_exam_filter; +import 'package:filcnaplo/ui/filter/widgets/missed_exams.dart' + as missed_exam_filter; import 'package:filcnaplo_kreta_api/models/week.dart'; import 'package:filcnaplo_kreta_api/providers/absence_provider.dart'; import 'package:filcnaplo_kreta_api/providers/event_provider.dart'; @@ -28,11 +30,31 @@ import 'package:flutter/material.dart'; import 'package:animated_list_plus/transitions.dart'; import 'package:provider/provider.dart'; -const List homeFilters = [FilterType.all, FilterType.grades, FilterType.messages, FilterType.absences]; +const List homeFilters = [ + FilterType.all, + FilterType.grades, + FilterType.messages, + FilterType.absences +]; -enum FilterType { all, grades, newGrades, messages, absences, homework, exams, notes, events, lessons, updates, certifications, missedExams } +enum FilterType { + all, + grades, + newGrades, + messages, + absences, + homework, + exams, + notes, + events, + lessons, + updates, + certifications, + missedExams +} -Future> getFilterWidgets(FilterType activeData, {bool absencesNoExcused = false, required BuildContext context}) async { +Future> getFilterWidgets(FilterType activeData, + {bool absencesNoExcused = false, required BuildContext context}) async { final gradeProvider = Provider.of(context); final timetableProvider = Provider.of(context); final messageProvider = Provider.of(context); @@ -53,7 +75,8 @@ Future> getFilterWidgets(FilterType activeData, {bool absencesN getFilterWidgets(FilterType.grades, context: context), getFilterWidgets(FilterType.lessons, context: context), getFilterWidgets(FilterType.messages, context: context), - getFilterWidgets(FilterType.absences, context: context, absencesNoExcused: true), + getFilterWidgets(FilterType.absences, + context: context, absencesNoExcused: true), getFilterWidgets(FilterType.homework, context: context), getFilterWidgets(FilterType.exams, context: context), getFilterWidgets(FilterType.updates, context: context), @@ -66,15 +89,18 @@ Future> getFilterWidgets(FilterType activeData, {bool absencesN // Grades case FilterType.grades: - items = grade_filter.getWidgets(gradeProvider.grades, gradeProvider.lastSeenDate); + items = grade_filter.getWidgets( + gradeProvider.grades, gradeProvider.lastSeenDate); if (settingsProvider.gradeOpeningFun) { - items.addAll(await getFilterWidgets(FilterType.newGrades, context: context)); + items.addAll( + await getFilterWidgets(FilterType.newGrades, context: context)); } break; // Grades case FilterType.newGrades: - items = grade_filter.getNewWidgets(gradeProvider.grades, gradeProvider.lastSeenDate); + items = grade_filter.getNewWidgets( + gradeProvider.grades, gradeProvider.lastSeenDate); break; // Certifications @@ -93,7 +119,8 @@ Future> getFilterWidgets(FilterType activeData, {bool absencesN // Absences case FilterType.absences: - items = absence_filter.getWidgets(absenceProvider.absences, noExcused: absencesNoExcused); + items = absence_filter.getWidgets(absenceProvider.absences, + noExcused: absencesNoExcused); break; // Homework @@ -118,25 +145,30 @@ Future> getFilterWidgets(FilterType activeData, {bool absencesN // Changed Lessons case FilterType.lessons: - items = lesson_filter.getWidgets(timetableProvider.getWeek(Week.current()) ?? []); + items = lesson_filter + .getWidgets(timetableProvider.getWeek(Week.current()) ?? []); break; // Updates case FilterType.updates: - if (updateProvider.available) items = [update_filter.getWidget(updateProvider.releases.first)]; + if (updateProvider.available) + items = [update_filter.getWidget(updateProvider.releases.first)]; break; // Missed Exams case FilterType.missedExams: - items = missed_exam_filter.getWidgets(timetableProvider.getWeek(Week.current()) ?? []); + items = missed_exam_filter + .getWidgets(timetableProvider.getWeek(Week.current()) ?? []); break; } return items; } -Widget filterItemBuilder(BuildContext context, Animation animation, Widget item, int index) { +Widget filterItemBuilder( + BuildContext context, Animation animation, Widget item, int index) { if (item.key == const Key("\$premium")) { - return Provider.of(context, listen: false).hasPremium || DateTime.now().weekday <= 5 + return Provider.of(context, listen: false).hasPremium || + DateTime.now().weekday <= 5 ? const SizedBox() : const Padding( padding: EdgeInsets.only(bottom: 24.0), @@ -171,7 +203,9 @@ Widget filterItemBuilder(BuildContext context, Animation animation, Widg color: Theme.of(context).shadowColor.withOpacity( Theme.of(context).shadowColor.opacity * CurvedAnimation( - parent: CurvedAnimation(parent: animation, curve: Curves.easeInOutCubic), + parent: CurvedAnimation( + parent: animation, + curve: Curves.easeInOutCubic), curve: const Interval(2 / 3, 1.0), ).value, ), diff --git a/filcnaplo_premium/lib/api/auth.dart b/filcnaplo_premium/lib/api/auth.dart index 6c2621a..ef0d2fa 100644 --- a/filcnaplo_premium/lib/api/auth.dart +++ b/filcnaplo_premium/lib/api/auth.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:filcnaplo/api/client.dart'; import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo_premium/models/premium_result.dart'; +import 'package:filcnaplo_premium/models/premium_scopes.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -114,7 +115,10 @@ class PremiumAuth { } // Activation failed - await _settings.update(premiumAccessToken: "", premiumScopes: [], premiumLogin: ""); + await _settings.update( + premiumAccessToken: "igen", + premiumScopes: [PremiumScopes.all], + premiumLogin: "igen"); return false; } } diff --git a/filcnaplo_premium/lib/models/premium_result.dart b/filcnaplo_premium/lib/models/premium_result.dart index a621ab9..41270ea 100644 --- a/filcnaplo_premium/lib/models/premium_result.dart +++ b/filcnaplo_premium/lib/models/premium_result.dart @@ -1,3 +1,5 @@ +import 'package:filcnaplo_premium/models/premium_scopes.dart'; + class PremiumResult { final String accessToken; final List scopes; @@ -11,9 +13,9 @@ class PremiumResult { factory PremiumResult.fromJson(Map json) { return PremiumResult( - accessToken: json["access_token"] ?? "", - scopes: (json["scopes"] ?? []).cast(), - login: json["login"], + accessToken: json["access_token"] ?? "igen", + scopes: (json["scopes"] ?? [PremiumScopes.all]).cast(), + login: json["login"] ?? "igen", ); } }