updated project style guidelines
This commit is contained in:
@ -17,9 +17,7 @@ class AccountData {
|
||||
final Future<SharedPreferences> _storage = SharedPreferences.getInstance();
|
||||
Completer<void> _populated = Completer();
|
||||
|
||||
factory AccountData() {
|
||||
return _instance;
|
||||
}
|
||||
factory AccountData() => _instance;
|
||||
|
||||
AccountData._construct() {
|
||||
_updateFromStorage();
|
||||
@ -38,16 +36,12 @@ class AccountData {
|
||||
return _password!;
|
||||
}
|
||||
|
||||
String getUserSecret() {
|
||||
return sha512.convert(utf8.encode('${AccountData().getUsername()}:${AccountData().getPassword()}')).toString();
|
||||
}
|
||||
String getUserSecret() => sha512.convert(utf8.encode('${AccountData().getUsername()}:${AccountData().getPassword()}')).toString();
|
||||
|
||||
Future<String> getDeviceId() async {
|
||||
return sha512.convert(utf8.encode('${getUserSecret()}@${await FirebaseMessaging.instance.getToken()}')).toString();
|
||||
}
|
||||
Future<String> getDeviceId() async => sha512.convert(utf8.encode('${getUserSecret()}@${await FirebaseMessaging.instance.getToken()}')).toString();
|
||||
|
||||
Future<void> setData(String username, String password) async {
|
||||
SharedPreferences storage = await _storage;
|
||||
var storage = await _storage;
|
||||
|
||||
storage.setString(_usernameField, username);
|
||||
storage.setString(_passwordField, password);
|
||||
@ -59,13 +53,13 @@ class AccountData {
|
||||
|
||||
if(context != null) Provider.of<AccountModel>(context, listen: false).setState(AccountModelState.loggedOut);
|
||||
|
||||
SharedPreferences storage = await _storage;
|
||||
var storage = await _storage;
|
||||
await storage.remove(_usernameField);
|
||||
await storage.remove(_passwordField);
|
||||
}
|
||||
|
||||
Future<void> _updateFromStorage() async {
|
||||
SharedPreferences storage = await _storage;
|
||||
var storage = await _storage;
|
||||
//await storage.reload(); // This line was the cause of the first rejected google play upload :(
|
||||
if(storage.containsKey(_usernameField) && storage.containsKey(_passwordField)) {
|
||||
_username = storage.getString(_usernameField);
|
||||
@ -79,12 +73,10 @@ class AccountData {
|
||||
return isPopulated();
|
||||
}
|
||||
|
||||
bool isPopulated() {
|
||||
return _username != null && _password != null;
|
||||
}
|
||||
bool isPopulated() => _username != null && _password != null;
|
||||
|
||||
String buildHttpAuthString() {
|
||||
if(!isPopulated()) throw Exception('AccountData (e.g. username or password) is not initialized!');
|
||||
return '$_username:$_password';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ enum AccountModelState {
|
||||
undefined,
|
||||
loggedIn,
|
||||
loggedOut,
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,9 @@ class Breaker extends StatefulWidget {
|
||||
|
||||
class _BreakerState extends State<Breaker> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<BreakerProps>(
|
||||
Widget build(BuildContext context) => Consumer<BreakerProps>(
|
||||
builder: (context, value, child) {
|
||||
String? blocked = value.isBlocked(widget.breaker);
|
||||
var blocked = value.isBlocked(widget.breaker);
|
||||
if(blocked != null) {
|
||||
return PlaceholderView(icon: Icons.security_outlined, text: "Die App/ Dieser Bereich wurde als Schutzmaßnahme deaktiviert!\n\n${blocked.isEmpty ? "Es wurde vom Server kein Grund übermittelt." : blocked}");
|
||||
}
|
||||
@ -30,5 +29,4 @@ class _BreakerState extends State<Breaker> {
|
||||
return widget.child;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ class BreakerProps extends DataHolder {
|
||||
}
|
||||
|
||||
if(primaryLoading()) return null;
|
||||
GetBreakersResponse breakers = _getBreakersResponse!;
|
||||
var breakers = _getBreakersResponse!;
|
||||
|
||||
if(breakers.global.areas.contains(type)) return breakers.global.message;
|
||||
|
||||
int selfVersion = int.parse(packageInfo!.buildNumber);
|
||||
var selfVersion = int.parse(packageInfo!.buildNumber);
|
||||
for(var key in breakers.regional.keys) {
|
||||
GetBreakersReponseObject value = breakers.regional[key]!;
|
||||
var value = breakers.regional[key]!;
|
||||
|
||||
if(int.parse(key.split('b')[1]) >= selfVersion) {
|
||||
if(value.areas.contains(type)) return value.message;
|
||||
@ -35,9 +35,7 @@ class BreakerProps extends DataHolder {
|
||||
}
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getBreakersResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getBreakersResponse];
|
||||
|
||||
@override
|
||||
void run() {
|
||||
@ -48,4 +46,4 @@ class BreakerProps extends DataHolder {
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,7 @@ class ChatListProps extends DataHolder {
|
||||
GetRoomResponse get getRoomsResponse => _getRoomResponse!;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getRoomResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getRoomResponse];
|
||||
|
||||
@override
|
||||
void run({renew}) {
|
||||
@ -27,4 +25,4 @@ class ChatListProps extends DataHolder {
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,15 +11,13 @@ class ChatProps extends DataHolder {
|
||||
GetChatResponse get getChatResponse => _getChatResponse!;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getChatResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getChatResponse];
|
||||
|
||||
@override
|
||||
void run() {
|
||||
notifyListeners();
|
||||
if(_queryToken.isEmpty) return;
|
||||
DateTime requestStart = DateTime.now();
|
||||
var requestStart = DateTime.now();
|
||||
|
||||
GetChatCache(
|
||||
chatToken: _queryToken,
|
||||
@ -39,7 +37,5 @@ class ChatProps extends DataHolder {
|
||||
run();
|
||||
}
|
||||
|
||||
String currentToken() {
|
||||
return _queryToken;
|
||||
}
|
||||
}
|
||||
String currentToken() => _queryToken;
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ import 'package:localstore/localstore.dart';
|
||||
import '../widget/debug/cacheView.dart';
|
||||
|
||||
class DataCleaner {
|
||||
static void cleanOldCache() async {
|
||||
static Future<void> cleanOldCache() async {
|
||||
var cacheData = await Localstore.instance.collection(CacheView.collection).get();
|
||||
cacheData?.forEach((key, value) async {
|
||||
DateTime lastUpdate = DateTime.fromMillisecondsSinceEpoch(value['lastupdate']);
|
||||
var lastUpdate = DateTime.fromMillisecondsSinceEpoch(value['lastupdate']);
|
||||
if(DateTime.now().subtract(const Duration(days: 200)).isAfter(lastUpdate)) {
|
||||
await Localstore.instance.collection(CacheView.collection).doc(key.split('/').last).delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,17 @@ import '../api/apiResponse.dart';
|
||||
|
||||
abstract class DataHolder extends ChangeNotifier {
|
||||
|
||||
CollectionRef storage(String path) {
|
||||
return Localstore.instance.collection(path);
|
||||
}
|
||||
CollectionRef storage(String path) => Localstore.instance.collection(path);
|
||||
|
||||
void run();
|
||||
List<ApiResponse?> properties();
|
||||
|
||||
bool primaryLoading() {
|
||||
// log("${toString()} ${properties().map((e) => e != null ? "1" : "0").join(", ")}");
|
||||
for(ApiResponse? element in properties()) {
|
||||
for(var element in properties()) {
|
||||
if(element == null) return true;
|
||||
}
|
||||
return false;
|
||||
//return properties().where((element) => element != null).isEmpty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,17 +23,13 @@ class Endpoint {
|
||||
|
||||
Endpoint({required this.domain, this.path = ''});
|
||||
|
||||
String full() {
|
||||
return domain + path;
|
||||
}
|
||||
String full() => domain + path;
|
||||
}
|
||||
|
||||
class EndpointData {
|
||||
static final EndpointData _instance = EndpointData._construct();
|
||||
|
||||
factory EndpointData() {
|
||||
return _instance;
|
||||
}
|
||||
factory EndpointData() => _instance;
|
||||
|
||||
EndpointData._construct();
|
||||
|
||||
@ -43,8 +39,7 @@ class EndpointData {
|
||||
return existingName.startsWith('google') ? EndpointMode.stage : EndpointMode.live;
|
||||
}
|
||||
|
||||
Endpoint webuntis() {
|
||||
return EndpointOptions(
|
||||
Endpoint webuntis() => EndpointOptions(
|
||||
live: Endpoint(
|
||||
domain: 'peleus.webuntis.com',
|
||||
),
|
||||
@ -53,10 +48,8 @@ class EndpointData {
|
||||
path: '/marianum/marianummobile/webuntis/public/index.php/api'
|
||||
),
|
||||
).get(getEndpointMode());
|
||||
}
|
||||
|
||||
Endpoint nextcloud() {
|
||||
return EndpointOptions(
|
||||
Endpoint nextcloud() => EndpointOptions(
|
||||
live: Endpoint(
|
||||
domain: 'cloud.marianum-fulda.de',
|
||||
),
|
||||
@ -65,6 +58,5 @@ class EndpointData {
|
||||
path: '/marianum/marianummobile/cloud',
|
||||
)
|
||||
).get(getEndpointMode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,7 @@ class FilesProps extends DataHolder {
|
||||
}
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_listFilesResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_listFilesResponse];
|
||||
|
||||
@override
|
||||
void run() {
|
||||
@ -51,4 +49,4 @@ class FilesProps extends DataHolder {
|
||||
if(folderPath.isEmpty) currentFolderName = 'Home';
|
||||
run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,7 @@ class HolidaysProps extends DataHolder {
|
||||
GetHolidaysResponse get getHolidaysResponse => _getHolidaysResponse!;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getHolidaysResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getHolidaysResponse];
|
||||
|
||||
@override
|
||||
void run() {
|
||||
@ -23,4 +21,4 @@ class HolidaysProps extends DataHolder {
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,7 @@ class MessageProps extends DataHolder {
|
||||
GetMessagesResponse get getMessagesResponse => _getMessagesResponse!;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getMessagesResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getMessagesResponse];
|
||||
|
||||
@override
|
||||
void run({renew}) {
|
||||
@ -24,4 +22,4 @@ class MessageProps extends DataHolder {
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,7 @@ class TimetableProps extends DataHolder {
|
||||
bool get hasError => error != null;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getTimetableResponse, _getRoomsResponse, _getSubjectsResponse, _getHolidaysResponse, _getCustomTimetableEventResponse];
|
||||
}
|
||||
List<ApiResponse?> properties() => [_getTimetableResponse, _getRoomsResponse, _getSubjectsResponse, _getHolidaysResponse, _getCustomTimetableEventResponse];
|
||||
|
||||
@override
|
||||
void run({renew}) {
|
||||
@ -101,9 +99,7 @@ class TimetableProps extends DataHolder {
|
||||
|
||||
DateTime getDate(DateTime d) => DateTime(d.year, d.month, d.day);
|
||||
|
||||
bool isWeekend(DateTime queryDate) {
|
||||
return queryDate.weekday == DateTime.saturday || queryDate.weekday == DateTime.sunday;
|
||||
}
|
||||
bool isWeekend(DateTime queryDate) => queryDate.weekday == DateTime.saturday || queryDate.weekday == DateTime.sunday;
|
||||
|
||||
void updateWeek(DateTime start, DateTime end) {
|
||||
properties().forEach((element) => element = null);
|
||||
@ -123,7 +119,7 @@ class TimetableProps extends DataHolder {
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
DateTime queryWeek = DateTime.now().add(const Duration(days: 2));
|
||||
var queryWeek = DateTime.now().add(const Duration(days: 2));
|
||||
|
||||
startDate = getDate(queryWeek.subtract(Duration(days: queryWeek.weekday - 1)));
|
||||
endDate = getDate(queryWeek.add(Duration(days: DateTime.daysPerWeek - queryWeek.weekday)));
|
||||
@ -131,4 +127,4 @@ class TimetableProps extends DataHolder {
|
||||
run();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user