Erweiterungen
This commit is contained in:
1 parent
7015d83fd1
commit
6981cfbf8a
4 files changed
+56
-39
No files matched your search
@@ -18,11 +18,14 @@ import 'package:badges/badges.dart' as badges;
|
||||
|
||||
import '../tools/messages/publish_payload_message.dart';
|
||||
|
||||
Timer? _checkForNewJobsTimer;
|
||||
|
||||
Map<int, DateTime> _firstDelayTimeMap = {};
|
||||
late bool _initTimer;
|
||||
late Timer _checkForNewJobsTimer;
|
||||
late Map<int, DateTime> _firstDelayTimeMap;
|
||||
|
||||
Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapReference, Function() onFinished) async {
|
||||
_initTimer = true;
|
||||
_firstDelayTimeMap = {};
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
@@ -41,7 +44,11 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
_startTimer(mapReference, setState);
|
||||
if (_initTimer) {
|
||||
_initTimer = false;
|
||||
|
||||
_startTimer(context, mapReference, setState, onFinished);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
key: GlobalKey(),
|
||||
@@ -51,7 +58,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
|
||||
height: 100,
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: FutureBuilder<List<Widget>>(
|
||||
future: _fetchJobWidgets(mapReference),
|
||||
future: _fetchJobWidgets(setState, onFinished, mapReference),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return Util.getWaitWidget(context);
|
||||
@@ -67,26 +74,28 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
|
||||
});
|
||||
}
|
||||
|
||||
void _startTimer(SharedMapReference mapReference, StateSetter setState) {
|
||||
_checkForNewJobsTimer ??= Timer.periodic(const Duration(seconds: 5), (Timer t) async {
|
||||
void _startTimer(BuildContext context, SharedMapReference mapReference, StateSetter setState, Function() onFinished) {
|
||||
_checkForNewJobsTimer = Timer.periodic(const Duration(seconds: 5), (Timer t) async {
|
||||
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
|
||||
|
||||
if (await jobMap.length() > 0) {
|
||||
setState(() { });
|
||||
} else {
|
||||
_stopTimer();
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
onFinished();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _stopTimer() {
|
||||
if (_checkForNewJobsTimer != null) {
|
||||
_checkForNewJobsTimer!.cancel();
|
||||
|
||||
_checkForNewJobsTimer = null;
|
||||
}
|
||||
_checkForNewJobsTimer.cancel();
|
||||
}
|
||||
|
||||
|
||||
Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
|
||||
Future<List<Widget>> _fetchJobWidgets(StateSetter dialogState, Function() onFinished, SharedMapReference mapReference) async {
|
||||
List<Widget> widgets = [];
|
||||
|
||||
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
|
||||
@@ -198,20 +207,40 @@ Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren', () {
|
||||
setState(() {
|
||||
_sendAnswer(job, !job.global ? 2 : 3);
|
||||
dialogState(() {
|
||||
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),
|
||||
Expanded(
|
||||
child: getDefaultButton('Annehmen', enabledTimerActive: enableDelay > 0, enabledTimerDelay: enableDelay, () {
|
||||
setState(() {
|
||||
_sendAnswer(job, 1);
|
||||
dialogState(() {
|
||||
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;
|
||||
}
|
||||
|
||||
_sendAnswer(Job job, int item) async {
|
||||
_sendAnswer(SharedMapReference mapReference, Job job, int item) async {
|
||||
var currentPosition = MyApp.currentPosition;
|
||||
|
||||
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 MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.delete(job.id);
|
||||
});
|
||||
|
||||
await MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage());
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ showZipPopup(BuildContext context, String text, String buttonText, Function(Stri
|
||||
|
||||
return SizedBox(
|
||||
key: GlobalKey(),
|
||||
height: 280,
|
||||
height: 293,
|
||||
width: MediaQuery.of(context).size.width * 0.8,
|
||||
child: Container(
|
||||
height: 100,
|
||||
|
||||
@@ -140,11 +140,7 @@ class MqttCore {
|
||||
bool _publishText(String topic, String text, MqttQos qos, {bool enqueueOnError = true}) {
|
||||
try {
|
||||
var buffer = Uint8Buffer();
|
||||
if (kDebugMode) {
|
||||
buffer.addAll(const Utf8Encoder().convert(text));
|
||||
} else {
|
||||
buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>);
|
||||
}
|
||||
buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>);
|
||||
|
||||
var messageTopic = "$_toServerTopic$_clientId/$topic";
|
||||
|
||||
@@ -178,12 +174,7 @@ class MqttCore {
|
||||
Util.logInfo('message received\ntopic: $topic\n');
|
||||
Util.logInfo("size in bytes: ${message.payload.message.length.toString()}");
|
||||
|
||||
String payload;
|
||||
if (kDebugMode) {
|
||||
payload = utf8.decode(message.payload.message);
|
||||
} else {
|
||||
payload = utf8.decode(GZipDecoder().decodeBytes(message.payload.message));
|
||||
}
|
||||
var payload = utf8.decode(GZipDecoder().decodeBytes(message.payload.message));
|
||||
|
||||
Util.logInfo('$topic\nmessage: $payload');
|
||||
|
||||
@@ -453,8 +444,8 @@ class MqttCore {
|
||||
var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText));
|
||||
|
||||
var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":");
|
||||
_brokerUri = "192.168.180.27"; //brokerUriAndPortArray[0];
|
||||
_brokerPort = 1883; //int.parse(brokerUriAndPortArray[1]);
|
||||
_brokerUri = brokerUriAndPortArray[0];
|
||||
_brokerPort = int.parse(brokerUriAndPortArray[1]);
|
||||
_clientId = bootstrapResponsePayload.id;
|
||||
_fromServerTopic = bootstrapResponsePayload.fromServer;
|
||||
_toServerTopic = bootstrapResponsePayload.toServer;
|
||||
|
||||
Reference in new issue
Block a user