Compare commits
97 Commits
feature-hi
...
ddeeaeaeac
Author | SHA1 | Date | |
---|---|---|---|
ddeeaeaeac | |||
c8e31b896b | |||
c443a1d567 | |||
08ef784f57 | |||
999e30ab3a | |||
c4c882a77d | |||
fe93a94fc6 | |||
a33c4ddac5 | |||
634fe41e78 | |||
328c4f410c | |||
43471fcf3d | |||
e78e2b8cd4 | |||
a57f42d4ed | |||
8ff993bf19 | |||
8968e53e5c | |||
430f2fe603 | |||
d00592c3e7 | |||
3fb48b5bcf | |||
69fc98ad45 | |||
76a1f65083 | |||
ed35e91d59 | |||
ebbb70dc96 | |||
3281b134e0 | |||
2056be23cd | |||
e57a1a915e | |||
181682a424 | |||
9fa711e460 | |||
1f30e2d97f | |||
0f84257eba | |||
b171fef348 | |||
81f5b662b7 | |||
7a393bf630 | |||
fc72391a75 | |||
6ad8203b6a | |||
f58a2ec8cd | |||
91ef689d2a | |||
ee6af2bc07 | |||
2db3b29359 | |||
107a5bdbf8 | |||
3802e4a5b9 | |||
04e8ce9c0a | |||
450c26b187 | |||
7129c0dee8 | |||
ae6b6511d7 | |||
232a767312 | |||
f5407d2477 | |||
19aca8f97f | |||
c4a7533315 | |||
d067ee702a | |||
dfd9459922 | |||
51373fe7a2 | |||
cafa1248d5 | |||
ed710b3c2e | |||
8dd3ca9eae | |||
07ffa374fe | |||
0302c10fcd | |||
92361ec455 | |||
cf4dea566e | |||
d8c72a5d28 | |||
9803b06af1 | |||
8131ccae1e | |||
e901f139d6 | |||
02dd659d1d | |||
277b3366f9 | |||
b4defb9eda | |||
4c7f53e309 | |||
27618f4404 | |||
8bf5e5a06a | |||
bc60362984 | |||
74c7c16877 | |||
0a577b5f48 | |||
57ddee2dc9 | |||
8ae8c97b41 | |||
883db8d7ef | |||
6450b292a7 | |||
65d15ffd4e | |||
07401d0864 | |||
21411e1517 | |||
339d402422 | |||
c54a42aa43 | |||
42574583ed | |||
9aa3f7c058 | |||
1b407562df | |||
f86c97dcf0 | |||
6b4d6a1c8c | |||
20dfe2c2e6 | |||
6c2c305f1c | |||
dbbf6f6c5c | |||
07b32f1e32 | |||
ea329d8d64 | |||
f45848331e | |||
a1ad6aa582 | |||
3e3e2579f0 | |||
681b5e42c3 | |||
a0c025b58b | |||
20d7b16ede | |||
afdc02f2a4 |
16
.gitignore
vendored
16
.gitignore
vendored
@ -48,14 +48,14 @@ lib/generated_plugin_registrant.dart
|
||||
#pubspec.lock
|
||||
|
||||
# Android related
|
||||
**/android/**/gradle-wrapper.jar
|
||||
**/android/.gradle
|
||||
**/android/captures/
|
||||
**/android/gradlew
|
||||
**/android/gradlew.bat
|
||||
**/android/key.properties
|
||||
**/android/local.properties
|
||||
**/android/**/GeneratedPluginRegistrant.java
|
||||
materials/screenshots/android/**/gradle-wrapper.jar
|
||||
materials/screenshots/android/.gradle
|
||||
materials/screenshots/android/captures/
|
||||
materials/screenshots/android/gradlew
|
||||
materials/screenshots/android/gradlew.bat
|
||||
materials/screenshots/android/key.properties
|
||||
materials/screenshots/android/local.properties
|
||||
materials/screenshots/android/**/GeneratedPluginRegistrant.java
|
||||
|
||||
# iOS/XCode related
|
||||
**/ios/**/*.mode1v3
|
||||
|
@ -9,6 +9,10 @@
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
errors:
|
||||
invalid_annotation_target: ignore
|
||||
|
||||
linter:
|
||||
# The lint rules applied to this project can be customized in the
|
||||
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
|
||||
@ -28,6 +32,13 @@ linter:
|
||||
prefer_relative_imports: true
|
||||
unnecessary_lambdas: true
|
||||
prefer_single_quotes: true
|
||||
prefer_if_elements_to_conditional_expressions: true
|
||||
prefer_expression_function_bodies: true
|
||||
omit_local_variable_types: true
|
||||
eol_at_end_of_file: true
|
||||
cast_nullable_to_non_nullable: true
|
||||
avoid_void_async: true
|
||||
avoid_multiple_declarations_per_line: true
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
|
@ -45,7 +45,7 @@ android {
|
||||
applicationId "eu.mhsl.marianum.mobile.client"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdkVersion 19
|
||||
minSdkVersion 21
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
@ -20,7 +20,7 @@ pluginManagement {
|
||||
plugins {
|
||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||
id "com.android.application" version "7.3.0" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
|
||||
}
|
||||
|
||||
include ":app"
|
||||
|
29
assets/ca/lets-encrypt-r10.pem
Normal file
29
assets/ca/lets-encrypt-r10.pem
Normal file
@ -0,0 +1,29 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFBTCCAu2gAwIBAgIQS6hSk/eaL6JzBkuoBI110DANBgkqhkiG9w0BAQsFADBP
|
||||
MQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFy
|
||||
Y2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTAeFw0yNDAzMTMwMDAwMDBa
|
||||
Fw0yNzAzMTIyMzU5NTlaMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBF
|
||||
bmNyeXB0MQwwCgYDVQQDEwNSMTAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||
AoIBAQDPV+XmxFQS7bRH/sknWHZGUCiMHT6I3wWd1bUYKb3dtVq/+vbOo76vACFL
|
||||
YlpaPAEvxVgD9on/jhFD68G14BQHlo9vH9fnuoE5CXVlt8KvGFs3Jijno/QHK20a
|
||||
/6tYvJWuQP/py1fEtVt/eA0YYbwX51TGu0mRzW4Y0YCF7qZlNrx06rxQTOr8IfM4
|
||||
FpOUurDTazgGzRYSespSdcitdrLCnF2YRVxvYXvGLe48E1KGAdlX5jgc3421H5KR
|
||||
mudKHMxFqHJV8LDmowfs/acbZp4/SItxhHFYyTr6717yW0QrPHTnj7JHwQdqzZq3
|
||||
DZb3EoEmUVQK7GH29/Xi8orIlQ2NAgMBAAGjgfgwgfUwDgYDVR0PAQH/BAQDAgGG
|
||||
MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATASBgNVHRMBAf8ECDAGAQH/
|
||||
AgEAMB0GA1UdDgQWBBS7vMNHpeS8qcbDpHIMEI2iNeHI6DAfBgNVHSMEGDAWgBR5
|
||||
tFnme7bl5AFzgAiIyBpY9umbbjAyBggrBgEFBQcBAQQmMCQwIgYIKwYBBQUHMAKG
|
||||
Fmh0dHA6Ly94MS5pLmxlbmNyLm9yZy8wEwYDVR0gBAwwCjAIBgZngQwBAgEwJwYD
|
||||
VR0fBCAwHjAcoBqgGIYWaHR0cDovL3gxLmMubGVuY3Iub3JnLzANBgkqhkiG9w0B
|
||||
AQsFAAOCAgEAkrHnQTfreZ2B5s3iJeE6IOmQRJWjgVzPw139vaBw1bGWKCIL0vIo
|
||||
zwzn1OZDjCQiHcFCktEJr59L9MhwTyAWsVrdAfYf+B9haxQnsHKNY67u4s5Lzzfd
|
||||
u6PUzeetUK29v+PsPmI2cJkxp+iN3epi4hKu9ZzUPSwMqtCceb7qPVxEbpYxY1p9
|
||||
1n5PJKBLBX9eb9LU6l8zSxPWV7bK3lG4XaMJgnT9x3ies7msFtpKK5bDtotij/l0
|
||||
GaKeA97pb5uwD9KgWvaFXMIEt8jVTjLEvwRdvCn294GPDF08U8lAkIv7tghluaQh
|
||||
1QnlE4SEN4LOECj8dsIGJXpGUk3aU3KkJz9icKy+aUgA+2cP21uh6NcDIS3XyfaZ
|
||||
QjmDQ993ChII8SXWupQZVBiIpcWO4RqZk3lr7Bz5MUCwzDIA359e57SSq5CCkY0N
|
||||
4B6Vulk7LktfwrdGNVI5BsC9qqxSwSKgRJeZ9wygIaehbHFHFhcBaMDKpiZlBHyz
|
||||
rsnnlFXCb5s8HKn5LsUgGvB24L7sGNZP2CX7dhHov+YhD+jozLW2p9W4959Bz2Ei
|
||||
RmqDtmiXLnzqTpXbI+suyCsohKRg6Un0RC47+cpiVwHiXZAW+cn8eiNIjqbVgXLx
|
||||
KPpdzvvtTnOPlC7SQZSYmdunr3Bf9b77AiC/ZidstK36dRILKz7OA54=
|
||||
-----END CERTIFICATE-----
|
7
build.yaml
Normal file
7
build.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
targets:
|
||||
$default:
|
||||
builders:
|
||||
json_serializable:
|
||||
options:
|
||||
explicit_to_json: false
|
||||
generic_argument_factories: true
|
Binary file not shown.
Before Width: | Height: | Size: 185 KiB |
Binary file not shown.
Before Width: | Height: | Size: 154 KiB |
@ -4,7 +4,5 @@ class ApiError {
|
||||
ApiError(this.message);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ApiError: $message';
|
||||
}
|
||||
String toString() => 'ApiError: $message';
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'getHolidaysResponse.dart';
|
||||
|
||||
class GetHolidays {
|
||||
Future<GetHolidaysResponse> query() async {
|
||||
String response = (await http.get(Uri.parse('https://ferien-api.de/api/v1/holidays/HE'))).body;
|
||||
var response = (await http.get(Uri.parse('https://ferien-api.de/api/v1/holidays/HE'))).body;
|
||||
var data = jsonDecode(response) as List<dynamic>;
|
||||
return GetHolidaysResponse(
|
||||
List<GetHolidaysResponseObject>.from(
|
||||
jsonDecode(response).map<GetHolidaysResponseObject>(
|
||||
GetHolidaysResponseObject.fromJson
|
||||
)
|
||||
data.map<GetHolidaysResponseObject>((e) => GetHolidaysResponseObject.fromJson(e as Map<String, dynamic>))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -6,24 +6,21 @@ import 'getHolidaysResponse.dart';
|
||||
|
||||
class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
|
||||
GetHolidaysCache({onUpdate, renew}) : super(RequestCache.cacheDay, onUpdate, renew: renew) {
|
||||
start('MarianumMobile', 'state-holidays');
|
||||
start('state-holidays');
|
||||
}
|
||||
|
||||
@override
|
||||
GetHolidaysResponse onLocalData(String json) {
|
||||
List<dynamic> parsedListJson = jsonDecode(json)['data'];
|
||||
return GetHolidaysResponse(
|
||||
List<GetHolidaysResponseObject>.from(
|
||||
parsedListJson.map<GetHolidaysResponseObject>(
|
||||
// ignore: unnecessary_lambdas
|
||||
(dynamic i) => GetHolidaysResponseObject.fromJson(i)
|
||||
)
|
||||
List<GetHolidaysResponseObject>.from(
|
||||
parsedListJson.map<GetHolidaysResponseObject>(
|
||||
(i) => GetHolidaysResponseObject.fromJson(i as Map<String, dynamic>)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetHolidaysResponse> onLoad() {
|
||||
return GetHolidays().query();
|
||||
}
|
||||
Future<GetHolidaysResponse> onLoad() => GetHolidays().query();
|
||||
}
|
@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../model/accountData.dart';
|
||||
import '../../../model/endpointData.dart';
|
||||
@ -10,7 +9,7 @@ import 'autocompleteResponse.dart';
|
||||
|
||||
class AutocompleteApi {
|
||||
Future<AutocompleteResponse> find(String query) async {
|
||||
Map<String, dynamic> getParameters = {
|
||||
var getParameters = <String, dynamic>{
|
||||
'search': query,
|
||||
'itemType': ' ',
|
||||
'itemId': ' ',
|
||||
@ -18,15 +17,15 @@ class AutocompleteApi {
|
||||
'limit': '10',
|
||||
};
|
||||
|
||||
Map<String, String> headers = {};
|
||||
var headers = <String, String>{};
|
||||
headers.putIfAbsent('Accept', () => 'application/json');
|
||||
headers.putIfAbsent('OCS-APIRequest', () => 'true');
|
||||
|
||||
Uri endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/core/autocomplete/get', getParameters);
|
||||
var endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/core/autocomplete/get', getParameters);
|
||||
|
||||
Response response = await http.get(endpoint, headers: headers);
|
||||
var response = await http.get(endpoint, headers: headers);
|
||||
if(response.statusCode != HttpStatus.ok) throw Exception('Api call failed with ${response.statusCode}: ${response.body}');
|
||||
String result = response.body;
|
||||
var result = response.body;
|
||||
return AutocompleteResponse.fromJson(jsonDecode(result)['ocs']);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../model/accountData.dart';
|
||||
import '../../../model/endpointData.dart';
|
||||
@ -9,12 +8,12 @@ import 'fileSharingApiParams.dart';
|
||||
|
||||
class FileSharingApi {
|
||||
Future<void> share(FileSharingApiParams query) async {
|
||||
Map<String, String> headers = {};
|
||||
var headers = <String, String>{};
|
||||
headers.putIfAbsent('Accept', () => 'application/json');
|
||||
headers.putIfAbsent('OCS-APIRequest', () => 'true');
|
||||
|
||||
Uri endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/apps/files_sharing/api/v1/shares', query.toJson().map((key, value) => MapEntry(key, value.toString())));
|
||||
Response response = await http.post(endpoint, headers: headers);
|
||||
var endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/apps/files_sharing/api/v1/shares', query.toJson().map((key, value) => MapEntry(key, value.toString())));
|
||||
var response = await http.post(endpoint, headers: headers);
|
||||
|
||||
if(response.statusCode != HttpStatus.ok) {
|
||||
throw Exception('Api call failed with ${response.statusCode}: ${response.body}');
|
||||
|
@ -14,13 +14,9 @@ class GetChat extends TalkApi<GetChatResponse> {
|
||||
GetChat(this.chatToken, this.params) : super('v1/chat/$chatToken', null, getParameters: params.toJson());
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return GetChatResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
assemble(String raw) => GetChatResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
return http.get(uri, headers: headers);
|
||||
}
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
}
|
@ -9,12 +9,11 @@ class GetChatCache extends RequestCache<GetChatResponse> {
|
||||
String chatToken;
|
||||
|
||||
GetChatCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||
start('MarianumMobile', 'nc-chat-$chatToken');
|
||||
start('nc-chat-$chatToken');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetChatResponse> onLoad() {
|
||||
return GetChat(
|
||||
Future<GetChatResponse> onLoad() => GetChat(
|
||||
chatToken,
|
||||
GetChatParams(
|
||||
lookIntoFuture: GetChatParamsSwitch.off,
|
||||
@ -22,11 +21,8 @@ class GetChatCache extends RequestCache<GetChatResponse> {
|
||||
limit: 200,
|
||||
)
|
||||
).run();
|
||||
}
|
||||
|
||||
@override
|
||||
GetChatResponse onLocalData(String json) {
|
||||
return GetChatResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetChatResponse onLocalData(String json) => GetChatResponse.fromJson(jsonDecode(json));
|
||||
|
||||
}
|
@ -16,7 +16,7 @@ class GetChatResponse extends ApiResponse {
|
||||
Map<String, dynamic> toJson() => _$GetChatResponseToJson(this);
|
||||
|
||||
List<GetChatResponseObject> sortByTimestamp() {
|
||||
List<GetChatResponseObject> sorted = data.toList();
|
||||
var sorted = data.toList();
|
||||
sorted.sort((a, b) => a.timestamp.compareTo(b.timestamp));
|
||||
return sorted;
|
||||
}
|
||||
@ -38,6 +38,7 @@ class GetChatResponseObject {
|
||||
Map<String, int>? reactions;
|
||||
List<String>? reactionsSelf;
|
||||
@JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters;
|
||||
GetChatResponseObject? parent;
|
||||
|
||||
GetChatResponseObject(
|
||||
this.id,
|
||||
@ -53,19 +54,19 @@ class GetChatResponseObject {
|
||||
this.message,
|
||||
this.messageParameters,
|
||||
this.reactions,
|
||||
this.reactionsSelf
|
||||
this.reactionsSelf,
|
||||
this.parent,
|
||||
);
|
||||
|
||||
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetChatResponseObjectToJson(this);
|
||||
|
||||
static GetChatResponseObject getDateDummy(int timestamp) {
|
||||
DateTime elementDate = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
||||
var elementDate = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
||||
return getTextDummy(Jiffy.parseFromDateTime(elementDate).format(pattern: 'dd.MM.yyyy'));
|
||||
}
|
||||
|
||||
static GetChatResponseObject getTextDummy(String text) {
|
||||
return GetChatResponseObject(
|
||||
static GetChatResponseObject getTextDummy(String text) => GetChatResponseObject(
|
||||
0,
|
||||
'',
|
||||
GetRoomResponseObjectMessageActorType.user,
|
||||
@ -79,15 +80,15 @@ class GetChatResponseObject {
|
||||
text,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<String, RichObjectString>? _fromJson(json) {
|
||||
if(json is Map<String, dynamic>) {
|
||||
Map<String, RichObjectString> data = {};
|
||||
var data = <String, RichObjectString>{};
|
||||
for (var element in json.keys) {
|
||||
data.putIfAbsent(element, () => RichObjectString.fromJson(json[element]));
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ GetChatResponseObject _$GetChatResponseObjectFromJson(
|
||||
(json['reactionsSelf'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList(),
|
||||
json['parent'] == null
|
||||
? null
|
||||
: GetChatResponseObject.fromJson(
|
||||
json['parent'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetChatResponseObjectToJson(
|
||||
@ -74,6 +78,7 @@ Map<String, dynamic> _$GetChatResponseObjectToJson(
|
||||
'reactionsSelf': instance.reactionsSelf,
|
||||
'messageParameters':
|
||||
instance.messageParameters?.map((k, e) => MapEntry(k, e.toJson())),
|
||||
'parent': instance.parent?.toJson(),
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectMessageActorTypeEnumMap = {
|
||||
|
@ -10,9 +10,7 @@ class CreateRoom extends TalkApi {
|
||||
CreateRoom(this.params) : super('v4/room', params);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
|
@ -10,13 +10,9 @@ class DeleteMessage extends TalkApi {
|
||||
DeleteMessage(this.chatToken, this.messageId) : super('v1/chat/$chatToken/$messageId', null);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
return http.delete(uri, headers: headers);
|
||||
}
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) => http.delete(uri, headers: headers);
|
||||
|
||||
}
|
@ -11,9 +11,7 @@ class DeleteReactMessage extends TalkApi {
|
||||
DeleteReactMessage({required this.chatToken, required this.messageId, required DeleteReactMessageParams params}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
|
@ -10,13 +10,9 @@ class GetParticipants extends TalkApi<GetParticipantsResponse> {
|
||||
GetParticipants(this.token) : super('v4/room/$token/participants', null);
|
||||
|
||||
@override
|
||||
GetParticipantsResponse assemble(String raw) {
|
||||
return GetParticipantsResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
GetParticipantsResponse assemble(String raw) => GetParticipantsResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
return http.get(uri, headers: headers);
|
||||
}
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
}
|
@ -8,19 +8,15 @@ class GetParticipantsCache extends RequestCache<GetParticipantsResponse> {
|
||||
String chatToken;
|
||||
|
||||
GetParticipantsCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||
start('MarianumMobile', 'nc-chat-participants-$chatToken');
|
||||
start('nc-chat-participants-$chatToken');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetParticipantsResponse> onLoad() {
|
||||
return GetParticipants(
|
||||
Future<GetParticipantsResponse> onLoad() => GetParticipants(
|
||||
chatToken,
|
||||
).run();
|
||||
}
|
||||
|
||||
@override
|
||||
GetParticipantsResponse onLocalData(String json) {
|
||||
return GetParticipantsResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetParticipantsResponse onLocalData(String json) => GetParticipantsResponse.fromJson(jsonDecode(json));
|
||||
|
||||
}
|
@ -13,13 +13,9 @@ class GetReactions extends TalkApi<GetReactionsResponse> {
|
||||
GetReactions({required this.chatToken, required this.messageId}) : super('v1/reaction/$chatToken/$messageId', null);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return GetReactionsResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
assemble(String raw) => GetReactionsResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
return http.get(uri, headers: headers);
|
||||
}
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
}
|
@ -9,12 +9,8 @@ class LeaveRoom extends TalkApi {
|
||||
LeaveRoom(this.chatToken) : super('v4/room/$chatToken/participants/self', null);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
return http.delete(uri, headers: headers);
|
||||
}
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.delete(uri, headers: headers);
|
||||
}
|
@ -11,9 +11,7 @@ class ReactMessage extends TalkApi {
|
||||
ReactMessage({required this.chatToken, required this.messageId, required ReactMessageParams params}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
|
@ -14,13 +14,9 @@ class GetRoom extends TalkApi<GetRoomResponse> {
|
||||
|
||||
|
||||
@override
|
||||
GetRoomResponse assemble(String raw) {
|
||||
return GetRoomResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
GetRoomResponse assemble(String raw) => GetRoomResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
return http.get(uri, headers: headers);
|
||||
}
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
}
|
@ -8,20 +8,16 @@ import 'getRoomResponse.dart';
|
||||
|
||||
class GetRoomCache extends RequestCache<GetRoomResponse> {
|
||||
GetRoomCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start('MarianumMobile', 'nc-rooms');
|
||||
start('nc-rooms');
|
||||
}
|
||||
|
||||
@override
|
||||
GetRoomResponse onLocalData(String json) {
|
||||
return GetRoomResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetRoomResponse onLocalData(String json) => GetRoomResponse.fromJson(jsonDecode(json));
|
||||
|
||||
@override
|
||||
Future<GetRoomResponse> onLoad() {
|
||||
return GetRoom(
|
||||
Future<GetRoomResponse> onLoad() => GetRoom(
|
||||
GetRoomParams(
|
||||
includeStatus: true,
|
||||
)
|
||||
).run();
|
||||
}
|
||||
}
|
@ -10,9 +10,7 @@ class SendMessage extends TalkApi {
|
||||
SendMessage(this.chatToken, SendMessageParams params) : super('v1/chat/$chatToken', params);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
|
@ -7,7 +7,7 @@ part 'sendMessageParams.g.dart';
|
||||
@JsonSerializable(explicitToJson: true, includeIfNull: false)
|
||||
class SendMessageParams extends ApiParams {
|
||||
String message;
|
||||
int? replyTo;
|
||||
String? replyTo;
|
||||
|
||||
SendMessageParams(this.message, {this.replyTo});
|
||||
|
||||
|
@ -9,7 +9,7 @@ part of 'sendMessageParams.dart';
|
||||
SendMessageParams _$SendMessageParamsFromJson(Map<String, dynamic> json) =>
|
||||
SendMessageParams(
|
||||
json['message'] as String,
|
||||
replyTo: json['replyTo'] as int?,
|
||||
replyTo: json['replyTo'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SendMessageParamsToJson(SendMessageParams instance) {
|
||||
|
@ -11,9 +11,7 @@ class SetFavorite extends TalkApi {
|
||||
SetFavorite(this.chatToken, this.favoriteState) : super('v4/room/$chatToken/favorite', null);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
|
@ -15,9 +15,7 @@ class SetReadMarker extends TalkApi {
|
||||
}
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
return null;
|
||||
}
|
||||
assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
|
@ -34,7 +34,7 @@ abstract class TalkApi<T extends ApiResponse?> extends ApiRequest {
|
||||
getParameters?.update(key, (value) => value.toString());
|
||||
});
|
||||
|
||||
Uri endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/apps/spreed/api/$path', getParameters);
|
||||
var endpoint = Uri.https('${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().domain}', '${EndpointData().nextcloud().path}/ocs/v2.php/apps/spreed/api/$path', getParameters);
|
||||
|
||||
headers ??= {};
|
||||
headers?.putIfAbsent('Accept', () => 'application/json');
|
||||
|
@ -6,7 +6,5 @@ class TalkError {
|
||||
TalkError(this.status, this.code, this.message);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Talk - $status - ($code): $message';
|
||||
}
|
||||
String toString() => 'Talk - $status - ($code): $message';
|
||||
}
|
@ -13,8 +13,8 @@ class ListFiles extends WebdavApi<ListFilesParams> {
|
||||
|
||||
@override
|
||||
Future<ListFilesResponse> run() async {
|
||||
List<WebDavFile> davFiles = (await (await WebdavApi.webdav).propfind(PathUri.parse(params.path))).toWebDavFiles();
|
||||
Set<CacheableFile> files = davFiles.map(CacheableFile.fromDavFile).toSet();
|
||||
var davFiles = (await (await WebdavApi.webdav).propfind(PathUri.parse(params.path))).toWebDavFiles();
|
||||
var files = davFiles.map(CacheableFile.fromDavFile).toSet();
|
||||
|
||||
// webdav handles subdirectories wrong, this is a fix
|
||||
// currently this fix is not needed anymore
|
||||
|
@ -11,19 +11,17 @@ class ListFilesCache extends RequestCache<ListFilesResponse> {
|
||||
|
||||
ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||
var bytes = utf8.encode('MarianumMobile-$path');
|
||||
String cacheName = md5.convert(bytes).toString();
|
||||
start('MarianumMobile', 'wd-folder-$cacheName');
|
||||
var cacheName = md5.convert(bytes).toString();
|
||||
start('wd-folder-$cacheName');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ListFilesResponse> onLoad() async {
|
||||
ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
|
||||
var data = await ListFiles(ListFilesParams(path)).run();
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
ListFilesResponse onLocalData(String json) {
|
||||
return ListFilesResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
ListFilesResponse onLocalData(String json) => ListFilesResponse.fromJson(jsonDecode(json));
|
||||
|
||||
}
|
@ -17,11 +17,7 @@ abstract class WebdavApi<T> extends ApiRequest {
|
||||
static Future<WebDavClient> webdav = establishWebdavConnection();
|
||||
static Future<String> webdavConnectString = buildWebdavConnectString();
|
||||
|
||||
static Future<WebDavClient> establishWebdavConnection() async {
|
||||
return NextcloudClient(Uri.parse('https://${EndpointData().nextcloud().full()}'), password: AccountData().getPassword(), loginName: AccountData().getUsername()).webdav;
|
||||
}
|
||||
static Future<WebDavClient> establishWebdavConnection() async => NextcloudClient(Uri.parse('https://${EndpointData().nextcloud().full()}'), password: AccountData().getPassword(), loginName: AccountData().getUsername()).webdav;
|
||||
|
||||
static Future<String> buildWebdavConnectString() async {
|
||||
return 'https://${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().full()}/remote.php/dav/files/${AccountData().getUsername()}/';
|
||||
}
|
||||
static Future<String> buildWebdavConnectString() async => 'https://${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().full()}/remote.php/dav/files/${AccountData().getUsername()}/';
|
||||
}
|
@ -9,13 +9,9 @@ class GetBreakers extends MhslApi<GetBreakersResponse> {
|
||||
GetBreakers() : super('breaker/');
|
||||
|
||||
@override
|
||||
GetBreakersResponse assemble(String raw) {
|
||||
return GetBreakersResponse.fromJson(jsonDecode(raw));
|
||||
}
|
||||
GetBreakersResponse assemble(String raw) => GetBreakersResponse.fromJson(jsonDecode(raw));
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.get(uri);
|
||||
}
|
||||
Future<Response>? request(Uri uri) => http.get(uri);
|
||||
|
||||
}
|
@ -6,16 +6,12 @@ import 'getBreakersResponse.dart';
|
||||
|
||||
class GetBreakersCache extends RequestCache<GetBreakersResponse> {
|
||||
GetBreakersCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start('MarianumMobile', 'breakers');
|
||||
start('breakers');
|
||||
}
|
||||
|
||||
@override
|
||||
GetBreakersResponse onLocalData(String json) {
|
||||
return GetBreakersResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetBreakersResponse onLocalData(String json) => GetBreakersResponse.fromJson(jsonDecode(json));
|
||||
|
||||
@override
|
||||
Future<GetBreakersResponse> onLoad() {
|
||||
return GetBreakers().run();
|
||||
}
|
||||
Future<GetBreakersResponse> onLoad() => GetBreakers().run();
|
||||
}
|
@ -16,7 +16,7 @@ class AddCustomTimetableEvent extends MhslApi<void> {
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
String body = jsonEncode(params.toJson());
|
||||
var body = jsonEncode(params.toJson());
|
||||
return http.post(uri, body: body);
|
||||
}
|
||||
}
|
@ -12,12 +12,8 @@ class GetCustomTimetableEvent extends MhslApi<GetCustomTimetableEventResponse> {
|
||||
GetCustomTimetableEvent(this.params) : super('server/timetable/customEvents?user=${params.user}');
|
||||
|
||||
@override
|
||||
GetCustomTimetableEventResponse assemble(String raw) {
|
||||
return GetCustomTimetableEventResponse.fromJson({'events': jsonDecode(raw)});
|
||||
}
|
||||
GetCustomTimetableEventResponse assemble(String raw) => GetCustomTimetableEventResponse.fromJson({'events': jsonDecode(raw)});
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.get(uri);
|
||||
}
|
||||
Future<Response>? request(Uri uri) => http.get(uri);
|
||||
}
|
@ -9,16 +9,12 @@ class GetCustomTimetableEventCache extends RequestCache<GetCustomTimetableEventR
|
||||
GetCustomTimetableEventParams params;
|
||||
|
||||
GetCustomTimetableEventCache(this.params, {onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start('MarianumMobile', 'customTimetableEvents');
|
||||
start('customTimetableEvents');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetCustomTimetableEventResponse> onLoad() {
|
||||
return GetCustomTimetableEvent(params).run();
|
||||
}
|
||||
Future<GetCustomTimetableEventResponse> onLoad() => GetCustomTimetableEvent(params).run();
|
||||
|
||||
@override
|
||||
GetCustomTimetableEventResponse onLocalData(String json) {
|
||||
return GetCustomTimetableEventResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetCustomTimetableEventResponse onLocalData(String json) => GetCustomTimetableEventResponse.fromJson(jsonDecode(json));
|
||||
}
|
@ -15,7 +15,5 @@ class RemoveCustomTimetableEvent extends MhslApi<void> {
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.delete(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
||||
Future<Response>? request(Uri uri) => http.delete(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
@ -15,7 +15,5 @@ class UpdateCustomTimetableEvent extends MhslApi<void> {
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.patch(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
||||
Future<Response>? request(Uri uri) => http.patch(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'getMessagesResponse.dart';
|
||||
|
||||
class GetMessages extends MhslApi<GetMessagesResponse> {
|
||||
GetMessages() : super('message/messages.json');
|
||||
|
||||
|
||||
@override
|
||||
GetMessagesResponse assemble(String raw) {
|
||||
return GetMessagesResponse.fromJson(jsonDecode(raw));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri) {
|
||||
return http.get(uri);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../requestCache.dart';
|
||||
import 'getMessages.dart';
|
||||
import 'getMessagesResponse.dart';
|
||||
|
||||
class GetMessagesCache extends RequestCache<GetMessagesResponse> {
|
||||
GetMessagesCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start('MarianumMobile', 'message');
|
||||
}
|
||||
|
||||
@override
|
||||
GetMessagesResponse onLocalData(String json) {
|
||||
return GetMessagesResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetMessagesResponse> onLoad() {
|
||||
return GetMessages().run();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiResponse.dart';
|
||||
|
||||
part 'getMessagesResponse.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetMessagesResponse extends ApiResponse {
|
||||
String base;
|
||||
Set<GetMessagesResponseObject> messages;
|
||||
|
||||
GetMessagesResponse(this.base, this.messages);
|
||||
|
||||
factory GetMessagesResponse.fromJson(Map<String, dynamic> json) => _$GetMessagesResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetMessagesResponseToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetMessagesResponseObject {
|
||||
String name;
|
||||
String date;
|
||||
String url;
|
||||
|
||||
GetMessagesResponseObject(this.name, this.date, this.url);
|
||||
|
||||
factory GetMessagesResponseObject.fromJson(Map<String, dynamic> json) => _$GetMessagesResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetMessagesResponseObjectToJson(this);
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getMessagesResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetMessagesResponse _$GetMessagesResponseFromJson(Map<String, dynamic> json) =>
|
||||
GetMessagesResponse(
|
||||
json['base'] as String,
|
||||
(json['messages'] as List<dynamic>)
|
||||
.map((e) =>
|
||||
GetMessagesResponseObject.fromJson(e as Map<String, dynamic>))
|
||||
.toSet(),
|
||||
)..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetMessagesResponseToJson(GetMessagesResponse instance) {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('headers', instance.headers);
|
||||
val['base'] = instance.base;
|
||||
val['messages'] = instance.messages.map((e) => e.toJson()).toList();
|
||||
return val;
|
||||
}
|
||||
|
||||
GetMessagesResponseObject _$GetMessagesResponseObjectFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetMessagesResponseObject(
|
||||
json['name'] as String,
|
||||
json['date'] as String,
|
||||
json['url'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetMessagesResponseObjectToJson(
|
||||
GetMessagesResponseObject instance) =>
|
||||
<String, dynamic>{
|
||||
'name': instance.name,
|
||||
'date': instance.date,
|
||||
'url': instance.url,
|
||||
};
|
@ -15,9 +15,9 @@ abstract class MhslApi<T> extends ApiRequest {
|
||||
T assemble(String raw);
|
||||
|
||||
Future<T> run() async {
|
||||
Uri endpoint = Uri.parse('https://mhsl.eu/marianum/marianummobile/$subpath');
|
||||
var endpoint = Uri.parse('https://mhsl.eu/marianum/marianummobile/$subpath');
|
||||
|
||||
http.Response? data = await request(endpoint);
|
||||
var data = await request(endpoint);
|
||||
if(data == null) {
|
||||
throw ApiError('Request could not be dispatched!');
|
||||
}
|
||||
@ -31,5 +31,4 @@ abstract class MhslApi<T> extends ApiRequest {
|
||||
|
||||
static String dateTimeToJson(DateTime time) => Jiffy.parseFromDateTime(time).format(pattern: 'yyyy-MM-dd HH:mm:ss');
|
||||
static DateTime dateTimeFromJson(String time) => DateTime.parse(time);
|
||||
|
||||
}
|
@ -19,8 +19,8 @@ class NotifyRegister extends MhslApi<void> {
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri) {
|
||||
String requestString = jsonEncode(params.toJson());
|
||||
log(requestString);
|
||||
var requestString = jsonEncode(params.toJson());
|
||||
log('register at push proxy with username ${params.username}');
|
||||
return http.post(uri, body: requestString);
|
||||
}
|
||||
}
|
@ -15,7 +15,5 @@ class AddFeedback extends MhslApi<void> {
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.post(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
||||
Future<Response>? request(Uri uri) => http.post(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
@ -6,12 +6,14 @@ part 'addFeedbackParams.g.dart';
|
||||
class AddFeedbackParams {
|
||||
String user;
|
||||
String feedback;
|
||||
String? screenshot;
|
||||
int appVersion;
|
||||
|
||||
|
||||
AddFeedbackParams({
|
||||
required this.user,
|
||||
required this.feedback,
|
||||
this.screenshot,
|
||||
required this.appVersion,
|
||||
});
|
||||
|
||||
|
@ -10,6 +10,7 @@ AddFeedbackParams _$AddFeedbackParamsFromJson(Map<String, dynamic> json) =>
|
||||
AddFeedbackParams(
|
||||
user: json['user'] as String,
|
||||
feedback: json['feedback'] as String,
|
||||
screenshot: json['screenshot'] as String?,
|
||||
appVersion: json['appVersion'] as int,
|
||||
);
|
||||
|
||||
@ -17,5 +18,6 @@ Map<String, dynamic> _$AddFeedbackParamsToJson(AddFeedbackParams instance) =>
|
||||
<String, dynamic>{
|
||||
'user': instance.user,
|
||||
'feedback': instance.feedback,
|
||||
'screenshot': instance.screenshot,
|
||||
'appVersion': instance.appVersion,
|
||||
};
|
||||
|
@ -19,12 +19,12 @@ class UpdateUserIndex extends MhslApi<void> {
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri) {
|
||||
String data = jsonEncode(params.toJson());
|
||||
log('Updating userindex:\n $data');
|
||||
var data = jsonEncode(params.toJson());
|
||||
log('Updating userindex: ${data.length}');
|
||||
return http.post(uri, body: data);
|
||||
}
|
||||
|
||||
static void index() async {
|
||||
static Future<void> index() async {
|
||||
UpdateUserIndex(
|
||||
UpdateUserIndexParams(
|
||||
username: AccountData().getUsername(),
|
||||
|
@ -1,9 +1,9 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:localstore/localstore.dart';
|
||||
|
||||
import 'apiResponse.dart';
|
||||
import 'webuntis/webuntisError.dart';
|
||||
|
||||
abstract class RequestCache<T extends ApiResponse?> {
|
||||
static const int cacheNothing = 0;
|
||||
@ -11,6 +11,8 @@ abstract class RequestCache<T extends ApiResponse?> {
|
||||
static const int cacheHour = 60 * 60;
|
||||
static const int cacheDay = 60 * 60 * 24;
|
||||
|
||||
static String collection = 'MarianumMobile';
|
||||
|
||||
int maxCacheTime;
|
||||
Function(T) onUpdate;
|
||||
Function(Exception) onError;
|
||||
@ -20,8 +22,8 @@ abstract class RequestCache<T extends ApiResponse?> {
|
||||
|
||||
static void ignore(Exception e) {}
|
||||
|
||||
void start(String file, String document) async {
|
||||
Map<String, dynamic>? tableData = await Localstore.instance.collection(file).doc(document).get();
|
||||
Future<void> start(String document) async {
|
||||
var tableData = await Localstore.instance.collection(collection).doc(document).get();
|
||||
if(tableData != null) {
|
||||
onUpdate(onLocalData(tableData['json']));
|
||||
}
|
||||
@ -30,18 +32,16 @@ abstract class RequestCache<T extends ApiResponse?> {
|
||||
if(renew == null || !renew!) return;
|
||||
}
|
||||
|
||||
T? newValue;
|
||||
try {
|
||||
newValue = await onLoad();
|
||||
onUpdate(newValue as T);
|
||||
var newValue = await onLoad();
|
||||
onUpdate(newValue);
|
||||
|
||||
Localstore.instance.collection(file).doc(document).set({
|
||||
Localstore.instance.collection(collection).doc(document).set({
|
||||
'json': jsonEncode(newValue),
|
||||
'lastupdate': DateTime.now().millisecondsSinceEpoch
|
||||
});
|
||||
} catch(e) {
|
||||
log("Error while fetching/ parsing. Raw server response: ${newValue?.rawResponse.body ?? "no response"}");
|
||||
onError(Exception(e.toString()));
|
||||
} on WebuntisError catch(e) {
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class Authenticate extends WebuntisApi {
|
||||
@override
|
||||
Future<AuthenticateResponse> run() async {
|
||||
awaitingResponse = true;
|
||||
String rawAnswer = await query(this);
|
||||
var rawAnswer = await query(this);
|
||||
AuthenticateResponse response = finalize(AuthenticateResponse.fromJson(jsonDecode(rawAnswer)['result']));
|
||||
_lastResponse = response;
|
||||
if(!awaitedResponse.isCompleted) awaitedResponse.complete();
|
||||
|
@ -8,7 +8,7 @@ class GetHolidays extends WebuntisApi {
|
||||
|
||||
@override
|
||||
Future<GetHolidaysResponse> run() async {
|
||||
String rawAnswer = await query(this);
|
||||
var rawAnswer = await query(this);
|
||||
return finalize(GetHolidaysResponse.fromJson(jsonDecode(rawAnswer)));
|
||||
}
|
||||
|
||||
@ -17,8 +17,8 @@ class GetHolidays extends WebuntisApi {
|
||||
time = DateTime(time.year, time.month, time.day, 0, 0, 0, 0, 0);
|
||||
|
||||
for (var element in holidaysResponse.result) {
|
||||
DateTime start = DateTime.parse(element.startDate.toString());
|
||||
DateTime end = DateTime.parse(element.endDate.toString());
|
||||
var start = DateTime.parse(element.startDate.toString());
|
||||
var end = DateTime.parse(element.endDate.toString());
|
||||
|
||||
if(!start.isAfter(time) && !end.isBefore(time)) return element;
|
||||
}
|
||||
|
@ -6,16 +6,12 @@ import 'getHolidaysResponse.dart';
|
||||
|
||||
class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
|
||||
GetHolidaysCache({onUpdate}) : super(RequestCache.cacheDay, onUpdate) {
|
||||
start('MarianumMobile', 'wu-holidays');
|
||||
start('wu-holidays');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetHolidaysResponse> onLoad() {
|
||||
return GetHolidays().run();
|
||||
}
|
||||
Future<GetHolidaysResponse> onLoad() => GetHolidays().run();
|
||||
|
||||
@override
|
||||
GetHolidaysResponse onLocalData(String json) {
|
||||
return GetHolidaysResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetHolidaysResponse onLocalData(String json) => GetHolidaysResponse.fromJson(jsonDecode(json));
|
||||
}
|
@ -9,7 +9,7 @@ class GetRooms extends WebuntisApi {
|
||||
|
||||
@override
|
||||
Future<GetRoomsResponse> run() async {
|
||||
String rawAnswer = await query(this);
|
||||
var rawAnswer = await query(this);
|
||||
try {
|
||||
return finalize(GetRoomsResponse.fromJson(jsonDecode(rawAnswer)));
|
||||
} catch(e, trace) {
|
||||
|
@ -6,17 +6,13 @@ import 'getRoomsResponse.dart';
|
||||
|
||||
class GetRoomsCache extends RequestCache<GetRoomsResponse> {
|
||||
GetRoomsCache({onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
|
||||
start('MarianumMobile', 'wu-rooms');
|
||||
start('wu-rooms');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetRoomsResponse> onLoad() {
|
||||
return GetRooms().run();
|
||||
}
|
||||
Future<GetRoomsResponse> onLoad() => GetRooms().run();
|
||||
|
||||
@override
|
||||
GetRoomsResponse onLocalData(String json) {
|
||||
return GetRoomsResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetRoomsResponse onLocalData(String json) => GetRoomsResponse.fromJson(jsonDecode(json));
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ class GetSubjects extends WebuntisApi {
|
||||
|
||||
@override
|
||||
Future<GetSubjectsResponse> run() async {
|
||||
String rawAnswer = await query(this);
|
||||
var rawAnswer = await query(this);
|
||||
return finalize(GetSubjectsResponse.fromJson(jsonDecode(rawAnswer)));
|
||||
}
|
||||
}
|
@ -6,17 +6,13 @@ import 'getSubjectsResponse.dart';
|
||||
|
||||
class GetSubjectsCache extends RequestCache<GetSubjectsResponse> {
|
||||
GetSubjectsCache({onUpdate}) : super(RequestCache.cacheHour, onUpdate) {
|
||||
start('MarianumMobile', 'wu-subjects');
|
||||
start('wu-subjects');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetSubjectsResponse> onLoad() {
|
||||
return GetSubjects().run();
|
||||
}
|
||||
Future<GetSubjectsResponse> onLoad() => GetSubjects().run();
|
||||
|
||||
@override
|
||||
onLocalData(String json) {
|
||||
return GetSubjectsResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
onLocalData(String json) => GetSubjectsResponse.fromJson(jsonDecode(json));
|
||||
|
||||
}
|
@ -11,7 +11,7 @@ class GetTimetable extends WebuntisApi {
|
||||
|
||||
@override
|
||||
Future<GetTimetableResponse> run() async {
|
||||
String rawAnswer = await query(this);
|
||||
var rawAnswer = await query(this);
|
||||
return finalize(GetTimetableResponse.fromJson(jsonDecode(rawAnswer)));
|
||||
}
|
||||
|
||||
|
@ -11,17 +11,14 @@ class GetTimetableCache extends RequestCache<GetTimetableResponse> {
|
||||
int enddate;
|
||||
|
||||
GetTimetableCache({required onUpdate, onError, required this.startdate, required this.enddate}) : super(RequestCache.cacheMinute, onUpdate, onError: onError) {
|
||||
start('MarianumMobile', 'wu-timetable-$startdate-$enddate');
|
||||
start('wu-timetable-$startdate-$enddate');
|
||||
}
|
||||
|
||||
@override
|
||||
GetTimetableResponse onLocalData(String json) {
|
||||
return GetTimetableResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
GetTimetableResponse onLocalData(String json) => GetTimetableResponse.fromJson(jsonDecode(json));
|
||||
|
||||
@override
|
||||
Future<GetTimetableResponse> onLoad() async {
|
||||
return GetTimetable(
|
||||
Future<GetTimetableResponse> onLoad() async => GetTimetable(
|
||||
GetTimetableParams(
|
||||
options: GetTimetableParamsOptions(
|
||||
element: GetTimetableParamsOptionsElement(
|
||||
@ -38,5 +35,4 @@ class GetTimetableCache extends RequestCache<GetTimetableResponse> {
|
||||
)
|
||||
)
|
||||
).run();
|
||||
}
|
||||
}
|
@ -20,13 +20,13 @@ abstract class WebuntisApi extends ApiRequest {
|
||||
|
||||
|
||||
Future<String> query(WebuntisApi untis) async {
|
||||
String query = '{"id":"ID","method":"$method","params":${untis._body()},"jsonrpc":"2.0"}';
|
||||
var query = '{"id":"ID","method":"$method","params":${untis._body()},"jsonrpc":"2.0"}';
|
||||
|
||||
String sessionId = '0';
|
||||
var sessionId = '0';
|
||||
if(authenticatedResponse) {
|
||||
sessionId = (await Authenticate.getSession()).sessionId;
|
||||
}
|
||||
http.Response data = await post(query, {'Cookie': 'JSESSIONID=$sessionId'});
|
||||
var data = await post(query, {'Cookie': 'JSESSIONID=$sessionId'});
|
||||
response = data;
|
||||
|
||||
dynamic jsonData = jsonDecode(data.body);
|
||||
@ -48,16 +48,12 @@ abstract class WebuntisApi extends ApiRequest {
|
||||
|
||||
Future<ApiResponse> run();
|
||||
|
||||
String _body() {
|
||||
return genericParam == null ? '{}' : jsonEncode(genericParam);
|
||||
}
|
||||
String _body() => genericParam == null ? '{}' : jsonEncode(genericParam);
|
||||
|
||||
Future<http.Response> post(String data, Map<String, String>? headers) async {
|
||||
return await http
|
||||
Future<http.Response> post(String data, Map<String, String>? headers) async => await http
|
||||
.post(endpoint, body: data, headers: headers)
|
||||
.timeout(
|
||||
const Duration(seconds: 10),
|
||||
onTimeout: () => throw WebuntisError('Timeout', 1)
|
||||
);
|
||||
}
|
||||
}
|
@ -5,7 +5,5 @@ class WebuntisError implements Exception {
|
||||
WebuntisError(this.message, this.code);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WebUntis ($code): $message';
|
||||
}
|
||||
String toString() => 'WebUntis ($code): $message';
|
||||
}
|
84
lib/app.dart
84
lib/app.dart
@ -5,35 +5,34 @@ import 'dart:developer';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'state/app/modules/app_modules.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
|
||||
import 'api/mhsl/breaker/getBreakers/getBreakersResponse.dart';
|
||||
import 'api/mhsl/server/userIndex/update/updateUserindex.dart';
|
||||
import 'main.dart';
|
||||
import 'model/breakers/Breaker.dart';
|
||||
import 'model/breakers/BreakerProps.dart';
|
||||
import 'model/chatList/chatListProps.dart';
|
||||
import 'model/dataCleaner.dart';
|
||||
import 'model/timetable/timetableProps.dart';
|
||||
import 'notification/notificationController.dart';
|
||||
import 'notification/notificationTasks.dart';
|
||||
import 'notification/notifyUpdater.dart';
|
||||
import 'storage/base/settingsProvider.dart';
|
||||
import 'view/pages/files/files.dart';
|
||||
import 'view/pages/overhang.dart';
|
||||
import 'view/pages/talk/chatList.dart';
|
||||
import 'view/pages/timetable/timetable.dart';
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({super.key});
|
||||
|
||||
static PersistentTabController bottomNavigator = PersistentTabController(initialIndex: 0);
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
}
|
||||
|
||||
class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
|
||||
late Timer refetchChats;
|
||||
late Timer updateTimings;
|
||||
|
||||
@ -57,6 +56,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Main.bottomNavigator = PersistentTabController(initialIndex: 0);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<BreakerProps>(context, listen: false).run();
|
||||
@ -87,63 +87,44 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((message) => NotificationController.onAppOpenedByNotification(message, context));
|
||||
FirebaseMessaging.instance.getInitialMessage().then((message) => message == null ? null : NotificationController.onAppOpenedByNotification(message, context));
|
||||
|
||||
DataCleaner.cleanOldCache();
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PersistentTabView(
|
||||
controller: App.bottomNavigator,
|
||||
gestureNavigationEnabled: true,
|
||||
Widget build(BuildContext context) => PersistentTabView(
|
||||
controller: Main.bottomNavigator,
|
||||
navBarOverlap: const NavBarOverlap.none(),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
handleAndroidBackButtonPress: false,
|
||||
|
||||
screenTransitionAnimation: const ScreenTransitionAnimation(curve: Curves.easeOutQuad, duration: Duration(milliseconds: 200)),
|
||||
tabs: [
|
||||
PersistentTabConfig(
|
||||
screen: const Breaker(breaker: BreakerArea.timetable, child: Timetable()),
|
||||
item: ItemConfig(
|
||||
activeForegroundColor: Theme.of(context).primaryColor,
|
||||
inactiveForegroundColor: Theme.of(context).colorScheme.secondary,
|
||||
icon: const Icon(Icons.calendar_month),
|
||||
title: 'Vertretung'
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: const Breaker(breaker: BreakerArea.talk, child: ChatList()),
|
||||
item: ItemConfig(
|
||||
activeForegroundColor: Theme.of(context).primaryColor,
|
||||
inactiveForegroundColor: Theme.of(context).colorScheme.secondary,
|
||||
icon: Consumer<ChatListProps>(
|
||||
builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return const Icon(Icons.chat);
|
||||
int messages = value.getRoomsResponse.data.map((e) => e.unreadMessages).reduce((a, b) => a+b);
|
||||
return badges.Badge(
|
||||
showBadge: messages > 0,
|
||||
position: badges.BadgePosition.topEnd(top: -3, end: -3),
|
||||
stackFit: StackFit.loose,
|
||||
badgeStyle: badges.BadgeStyle(
|
||||
padding: const EdgeInsets.all(3),
|
||||
badgeColor: Theme.of(context).primaryColor,
|
||||
elevation: 1,
|
||||
),
|
||||
badgeContent: Text('$messages', style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold)),
|
||||
child: const Icon(Icons.chat),
|
||||
);
|
||||
},
|
||||
),
|
||||
title: 'Talk',
|
||||
),
|
||||
),
|
||||
PersistentTabConfig(
|
||||
screen: const Breaker(breaker: BreakerArea.files, child: Files([])),
|
||||
item: ItemConfig(
|
||||
activeForegroundColor: Theme.of(context).primaryColor,
|
||||
inactiveForegroundColor: Theme.of(context).colorScheme.secondary,
|
||||
icon: const Icon(Icons.folder),
|
||||
title: 'Dateien'
|
||||
AppModule.getModule(Modules.timetable).toBottomTab(context),
|
||||
AppModule.getModule(Modules.talk).toBottomTab(
|
||||
context,
|
||||
itemBuilder: (icon) => Consumer<ChatListProps>(
|
||||
builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return Icon(icon);
|
||||
var messages = value.getRoomsResponse.data.map((e) => e.unreadMessages).reduce((a, b) => a+b);
|
||||
return badges.Badge(
|
||||
showBadge: messages > 0,
|
||||
position: badges.BadgePosition.topEnd(top: -3, end: -3),
|
||||
stackFit: StackFit.loose,
|
||||
badgeStyle: badges.BadgeStyle(
|
||||
padding: const EdgeInsets.all(3),
|
||||
badgeColor: Theme.of(context).primaryColor,
|
||||
elevation: 1,
|
||||
),
|
||||
badgeContent: Text('$messages', style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold)),
|
||||
child: Icon(icon),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
AppModule.getModule(Modules.files).toBottomTab(context),
|
||||
|
||||
PersistentTabConfig(
|
||||
screen: const Breaker(breaker: BreakerArea.more, child: Overhang()),
|
||||
item: ItemConfig(
|
||||
@ -162,7 +143,6 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -1,19 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension IsSameDay on DateTime {
|
||||
bool isSameDay(DateTime other) {
|
||||
return year == other.year && month == other.month && day == other.day;
|
||||
bool isSameDay(DateTime other) => year == other.year && month == other.month && day == other.day;
|
||||
|
||||
DateTime nextWeekday(int day) => add(Duration(days: (day - weekday) % DateTime.daysPerWeek));
|
||||
|
||||
DateTime withTime(TimeOfDay time) => copyWith(hour: time.hour, minute: time.minute);
|
||||
|
||||
TimeOfDay toTimeOfDay() => TimeOfDay(hour: hour, minute: minute);
|
||||
|
||||
bool isSameDateTime(DateTime other) {
|
||||
var isSameDay = this.isSameDay(other);
|
||||
var isSameTimeOfDay = (toTimeOfDay() == other.toTimeOfDay());
|
||||
|
||||
return isSameDay && isSameTimeOfDay;
|
||||
}
|
||||
|
||||
DateTime nextWeekday(int day) {
|
||||
return add(Duration(days: (day - weekday) % DateTime.daysPerWeek));
|
||||
}
|
||||
|
||||
DateTime withTime(TimeOfDay time) {
|
||||
return copyWith(hour: time.hour, minute: time.minute);
|
||||
}
|
||||
|
||||
TimeOfDay toTimeOfDay() {
|
||||
return TimeOfDay(hour: hour, minute: minute);
|
||||
}
|
||||
bool isSameOrAfter(DateTime other) => isSameDateTime(other) || isAfter(other);
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
extension RenderNotNullExt<T> on T? {
|
||||
R? wrapNullable<R>(R Function(T data) defaultValueCallback) {
|
||||
return this != null ? defaultValueCallback(this as T) : null;
|
||||
}
|
||||
R? wrapNullable<R>(R Function(T data) defaultValueCallback) => this != null ? defaultValueCallback(this as T) : null;
|
||||
}
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
extension TextExt on Text {
|
||||
Size get size {
|
||||
final TextPainter textPainter = TextPainter(
|
||||
final textPainter = TextPainter(
|
||||
text: TextSpan(text: data, style: style),
|
||||
maxLines: 1,
|
||||
textDirection: TextDirection.ltr
|
||||
|
@ -1,15 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension TimeOfDayExt on TimeOfDay {
|
||||
bool isBefore(TimeOfDay other) {
|
||||
return hour < other.hour && minute < other.minute;
|
||||
}
|
||||
bool isBefore(TimeOfDay other) => hour < other.hour && minute < other.minute;
|
||||
|
||||
bool isAfter(TimeOfDay other) {
|
||||
return hour > other.hour && minute > other.minute;
|
||||
}
|
||||
bool isAfter(TimeOfDay other) => hour > other.hour && minute > other.minute;
|
||||
|
||||
TimeOfDay add({int hours = 0, int minutes = 0}) {
|
||||
return replacing(hour: hour + hours, minute: minute + minutes);
|
||||
}
|
||||
TimeOfDay add({int hours = 0, int minutes = 0}) => replacing(hour: hour + hours, minute: minute + minutes);
|
||||
}
|
@ -7,8 +7,11 @@ import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hydrated_bloc/hydrated_bloc.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
@ -23,37 +26,44 @@ import 'model/chatList/chatListProps.dart';
|
||||
import 'model/chatList/chatProps.dart';
|
||||
import 'model/files/filesProps.dart';
|
||||
import 'model/holidays/holidaysProps.dart';
|
||||
import 'model/message/messageProps.dart';
|
||||
import 'model/timetable/timetableProps.dart';
|
||||
import 'storage/base/settingsProvider.dart';
|
||||
import 'theming/darkAppTheme.dart';
|
||||
import 'theming/lightAppTheme.dart';
|
||||
import 'view/login/login.dart';
|
||||
import 'view/pages/more/abiturCalculator/models/abiturCalculatorModel.dart';
|
||||
import 'widget/placeholderView.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
log('MarianumMobile started');
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
log("Firebase token: ${await FirebaseMessaging.instance.getToken() ?? "Error: no Firebase token!"}");
|
||||
} catch (e) {
|
||||
log('Error initializing Firebase app!');
|
||||
}
|
||||
addCertificateAsTrusted(ByteData certificate) => SecurityContext.defaultContext.setTrustedCertificatesBytes(certificate.buffer.asUint8List());
|
||||
|
||||
ByteData data = await PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem');
|
||||
SecurityContext.defaultContext.setTrustedCertificatesBytes(data.buffer.asUint8List());
|
||||
var initialisationTasks = [
|
||||
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)
|
||||
.then((value) async => log("Firebase token: ${await FirebaseMessaging.instance.getToken() ?? "Error: no Firebase token!"}"))
|
||||
.onError((error, stackTrace) => log('Error initializing Firebase: $error')),
|
||||
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem').then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r10.pem').then(addCertificateAsTrusted),
|
||||
|
||||
Future(() async {
|
||||
await HydratedStorage.build(storageDirectory: await getTemporaryDirectory()).then((storage) => HydratedBloc.storage = storage);
|
||||
})
|
||||
];
|
||||
|
||||
log('starting app initialisation...');
|
||||
await Future.wait(initialisationTasks);
|
||||
log('app initialisation done!');
|
||||
|
||||
if(kReleaseMode) {
|
||||
ErrorWidget.builder = (error) {
|
||||
return PlaceholderView(
|
||||
icon: Icons.phonelink_erase_rounded,
|
||||
text: error.toStringShort(),
|
||||
);
|
||||
};
|
||||
ErrorWidget.builder = (error) => PlaceholderView(
|
||||
icon: Icons.phonelink_erase_rounded,
|
||||
text: error.toStringShort(),
|
||||
);
|
||||
}
|
||||
|
||||
log('running app...');
|
||||
runApp(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
@ -67,10 +77,7 @@ Future<void> main() async {
|
||||
ChangeNotifierProvider(create: (context) => ChatProps()),
|
||||
ChangeNotifierProvider(create: (context) => FilesProps()),
|
||||
|
||||
ChangeNotifierProvider(create: (context) => MessageProps()),
|
||||
ChangeNotifierProvider(create: (context) => HolidaysProps()),
|
||||
|
||||
ChangeNotifierProvider(create: (context) => AbiturCalculatorModel()),
|
||||
],
|
||||
child: const Main(),
|
||||
)
|
||||
@ -79,6 +86,8 @@ Future<void> main() async {
|
||||
|
||||
class Main extends StatefulWidget {
|
||||
const Main({super.key});
|
||||
static PersistentTabController bottomNavigator = PersistentTabController(initialIndex: 0);
|
||||
|
||||
|
||||
@override
|
||||
State<Main> createState() => _MainState();
|
||||
@ -104,8 +113,7 @@ class _MainState extends State<Main> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Directionality(
|
||||
Widget build(BuildContext context) => Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Consumer<SettingsProvider>(
|
||||
builder: (context, settings, child) {
|
||||
@ -149,7 +157,6 @@ class _MainState extends State<Main> {
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -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,9 +73,7 @@ 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!');
|
||||
|
@ -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() {
|
||||
|
@ -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}) {
|
||||
|
@ -1,25 +1,31 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../api/apiResponse.dart';
|
||||
import '../../api/marianumcloud/talk/chat/getChatCache.dart';
|
||||
import '../../api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import '../../storage/base/settingsProvider.dart';
|
||||
import '../dataHolder.dart';
|
||||
|
||||
class ChatProps extends DataHolder {
|
||||
String _queryToken = '';
|
||||
DateTime _lastTokenSet = DateTime.now();
|
||||
int? _referenceMessageId;
|
||||
|
||||
GetChatResponse? _getChatResponse;
|
||||
GetChatResponse get getChatResponse => _getChatResponse!;
|
||||
|
||||
int? get getReferenceMessageId => _referenceMessageId;
|
||||
set unsafeInternalSetReferenceMessageId(int? reference) => _referenceMessageId = reference;
|
||||
|
||||
@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,
|
||||
@ -32,6 +38,20 @@ class ChatProps extends DataHolder {
|
||||
);
|
||||
}
|
||||
|
||||
void setReferenceMessageId(int? messageId, BuildContext context, String sendToToken) {
|
||||
Future.microtask(() {
|
||||
_referenceMessageId = messageId;
|
||||
notifyListeners();
|
||||
|
||||
var settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
if(messageId != null) {
|
||||
settings.val(write: true).talkSettings.draftReplies[sendToToken] = messageId;
|
||||
} else {
|
||||
settings.val(write: true).talkSettings.draftReplies.removeWhere((key, value) => key == sendToToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setQueryToken(String token) {
|
||||
_queryToken = token;
|
||||
_getChatResponse = null;
|
||||
@ -39,7 +59,5 @@ class ChatProps extends DataHolder {
|
||||
run();
|
||||
}
|
||||
|
||||
String currentToken() {
|
||||
return _queryToken;
|
||||
}
|
||||
String currentToken() => _queryToken;
|
||||
}
|
15
lib/model/dataCleaner.dart
Normal file
15
lib/model/dataCleaner.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:localstore/localstore.dart';
|
||||
|
||||
import '../api/requestCache.dart';
|
||||
|
||||
class DataCleaner {
|
||||
static Future<void> cleanOldCache() async {
|
||||
var cacheData = await Localstore.instance.collection(RequestCache.collection).get();
|
||||
cacheData?.forEach((key, value) async {
|
||||
var lastUpdate = DateTime.fromMillisecondsSinceEpoch(value['lastupdate']);
|
||||
if(DateTime.now().subtract(const Duration(days: 200)).isAfter(lastUpdate)) {
|
||||
await Localstore.instance.collection(RequestCache.collection).doc(key.split('/').last).delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -6,16 +6,14 @@ 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;
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -1,27 +0,0 @@
|
||||
|
||||
import '../../api/apiResponse.dart';
|
||||
import '../../api/mhsl/message/getMessages/getMessagesCache.dart';
|
||||
import '../../api/mhsl/message/getMessages/getMessagesResponse.dart';
|
||||
import '../dataHolder.dart';
|
||||
|
||||
class MessageProps extends DataHolder {
|
||||
GetMessagesResponse? _getMessagesResponse;
|
||||
GetMessagesResponse get getMessagesResponse => _getMessagesResponse!;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() {
|
||||
return [_getMessagesResponse];
|
||||
}
|
||||
|
||||
@override
|
||||
void run({renew}) {
|
||||
GetMessagesCache(
|
||||
renew: renew,
|
||||
onUpdate: (GetMessagesResponse data) => {
|
||||
_getMessagesResponse = data,
|
||||
notifyListeners(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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)));
|
||||
|
@ -3,27 +3,25 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
class NotificationService {
|
||||
static final NotificationService _instance = NotificationService._internal();
|
||||
|
||||
factory NotificationService() {
|
||||
return _instance;
|
||||
}
|
||||
factory NotificationService() => _instance;
|
||||
|
||||
NotificationService._internal();
|
||||
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
|
||||
Future<void> initializeNotifications() async {
|
||||
const AndroidInitializationSettings androidSettings = AndroidInitializationSettings(
|
||||
const androidSettings = AndroidInitializationSettings(
|
||||
'@mipmap/ic_launcher'
|
||||
);
|
||||
|
||||
final DarwinInitializationSettings iosSettings = DarwinInitializationSettings(
|
||||
final iosSettings = DarwinInitializationSettings(
|
||||
onDidReceiveLocalNotification: (id, title, body, payload) {
|
||||
// TODO Navigate to Talk section (This runs when an Notification is tapped)
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
final InitializationSettings initializationSettings = InitializationSettings(
|
||||
final initializationSettings = InitializationSettings(
|
||||
android: androidSettings,
|
||||
iOS: iosSettings,
|
||||
);
|
||||
@ -34,7 +32,7 @@ class NotificationService {
|
||||
}
|
||||
|
||||
Future<void> showNotification({required String title, required String body, required int badgeCount}) async {
|
||||
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
||||
const androidPlatformChannelSpecifics =
|
||||
AndroidNotificationDetails(
|
||||
'marmobile',
|
||||
'Marianum Fulda',
|
||||
@ -43,9 +41,9 @@ class NotificationService {
|
||||
ticker: 'Marianum Fulda',
|
||||
);
|
||||
|
||||
const DarwinNotificationDetails iosPlatformChannelSpecifics = DarwinNotificationDetails();
|
||||
const iosPlatformChannelSpecifics = DarwinNotificationDetails();
|
||||
|
||||
const NotificationDetails platformChannelSpecifics = NotificationDetails(
|
||||
const platformChannelSpecifics = NotificationDetails(
|
||||
android: androidPlatformChannelSpecifics,
|
||||
iOS: iosPlatformChannelSpecifics
|
||||
);
|
||||
|
@ -3,7 +3,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../app.dart';
|
||||
import '../main.dart';
|
||||
import '../model/chatList/chatListProps.dart';
|
||||
import '../model/chatList/chatProps.dart';
|
||||
|
||||
@ -18,6 +18,6 @@ class NotificationTasks {
|
||||
}
|
||||
|
||||
static void navigateToTalk() {
|
||||
App.bottomNavigator.jumpToTab(1);
|
||||
Main.bottomNavigator.jumpToTab(1);
|
||||
}
|
||||
}
|
@ -8,8 +8,7 @@ import '../storage/base/settingsProvider.dart';
|
||||
import '../widget/confirmDialog.dart';
|
||||
|
||||
class NotifyUpdater {
|
||||
static ConfirmDialog enableAfterDisclaimer(SettingsProvider settings) {
|
||||
return ConfirmDialog(
|
||||
static ConfirmDialog enableAfterDisclaimer(SettingsProvider settings) => ConfirmDialog(
|
||||
title: 'Warnung',
|
||||
icon: Icons.warning_amber,
|
||||
content: ''
|
||||
@ -25,9 +24,9 @@ class NotifyUpdater {
|
||||
NotifyUpdater.registerToServer();
|
||||
},
|
||||
);
|
||||
}
|
||||
static void registerToServer() async {
|
||||
String? fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
|
||||
static Future<void> registerToServer() async {
|
||||
var fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
|
||||
if(fcmToken == null) throw Exception('Failed to register push notification because there is no FBC token!');
|
||||
|
||||
|
9
lib/state/app/basis/dataloader/holiday_data_loader.dart
Normal file
9
lib/state/app/basis/dataloader/holiday_data_loader.dart
Normal file
@ -0,0 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../infrastructure/dataLoader/data_loader.dart';
|
||||
|
||||
abstract class HolidayDataLoader<TResult> extends DataLoader<TResult> {
|
||||
HolidayDataLoader() : super(Dio(BaseOptions(
|
||||
baseUrl: 'https://ferien-api.de/api/v1/',
|
||||
)));
|
||||
}
|
9
lib/state/app/basis/dataloader/mhsl_data_loader.dart
Normal file
9
lib/state/app/basis/dataloader/mhsl_data_loader.dart
Normal file
@ -0,0 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../infrastructure/dataLoader/data_loader.dart';
|
||||
|
||||
abstract class MhslDataLoader<TResult> extends DataLoader<TResult> {
|
||||
MhslDataLoader() : super(Dio(BaseOptions(
|
||||
baseUrl: 'https://mhsl.eu/marianum/marianummobile/'
|
||||
)));
|
||||
}
|
46
lib/state/app/infrastructure/dataLoader/data_loader.dart
Normal file
46
lib/state/app/infrastructure/dataLoader/data_loader.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
abstract class DataLoader<TResult> {
|
||||
final Dio dio;
|
||||
DataLoader(this.dio) {
|
||||
dio.options.connectTimeout = const Duration(seconds: 10).inMilliseconds;
|
||||
dio.options.sendTimeout = const Duration(seconds: 30).inMilliseconds;
|
||||
dio.options.receiveTimeout = const Duration(seconds: 30).inMilliseconds;
|
||||
}
|
||||
|
||||
Future<TResult> run() async {
|
||||
var fetcher = fetch();
|
||||
await Future.wait([
|
||||
fetcher,
|
||||
Future.delayed(const Duration(milliseconds: 500)) // TODO tune or remove
|
||||
]);
|
||||
|
||||
var response = await fetcher;
|
||||
try {
|
||||
return assemble(DataLoaderResult(
|
||||
json: jsonDecode(response.data!),
|
||||
headers: response.headers.map.map((key, value) => MapEntry(key, value.join(';'))),
|
||||
));
|
||||
} catch(trace, e) {
|
||||
log(trace.toString());
|
||||
throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response<String>> fetch();
|
||||
TResult assemble(DataLoaderResult data);
|
||||
}
|
||||
|
||||
class DataLoaderResult {
|
||||
final dynamic json;
|
||||
final Map<String, String> headers;
|
||||
|
||||
Map<String, dynamic> asMap() => json as Map<String, dynamic>;
|
||||
List<dynamic> asList() => json as List<dynamic>;
|
||||
List<Map<String, dynamic>> asListOfMaps() => asList().map((e) => e as Map<String, dynamic>).toList();
|
||||
|
||||
DataLoaderResult({required this.json, required this.headers});
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
|
||||
import 'loadable_state_event.dart';
|
||||
import 'loadable_state_state.dart';
|
||||
|
||||
class LoadableStateBloc extends Bloc<LoadableStateEvent, LoadableStateState> {
|
||||
late StreamSubscription<List<ConnectivityResult>> _updateStream;
|
||||
void Function()? reFetch;
|
||||
|
||||
LoadableStateBloc() : super(const LoadableStateState(connections: null)) {
|
||||
on<ConnectivityChanged>((event, emit) {
|
||||
emit(event.state);
|
||||
if(connectivityStatusKnown() && isConnected()) {
|
||||
if(reFetch == null) return;
|
||||
reFetch!();
|
||||
}
|
||||
});
|
||||
|
||||
emitConnectivity(List<ConnectivityResult> result) => add(ConnectivityChanged(LoadableStateState(connections: result)));
|
||||
|
||||
Connectivity().checkConnectivity().then(emitConnectivity);
|
||||
_updateStream = Connectivity().onConnectivityChanged.listen(emitConnectivity);
|
||||
}
|
||||
|
||||
bool connectivityStatusKnown() => state.connections != null;
|
||||
bool isConnected() => !(state.connections?.contains(ConnectivityResult.none) ?? true);
|
||||
bool allowRetry() => reFetch != null;
|
||||
|
||||
IconData connectionIcon() => connectivityStatusKnown()
|
||||
? isConnected()
|
||||
? Icons.nearby_error
|
||||
: Icons.signal_wifi_connected_no_internet_4
|
||||
: Icons.device_unknown;
|
||||
|
||||
Color connectionColor(BuildContext context) => connectivityStatusKnown() && !isConnected()
|
||||
? Colors.grey.shade600
|
||||
: Theme.of(context).primaryColor;
|
||||
|
||||
String connectionText({int? lastUpdated}) => connectivityStatusKnown()
|
||||
? isConnected()
|
||||
? 'Verbindung fehlgeschlagen'
|
||||
: 'Offline${lastUpdated == null ? '' : ' - Stand von ${Jiffy.parseFromMillisecondsSinceEpoch(lastUpdated).fromNow()}'}'
|
||||
: 'Unbekannte Fehlerursache';
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_updateStream.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import 'loadable_state_state.dart';
|
||||
|
||||
sealed class LoadableStateEvent {}
|
||||
final class ConnectivityChanged extends LoadableStateEvent {
|
||||
final LoadableStateState state;
|
||||
ConnectivityChanged(this.state);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'loadable_state_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class LoadableStateState with _$LoadableStateState {
|
||||
const factory LoadableStateState({
|
||||
required List<ConnectivityResult>? connections,
|
||||
}) = _LoadableStateState;
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'loadable_state_state.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
/// @nodoc
|
||||
mixin _$LoadableStateState {
|
||||
List<ConnectivityResult>? get connections =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$LoadableStateStateCopyWith<LoadableStateState> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $LoadableStateStateCopyWith<$Res> {
|
||||
factory $LoadableStateStateCopyWith(
|
||||
LoadableStateState value, $Res Function(LoadableStateState) then) =
|
||||
_$LoadableStateStateCopyWithImpl<$Res, LoadableStateState>;
|
||||
@useResult
|
||||
$Res call({List<ConnectivityResult>? connections});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$LoadableStateStateCopyWithImpl<$Res, $Val extends LoadableStateState>
|
||||
implements $LoadableStateStateCopyWith<$Res> {
|
||||
_$LoadableStateStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? connections = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
connections: freezed == connections
|
||||
? _value.connections
|
||||
: connections // ignore: cast_nullable_to_non_nullable
|
||||
as List<ConnectivityResult>?,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$LoadableStateStateImplCopyWith<$Res>
|
||||
implements $LoadableStateStateCopyWith<$Res> {
|
||||
factory _$$LoadableStateStateImplCopyWith(_$LoadableStateStateImpl value,
|
||||
$Res Function(_$LoadableStateStateImpl) then) =
|
||||
__$$LoadableStateStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({List<ConnectivityResult>? connections});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$LoadableStateStateImplCopyWithImpl<$Res>
|
||||
extends _$LoadableStateStateCopyWithImpl<$Res, _$LoadableStateStateImpl>
|
||||
implements _$$LoadableStateStateImplCopyWith<$Res> {
|
||||
__$$LoadableStateStateImplCopyWithImpl(_$LoadableStateStateImpl _value,
|
||||
$Res Function(_$LoadableStateStateImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? connections = freezed,
|
||||
}) {
|
||||
return _then(_$LoadableStateStateImpl(
|
||||
connections: freezed == connections
|
||||
? _value._connections
|
||||
: connections // ignore: cast_nullable_to_non_nullable
|
||||
as List<ConnectivityResult>?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$LoadableStateStateImpl implements _LoadableStateState {
|
||||
const _$LoadableStateStateImpl(
|
||||
{required final List<ConnectivityResult>? connections})
|
||||
: _connections = connections;
|
||||
|
||||
final List<ConnectivityResult>? _connections;
|
||||
@override
|
||||
List<ConnectivityResult>? get connections {
|
||||
final value = _connections;
|
||||
if (value == null) return null;
|
||||
if (_connections is EqualUnmodifiableListView) return _connections;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LoadableStateState(connections: $connections)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$LoadableStateStateImpl &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._connections, _connections));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType, const DeepCollectionEquality().hash(_connections));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$LoadableStateStateImplCopyWith<_$LoadableStateStateImpl> get copyWith =>
|
||||
__$$LoadableStateStateImplCopyWithImpl<_$LoadableStateStateImpl>(
|
||||
this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _LoadableStateState implements LoadableStateState {
|
||||
const factory _LoadableStateState(
|
||||
{required final List<ConnectivityResult>? connections}) =
|
||||
_$LoadableStateStateImpl;
|
||||
|
||||
@override
|
||||
List<ConnectivityResult>? get connections;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$LoadableStateStateImplCopyWith<_$LoadableStateStateImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'loading_error.dart';
|
||||
|
||||
part 'loadable_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class LoadableState<TState> with _$LoadableState {
|
||||
const LoadableState._();
|
||||
|
||||
const factory LoadableState({
|
||||
required bool isLoading,
|
||||
required TState? data,
|
||||
required int? lastFetch,
|
||||
required void Function()? reFetch,
|
||||
required LoadingError? error,
|
||||
}) = _LoadableState;
|
||||
|
||||
bool _hasError() => error != null;
|
||||
bool _hasData() => data != null;
|
||||
|
||||
bool showPrimaryLoading() => isLoading && !_hasData();
|
||||
bool showBackgroundLoading() => isLoading && _hasData();
|
||||
bool showErrorBar() => _hasError() && _hasData();
|
||||
bool showError() => _hasError() && !_hasData();
|
||||
bool showContent() => _hasData();
|
||||
}
|
@ -0,0 +1,246 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'loadable_state.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
/// @nodoc
|
||||
mixin _$LoadableState<TState> {
|
||||
bool get isLoading => throw _privateConstructorUsedError;
|
||||
TState? get data => throw _privateConstructorUsedError;
|
||||
int? get lastFetch => throw _privateConstructorUsedError;
|
||||
void Function()? get reFetch => throw _privateConstructorUsedError;
|
||||
LoadingError? get error => throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$LoadableStateCopyWith<TState, LoadableState<TState>> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $LoadableStateCopyWith<TState, $Res> {
|
||||
factory $LoadableStateCopyWith(LoadableState<TState> value,
|
||||
$Res Function(LoadableState<TState>) then) =
|
||||
_$LoadableStateCopyWithImpl<TState, $Res, LoadableState<TState>>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{bool isLoading,
|
||||
TState? data,
|
||||
int? lastFetch,
|
||||
void Function()? reFetch,
|
||||
LoadingError? error});
|
||||
|
||||
$LoadingErrorCopyWith<$Res>? get error;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$LoadableStateCopyWithImpl<TState, $Res,
|
||||
$Val extends LoadableState<TState>>
|
||||
implements $LoadableStateCopyWith<TState, $Res> {
|
||||
_$LoadableStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? isLoading = null,
|
||||
Object? data = freezed,
|
||||
Object? lastFetch = freezed,
|
||||
Object? reFetch = freezed,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
isLoading: null == isLoading
|
||||
? _value.isLoading
|
||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as TState?,
|
||||
lastFetch: freezed == lastFetch
|
||||
? _value.lastFetch
|
||||
: lastFetch // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
reFetch: freezed == reFetch
|
||||
? _value.reFetch
|
||||
: reFetch // ignore: cast_nullable_to_non_nullable
|
||||
as void Function()?,
|
||||
error: freezed == error
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as LoadingError?,
|
||||
) as $Val);
|
||||
}
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$LoadingErrorCopyWith<$Res>? get error {
|
||||
if (_value.error == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $LoadingErrorCopyWith<$Res>(_value.error!, (value) {
|
||||
return _then(_value.copyWith(error: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$LoadableStateImplCopyWith<TState, $Res>
|
||||
implements $LoadableStateCopyWith<TState, $Res> {
|
||||
factory _$$LoadableStateImplCopyWith(_$LoadableStateImpl<TState> value,
|
||||
$Res Function(_$LoadableStateImpl<TState>) then) =
|
||||
__$$LoadableStateImplCopyWithImpl<TState, $Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{bool isLoading,
|
||||
TState? data,
|
||||
int? lastFetch,
|
||||
void Function()? reFetch,
|
||||
LoadingError? error});
|
||||
|
||||
@override
|
||||
$LoadingErrorCopyWith<$Res>? get error;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$LoadableStateImplCopyWithImpl<TState, $Res>
|
||||
extends _$LoadableStateCopyWithImpl<TState, $Res,
|
||||
_$LoadableStateImpl<TState>>
|
||||
implements _$$LoadableStateImplCopyWith<TState, $Res> {
|
||||
__$$LoadableStateImplCopyWithImpl(_$LoadableStateImpl<TState> _value,
|
||||
$Res Function(_$LoadableStateImpl<TState>) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? isLoading = null,
|
||||
Object? data = freezed,
|
||||
Object? lastFetch = freezed,
|
||||
Object? reFetch = freezed,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(_$LoadableStateImpl<TState>(
|
||||
isLoading: null == isLoading
|
||||
? _value.isLoading
|
||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as TState?,
|
||||
lastFetch: freezed == lastFetch
|
||||
? _value.lastFetch
|
||||
: lastFetch // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
reFetch: freezed == reFetch
|
||||
? _value.reFetch
|
||||
: reFetch // ignore: cast_nullable_to_non_nullable
|
||||
as void Function()?,
|
||||
error: freezed == error
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as LoadingError?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$LoadableStateImpl<TState> extends _LoadableState<TState> {
|
||||
const _$LoadableStateImpl(
|
||||
{this.isLoading = true,
|
||||
this.data = null,
|
||||
this.lastFetch = null,
|
||||
this.reFetch = null,
|
||||
this.error = null})
|
||||
: super._();
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isLoading;
|
||||
@override
|
||||
@JsonKey()
|
||||
final TState? data;
|
||||
@override
|
||||
@JsonKey()
|
||||
final int? lastFetch;
|
||||
@override
|
||||
@JsonKey()
|
||||
final void Function()? reFetch;
|
||||
@override
|
||||
@JsonKey()
|
||||
final LoadingError? error;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LoadableState<$TState>(isLoading: $isLoading, data: $data, lastFetch: $lastFetch, reFetch: $reFetch, error: $error)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$LoadableStateImpl<TState> &&
|
||||
(identical(other.isLoading, isLoading) ||
|
||||
other.isLoading == isLoading) &&
|
||||
const DeepCollectionEquality().equals(other.data, data) &&
|
||||
(identical(other.lastFetch, lastFetch) ||
|
||||
other.lastFetch == lastFetch) &&
|
||||
(identical(other.reFetch, reFetch) || other.reFetch == reFetch) &&
|
||||
(identical(other.error, error) || other.error == error));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, isLoading,
|
||||
const DeepCollectionEquality().hash(data), lastFetch, reFetch, error);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$LoadableStateImplCopyWith<TState, _$LoadableStateImpl<TState>>
|
||||
get copyWith => __$$LoadableStateImplCopyWithImpl<TState,
|
||||
_$LoadableStateImpl<TState>>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _LoadableState<TState> extends LoadableState<TState> {
|
||||
const factory _LoadableState(
|
||||
{final bool isLoading,
|
||||
final TState? data,
|
||||
final int? lastFetch,
|
||||
final void Function()? reFetch,
|
||||
final LoadingError? error}) = _$LoadableStateImpl<TState>;
|
||||
const _LoadableState._() : super._();
|
||||
|
||||
@override
|
||||
bool get isLoading;
|
||||
@override
|
||||
TState? get data;
|
||||
@override
|
||||
int? get lastFetch;
|
||||
@override
|
||||
void Function()? get reFetch;
|
||||
@override
|
||||
LoadingError? get error;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$LoadableStateImplCopyWith<TState, _$LoadableStateImpl<TState>>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'loading_error.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class LoadingError with _$LoadingError {
|
||||
const factory LoadingError({
|
||||
required String message,
|
||||
@Default(false) bool allowRetry,
|
||||
}) = _LoadingError;
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'loading_error.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
/// @nodoc
|
||||
mixin _$LoadingError {
|
||||
String get message => throw _privateConstructorUsedError;
|
||||
bool get allowRetry => throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$LoadingErrorCopyWith<LoadingError> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $LoadingErrorCopyWith<$Res> {
|
||||
factory $LoadingErrorCopyWith(
|
||||
LoadingError value, $Res Function(LoadingError) then) =
|
||||
_$LoadingErrorCopyWithImpl<$Res, LoadingError>;
|
||||
@useResult
|
||||
$Res call({String message, bool allowRetry});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$LoadingErrorCopyWithImpl<$Res, $Val extends LoadingError>
|
||||
implements $LoadingErrorCopyWith<$Res> {
|
||||
_$LoadingErrorCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? message = null,
|
||||
Object? allowRetry = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
allowRetry: null == allowRetry
|
||||
? _value.allowRetry
|
||||
: allowRetry // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$LoadingErrorImplCopyWith<$Res>
|
||||
implements $LoadingErrorCopyWith<$Res> {
|
||||
factory _$$LoadingErrorImplCopyWith(
|
||||
_$LoadingErrorImpl value, $Res Function(_$LoadingErrorImpl) then) =
|
||||
__$$LoadingErrorImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String message, bool allowRetry});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$LoadingErrorImplCopyWithImpl<$Res>
|
||||
extends _$LoadingErrorCopyWithImpl<$Res, _$LoadingErrorImpl>
|
||||
implements _$$LoadingErrorImplCopyWith<$Res> {
|
||||
__$$LoadingErrorImplCopyWithImpl(
|
||||
_$LoadingErrorImpl _value, $Res Function(_$LoadingErrorImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? message = null,
|
||||
Object? allowRetry = null,
|
||||
}) {
|
||||
return _then(_$LoadingErrorImpl(
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
allowRetry: null == allowRetry
|
||||
? _value.allowRetry
|
||||
: allowRetry // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$LoadingErrorImpl implements _LoadingError {
|
||||
const _$LoadingErrorImpl({required this.message, this.allowRetry = false});
|
||||
|
||||
@override
|
||||
final String message;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool allowRetry;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LoadingError(message: $message, allowRetry: $allowRetry)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$LoadingErrorImpl &&
|
||||
(identical(other.message, message) || other.message == message) &&
|
||||
(identical(other.allowRetry, allowRetry) ||
|
||||
other.allowRetry == allowRetry));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, message, allowRetry);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$LoadingErrorImplCopyWith<_$LoadingErrorImpl> get copyWith =>
|
||||
__$$LoadingErrorImplCopyWithImpl<_$LoadingErrorImpl>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _LoadingError implements LoadingError {
|
||||
const factory _LoadingError(
|
||||
{required final String message,
|
||||
final bool allowRetry}) = _$LoadingErrorImpl;
|
||||
|
||||
@override
|
||||
String get message;
|
||||
@override
|
||||
bool get allowRetry;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$LoadingErrorImplCopyWith<_$LoadingErrorImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'loadable_state_consumer.dart';
|
||||
|
||||
class LoadableStateBackgroundLoading extends StatelessWidget {
|
||||
final bool visible;
|
||||
const LoadableStateBackgroundLoading({required this.visible, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedSwitcher(
|
||||
duration: LoadableStateConsumer.animationDuration,
|
||||
transitionBuilder: (Widget child, Animation<double> animation) => SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0.0, -1.0),
|
||||
end: Offset.zero,
|
||||
).animate(animation),
|
||||
child: child,
|
||||
),
|
||||
child: visible ? const LinearProgressIndicator() : const SizedBox.shrink(),
|
||||
);
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../../../widget/conditional_wrapper.dart';
|
||||
import '../../utilityWidgets/bloc_module.dart';
|
||||
import '../../utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc_event.dart';
|
||||
import '../bloc/loadable_state_bloc.dart';
|
||||
import '../bloc/loadable_state_state.dart';
|
||||
import '../loadable_state.dart';
|
||||
import 'loadable_state_background_loading.dart';
|
||||
import 'loadable_state_error_bar.dart';
|
||||
import 'loadable_state_error_screen.dart';
|
||||
import 'loadable_state_primary_loading.dart';
|
||||
|
||||
class LoadableStateConsumer<TController extends Bloc<LoadableHydratedBlocEvent<TState>, LoadableState<TState>>, TState> extends StatelessWidget {
|
||||
final Widget Function(TState state, bool loading) child;
|
||||
final void Function(TState state)? onLoad;
|
||||
final bool wrapWithScrollView;
|
||||
const LoadableStateConsumer({required this.child, this.onLoad, this.wrapWithScrollView = false, super.key});
|
||||
|
||||
static Duration animationDuration = const Duration(milliseconds: 200);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var loadableState = context.watch<TController>().state;
|
||||
|
||||
if(!loadableState.isLoading && onLoad != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) => onLoad!(loadableState.data));
|
||||
}
|
||||
|
||||
var childWidget = ConditionalWrapper(
|
||||
condition: loadableState.reFetch != null,
|
||||
wrapper: (child) => RefreshIndicator(
|
||||
onRefresh: () {
|
||||
if(loadableState.reFetch != null) loadableState.reFetch!();
|
||||
return Future.value();
|
||||
},
|
||||
child: ConditionalWrapper(
|
||||
condition: wrapWithScrollView,
|
||||
wrapper: (child) => SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: child
|
||||
),
|
||||
child: child,
|
||||
)
|
||||
),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: loadableState.showContent()
|
||||
? child(loadableState.data, loadableState.isLoading)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
|
||||
return BlocModule<LoadableStateBloc, LoadableStateState>(
|
||||
create: (context) => LoadableStateBloc(),
|
||||
child: (context, bloc, state) {
|
||||
bloc.reFetch = loadableState.reFetch;
|
||||
return Column(
|
||||
children: [
|
||||
LoadableStateErrorBar(visible: loadableState.showErrorBar(), message: loadableState.error?.message, lastUpdated: loadableState.lastFetch),
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
LoadableStatePrimaryLoading(visible: loadableState.showPrimaryLoading()),
|
||||
LoadableStateBackgroundLoading(visible: loadableState.showBackgroundLoading()),
|
||||
LoadableStateErrorScreen(visible: loadableState.showError(), message: loadableState.error?.message),
|
||||
|
||||
AnimatedOpacity(
|
||||
opacity: loadableState.showContent() ? 1.0 : 0.0,
|
||||
duration: animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
child: childWidget,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user