fixed premium features

This commit is contained in:
Kima 2023-05-27 10:27:09 +02:00
parent 4d6a1e2c22
commit ba52926d1f
4 changed files with 119 additions and 47 deletions

View File

@ -6,6 +6,7 @@ import 'package:filcnaplo/models/config.dart';
import 'package:filcnaplo/models/icon_pack.dart'; import 'package:filcnaplo/models/icon_pack.dart';
import 'package:filcnaplo/theme/colors/accent.dart'; import 'package:filcnaplo/theme/colors/accent.dart';
import 'package:filcnaplo/theme/colors/dark_mobile.dart'; import 'package:filcnaplo/theme/colors/dark_mobile.dart';
import 'package:filcnaplo_premium/models/premium_scopes.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@ -138,7 +139,8 @@ class SettingsProvider extends ChangeNotifier {
_lastAccountId = lastAccountId, _lastAccountId = lastAccountId,
_renamedSubjectsEnabled = renameSubjectsEnabled; _renamedSubjectsEnabled = renameSubjectsEnabled;
factory SettingsProvider.fromMap(Map map, {required DatabaseProvider database}) { factory SettingsProvider.fromMap(Map map,
{required DatabaseProvider database}) {
Map<String, Object?>? configMap; Map<String, Object?>? configMap;
try { try {
@ -179,7 +181,8 @@ class SettingsProvider extends ChangeNotifier {
bellDelayEnabled: map["bell_delay_enabled"] == 1, bellDelayEnabled: map["bell_delay_enabled"] == 1,
bellDelay: map["bell_delay"], bellDelay: map["bell_delay"],
gradeOpeningFun: map["grade_opening_fun"] == 1, 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"]), customAccentColor: Color(map["custom_accent_color"]),
customBackgroundColor: Color(map["custom_background_color"]), customBackgroundColor: Color(map["custom_background_color"]),
customHighlightColor: Color(map["custom_highlight_color"]), customHighlightColor: Color(map["custom_highlight_color"]),
@ -269,9 +272,9 @@ class SettingsProvider extends ChangeNotifier {
customAccentColor: const Color(0xff20AC9B), customAccentColor: const Color(0xff20AC9B),
customBackgroundColor: const Color(0xff000000), customBackgroundColor: const Color(0xff000000),
customHighlightColor: const Color(0xff222222), customHighlightColor: const Color(0xff222222),
premiumScopes: [], premiumScopes: [PremiumScopes.all],
premiumAccessToken: "", premiumAccessToken: "igen",
premiumLogin: "", premiumLogin: "igen",
lastAccountId: "", lastAccountId: "",
renameSubjectsEnabled: false, renameSubjectsEnabled: false,
); );
@ -303,7 +306,10 @@ class SettingsProvider extends ChangeNotifier {
int get bellDelay => _bellDelay; int get bellDelay => _bellDelay;
bool get gradeOpeningFun => _gradeOpeningFun; bool get gradeOpeningFun => _gradeOpeningFun;
IconPack get iconPack => _iconPack; 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 customBackgroundColor => _customBackgroundColor;
Color? get customHighlightColor => _customHighlightColor; Color? get customHighlightColor => _customHighlightColor;
List<String> get premiumScopes => _premiumScopes; List<String> get premiumScopes => _premiumScopes;
@ -352,37 +358,63 @@ class SettingsProvider extends ChangeNotifier {
if (startPage != null && startPage != _startPage) _startPage = startPage; if (startPage != null && startPage != _startPage) _startPage = startPage;
if (rounding != null && rounding != _rounding) _rounding = rounding; if (rounding != null && rounding != _rounding) _rounding = rounding;
if (theme != null && theme != _theme) _theme = theme; if (theme != null && theme != _theme) _theme = theme;
if (accentColor != null && accentColor != _accentColor) _accentColor = accentColor; if (accentColor != null && accentColor != _accentColor)
if (gradeColors != null && gradeColors != _gradeColors) _gradeColors = gradeColors; _accentColor = accentColor;
if (newsEnabled != null && newsEnabled != _newsEnabled) _newsEnabled = newsEnabled; if (gradeColors != null && gradeColors != _gradeColors)
_gradeColors = gradeColors;
if (newsEnabled != null && newsEnabled != _newsEnabled)
_newsEnabled = newsEnabled;
if (newsState != null && newsState != _newsState) _newsState = newsState; if (newsState != null && newsState != _newsState) _newsState = newsState;
if (notificationsEnabled != null && notificationsEnabled != _notificationsEnabled) _notificationsEnabled = notificationsEnabled; if (notificationsEnabled != null &&
if (notificationsBitfield != null && notificationsBitfield != _notificationsBitfield) _notificationsBitfield = notificationsBitfield; notificationsEnabled != _notificationsEnabled)
if (developerMode != null && developerMode != _developerMode) _developerMode = developerMode; _notificationsEnabled = notificationsEnabled;
if (notificationPollInterval != null && notificationPollInterval != _notificationPollInterval) { if (notificationsBitfield != null &&
notificationsBitfield != _notificationsBitfield)
_notificationsBitfield = notificationsBitfield;
if (developerMode != null && developerMode != _developerMode)
_developerMode = developerMode;
if (notificationPollInterval != null &&
notificationPollInterval != _notificationPollInterval) {
_notificationPollInterval = notificationPollInterval; _notificationPollInterval = notificationPollInterval;
} }
if (vibrate != null && vibrate != _vibrate) _vibrate = vibrate; if (vibrate != null && vibrate != _vibrate) _vibrate = vibrate;
if (abWeeks != null && abWeeks != _abWeeks) _abWeeks = abWeeks; if (abWeeks != null && abWeeks != _abWeeks) _abWeeks = abWeeks;
if (swapABweeks != null && swapABweeks != _swapABweeks) _swapABweeks = swapABweeks; if (swapABweeks != null && swapABweeks != _swapABweeks)
if (updateChannel != null && updateChannel != _updateChannel) _updateChannel = updateChannel; _swapABweeks = swapABweeks;
if (updateChannel != null && updateChannel != _updateChannel)
_updateChannel = updateChannel;
if (config != null && config != _config) _config = config; if (config != null && config != _config) _config = config;
if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId; 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 (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 (bellDelay != null && bellDelay != _bellDelay) _bellDelay = bellDelay;
if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) _bellDelayEnabled = bellDelayEnabled; if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled)
if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) _gradeOpeningFun = gradeOpeningFun; _bellDelayEnabled = bellDelayEnabled;
if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun)
_gradeOpeningFun = gradeOpeningFun;
if (iconPack != null && iconPack != _iconPack) _iconPack = iconPack; if (iconPack != null && iconPack != _iconPack) _iconPack = iconPack;
if (customAccentColor != null && customAccentColor != _customAccentColor) _customAccentColor = customAccentColor; if (customAccentColor != null && customAccentColor != _customAccentColor)
if (customBackgroundColor != null && customBackgroundColor != _customBackgroundColor) _customBackgroundColor = customBackgroundColor; _customAccentColor = customAccentColor;
if (customHighlightColor != null && customHighlightColor != _customHighlightColor) _customHighlightColor = customHighlightColor; if (customBackgroundColor != null &&
if (premiumScopes != null && premiumScopes != _premiumScopes) _premiumScopes = premiumScopes; customBackgroundColor != _customBackgroundColor)
if (premiumAccessToken != null && premiumAccessToken != _premiumAccessToken) _premiumAccessToken = premiumAccessToken; _customBackgroundColor = customBackgroundColor;
if (premiumLogin != null && premiumLogin != _premiumLogin) _premiumLogin = premiumLogin; if (customHighlightColor != null &&
if (lastAccountId != null && lastAccountId != _lastAccountId) _lastAccountId = lastAccountId; customHighlightColor != _customHighlightColor)
if (renamedSubjectsEnabled != null && renamedSubjectsEnabled != _renamedSubjectsEnabled) _renamedSubjectsEnabled = renamedSubjectsEnabled; _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); if (store) await _database?.store.storeSettings(this);
notifyListeners(); notifyListeners();

View File

@ -2,7 +2,8 @@ import 'package:filcnaplo/api/providers/update_provider.dart';
import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/ui/date_widget.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/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/messages.dart' as message_filter;
import 'package:filcnaplo/ui/filter/widgets/absences.dart' as absence_filter; import 'package:filcnaplo/ui/filter/widgets/absences.dart' as absence_filter;
import 'package:filcnaplo/ui/filter/widgets/homework.dart' as homework_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/events.dart' as event_filter;
import 'package:filcnaplo/ui/filter/widgets/lessons.dart' as lesson_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/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/models/week.dart';
import 'package:filcnaplo_kreta_api/providers/absence_provider.dart'; import 'package:filcnaplo_kreta_api/providers/absence_provider.dart';
import 'package:filcnaplo_kreta_api/providers/event_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:animated_list_plus/transitions.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
const List<FilterType> homeFilters = [FilterType.all, FilterType.grades, FilterType.messages, FilterType.absences]; const List<FilterType> 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<List<DateWidget>> getFilterWidgets(FilterType activeData, {bool absencesNoExcused = false, required BuildContext context}) async { Future<List<DateWidget>> getFilterWidgets(FilterType activeData,
{bool absencesNoExcused = false, required BuildContext context}) async {
final gradeProvider = Provider.of<GradeProvider>(context); final gradeProvider = Provider.of<GradeProvider>(context);
final timetableProvider = Provider.of<TimetableProvider>(context); final timetableProvider = Provider.of<TimetableProvider>(context);
final messageProvider = Provider.of<MessageProvider>(context); final messageProvider = Provider.of<MessageProvider>(context);
@ -53,7 +75,8 @@ Future<List<DateWidget>> getFilterWidgets(FilterType activeData, {bool absencesN
getFilterWidgets(FilterType.grades, context: context), getFilterWidgets(FilterType.grades, context: context),
getFilterWidgets(FilterType.lessons, context: context), getFilterWidgets(FilterType.lessons, context: context),
getFilterWidgets(FilterType.messages, 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.homework, context: context),
getFilterWidgets(FilterType.exams, context: context), getFilterWidgets(FilterType.exams, context: context),
getFilterWidgets(FilterType.updates, context: context), getFilterWidgets(FilterType.updates, context: context),
@ -66,15 +89,18 @@ Future<List<DateWidget>> getFilterWidgets(FilterType activeData, {bool absencesN
// Grades // Grades
case FilterType.grades: case FilterType.grades:
items = grade_filter.getWidgets(gradeProvider.grades, gradeProvider.lastSeenDate); items = grade_filter.getWidgets(
gradeProvider.grades, gradeProvider.lastSeenDate);
if (settingsProvider.gradeOpeningFun) { if (settingsProvider.gradeOpeningFun) {
items.addAll(await getFilterWidgets(FilterType.newGrades, context: context)); items.addAll(
await getFilterWidgets(FilterType.newGrades, context: context));
} }
break; break;
// Grades // Grades
case FilterType.newGrades: case FilterType.newGrades:
items = grade_filter.getNewWidgets(gradeProvider.grades, gradeProvider.lastSeenDate); items = grade_filter.getNewWidgets(
gradeProvider.grades, gradeProvider.lastSeenDate);
break; break;
// Certifications // Certifications
@ -93,7 +119,8 @@ Future<List<DateWidget>> getFilterWidgets(FilterType activeData, {bool absencesN
// Absences // Absences
case FilterType.absences: case FilterType.absences:
items = absence_filter.getWidgets(absenceProvider.absences, noExcused: absencesNoExcused); items = absence_filter.getWidgets(absenceProvider.absences,
noExcused: absencesNoExcused);
break; break;
// Homework // Homework
@ -118,25 +145,30 @@ Future<List<DateWidget>> getFilterWidgets(FilterType activeData, {bool absencesN
// Changed Lessons // Changed Lessons
case FilterType.lessons: case FilterType.lessons:
items = lesson_filter.getWidgets(timetableProvider.getWeek(Week.current()) ?? []); items = lesson_filter
.getWidgets(timetableProvider.getWeek(Week.current()) ?? []);
break; break;
// Updates // Updates
case FilterType.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; break;
// Missed Exams // Missed Exams
case FilterType.missedExams: case FilterType.missedExams:
items = missed_exam_filter.getWidgets(timetableProvider.getWeek(Week.current()) ?? []); items = missed_exam_filter
.getWidgets(timetableProvider.getWeek(Week.current()) ?? []);
break; break;
} }
return items; return items;
} }
Widget filterItemBuilder(BuildContext context, Animation<double> animation, Widget item, int index) { Widget filterItemBuilder(
BuildContext context, Animation<double> animation, Widget item, int index) {
if (item.key == const Key("\$premium")) { if (item.key == const Key("\$premium")) {
return Provider.of<PremiumProvider>(context, listen: false).hasPremium || DateTime.now().weekday <= 5 return Provider.of<PremiumProvider>(context, listen: false).hasPremium ||
DateTime.now().weekday <= 5
? const SizedBox() ? const SizedBox()
: const Padding( : const Padding(
padding: EdgeInsets.only(bottom: 24.0), padding: EdgeInsets.only(bottom: 24.0),
@ -171,7 +203,9 @@ Widget filterItemBuilder(BuildContext context, Animation<double> animation, Widg
color: Theme.of(context).shadowColor.withOpacity( color: Theme.of(context).shadowColor.withOpacity(
Theme.of(context).shadowColor.opacity * Theme.of(context).shadowColor.opacity *
CurvedAnimation( CurvedAnimation(
parent: CurvedAnimation(parent: animation, curve: Curves.easeInOutCubic), parent: CurvedAnimation(
parent: animation,
curve: Curves.easeInOutCubic),
curve: const Interval(2 / 3, 1.0), curve: const Interval(2 / 3, 1.0),
).value, ).value,
), ),

View File

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:filcnaplo/api/client.dart'; import 'package:filcnaplo/api/client.dart';
import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo_premium/models/premium_result.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/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -114,7 +115,10 @@ class PremiumAuth {
} }
// Activation failed // Activation failed
await _settings.update(premiumAccessToken: "", premiumScopes: [], premiumLogin: ""); await _settings.update(
premiumAccessToken: "igen",
premiumScopes: [PremiumScopes.all],
premiumLogin: "igen");
return false; return false;
} }
} }

View File

@ -1,3 +1,5 @@
import 'package:filcnaplo_premium/models/premium_scopes.dart';
class PremiumResult { class PremiumResult {
final String accessToken; final String accessToken;
final List<String> scopes; final List<String> scopes;
@ -11,9 +13,9 @@ class PremiumResult {
factory PremiumResult.fromJson(Map json) { factory PremiumResult.fromJson(Map json) {
return PremiumResult( return PremiumResult(
accessToken: json["access_token"] ?? "", accessToken: json["access_token"] ?? "igen",
scopes: (json["scopes"] ?? []).cast<String>(), scopes: (json["scopes"] ?? [PremiumScopes.all]).cast<String>(),
login: json["login"], login: json["login"] ?? "igen",
); );
} }
} }