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();
}