Erweiterungen

This commit is contained in:
Sven committed 2024-08-07 10:00:59 +02:00
1 parent 7015d83fd1
commit 6981cfbf8a
4 files changed
+56 -39

No files matched your search

+50 -24
View File
@@ -18,11 +18,14 @@ import 'package:badges/badges.dart' as badges;
import '../tools/messages/publish_payload_message.dart'; import '../tools/messages/publish_payload_message.dart';
Timer? _checkForNewJobsTimer; late bool _initTimer;
late Timer _checkForNewJobsTimer;
Map<int, DateTime> _firstDelayTimeMap = {}; late Map<int, DateTime> _firstDelayTimeMap;
Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapReference, Function() onFinished) async { Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapReference, Function() onFinished) async {
_initTimer = true;
_firstDelayTimeMap = {};
await showDialog<void>( await showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
@@ -41,7 +44,11 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
shadowColor: Colors.transparent, shadowColor: Colors.transparent,
backgroundColor: Colors.white, backgroundColor: Colors.white,
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
_startTimer(mapReference, setState); if (_initTimer) {
_initTimer = false;
_startTimer(context, mapReference, setState, onFinished);
}
return SizedBox( return SizedBox(
key: GlobalKey(), key: GlobalKey(),
@@ -51,7 +58,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
height: 100, height: 100,
padding: const EdgeInsets.all(5), padding: const EdgeInsets.all(5),
child: FutureBuilder<List<Widget>>( child: FutureBuilder<List<Widget>>(
future: _fetchJobWidgets(mapReference), future: _fetchJobWidgets(setState, onFinished, mapReference),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { if (snapshot.connectionState == ConnectionState.waiting) {
return Util.getWaitWidget(context); return Util.getWaitWidget(context);
@@ -67,26 +74,28 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
}); });
} }
void _startTimer(SharedMapReference mapReference, StateSetter setState) { void _startTimer(BuildContext context, SharedMapReference mapReference, StateSetter setState, Function() onFinished) {
_checkForNewJobsTimer ??= Timer.periodic(const Duration(seconds: 5), (Timer t) async { _checkForNewJobsTimer = Timer.periodic(const Duration(seconds: 5), (Timer t) async {
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference); var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
if (await jobMap.length() > 0) { if (await jobMap.length() > 0) {
setState(() { }); setState(() { });
} else {
_stopTimer();
Navigator.of(context).pop();
onFinished();
} }
}); });
} }
void _stopTimer() { void _stopTimer() {
if (_checkForNewJobsTimer != null) { _checkForNewJobsTimer.cancel();
_checkForNewJobsTimer!.cancel();
_checkForNewJobsTimer = null;
}
} }
Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async { Future<List<Widget>> _fetchJobWidgets(StateSetter dialogState, Function() onFinished, SharedMapReference mapReference) async {
List<Widget> widgets = []; List<Widget> widgets = [];
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference); var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
@@ -198,20 +207,40 @@ Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
Row(children: [ Row(children: [
Expanded( Expanded(
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren', () { child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren', () {
setState(() { dialogState(() {
_sendAnswer(job, !job.global ? 2 : 3); if (jobMap.length() == 1) {
_stopTimer();
}
//jobs.removeWhere((value) => value.id == job.id); _sendAnswer(mapReference, job, !job.global ? 2 : 3);
jobMap.remove(job.id);
if (jobMap.length() == 0) {
Navigator.of(context).pop();
onFinished();
}
}); });
}), }),
), ),
const SizedBox(width: 20), const SizedBox(width: 20),
Expanded( Expanded(
child: getDefaultButton('Annehmen', enabledTimerActive: enableDelay > 0, enabledTimerDelay: enableDelay, () { child: getDefaultButton('Annehmen', enabledTimerActive: enableDelay > 0, enabledTimerDelay: enableDelay, () {
setState(() { dialogState(() {
_sendAnswer(job, 1); if (jobMap.length() == 1) {
_stopTimer();
}
//jobs.removeWhere((value) => value.id == job.id); _sendAnswer(mapReference, job, 1);
jobMap.remove(job.id);
if (jobMap.length() == 0) {
Navigator.of(context).pop();
onFinished();
}
}); });
}), }),
) )
@@ -229,7 +258,7 @@ Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
return widgets; return widgets;
} }
_sendAnswer(Job job, int item) async { _sendAnswer(SharedMapReference mapReference, Job job, int item) async {
var currentPosition = MyApp.currentPosition; var currentPosition = MyApp.currentPosition;
var message = Reaction(); var message = Reaction();
@@ -245,9 +274,6 @@ _sendAnswer(Job job, int item) async {
await MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "reaction", message: message.toJson(), qos: MqttQos.exactlyOnce)); await MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "reaction", message: message.toJson(), qos: MqttQos.exactlyOnce));
await MyApp.isarInstance.writeTxn(() async {
await MyApp.isarInstance.jobs.delete(job.id);
});
await MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage()); await MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage());
} }
+1 -1
View File
@@ -18,7 +18,7 @@ showZipPopup(BuildContext context, String text, String buttonText, Function(Stri
return SizedBox( return SizedBox(
key: GlobalKey(), key: GlobalKey(),
height: 280, height: 293,
width: MediaQuery.of(context).size.width * 0.8, width: MediaQuery.of(context).size.width * 0.8,
child: Container( child: Container(
height: 100, height: 100,
+4 -13
View File
@@ -140,11 +140,7 @@ class MqttCore {
bool _publishText(String topic, String text, MqttQos qos, {bool enqueueOnError = true}) { bool _publishText(String topic, String text, MqttQos qos, {bool enqueueOnError = true}) {
try { try {
var buffer = Uint8Buffer(); var buffer = Uint8Buffer();
if (kDebugMode) { buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>);
buffer.addAll(const Utf8Encoder().convert(text));
} else {
buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>);
}
var messageTopic = "$_toServerTopic$_clientId/$topic"; var messageTopic = "$_toServerTopic$_clientId/$topic";
@@ -178,12 +174,7 @@ class MqttCore {
Util.logInfo('message received\ntopic: $topic\n'); Util.logInfo('message received\ntopic: $topic\n');
Util.logInfo("size in bytes: ${message.payload.message.length.toString()}"); Util.logInfo("size in bytes: ${message.payload.message.length.toString()}");
String payload; var payload = utf8.decode(GZipDecoder().decodeBytes(message.payload.message));
if (kDebugMode) {
payload = utf8.decode(message.payload.message);
} else {
payload = utf8.decode(GZipDecoder().decodeBytes(message.payload.message));
}
Util.logInfo('$topic\nmessage: $payload'); Util.logInfo('$topic\nmessage: $payload');
@@ -453,8 +444,8 @@ class MqttCore {
var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText)); var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText));
var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":"); var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":");
_brokerUri = "192.168.180.27"; //brokerUriAndPortArray[0]; _brokerUri = brokerUriAndPortArray[0];
_brokerPort = 1883; //int.parse(brokerUriAndPortArray[1]); _brokerPort = int.parse(brokerUriAndPortArray[1]);
_clientId = bootstrapResponsePayload.id; _clientId = bootstrapResponsePayload.id;
_fromServerTopic = bootstrapResponsePayload.fromServer; _fromServerTopic = bootstrapResponsePayload.fromServer;
_toServerTopic = bootstrapResponsePayload.toServer; _toServerTopic = bootstrapResponsePayload.toServer;
+1 -1
View File
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 319.0.0+319 version: 320.0.0+320
environment: environment:
sdk: '>=2.19.6 <3.0.0' sdk: '>=2.19.6 <3.0.0'