premium assets + livecard fix

This commit is contained in:
55nknown
2022-12-19 09:14:36 +01:00
parent 695f4e44f5
commit 84e65d2b7a
35 changed files with 183 additions and 62 deletions

View File

@@ -1,5 +1,3 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'dart:developer';
@@ -16,7 +14,7 @@ class FilcAPI {
// Public API
static const schoolList = "https://filcnaplo.hu/v2/school_list.json";
static const news = "https://filcnaplo.hu/v2/news.json";
static const supporters = "https://filcnaplo.hu/v2/supporters.json";
static const supporters = "https://api.filcnaplo.hu/sponsors";
// Private API
static const config = "https://api.filcnaplo.hu/config";
@@ -45,8 +43,8 @@ class FilcAPI {
} else {
throw "HTTP ${res.statusCode}: ${res.body}";
}
} catch (error) {
print("ERROR: FilcAPI.getSchools: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.getSchools: $error $stacktrace");
}
return null;
}
@@ -72,8 +70,8 @@ class FilcAPI {
if (res.statusCode == 200) return Config.fromJson(jsonDecode(res.body));
}
throw "HTTP ${res.statusCode}: ${res.body}";
} catch (error) {
print("ERROR: FilcAPI.getConfig: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.getConfig: $error $stacktrace");
}
return null;
}
@@ -87,8 +85,8 @@ class FilcAPI {
} else {
throw "HTTP ${res.statusCode}: ${res.body}";
}
} catch (error) {
print("ERROR: FilcAPI.getNews: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.getNews: $error $stacktrace");
}
return null;
}
@@ -102,8 +100,8 @@ class FilcAPI {
} else {
throw "HTTP ${res.statusCode}: ${res.body}";
}
} catch (error) {
print("ERROR: FilcAPI.getSupporters: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.getSupporters: $error $stacktrace");
}
return null;
}
@@ -117,8 +115,8 @@ class FilcAPI {
} else {
throw "HTTP ${res.statusCode}: ${res.body}";
}
} catch (error) {
print("ERROR: FilcAPI.getReleases: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.getReleases: $error $stacktrace");
}
return null;
}
@@ -128,8 +126,8 @@ class FilcAPI {
var client = http.Client();
var request = http.Request('GET', Uri.parse(release.url));
return client.send(request);
} catch (error) {
print("ERROR: FilcAPI.downloadRelease: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.downloadRelease: $error $stacktrace");
return Future.value(null);
}
}
@@ -146,8 +144,8 @@ class FilcAPI {
if (res.statusCode != 200) {
throw "HTTP ${res.statusCode}: ${res.body}";
}
} catch (error) {
print("ERROR: FilcAPI.sendReport: $error");
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.sendReport: $error $stacktrace");
}
}
}

View File

@@ -36,6 +36,7 @@ class LiveCardProvider extends ChangeNotifier {
required SettingsProvider settings,
}) : _timetable = timetable,
_settings = settings {
_liveActivitiesPlugin.init(appGroupId: "group.filcnaplo.livecard");
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
timetable.restore().then((_) => update());
_delay = settings.bellDelayEnabled ? Duration(seconds: settings.bellDelay) : Duration.zero;
@@ -115,7 +116,7 @@ class LiveCardProvider extends ChangeNotifier {
if (cmap != _lastActivity) {
_lastActivity = cmap;
if (_lastActivity != {}) {
if (_lastActivity.isNotEmpty) {
if (_latestActivityId == null) {
_liveActivitiesPlugin.createActivity(_lastActivity).then((value) => _latestActivityId = value);
} else {

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/models/user.dart';
import 'package:filcnaplo_kreta_api/models/student.dart';
@@ -28,7 +30,7 @@ class UserProvider with ChangeNotifier {
void setUser(String userId) async {
_selectedUserId = userId;
await _settings.update(lastAccountId: userId);
updateWidget();
if (Platform.isAndroid) updateWidget();
notifyListeners();
}
@@ -57,7 +59,7 @@ class UserProvider with ChangeNotifier {
} else {
await _settings.update(lastAccountId: "");
}
updateWidget();
if (Platform.isAndroid) updateWidget();
notifyListeners();
}

View File

@@ -19,4 +19,10 @@ class FilcIcons {
/// premium
static const IconData premium = IconData(0x04, fontFamily: iconFontFamily);
/// tinta
static const IconData tinta = IconData(0x05, fontFamily: iconFontFamily);
/// kupak
static const IconData kupak = IconData(0x06, fontFamily: iconFontFamily);
}

View File

@@ -1,38 +1,47 @@
class Supporter {
String name;
String amount;
String platform;
enum DonationType { once, monthly }
Supporter(this.name, this.amount, this.platform);
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) {
return Supporter(
(json["name"] ?? "").trim(),
json["amount"] ?? "",
json["platform"] ?? "",
avatar: json["avatar"] ?? "",
name: json["name"] ?? "Unknown",
comment: json["comment"] ?? "",
price: json["price"].toInt() ?? 0,
type: DonationType.values.asNameMap()[json["type"] ?? "once"] ?? DonationType.once,
);
}
}
class Supporters {
List<Supporter> top;
List<Supporter> all;
int progress;
int max;
final double progress;
final double max;
final String description;
final List<Supporter> github;
final List<Supporter> patreon;
Supporters({
required this.top,
required this.all,
required this.progress,
required this.max,
required this.description,
required this.github,
required this.patreon,
});
factory Supporters.fromJson(Map json) {
return Supporters(
max: (json["progress"] ?? {})["max"] ?? 1,
progress: (json["progress"] ?? {})["value"] ?? 0,
all: ((json["all"] ?? []) as List).cast<Map>().map((e) => Supporter.fromJson(e)).toList(),
top: ((json["top"] ?? []) as List).cast<Map>().map((e) => Supporter.fromJson(e)).toList(),
progress: json["percentage"].toDouble() ?? 100.0,
max: json["target"].toDouble() ?? 1.0,
description: json["description"] ?? "",
github: json["sponsors"]["github"].map((e) => Supporter.fromJson(e)).cast<Supporter>().toList(),
patreon: json["sponsors"]["patreon"].map((e) => Supporter.fromJson(e)).cast<Supporter>().toList(),
);
}
}

View File

@@ -35,7 +35,7 @@ class AppTheme {
Color backgroundColor =
accentColor == AccentColor.custom ? settings.customBackgroundColor : _paletteBackgroundLight(palette) ?? lightColors.background;
Color highlighColor =
Color highlightColor =
accentColor == AccentColor.custom ? settings.customHighlightColor : _paletteHighlightLight(palette) ?? lightColors.highlight;
return ThemeData(
@@ -43,25 +43,25 @@ class AppTheme {
useMaterial3: false,
fontFamily: _fontFamily,
scaffoldBackgroundColor: backgroundColor,
backgroundColor: highlighColor,
backgroundColor: highlightColor,
primaryColor: lightColors.filc,
dividerColor: const Color(0x00000000),
colorScheme: ColorScheme.fromSwatch(
accentColor: accent,
backgroundColor: backgroundColor,
brightness: Brightness.light,
cardColor: highlighColor,
cardColor: highlightColor,
errorColor: lightColors.red,
primaryColorDark: lightColors.filc,
),
shadowColor: highlighColor.withOpacity(.5), //lightColors.shadow,
shadowColor: highlightColor.withOpacity(.5), //lightColors.shadow,
appBarTheme: AppBarTheme(backgroundColor: backgroundColor),
indicatorColor: accent,
iconTheme: IconThemeData(color: lightColors.text.withOpacity(.75)),
navigationBarTheme: NavigationBarThemeData(
indicatorColor: accent.withOpacity(accentColor == AccentColor.adaptive ? 0.4 : 0.8),
iconTheme: MaterialStateProperty.all(IconThemeData(color: lightColors.text)),
backgroundColor: highlighColor,
backgroundColor: highlightColor,
labelTextStyle: MaterialStateProperty.all(TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.w500,
@@ -75,6 +75,7 @@ class AppTheme {
),
progressIndicatorTheme: ProgressIndicatorThemeData(color: accent),
expansionTileTheme: ExpansionTileThemeData(iconColor: accent),
cardColor: highlightColor,
);
}
@@ -133,6 +134,11 @@ class AppTheme {
),
progressIndicatorTheme: ProgressIndicatorThemeData(color: accent),
expansionTileTheme: ExpansionTileThemeData(iconColor: accent),
cardColor: highlightColor,
chipTheme: ChipThemeData(
backgroundColor: accent.withOpacity(.2),
elevation: 1,
),
);
}
}