This commit is contained in:
Sven committed 2024-03-07 12:26:33 +01:00
1 parent d7b49e2b66
commit e003c508f3
5 files changed
+181 -138

No files matched your search

+12
View File
@@ -7,6 +7,8 @@ import 'package:intl/intl.dart';
import 'package:badges/badges.dart' as badges; import 'package:badges/badges.dart' as badges;
import 'package:stadtbote/protocoll_messages/accept_job_message.dart'; import 'package:stadtbote/protocoll_messages/accept_job_message.dart';
import 'package:stadtbote/protocoll_messages/fin_task_message.dart'; import 'package:stadtbote/protocoll_messages/fin_task_message.dart';
import 'package:stadtbote/tools/message_service.dart';
import 'package:stadtbote/tools/messages/job_deleted_message.dart';
import 'package:stadtbote/tools/mqtt_core.dart'; import 'package:stadtbote/tools/mqtt_core.dart';
import '../main.dart'; import '../main.dart';
@@ -49,6 +51,8 @@ class _AssignedJobsPageState extends State<AssignedJobsPage> {
Future.delayed(const Duration(seconds: 0), () async { Future.delayed(const Duration(seconds: 0), () async {
_entries = await _createListEntries(); _entries = await _createListEntries();
_initMessages();
_initCompleted = true; _initCompleted = true;
setState(() {}); setState(() {});
@@ -208,4 +212,12 @@ class _AssignedJobsPageState extends State<AssignedJobsPage> {
setState(() {}); setState(() {});
} }
_initMessages() {
MessageService().subscribe<JobDeletedMessage>(Constants.messageTopicJobDeleted, this, (jobDeletedMessage) async {
_entries = await _createListEntries();
setState(() {});
});
}
} }
+9 -1
View File
@@ -153,6 +153,8 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
late AnimationController _animationController; late AnimationController _animationController;
late Animation<double> _animation; late Animation<double> _animation;
bool _dialogOpened = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -423,7 +425,13 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
void _jobReceived(Job job) async { void _jobReceived(Job job) async {
if (!MyApp.suppressAcceptDialog) { if (!MyApp.suppressAcceptDialog) {
if (job.state == 0) { if (job.state == 0) {
await showAcceptJobsPopup(context, await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll()); if (!_dialogOpened) {
_dialogOpened = true;
await showAcceptJobsPopup(context, await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll(), () {
_dialogOpened = false;
});
}
} }
} }
} }
+151 -126
View File
@@ -6,154 +6,179 @@ import 'package:stadtbote/protocoll_messages/accept_job_message.dart';
import 'package:stadtbote/model/job.dart'; import 'package:stadtbote/model/job.dart';
import 'package:stadtbote/protocoll_messages/fin_task_message.dart'; import 'package:stadtbote/protocoll_messages/fin_task_message.dart';
import 'package:stadtbote/tools/constants.dart'; import 'package:stadtbote/tools/constants.dart';
import 'package:stadtbote/tools/message_service.dart';
import 'package:stadtbote/tools/messages/job_deleted_message.dart';
import 'package:stadtbote/tools/messages/job_received_message.dart';
import 'package:stadtbote/tools/mqtt_core.dart'; import 'package:stadtbote/tools/mqtt_core.dart';
import 'package:stadtbote/tools/util.dart'; import 'package:stadtbote/tools/util.dart';
import 'package:badges/badges.dart' as badges; import 'package:badges/badges.dart' as badges;
Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs) async { Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function onFinished) async {
var jobsSet = jobs.toSet(); var jobsSet = jobs.toSet();
await showDialog<void>( await showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return WillPopScope(
contentPadding: EdgeInsets.zero, onWillPop: () async {
shadowColor: Colors.transparent, Navigator.of(context).pop();
backgroundColor: Colors.white,
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
if (jobsSet.isEmpty) {
Navigator.of(context).pop();
}
return SizedBox( onFinished();
key: GlobalKey(),
height: MediaQuery.of(context).size.height * 1,
width: MediaQuery.of(context).size.width * 1.2,
child: Container(
height: 100,
padding: const EdgeInsets.all(5),
child: ListView.builder(
itemCount: jobsSet.length,
itemBuilder: (_, i) {
var job = jobsSet.toList()[i];
String remarkString = ''; return true;
for (var remark in job.rem) { }, // False will prevent and true will allow to dismiss
remarkString += '$remark\n'; child: AlertDialog(
} contentPadding: EdgeInsets.zero,
remarkString = remarkString.trim(); shadowColor: Colors.transparent,
backgroundColor: Colors.white,
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
if (jobsSet.isEmpty) {
Navigator.of(context).pop();
return ExpandableNotifier( onFinished();
child: ListTile( }
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
title: Container( MessageService().subscribe<JobDeletedMessage>(Constants.messageTopicJobDeleted, jobsSet, (jobDeletedMessage) async {
decoration: BoxDecoration( jobsSet.removeWhere((element) => element.id == jobDeletedMessage.jobId);
borderRadius: BorderRadius.circular(10),
border: Border.all( setState(() {});
color: Constants.colorPrimary, });
width: 1,
), MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, jobsSet, (jobdMessage) async {
), jobsSet.add(jobdMessage.job);
child: badges.Badge(
position: badges.BadgePosition.topEnd(top: -13, end: -5), setState(() {});
showBadge: false, });
badgeContent: const Text(
'Neu', return SizedBox(
style: TextStyle( key: GlobalKey(),
color: Colors.white, height: MediaQuery.of(context).size.height * 1,
fontSize: 18.0, width: MediaQuery.of(context).size.width * 1.2,
child: Container(
height: 100,
padding: const EdgeInsets.all(5),
child: ListView.builder(
itemCount: jobsSet.length,
itemBuilder: (_, i) {
var job = jobsSet.toList()[i];
String remarkString = '';
for (var remark in job.rem) {
remarkString += '$remark\n';
}
remarkString = remarkString.trim();
return ExpandableNotifier(
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Constants.colorPrimary,
width: 1,
),
), ),
), child: badges.Badge(
badgeStyle: badges.BadgeStyle( position: badges.BadgePosition.topEnd(top: -13, end: -5),
shape: badges.BadgeShape.square, showBadge: false,
badgeColor: Constants.colorPrimary, badgeContent: const Text(
padding: const EdgeInsets.all(5), 'Neu',
borderRadius: BorderRadius.circular(5), style: TextStyle(
borderSide: const BorderSide(color: Constants.colorPrimary, width: 0), color: Colors.white,
), fontSize: 18.0,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: [
SizedBox(
width: double.infinity,
child: Text(
DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(),
textAlign: TextAlign.left,
style: TextStyle(backgroundColor: isJobInFuture(job) ? Colors.yellow : Colors.transparent),
),
), ),
SizedBox(width: double.infinity, child: Text('Auftragsnummer: ${job.id}', textAlign: TextAlign.left)), ),
SizedBox(width: double.infinity, child: Text(job.tours[0].comp, textAlign: TextAlign.left)), badgeStyle: badges.BadgeStyle(
SizedBox(width: double.infinity, child: Text(job.tours[0].street, textAlign: TextAlign.left)), shape: badges.BadgeShape.square,
SizedBox(width: double.infinity, child: Text(job.tours[0].city, textAlign: TextAlign.left)), badgeColor: Constants.colorPrimary,
Row( padding: const EdgeInsets.all(5),
borderRadius: BorderRadius.circular(5),
borderSide: const BorderSide(color: Constants.colorPrimary, width: 0),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: [ children: [
Image.asset("assets/${mapVehicleTypeToImageName(job.vhtId)}", width: 60, height: 60), SizedBox(
const SizedBox(width: 10), width: double.infinity,
Text(mapVehicleTypeToText(job.vhtId)), child: Text(
], DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(),
), textAlign: TextAlign.left,
const SizedBox(height: 10), style: TextStyle(backgroundColor: isJobInFuture(job) ? Colors.yellow : Colors.transparent),
ScrollOnExpand( ),
scrollOnExpand: true,
scrollOnCollapse: false,
child: ExpandablePanel(
theme: const ExpandableThemeData(
headerAlignment: ExpandablePanelHeaderAlignment.center,
tapBodyToCollapse: true,
), ),
header: const Padding( SizedBox(width: double.infinity, child: Text('Auftragsnummer: ${job.id}', textAlign: TextAlign.left)),
padding: EdgeInsets.all(0), SizedBox(width: double.infinity, child: Text(job.tours[0].comp, textAlign: TextAlign.left)),
child: Text( SizedBox(width: double.infinity, child: Text(job.tours[0].street, textAlign: TextAlign.left)),
"Weitere Infos....", SizedBox(width: double.infinity, child: Text(job.tours[0].city, textAlign: TextAlign.left)),
style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.bold), Row(
)), children: [
collapsed: const SizedBox(), Image.asset("assets/${mapVehicleTypeToImageName(job.vhtId)}", width: 60, height: 60),
expanded: Column( const SizedBox(width: 10),
crossAxisAlignment: CrossAxisAlignment.stretch, Text(mapVehicleTypeToText(job.vhtId)),
children: <Widget>[
Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xfffff4e4),
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(remarkString),
),
),
], ],
), ),
), const SizedBox(height: 10),
ScrollOnExpand(
scrollOnExpand: true,
scrollOnCollapse: false,
child: ExpandablePanel(
theme: const ExpandableThemeData(
headerAlignment: ExpandablePanelHeaderAlignment.center,
tapBodyToCollapse: true,
),
header: const Padding(
padding: EdgeInsets.all(0),
child: Text(
"Weitere Infos....",
style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.bold),
)),
collapsed: const SizedBox(),
expanded: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xfffff4e4),
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(remarkString),
),
),
],
),
),
),
const SizedBox(height: 20),
Row(children: [
Expanded(
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren',
() => {_sendAnswer(job, !job.global ? 2 : 3), jobsSet.remove(job), setState(() {})}),
),
const SizedBox(width: 20),
Expanded(
child: getDefaultButton('Annehmen', () => {_sendAnswer(job, 1), jobsSet.remove(job), setState(() {})}),
)
])
],
), ),
const SizedBox(height: 20), ),
Row(children: [
Expanded(
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren',
() => {_sendAnswer(job, !job.global ? 2 : 3), jobsSet.remove(job), setState(() {})}),
),
const SizedBox(width: 20),
Expanded(
child: getDefaultButton('Annehmen', () => {_sendAnswer(job, 1), jobsSet.remove(job), setState(() {})}),
)
])
],
), ),
), ),
), ),
), );
), },
); )),
}, );
)), })));
);
}));
}); });
} }
+3 -9
View File
@@ -196,9 +196,7 @@ class MqttCore {
break; break;
case 'job_del': case 'job_del':
if (!kDebugMode) { _jobDeleteReceived(payloadData);
_jobDeleteReceived(payloadData);
}
break; break;
case 'sync_request': case 'sync_request':
@@ -291,12 +289,8 @@ class MqttCore {
} }
} }
void _jobDeleteReceived(List<dynamic> payloadData) async { void _jobDeleteReceived(payloadData) async {
Map<String, dynamic> map = {}; for(var jobId in payloadData) {
map["jobDel"] = payloadData;
var jobDelMessage = JobDelMessage.fromJson(map);
for(var jobId in jobDelMessage.jobDel) {
await MyApp.isarInstance.writeTxn(() async { await MyApp.isarInstance.writeTxn(() async {
await MyApp.isarInstance.jobs.delete(jobId); await MyApp.isarInstance.jobs.delete(jobId);
}); });
+6 -2
View File
@@ -72,12 +72,16 @@ class Util {
return currentUuid; return currentUuid;
} }
static _printLongText(String text) {
final pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((match) => debugPrint(match.group(0)));
}
static logInfo(String message) { static logInfo(String message) {
debugPrint(message); _printLongText(message);
} }
static logException(String message) { static logException(String message) {
debugPrint('Exception: $message'); _printLongText(message);
} }
static int fastHash(String string) { static int fastHash(String string) {