igen
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
import 'dart:io';
|
||||
|
||||
class Config {
|
||||
String _userAgent;
|
||||
Map? json;
|
||||
static const String _version = String.fromEnvironment("APPVER", defaultValue: "2.2.0");
|
||||
|
||||
Config({required String userAgent, this.json}) : _userAgent = userAgent;
|
||||
|
||||
factory Config.fromJson(Map json) {
|
||||
return Config(
|
||||
userAgent: json["user_agent"] ?? "hu.filc.naplo/\$0/\$1/\$2",
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
|
||||
String get userAgent => _userAgent.replaceAll("\$0", _version).replaceAll("\$1", platform).replaceAll("\$2", "0");
|
||||
|
||||
static String get platform {
|
||||
if (Platform.isAndroid) {
|
||||
return "Android";
|
||||
} else if (Platform.isIOS) {
|
||||
return "iOS";
|
||||
} else if (Platform.isLinux) {
|
||||
return "Linux";
|
||||
} else if (Platform.isWindows) {
|
||||
return "Windows";
|
||||
} else if (Platform.isMacOS) {
|
||||
return "MacOS";
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => json.toString();
|
||||
}
|
||||
import 'dart:io';
|
||||
|
||||
class Config {
|
||||
String _userAgent;
|
||||
Map? json;
|
||||
static const String _version = String.fromEnvironment("APPVER", defaultValue: "2.2.0");
|
||||
|
||||
Config({required String userAgent, this.json}) : _userAgent = userAgent;
|
||||
|
||||
factory Config.fromJson(Map json) {
|
||||
return Config(
|
||||
userAgent: json["user_agent"] ?? "hu.filc.naplo/\$0/\$1/\$2",
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
|
||||
String get userAgent => _userAgent.replaceAll("\$0", _version).replaceAll("\$1", platform).replaceAll("\$2", "0");
|
||||
|
||||
static String get platform {
|
||||
if (Platform.isAndroid) {
|
||||
return "Android";
|
||||
} else if (Platform.isIOS) {
|
||||
return "iOS";
|
||||
} else if (Platform.isLinux) {
|
||||
return "Linux";
|
||||
} else if (Platform.isWindows) {
|
||||
return "Windows";
|
||||
} else if (Platform.isMacOS) {
|
||||
return "MacOS";
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => json.toString();
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
enum IconPack { material, cupertino }
|
||||
enum IconPack { material, cupertino }
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
class News {
|
||||
String title;
|
||||
String content;
|
||||
String link;
|
||||
String openLabel;
|
||||
String platform;
|
||||
bool emergency;
|
||||
Map? json;
|
||||
|
||||
News({
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.link,
|
||||
required this.openLabel,
|
||||
required this.platform,
|
||||
required this.emergency,
|
||||
this.json,
|
||||
});
|
||||
|
||||
factory News.fromJson(Map json) {
|
||||
return News(
|
||||
title: json["title"] ?? "",
|
||||
content: json["content"] ?? "",
|
||||
link: json["link"] ?? "",
|
||||
openLabel: json["open_label"] ?? "",
|
||||
platform: json["platform"] ?? "",
|
||||
emergency: json["emergency"] ?? false,
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
}
|
||||
class News {
|
||||
String title;
|
||||
String content;
|
||||
String link;
|
||||
String openLabel;
|
||||
String platform;
|
||||
bool emergency;
|
||||
Map? json;
|
||||
|
||||
News({
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.link,
|
||||
required this.openLabel,
|
||||
required this.platform,
|
||||
required this.emergency,
|
||||
this.json,
|
||||
});
|
||||
|
||||
factory News.fromJson(Map json) {
|
||||
return News(
|
||||
title: json["title"] ?? "",
|
||||
content: json["content"] ?? "",
|
||||
link: json["link"] ?? "",
|
||||
openLabel: json["open_label"] ?? "",
|
||||
platform: json["platform"] ?? "",
|
||||
emergency: json["emergency"] ?? false,
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,151 +1,151 @@
|
||||
class ReleaseDownload {
|
||||
String url;
|
||||
int size;
|
||||
|
||||
ReleaseDownload({
|
||||
required this.url,
|
||||
required this.size,
|
||||
});
|
||||
|
||||
factory ReleaseDownload.fromJson(Map json) {
|
||||
return ReleaseDownload(
|
||||
url: json["browser_download_url"] ?? "",
|
||||
size: json["size"] ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Release {
|
||||
String tag;
|
||||
Version version;
|
||||
String author;
|
||||
String body;
|
||||
List<ReleaseDownload> downloads;
|
||||
bool prerelease;
|
||||
|
||||
Release({
|
||||
required this.tag,
|
||||
required this.author,
|
||||
required this.body,
|
||||
required this.downloads,
|
||||
required this.prerelease,
|
||||
required this.version,
|
||||
});
|
||||
|
||||
factory Release.fromJson(Map json) {
|
||||
return Release(
|
||||
tag: json["tag_name"] ?? Version.zero.toString(),
|
||||
author: json["author"] != null ? json["author"]["login"] ?? "" : "",
|
||||
body: json["body"] ?? "",
|
||||
downloads: json["assets"] != null ? json["assets"].map((a) => ReleaseDownload.fromJson(a)).toList().cast<ReleaseDownload>() : [],
|
||||
prerelease: json["prerelease"] ?? false,
|
||||
version: Version.fromString(json["tag_name"] ?? ""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Version {
|
||||
final int major;
|
||||
final int minor;
|
||||
final int patch;
|
||||
final String prerelease;
|
||||
final int prever;
|
||||
|
||||
const Version(this.major, this.minor, this.patch, {this.prerelease = "", this.prever = 0});
|
||||
|
||||
factory Version.fromString(String o) {
|
||||
String string = o;
|
||||
int x = 0, y = 0, z = 0; // major, minor, patch (1.1.1)
|
||||
String pre = ""; // prerelease string (-beta)
|
||||
int prev = 0; // prerelease version (.1)
|
||||
|
||||
try {
|
||||
// cut build
|
||||
string = string.split("+")[0];
|
||||
|
||||
// cut prerelease
|
||||
var p = string.split("-");
|
||||
string = p[0];
|
||||
if (p.length > 1) pre = p[1];
|
||||
|
||||
// prerelease
|
||||
p = pre.split(".");
|
||||
|
||||
if (p.length > 1) prev = int.tryParse(p[1]) ?? 0;
|
||||
|
||||
// check for valid prerelease name
|
||||
if (p[0] != "") {
|
||||
if (prereleases.contains(p[0].toLowerCase().trim())) {
|
||||
pre = p[0];
|
||||
} else {
|
||||
throw "invalid prerelease name: ${p[0]}";
|
||||
}
|
||||
}
|
||||
|
||||
// core
|
||||
p = string.split(".");
|
||||
if (p.length != 3) throw "invalid core length: ${p.length}";
|
||||
|
||||
x = int.tryParse(p[0]) ?? 0;
|
||||
y = int.tryParse(p[1]) ?? 0;
|
||||
z = int.tryParse(p[2]) ?? 0;
|
||||
|
||||
return Version(x, y, z, prerelease: pre, prever: prev);
|
||||
} catch (error) {
|
||||
// ignore: avoid_print
|
||||
print("WARNING: Failed to parse version ($o): $error");
|
||||
return Version.zero;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (other is! Version) return false;
|
||||
return other.major == major && other.minor == minor && other.patch == patch && other.prei == prei && other.prever == prever;
|
||||
}
|
||||
|
||||
int compareTo(Version other) {
|
||||
if (other == this) return 0;
|
||||
|
||||
if (major > other.major) {
|
||||
return 1;
|
||||
} else if (major == other.major) {
|
||||
if (minor > other.minor) {
|
||||
return 1;
|
||||
} else if (minor == other.minor) {
|
||||
if (patch > other.patch) {
|
||||
return 1;
|
||||
} else if (patch == other.patch) {
|
||||
if (prei > other.prei) {
|
||||
return 1;
|
||||
} else if (other.prei == prei) {
|
||||
if (prever > other.prever) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String str = "$major.$minor.$patch";
|
||||
if (prerelease != "") str += "-$prerelease";
|
||||
if (prever != 0) str += ".$prever";
|
||||
return str;
|
||||
}
|
||||
|
||||
int get prei {
|
||||
if (prerelease != "") return prereleases.indexOf(prerelease);
|
||||
return prereleases.length;
|
||||
}
|
||||
|
||||
static const zero = Version(0, 0, 0);
|
||||
static const List<String> prereleases = ["dev", "pre", "alpha", "beta", "rc", "nightly", "test"];
|
||||
|
||||
@override
|
||||
int get hashCode => toString().hashCode;
|
||||
}
|
||||
class ReleaseDownload {
|
||||
String url;
|
||||
int size;
|
||||
|
||||
ReleaseDownload({
|
||||
required this.url,
|
||||
required this.size,
|
||||
});
|
||||
|
||||
factory ReleaseDownload.fromJson(Map json) {
|
||||
return ReleaseDownload(
|
||||
url: json["browser_download_url"] ?? "",
|
||||
size: json["size"] ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Release {
|
||||
String tag;
|
||||
Version version;
|
||||
String author;
|
||||
String body;
|
||||
List<ReleaseDownload> downloads;
|
||||
bool prerelease;
|
||||
|
||||
Release({
|
||||
required this.tag,
|
||||
required this.author,
|
||||
required this.body,
|
||||
required this.downloads,
|
||||
required this.prerelease,
|
||||
required this.version,
|
||||
});
|
||||
|
||||
factory Release.fromJson(Map json) {
|
||||
return Release(
|
||||
tag: json["tag_name"] ?? Version.zero.toString(),
|
||||
author: json["author"] != null ? json["author"]["login"] ?? "" : "",
|
||||
body: json["body"] ?? "",
|
||||
downloads: json["assets"] != null ? json["assets"].map((a) => ReleaseDownload.fromJson(a)).toList().cast<ReleaseDownload>() : [],
|
||||
prerelease: json["prerelease"] ?? false,
|
||||
version: Version.fromString(json["tag_name"] ?? ""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Version {
|
||||
final int major;
|
||||
final int minor;
|
||||
final int patch;
|
||||
final String prerelease;
|
||||
final int prever;
|
||||
|
||||
const Version(this.major, this.minor, this.patch, {this.prerelease = "", this.prever = 0});
|
||||
|
||||
factory Version.fromString(String o) {
|
||||
String string = o;
|
||||
int x = 0, y = 0, z = 0; // major, minor, patch (1.1.1)
|
||||
String pre = ""; // prerelease string (-beta)
|
||||
int prev = 0; // prerelease version (.1)
|
||||
|
||||
try {
|
||||
// cut build
|
||||
string = string.split("+")[0];
|
||||
|
||||
// cut prerelease
|
||||
var p = string.split("-");
|
||||
string = p[0];
|
||||
if (p.length > 1) pre = p[1];
|
||||
|
||||
// prerelease
|
||||
p = pre.split(".");
|
||||
|
||||
if (p.length > 1) prev = int.tryParse(p[1]) ?? 0;
|
||||
|
||||
// check for valid prerelease name
|
||||
if (p[0] != "") {
|
||||
if (prereleases.contains(p[0].toLowerCase().trim())) {
|
||||
pre = p[0];
|
||||
} else {
|
||||
throw "invalid prerelease name: ${p[0]}";
|
||||
}
|
||||
}
|
||||
|
||||
// core
|
||||
p = string.split(".");
|
||||
if (p.length != 3) throw "invalid core length: ${p.length}";
|
||||
|
||||
x = int.tryParse(p[0]) ?? 0;
|
||||
y = int.tryParse(p[1]) ?? 0;
|
||||
z = int.tryParse(p[2]) ?? 0;
|
||||
|
||||
return Version(x, y, z, prerelease: pre, prever: prev);
|
||||
} catch (error) {
|
||||
// ignore: avoid_print
|
||||
print("WARNING: Failed to parse version ($o): $error");
|
||||
return Version.zero;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (other is! Version) return false;
|
||||
return other.major == major && other.minor == minor && other.patch == patch && other.prei == prei && other.prever == prever;
|
||||
}
|
||||
|
||||
int compareTo(Version other) {
|
||||
if (other == this) return 0;
|
||||
|
||||
if (major > other.major) {
|
||||
return 1;
|
||||
} else if (major == other.major) {
|
||||
if (minor > other.minor) {
|
||||
return 1;
|
||||
} else if (minor == other.minor) {
|
||||
if (patch > other.patch) {
|
||||
return 1;
|
||||
} else if (patch == other.patch) {
|
||||
if (prei > other.prei) {
|
||||
return 1;
|
||||
} else if (other.prei == prei) {
|
||||
if (prever > other.prever) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String str = "$major.$minor.$patch";
|
||||
if (prerelease != "") str += "-$prerelease";
|
||||
if (prever != 0) str += ".$prever";
|
||||
return str;
|
||||
}
|
||||
|
||||
int get prei {
|
||||
if (prerelease != "") return prereleases.indexOf(prerelease);
|
||||
return prereleases.length;
|
||||
}
|
||||
|
||||
static const zero = Version(0, 0, 0);
|
||||
static const List<String> prereleases = ["dev", "pre", "alpha", "beta", "rc", "nightly", "test"];
|
||||
|
||||
@override
|
||||
int get hashCode => toString().hashCode;
|
||||
}
|
||||
|
||||
@@ -1,390 +1,390 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
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:flutter/material.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum Pages { home, grades, timetable, messages, absences }
|
||||
|
||||
enum UpdateChannel { stable, beta, dev }
|
||||
|
||||
enum VibrationStrength { off, light, medium, strong }
|
||||
|
||||
class SettingsProvider extends ChangeNotifier {
|
||||
final DatabaseProvider? _database;
|
||||
|
||||
// en_en, hu_hu, de_de
|
||||
String _language;
|
||||
Pages _startPage;
|
||||
// divide by 10
|
||||
int _rounding;
|
||||
ThemeMode _theme;
|
||||
AccentColor _accentColor;
|
||||
// zero is one, ...
|
||||
List<Color> _gradeColors;
|
||||
bool _newsEnabled;
|
||||
int _newsState;
|
||||
bool _notificationsEnabled;
|
||||
/*
|
||||
notificationsBitfield values:
|
||||
|
||||
1 << 0 current lesson
|
||||
1 << 1 newsletter
|
||||
1 << 2 grades
|
||||
1 << 3 notes and events
|
||||
1 << 4 inbox messages
|
||||
1 << 5 substituted lessons and cancelled lessons
|
||||
1 << 6 absences and misses
|
||||
1 << 7 exams and homework
|
||||
*/
|
||||
int _notificationsBitfield;
|
||||
// minutes: times 15
|
||||
int _notificationPollInterval;
|
||||
bool _developerMode;
|
||||
VibrationStrength _vibrate;
|
||||
bool _abWeeks;
|
||||
bool _swapABweeks;
|
||||
UpdateChannel _updateChannel;
|
||||
Config _config;
|
||||
String _xFilcId;
|
||||
bool _graphClassAvg;
|
||||
bool _goodStudent;
|
||||
bool _presentationMode;
|
||||
bool _bellDelayEnabled;
|
||||
int _bellDelay;
|
||||
bool _gradeOpeningFun;
|
||||
IconPack _iconPack;
|
||||
Color _customAccentColor;
|
||||
Color _customBackgroundColor;
|
||||
Color _customHighlightColor;
|
||||
List<String> _premiumScopes;
|
||||
String _premiumAccessToken;
|
||||
String _premiumLogin;
|
||||
String _lastAccountId;
|
||||
bool _renamedSubjectsEnabled;
|
||||
|
||||
SettingsProvider({
|
||||
DatabaseProvider? database,
|
||||
required String language,
|
||||
required Pages startPage,
|
||||
required int rounding,
|
||||
required ThemeMode theme,
|
||||
required AccentColor accentColor,
|
||||
required List<Color> gradeColors,
|
||||
required bool newsEnabled,
|
||||
required int newsState,
|
||||
required bool notificationsEnabled,
|
||||
required int notificationsBitfield,
|
||||
required bool developerMode,
|
||||
required int notificationPollInterval,
|
||||
required VibrationStrength vibrate,
|
||||
required bool abWeeks,
|
||||
required bool swapABweeks,
|
||||
required UpdateChannel updateChannel,
|
||||
required Config config,
|
||||
required String xFilcId,
|
||||
required bool graphClassAvg,
|
||||
required bool goodStudent,
|
||||
required bool presentationMode,
|
||||
required bool bellDelayEnabled,
|
||||
required int bellDelay,
|
||||
required bool gradeOpeningFun,
|
||||
required IconPack iconPack,
|
||||
required Color customAccentColor,
|
||||
required Color customBackgroundColor,
|
||||
required Color customHighlightColor,
|
||||
required List<String> premiumScopes,
|
||||
required String premiumAccessToken,
|
||||
required String premiumLogin,
|
||||
required String lastAccountId,
|
||||
required bool renameSubjectsEnabled,
|
||||
}) : _database = database,
|
||||
_language = language,
|
||||
_startPage = startPage,
|
||||
_rounding = rounding,
|
||||
_theme = theme,
|
||||
_accentColor = accentColor,
|
||||
_gradeColors = gradeColors,
|
||||
_newsEnabled = newsEnabled,
|
||||
_newsState = newsState,
|
||||
_notificationsEnabled = notificationsEnabled,
|
||||
_notificationsBitfield = notificationsBitfield,
|
||||
_developerMode = developerMode,
|
||||
_notificationPollInterval = notificationPollInterval,
|
||||
_vibrate = vibrate,
|
||||
_abWeeks = abWeeks,
|
||||
_swapABweeks = swapABweeks,
|
||||
_updateChannel = updateChannel,
|
||||
_config = config,
|
||||
_xFilcId = xFilcId,
|
||||
_graphClassAvg = graphClassAvg,
|
||||
_goodStudent = goodStudent,
|
||||
_presentationMode = presentationMode,
|
||||
_bellDelayEnabled = bellDelayEnabled,
|
||||
_bellDelay = bellDelay,
|
||||
_gradeOpeningFun = gradeOpeningFun,
|
||||
_iconPack = iconPack,
|
||||
_customAccentColor = customAccentColor,
|
||||
_customBackgroundColor = customBackgroundColor,
|
||||
_customHighlightColor = customHighlightColor,
|
||||
_premiumScopes = premiumScopes,
|
||||
_premiumAccessToken = premiumAccessToken,
|
||||
_premiumLogin = premiumLogin,
|
||||
_lastAccountId = lastAccountId,
|
||||
_renamedSubjectsEnabled = renameSubjectsEnabled;
|
||||
|
||||
factory SettingsProvider.fromMap(Map map, {required DatabaseProvider database}) {
|
||||
Map<String, Object?>? configMap;
|
||||
|
||||
try {
|
||||
configMap = jsonDecode(map["config"] ?? "{}");
|
||||
} catch (e) {
|
||||
log("[ERROR] SettingsProvider.fromMap: $e");
|
||||
}
|
||||
|
||||
return SettingsProvider(
|
||||
database: database,
|
||||
language: map["language"],
|
||||
startPage: Pages.values[map["start_page"]],
|
||||
rounding: map["rounding"],
|
||||
theme: ThemeMode.values[map["theme"]],
|
||||
accentColor: AccentColor.values[map["accent_color"]],
|
||||
gradeColors: [
|
||||
Color(map["grade_color1"]),
|
||||
Color(map["grade_color2"]),
|
||||
Color(map["grade_color3"]),
|
||||
Color(map["grade_color4"]),
|
||||
Color(map["grade_color5"]),
|
||||
],
|
||||
newsEnabled: map["news"] == 1,
|
||||
newsState: map["news_state"],
|
||||
notificationsEnabled: map["notifications"] == 1,
|
||||
notificationsBitfield: map["notifications_bitfield"],
|
||||
notificationPollInterval: map["notification_poll_interval"],
|
||||
developerMode: map["developer_mode"] == 1,
|
||||
vibrate: VibrationStrength.values[map["vibration_strength"]],
|
||||
abWeeks: map["ab_weeks"] == 1,
|
||||
swapABweeks: map["swap_ab_weeks"] == 1,
|
||||
updateChannel: UpdateChannel.values[map["update_channel"]],
|
||||
config: Config.fromJson(configMap ?? {}),
|
||||
xFilcId: map["x_filc_id"],
|
||||
graphClassAvg: map["graph_class_avg"] == 1,
|
||||
goodStudent: false,
|
||||
presentationMode: map["presentation_mode"] == 1,
|
||||
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"]]!,
|
||||
customAccentColor: Color(map["custom_accent_color"]),
|
||||
customBackgroundColor: Color(map["custom_background_color"]),
|
||||
customHighlightColor: Color(map["custom_highlight_color"]),
|
||||
premiumScopes: jsonDecode(map["premium_scopes"]).cast<String>(),
|
||||
premiumAccessToken: map["premium_token"],
|
||||
premiumLogin: map["premium_login"],
|
||||
lastAccountId: map["last_account_id"],
|
||||
renameSubjectsEnabled: map["renamed_subjects_enabled"] == 1,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"language": _language,
|
||||
"start_page": _startPage.index,
|
||||
"rounding": _rounding,
|
||||
"theme": _theme.index,
|
||||
"accent_color": _accentColor.index,
|
||||
"news": _newsEnabled ? 1 : 0,
|
||||
"news_state": _newsState,
|
||||
"notifications": _notificationsEnabled ? 1 : 0,
|
||||
"notifications_bitfield": _notificationsBitfield,
|
||||
"developer_mode": _developerMode ? 1 : 0,
|
||||
"grade_color1": _gradeColors[0].value,
|
||||
"grade_color2": _gradeColors[1].value,
|
||||
"grade_color3": _gradeColors[2].value,
|
||||
"grade_color4": _gradeColors[3].value,
|
||||
"grade_color5": _gradeColors[4].value,
|
||||
"update_channel": _updateChannel.index,
|
||||
"vibration_strength": _vibrate.index,
|
||||
"ab_weeks": _abWeeks ? 1 : 0,
|
||||
"swap_ab_weeks": _swapABweeks ? 1 : 0,
|
||||
"notification_poll_interval": _notificationPollInterval,
|
||||
"config": jsonEncode(config.json),
|
||||
"x_filc_id": _xFilcId,
|
||||
"graph_class_avg": _graphClassAvg ? 1 : 0,
|
||||
"presentation_mode": _presentationMode ? 1 : 0,
|
||||
"bell_delay_enabled": _bellDelayEnabled ? 1 : 0,
|
||||
"bell_delay": _bellDelay,
|
||||
"grade_opening_fun": _gradeOpeningFun ? 1 : 0,
|
||||
"icon_pack": _iconPack.name,
|
||||
"custom_accent_color": _customAccentColor.value,
|
||||
"custom_background_color": _customBackgroundColor.value,
|
||||
"custom_highlight_color": _customHighlightColor.value,
|
||||
"premium_scopes": jsonEncode(_premiumScopes),
|
||||
"premium_token": _premiumAccessToken,
|
||||
"premium_login": _premiumLogin,
|
||||
"last_account_id": _lastAccountId,
|
||||
"renamed_subjects_enabled": _renamedSubjectsEnabled ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
factory SettingsProvider.defaultSettings({DatabaseProvider? database}) {
|
||||
return SettingsProvider(
|
||||
database: database,
|
||||
language: "hu",
|
||||
startPage: Pages.home,
|
||||
rounding: 5,
|
||||
theme: ThemeMode.system,
|
||||
accentColor: AccentColor.filc,
|
||||
gradeColors: [
|
||||
DarkMobileAppColors().red,
|
||||
DarkMobileAppColors().orange,
|
||||
DarkMobileAppColors().yellow,
|
||||
DarkMobileAppColors().green,
|
||||
DarkMobileAppColors().filc,
|
||||
],
|
||||
newsEnabled: true,
|
||||
newsState: -1,
|
||||
notificationsEnabled: true,
|
||||
notificationsBitfield: 255,
|
||||
developerMode: false,
|
||||
notificationPollInterval: 1,
|
||||
vibrate: VibrationStrength.medium,
|
||||
abWeeks: false,
|
||||
swapABweeks: false,
|
||||
updateChannel: UpdateChannel.stable,
|
||||
config: Config.fromJson({}),
|
||||
xFilcId: const Uuid().v4(),
|
||||
graphClassAvg: false,
|
||||
goodStudent: false,
|
||||
presentationMode: false,
|
||||
bellDelayEnabled: false,
|
||||
bellDelay: 0,
|
||||
gradeOpeningFun: true,
|
||||
iconPack: IconPack.cupertino,
|
||||
customAccentColor: const Color(0xff20AC9B),
|
||||
customBackgroundColor: const Color(0xff000000),
|
||||
customHighlightColor: const Color(0xff222222),
|
||||
premiumScopes: [],
|
||||
premiumAccessToken: "",
|
||||
premiumLogin: "",
|
||||
lastAccountId: "",
|
||||
renameSubjectsEnabled: false,
|
||||
);
|
||||
}
|
||||
|
||||
// Getters
|
||||
String get language => _language;
|
||||
Pages get startPage => _startPage;
|
||||
int get rounding => _rounding;
|
||||
ThemeMode get theme => _theme;
|
||||
AccentColor get accentColor => _accentColor;
|
||||
List<Color> get gradeColors => _gradeColors;
|
||||
bool get newsEnabled => _newsEnabled;
|
||||
int get newsState => _newsState;
|
||||
bool get notificationsEnabled => _notificationsEnabled;
|
||||
int get notificationsBitfield => _notificationsBitfield;
|
||||
bool get developerMode => _developerMode;
|
||||
int get notificationPollInterval => _notificationPollInterval;
|
||||
VibrationStrength get vibrate => _vibrate;
|
||||
bool get abWeeks => _abWeeks;
|
||||
bool get swapABweeks => _swapABweeks;
|
||||
UpdateChannel get updateChannel => _updateChannel;
|
||||
Config get config => _config;
|
||||
String get xFilcId => _xFilcId;
|
||||
bool get graphClassAvg => _graphClassAvg;
|
||||
bool get goodStudent => _goodStudent;
|
||||
bool get presentationMode => _presentationMode;
|
||||
bool get bellDelayEnabled => _bellDelayEnabled;
|
||||
int get bellDelay => _bellDelay;
|
||||
bool get gradeOpeningFun => _gradeOpeningFun;
|
||||
IconPack get iconPack => _iconPack;
|
||||
Color? get customAccentColor => _customAccentColor == accentColorMap[AccentColor.custom] ? null : _customAccentColor;
|
||||
Color? get customBackgroundColor => _customBackgroundColor;
|
||||
Color? get customHighlightColor => _customHighlightColor;
|
||||
List<String> get premiumScopes => _premiumScopes;
|
||||
String get premiumAccessToken => _premiumAccessToken;
|
||||
String get premiumLogin => _premiumLogin;
|
||||
String get lastAccountId => _lastAccountId;
|
||||
bool get renamedSubjectsEnabled => _renamedSubjectsEnabled;
|
||||
|
||||
Future<void> update({
|
||||
bool store = true,
|
||||
String? language,
|
||||
Pages? startPage,
|
||||
int? rounding,
|
||||
ThemeMode? theme,
|
||||
AccentColor? accentColor,
|
||||
List<Color>? gradeColors,
|
||||
bool? newsEnabled,
|
||||
int? newsState,
|
||||
bool? notificationsEnabled,
|
||||
int? notificationsBitfield,
|
||||
bool? developerMode,
|
||||
int? notificationPollInterval,
|
||||
VibrationStrength? vibrate,
|
||||
bool? abWeeks,
|
||||
bool? swapABweeks,
|
||||
UpdateChannel? updateChannel,
|
||||
Config? config,
|
||||
String? xFilcId,
|
||||
bool? graphClassAvg,
|
||||
bool? goodStudent,
|
||||
bool? presentationMode,
|
||||
bool? bellDelayEnabled,
|
||||
int? bellDelay,
|
||||
bool? gradeOpeningFun,
|
||||
IconPack? iconPack,
|
||||
Color? customAccentColor,
|
||||
Color? customBackgroundColor,
|
||||
Color? customHighlightColor,
|
||||
List<String>? premiumScopes,
|
||||
String? premiumAccessToken,
|
||||
String? premiumLogin,
|
||||
String? lastAccountId,
|
||||
bool? renamedSubjectsEnabled,
|
||||
}) async {
|
||||
if (language != null && language != _language) _language = language;
|
||||
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 (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) {
|
||||
_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 (config != null && config != _config) _config = config;
|
||||
if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId;
|
||||
if (graphClassAvg != null && graphClassAvg != _graphClassAvg) _graphClassAvg = graphClassAvg;
|
||||
if (goodStudent != null) _goodStudent = goodStudent;
|
||||
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 (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 (store) await _database?.store.storeSettings(this);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
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:flutter/material.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum Pages { home, grades, timetable, messages, absences }
|
||||
|
||||
enum UpdateChannel { stable, beta, dev }
|
||||
|
||||
enum VibrationStrength { off, light, medium, strong }
|
||||
|
||||
class SettingsProvider extends ChangeNotifier {
|
||||
final DatabaseProvider? _database;
|
||||
|
||||
// en_en, hu_hu, de_de
|
||||
String _language;
|
||||
Pages _startPage;
|
||||
// divide by 10
|
||||
int _rounding;
|
||||
ThemeMode _theme;
|
||||
AccentColor _accentColor;
|
||||
// zero is one, ...
|
||||
List<Color> _gradeColors;
|
||||
bool _newsEnabled;
|
||||
int _newsState;
|
||||
bool _notificationsEnabled;
|
||||
/*
|
||||
notificationsBitfield values:
|
||||
|
||||
1 << 0 current lesson
|
||||
1 << 1 newsletter
|
||||
1 << 2 grades
|
||||
1 << 3 notes and events
|
||||
1 << 4 inbox messages
|
||||
1 << 5 substituted lessons and cancelled lessons
|
||||
1 << 6 absences and misses
|
||||
1 << 7 exams and homework
|
||||
*/
|
||||
int _notificationsBitfield;
|
||||
// minutes: times 15
|
||||
int _notificationPollInterval;
|
||||
bool _developerMode;
|
||||
VibrationStrength _vibrate;
|
||||
bool _abWeeks;
|
||||
bool _swapABweeks;
|
||||
UpdateChannel _updateChannel;
|
||||
Config _config;
|
||||
String _xFilcId;
|
||||
bool _graphClassAvg;
|
||||
bool _goodStudent;
|
||||
bool _presentationMode;
|
||||
bool _bellDelayEnabled;
|
||||
int _bellDelay;
|
||||
bool _gradeOpeningFun;
|
||||
IconPack _iconPack;
|
||||
Color _customAccentColor;
|
||||
Color _customBackgroundColor;
|
||||
Color _customHighlightColor;
|
||||
List<String> _premiumScopes;
|
||||
String _premiumAccessToken;
|
||||
String _premiumLogin;
|
||||
String _lastAccountId;
|
||||
bool _renamedSubjectsEnabled;
|
||||
|
||||
SettingsProvider({
|
||||
DatabaseProvider? database,
|
||||
required String language,
|
||||
required Pages startPage,
|
||||
required int rounding,
|
||||
required ThemeMode theme,
|
||||
required AccentColor accentColor,
|
||||
required List<Color> gradeColors,
|
||||
required bool newsEnabled,
|
||||
required int newsState,
|
||||
required bool notificationsEnabled,
|
||||
required int notificationsBitfield,
|
||||
required bool developerMode,
|
||||
required int notificationPollInterval,
|
||||
required VibrationStrength vibrate,
|
||||
required bool abWeeks,
|
||||
required bool swapABweeks,
|
||||
required UpdateChannel updateChannel,
|
||||
required Config config,
|
||||
required String xFilcId,
|
||||
required bool graphClassAvg,
|
||||
required bool goodStudent,
|
||||
required bool presentationMode,
|
||||
required bool bellDelayEnabled,
|
||||
required int bellDelay,
|
||||
required bool gradeOpeningFun,
|
||||
required IconPack iconPack,
|
||||
required Color customAccentColor,
|
||||
required Color customBackgroundColor,
|
||||
required Color customHighlightColor,
|
||||
required List<String> premiumScopes,
|
||||
required String premiumAccessToken,
|
||||
required String premiumLogin,
|
||||
required String lastAccountId,
|
||||
required bool renameSubjectsEnabled,
|
||||
}) : _database = database,
|
||||
_language = language,
|
||||
_startPage = startPage,
|
||||
_rounding = rounding,
|
||||
_theme = theme,
|
||||
_accentColor = accentColor,
|
||||
_gradeColors = gradeColors,
|
||||
_newsEnabled = newsEnabled,
|
||||
_newsState = newsState,
|
||||
_notificationsEnabled = notificationsEnabled,
|
||||
_notificationsBitfield = notificationsBitfield,
|
||||
_developerMode = developerMode,
|
||||
_notificationPollInterval = notificationPollInterval,
|
||||
_vibrate = vibrate,
|
||||
_abWeeks = abWeeks,
|
||||
_swapABweeks = swapABweeks,
|
||||
_updateChannel = updateChannel,
|
||||
_config = config,
|
||||
_xFilcId = xFilcId,
|
||||
_graphClassAvg = graphClassAvg,
|
||||
_goodStudent = goodStudent,
|
||||
_presentationMode = presentationMode,
|
||||
_bellDelayEnabled = bellDelayEnabled,
|
||||
_bellDelay = bellDelay,
|
||||
_gradeOpeningFun = gradeOpeningFun,
|
||||
_iconPack = iconPack,
|
||||
_customAccentColor = customAccentColor,
|
||||
_customBackgroundColor = customBackgroundColor,
|
||||
_customHighlightColor = customHighlightColor,
|
||||
_premiumScopes = premiumScopes,
|
||||
_premiumAccessToken = premiumAccessToken,
|
||||
_premiumLogin = premiumLogin,
|
||||
_lastAccountId = lastAccountId,
|
||||
_renamedSubjectsEnabled = renameSubjectsEnabled;
|
||||
|
||||
factory SettingsProvider.fromMap(Map map, {required DatabaseProvider database}) {
|
||||
Map<String, Object?>? configMap;
|
||||
|
||||
try {
|
||||
configMap = jsonDecode(map["config"] ?? "{}");
|
||||
} catch (e) {
|
||||
log("[ERROR] SettingsProvider.fromMap: $e");
|
||||
}
|
||||
|
||||
return SettingsProvider(
|
||||
database: database,
|
||||
language: map["language"],
|
||||
startPage: Pages.values[map["start_page"]],
|
||||
rounding: map["rounding"],
|
||||
theme: ThemeMode.values[map["theme"]],
|
||||
accentColor: AccentColor.values[map["accent_color"]],
|
||||
gradeColors: [
|
||||
Color(map["grade_color1"]),
|
||||
Color(map["grade_color2"]),
|
||||
Color(map["grade_color3"]),
|
||||
Color(map["grade_color4"]),
|
||||
Color(map["grade_color5"]),
|
||||
],
|
||||
newsEnabled: map["news"] == 1,
|
||||
newsState: map["news_state"],
|
||||
notificationsEnabled: map["notifications"] == 1,
|
||||
notificationsBitfield: map["notifications_bitfield"],
|
||||
notificationPollInterval: map["notification_poll_interval"],
|
||||
developerMode: map["developer_mode"] == 1,
|
||||
vibrate: VibrationStrength.values[map["vibration_strength"]],
|
||||
abWeeks: map["ab_weeks"] == 1,
|
||||
swapABweeks: map["swap_ab_weeks"] == 1,
|
||||
updateChannel: UpdateChannel.values[map["update_channel"]],
|
||||
config: Config.fromJson(configMap ?? {}),
|
||||
xFilcId: map["x_filc_id"],
|
||||
graphClassAvg: map["graph_class_avg"] == 1,
|
||||
goodStudent: false,
|
||||
presentationMode: map["presentation_mode"] == 1,
|
||||
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"]]!,
|
||||
customAccentColor: Color(map["custom_accent_color"]),
|
||||
customBackgroundColor: Color(map["custom_background_color"]),
|
||||
customHighlightColor: Color(map["custom_highlight_color"]),
|
||||
premiumScopes: jsonDecode(map["premium_scopes"]).cast<String>(),
|
||||
premiumAccessToken: map["premium_token"],
|
||||
premiumLogin: map["premium_login"],
|
||||
lastAccountId: map["last_account_id"],
|
||||
renameSubjectsEnabled: map["renamed_subjects_enabled"] == 1,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"language": _language,
|
||||
"start_page": _startPage.index,
|
||||
"rounding": _rounding,
|
||||
"theme": _theme.index,
|
||||
"accent_color": _accentColor.index,
|
||||
"news": _newsEnabled ? 1 : 0,
|
||||
"news_state": _newsState,
|
||||
"notifications": _notificationsEnabled ? 1 : 0,
|
||||
"notifications_bitfield": _notificationsBitfield,
|
||||
"developer_mode": _developerMode ? 1 : 0,
|
||||
"grade_color1": _gradeColors[0].value,
|
||||
"grade_color2": _gradeColors[1].value,
|
||||
"grade_color3": _gradeColors[2].value,
|
||||
"grade_color4": _gradeColors[3].value,
|
||||
"grade_color5": _gradeColors[4].value,
|
||||
"update_channel": _updateChannel.index,
|
||||
"vibration_strength": _vibrate.index,
|
||||
"ab_weeks": _abWeeks ? 1 : 0,
|
||||
"swap_ab_weeks": _swapABweeks ? 1 : 0,
|
||||
"notification_poll_interval": _notificationPollInterval,
|
||||
"config": jsonEncode(config.json),
|
||||
"x_filc_id": _xFilcId,
|
||||
"graph_class_avg": _graphClassAvg ? 1 : 0,
|
||||
"presentation_mode": _presentationMode ? 1 : 0,
|
||||
"bell_delay_enabled": _bellDelayEnabled ? 1 : 0,
|
||||
"bell_delay": _bellDelay,
|
||||
"grade_opening_fun": _gradeOpeningFun ? 1 : 0,
|
||||
"icon_pack": _iconPack.name,
|
||||
"custom_accent_color": _customAccentColor.value,
|
||||
"custom_background_color": _customBackgroundColor.value,
|
||||
"custom_highlight_color": _customHighlightColor.value,
|
||||
"premium_scopes": jsonEncode(_premiumScopes),
|
||||
"premium_token": _premiumAccessToken,
|
||||
"premium_login": _premiumLogin,
|
||||
"last_account_id": _lastAccountId,
|
||||
"renamed_subjects_enabled": _renamedSubjectsEnabled ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
factory SettingsProvider.defaultSettings({DatabaseProvider? database}) {
|
||||
return SettingsProvider(
|
||||
database: database,
|
||||
language: "hu",
|
||||
startPage: Pages.home,
|
||||
rounding: 5,
|
||||
theme: ThemeMode.system,
|
||||
accentColor: AccentColor.filc,
|
||||
gradeColors: [
|
||||
DarkMobileAppColors().red,
|
||||
DarkMobileAppColors().orange,
|
||||
DarkMobileAppColors().yellow,
|
||||
DarkMobileAppColors().green,
|
||||
DarkMobileAppColors().filc,
|
||||
],
|
||||
newsEnabled: true,
|
||||
newsState: -1,
|
||||
notificationsEnabled: true,
|
||||
notificationsBitfield: 255,
|
||||
developerMode: false,
|
||||
notificationPollInterval: 1,
|
||||
vibrate: VibrationStrength.medium,
|
||||
abWeeks: false,
|
||||
swapABweeks: false,
|
||||
updateChannel: UpdateChannel.stable,
|
||||
config: Config.fromJson({}),
|
||||
xFilcId: const Uuid().v4(),
|
||||
graphClassAvg: false,
|
||||
goodStudent: false,
|
||||
presentationMode: false,
|
||||
bellDelayEnabled: false,
|
||||
bellDelay: 0,
|
||||
gradeOpeningFun: true,
|
||||
iconPack: IconPack.cupertino,
|
||||
customAccentColor: const Color(0xff20AC9B),
|
||||
customBackgroundColor: const Color(0xff000000),
|
||||
customHighlightColor: const Color(0xff222222),
|
||||
premiumScopes: [],
|
||||
premiumAccessToken: "",
|
||||
premiumLogin: "",
|
||||
lastAccountId: "",
|
||||
renameSubjectsEnabled: false,
|
||||
);
|
||||
}
|
||||
|
||||
// Getters
|
||||
String get language => _language;
|
||||
Pages get startPage => _startPage;
|
||||
int get rounding => _rounding;
|
||||
ThemeMode get theme => _theme;
|
||||
AccentColor get accentColor => _accentColor;
|
||||
List<Color> get gradeColors => _gradeColors;
|
||||
bool get newsEnabled => _newsEnabled;
|
||||
int get newsState => _newsState;
|
||||
bool get notificationsEnabled => _notificationsEnabled;
|
||||
int get notificationsBitfield => _notificationsBitfield;
|
||||
bool get developerMode => _developerMode;
|
||||
int get notificationPollInterval => _notificationPollInterval;
|
||||
VibrationStrength get vibrate => _vibrate;
|
||||
bool get abWeeks => _abWeeks;
|
||||
bool get swapABweeks => _swapABweeks;
|
||||
UpdateChannel get updateChannel => _updateChannel;
|
||||
Config get config => _config;
|
||||
String get xFilcId => _xFilcId;
|
||||
bool get graphClassAvg => _graphClassAvg;
|
||||
bool get goodStudent => _goodStudent;
|
||||
bool get presentationMode => _presentationMode;
|
||||
bool get bellDelayEnabled => _bellDelayEnabled;
|
||||
int get bellDelay => _bellDelay;
|
||||
bool get gradeOpeningFun => _gradeOpeningFun;
|
||||
IconPack get iconPack => _iconPack;
|
||||
Color? get customAccentColor => _customAccentColor == accentColorMap[AccentColor.custom] ? null : _customAccentColor;
|
||||
Color? get customBackgroundColor => _customBackgroundColor;
|
||||
Color? get customHighlightColor => _customHighlightColor;
|
||||
List<String> get premiumScopes => _premiumScopes;
|
||||
String get premiumAccessToken => _premiumAccessToken;
|
||||
String get premiumLogin => _premiumLogin;
|
||||
String get lastAccountId => _lastAccountId;
|
||||
bool get renamedSubjectsEnabled => _renamedSubjectsEnabled;
|
||||
|
||||
Future<void> update({
|
||||
bool store = true,
|
||||
String? language,
|
||||
Pages? startPage,
|
||||
int? rounding,
|
||||
ThemeMode? theme,
|
||||
AccentColor? accentColor,
|
||||
List<Color>? gradeColors,
|
||||
bool? newsEnabled,
|
||||
int? newsState,
|
||||
bool? notificationsEnabled,
|
||||
int? notificationsBitfield,
|
||||
bool? developerMode,
|
||||
int? notificationPollInterval,
|
||||
VibrationStrength? vibrate,
|
||||
bool? abWeeks,
|
||||
bool? swapABweeks,
|
||||
UpdateChannel? updateChannel,
|
||||
Config? config,
|
||||
String? xFilcId,
|
||||
bool? graphClassAvg,
|
||||
bool? goodStudent,
|
||||
bool? presentationMode,
|
||||
bool? bellDelayEnabled,
|
||||
int? bellDelay,
|
||||
bool? gradeOpeningFun,
|
||||
IconPack? iconPack,
|
||||
Color? customAccentColor,
|
||||
Color? customBackgroundColor,
|
||||
Color? customHighlightColor,
|
||||
List<String>? premiumScopes,
|
||||
String? premiumAccessToken,
|
||||
String? premiumLogin,
|
||||
String? lastAccountId,
|
||||
bool? renamedSubjectsEnabled,
|
||||
}) async {
|
||||
if (language != null && language != _language) _language = language;
|
||||
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 (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) {
|
||||
_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 (config != null && config != _config) _config = config;
|
||||
if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId;
|
||||
if (graphClassAvg != null && graphClassAvg != _graphClassAvg) _graphClassAvg = graphClassAvg;
|
||||
if (goodStudent != null) _goodStudent = goodStudent;
|
||||
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 (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 (store) await _database?.store.storeSettings(this);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import 'package:filcnaplo_kreta_api/models/category.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/subject.dart';
|
||||
|
||||
enum SubjectLessonCountUpdateState { ready, updating }
|
||||
|
||||
class SubjectLessonCount {
|
||||
DateTime lastUpdated;
|
||||
Map<Subject, int> subjects;
|
||||
SubjectLessonCountUpdateState state;
|
||||
|
||||
SubjectLessonCount({required this.lastUpdated, required this.subjects, this.state = SubjectLessonCountUpdateState.ready});
|
||||
|
||||
factory SubjectLessonCount.fromMap(Map json) {
|
||||
return SubjectLessonCount(
|
||||
lastUpdated: DateTime.fromMillisecondsSinceEpoch(json["last_updated"] ?? 0),
|
||||
subjects: ((json["subjects"] as Map?) ?? {}).map(
|
||||
(key, value) => MapEntry(
|
||||
Subject(id: key, name: "", category: Category.fromJson({})),
|
||||
value,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Map toMap() {
|
||||
return {
|
||||
"last_updated": lastUpdated.millisecondsSinceEpoch,
|
||||
"subjects": subjects.map((key, value) => MapEntry(key.id, value)),
|
||||
};
|
||||
}
|
||||
}
|
||||
import 'package:filcnaplo_kreta_api/models/category.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/subject.dart';
|
||||
|
||||
enum SubjectLessonCountUpdateState { ready, updating }
|
||||
|
||||
class SubjectLessonCount {
|
||||
DateTime lastUpdated;
|
||||
Map<Subject, int> subjects;
|
||||
SubjectLessonCountUpdateState state;
|
||||
|
||||
SubjectLessonCount({required this.lastUpdated, required this.subjects, this.state = SubjectLessonCountUpdateState.ready});
|
||||
|
||||
factory SubjectLessonCount.fromMap(Map json) {
|
||||
return SubjectLessonCount(
|
||||
lastUpdated: DateTime.fromMillisecondsSinceEpoch(json["last_updated"] ?? 0),
|
||||
subjects: ((json["subjects"] as Map?) ?? {}).map(
|
||||
(key, value) => MapEntry(
|
||||
Subject(id: key, name: "", category: Category.fromJson({})),
|
||||
value,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Map toMap() {
|
||||
return {
|
||||
"last_updated": lastUpdated.millisecondsSinceEpoch,
|
||||
"subjects": subjects.map((key, value) => MapEntry(key.id, value)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
enum DonationType { once, monthly }
|
||||
|
||||
class Supporter {
|
||||
final String avatar;
|
||||
final String name;
|
||||
final String comment;
|
||||
final int price;
|
||||
final DonationType type;
|
||||
|
||||
const Supporter({required this.avatar, required this.name, this.comment = "", this.price = 0, this.type = DonationType.once});
|
||||
|
||||
factory Supporter.fromJson(Map json, {String? avatarPattern}) {
|
||||
return Supporter(
|
||||
avatar: json["avatar"] ?? avatarPattern != null ? avatarPattern!.replaceFirst("\$", json["name"]) : "",
|
||||
name: json["name"] ?? "Unknown",
|
||||
comment: json["comment"] ?? "",
|
||||
price: json["price"].toInt() ?? 0,
|
||||
type: DonationType.values.asNameMap()[json["type"] ?? "once"] ?? DonationType.once,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Supporters {
|
||||
final double progress;
|
||||
final double max;
|
||||
final String description;
|
||||
final List<Supporter> github;
|
||||
final List<Supporter> patreon;
|
||||
|
||||
Supporters({
|
||||
required this.progress,
|
||||
required this.max,
|
||||
required this.description,
|
||||
required this.github,
|
||||
required this.patreon,
|
||||
});
|
||||
|
||||
factory Supporters.fromJson(Map json) {
|
||||
return Supporters(
|
||||
progress: json["percentage"].toDouble() ?? 100.0,
|
||||
max: json["target"].toDouble() ?? 1.0,
|
||||
description: json["description"] ?? "",
|
||||
github: json["sponsors"]["github"]
|
||||
.map((e) => Supporter.fromJson(e, avatarPattern: "https://github.com/\$.png?size=200"))
|
||||
.cast<Supporter>()
|
||||
.toList(),
|
||||
patreon: json["sponsors"]["patreon"].map((e) => Supporter.fromJson(e)).cast<Supporter>().toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
enum DonationType { once, monthly }
|
||||
|
||||
class Supporter {
|
||||
final String avatar;
|
||||
final String name;
|
||||
final String comment;
|
||||
final int price;
|
||||
final DonationType type;
|
||||
|
||||
const Supporter({required this.avatar, required this.name, this.comment = "", this.price = 0, this.type = DonationType.once});
|
||||
|
||||
factory Supporter.fromJson(Map json, {String? avatarPattern}) {
|
||||
return Supporter(
|
||||
avatar: json["avatar"] ?? avatarPattern != null ? avatarPattern!.replaceFirst("\$", json["name"]) : "",
|
||||
name: json["name"] ?? "Unknown",
|
||||
comment: json["comment"] ?? "",
|
||||
price: json["price"].toInt() ?? 0,
|
||||
type: DonationType.values.asNameMap()[json["type"] ?? "once"] ?? DonationType.once,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Supporters {
|
||||
final double progress;
|
||||
final double max;
|
||||
final String description;
|
||||
final List<Supporter> github;
|
||||
final List<Supporter> patreon;
|
||||
|
||||
Supporters({
|
||||
required this.progress,
|
||||
required this.max,
|
||||
required this.description,
|
||||
required this.github,
|
||||
required this.patreon,
|
||||
});
|
||||
|
||||
factory Supporters.fromJson(Map json) {
|
||||
return Supporters(
|
||||
progress: json["percentage"].toDouble() ?? 100.0,
|
||||
max: json["target"].toDouble() ?? 1.0,
|
||||
description: json["description"] ?? "",
|
||||
github: json["sponsors"]["github"]
|
||||
.map((e) => Supporter.fromJson(e, avatarPattern: "https://github.com/\$.png?size=200"))
|
||||
.cast<Supporter>()
|
||||
.toList(),
|
||||
patreon: json["sponsors"]["patreon"].map((e) => Supporter.fromJson(e)).cast<Supporter>().toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
import 'dart:convert';
|
||||
import 'package:filcnaplo_kreta_api/client/api.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/student.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum Role { student, parent }
|
||||
|
||||
class User {
|
||||
late String id;
|
||||
String username;
|
||||
String password;
|
||||
String instituteCode;
|
||||
String name;
|
||||
Student student;
|
||||
Role role;
|
||||
String nickname;
|
||||
String picture;
|
||||
|
||||
String get displayName => nickname != '' ? nickname : name;
|
||||
|
||||
User({
|
||||
String? id,
|
||||
required this.name,
|
||||
required this.username,
|
||||
required this.password,
|
||||
required this.instituteCode,
|
||||
required this.student,
|
||||
required this.role,
|
||||
this.nickname = "",
|
||||
this.picture = "",
|
||||
}) {
|
||||
if (id != null) {
|
||||
this.id = id;
|
||||
} else {
|
||||
this.id = const Uuid().v4();
|
||||
}
|
||||
}
|
||||
|
||||
factory User.fromMap(Map map) {
|
||||
return User(
|
||||
id: map["id"],
|
||||
instituteCode: map["institute_code"],
|
||||
username: map["username"],
|
||||
password: map["password"],
|
||||
name: map["name"].trim(),
|
||||
student: Student.fromJson(jsonDecode(map["student"])),
|
||||
role: Role.values[map["role"] ?? 0],
|
||||
nickname: map["nickname"] ?? "",
|
||||
picture: map["picture"] ?? "",
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"id": id,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"institute_code": instituteCode,
|
||||
"name": name,
|
||||
"student": jsonEncode(student.json),
|
||||
"role": role.index,
|
||||
"nickname": nickname,
|
||||
"picture": picture,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => jsonEncode(toMap());
|
||||
|
||||
static Map<String, Object?> loginBody({
|
||||
required String username,
|
||||
required String password,
|
||||
required String instituteCode,
|
||||
}) {
|
||||
return {
|
||||
"userName": username,
|
||||
"password": password,
|
||||
"institute_code": instituteCode,
|
||||
"grant_type": "password",
|
||||
"client_id": KretaAPI.clientId,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, Object?> refreshBody({
|
||||
required String refreshToken,
|
||||
required String instituteCode,
|
||||
}) {
|
||||
return {
|
||||
"refresh_token": refreshToken,
|
||||
"institute_code": instituteCode,
|
||||
"client_id": KretaAPI.clientId,
|
||||
"grant_type": "refresh_token",
|
||||
"refresh_user_data": "false",
|
||||
};
|
||||
}
|
||||
}
|
||||
import 'dart:convert';
|
||||
import 'package:filcnaplo_kreta_api/client/api.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/student.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum Role { student, parent }
|
||||
|
||||
class User {
|
||||
late String id;
|
||||
String username;
|
||||
String password;
|
||||
String instituteCode;
|
||||
String name;
|
||||
Student student;
|
||||
Role role;
|
||||
String nickname;
|
||||
String picture;
|
||||
|
||||
String get displayName => nickname != '' ? nickname : name;
|
||||
|
||||
User({
|
||||
String? id,
|
||||
required this.name,
|
||||
required this.username,
|
||||
required this.password,
|
||||
required this.instituteCode,
|
||||
required this.student,
|
||||
required this.role,
|
||||
this.nickname = "",
|
||||
this.picture = "",
|
||||
}) {
|
||||
if (id != null) {
|
||||
this.id = id;
|
||||
} else {
|
||||
this.id = const Uuid().v4();
|
||||
}
|
||||
}
|
||||
|
||||
factory User.fromMap(Map map) {
|
||||
return User(
|
||||
id: map["id"],
|
||||
instituteCode: map["institute_code"],
|
||||
username: map["username"],
|
||||
password: map["password"],
|
||||
name: map["name"].trim(),
|
||||
student: Student.fromJson(jsonDecode(map["student"])),
|
||||
role: Role.values[map["role"] ?? 0],
|
||||
nickname: map["nickname"] ?? "",
|
||||
picture: map["picture"] ?? "",
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"id": id,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"institute_code": instituteCode,
|
||||
"name": name,
|
||||
"student": jsonEncode(student.json),
|
||||
"role": role.index,
|
||||
"nickname": nickname,
|
||||
"picture": picture,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => jsonEncode(toMap());
|
||||
|
||||
static Map<String, Object?> loginBody({
|
||||
required String username,
|
||||
required String password,
|
||||
required String instituteCode,
|
||||
}) {
|
||||
return {
|
||||
"userName": username,
|
||||
"password": password,
|
||||
"institute_code": instituteCode,
|
||||
"grant_type": "password",
|
||||
"client_id": KretaAPI.clientId,
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, Object?> refreshBody({
|
||||
required String refreshToken,
|
||||
required String instituteCode,
|
||||
}) {
|
||||
return {
|
||||
"refresh_token": refreshToken,
|
||||
"institute_code": instituteCode,
|
||||
"client_id": KretaAPI.clientId,
|
||||
"grant_type": "refresh_token",
|
||||
"refresh_user_data": "false",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user