#577 und Refactoring
This commit is contained in:
1 parent
d59260fe24
commit
f8100facf3
3 files changed
+81
-63
No files matched your search
@@ -23,7 +23,6 @@ import 'package:stadtbote/protocoll_messages/fin_tour_message.dart';
|
|||||||
import 'package:stadtbote/protocoll_messages/pic_message.dart';
|
import 'package:stadtbote/protocoll_messages/pic_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/message_service.dart';
|
||||||
import 'package:stadtbote/tools/mqtt_core.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
import '../model/task_info.dart';
|
import '../model/task_info.dart';
|
||||||
@@ -380,13 +379,13 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _processSignature(TaskInfo taskInfo) async {
|
void _processSignature(TaskInfo taskInfo) {
|
||||||
MyApp.suppressAcceptDialog = true;
|
MyApp.suppressAcceptDialog = true;
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
|
||||||
|
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () async {
|
||||||
showSignaturePopup(context, taskInfo, (String? signature) async {
|
showSignaturePopup(context, taskInfo, (String? signature) {
|
||||||
MyApp.suppressAcceptDialog = false;
|
MyApp.suppressAcceptDialog = false;
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
@@ -400,52 +399,61 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
|
|
||||||
_sendFinTourMessage();
|
_sendFinTourMessage();
|
||||||
|
|
||||||
await _finishTaskProcessing(taskInfo);
|
_finishTaskProcessing(taskInfo);
|
||||||
|
|
||||||
MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: widget.job.state == 1 ? 2 : 3));
|
MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 2));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _finishTaskProcessing(TaskInfo taskInfo) async {
|
_finishTaskProcessing(TaskInfo taskInfo) async {
|
||||||
|
Util.logInfo('Task ${taskInfo.task.sId} finished');
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.taskInfos.put(taskInfo);
|
await MyApp.isarInstance.taskInfos.put(taskInfo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isTaskActive(int index) {
|
bool isTaskActive(int index) {
|
||||||
var currentTaskInfo = _taskList[index];
|
if (!widget.readOnly) {
|
||||||
|
var currentTaskInfo = _taskList[index];
|
||||||
|
|
||||||
if (currentTaskInfo.completed && !currentTaskInfo.task.reenter!) return false;
|
if (currentTaskInfo.completed && !currentTaskInfo.task.reenter!) return false;
|
||||||
|
|
||||||
for (var taskInfo in _taskList)
|
for (var taskInfo in _taskList)
|
||||||
{
|
{
|
||||||
if (taskInfo == currentTaskInfo) break;
|
if (taskInfo == currentTaskInfo) break;
|
||||||
|
|
||||||
if (!taskInfo.task.opt! && !taskInfo.completed) return false;
|
if (!taskInfo.task.opt! && !taskInfo.completed) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentTaskInfo.task.reenter!) return true;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTaskInfo.task.reenter!) return true;
|
return false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendArrivedMessage(TaskInfo taskInfo) {
|
_sendArrivedMessage(TaskInfo taskInfo) {
|
||||||
var message = FinTask();
|
var finTaskMessage = FinTaskMessage();
|
||||||
message.trId = widget.tour.id;
|
finTaskMessage.finTask = FinTask();
|
||||||
message.task = Task();
|
finTaskMessage.finTask.trId = widget.tour.id;
|
||||||
message.task.sId = taskInfo.task.sId;
|
finTaskMessage.finTask.task = Task();
|
||||||
message.task.time = DateTime.now().toIso8601String();
|
finTaskMessage.finTask.task.sId = taskInfo.task.sId;
|
||||||
|
finTaskMessage.finTask.task.time = DateTime.now().toIso8601String();
|
||||||
|
|
||||||
var position = MyApp.currentPosition;
|
var position = MyApp.currentPosition;
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
message.task.pos = FinTaskPos();
|
finTaskMessage.finTask.task.pos = FinTaskPos();
|
||||||
message.task.pos!.lat = position.latitude;
|
finTaskMessage.finTask.task.pos!.lat = position.latitude;
|
||||||
message.task.pos!.long = position.longitude;
|
finTaskMessage.finTask.task.pos!.long = position.longitude;
|
||||||
|
} else {
|
||||||
|
finTaskMessage.finTask.task.pos = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishMessage("fin_task", jsonEncode(message.toJson()));
|
MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "job", message: finTaskMessage.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FinTourTask _createAnswerHeader(TaskInfo taskInfo) {
|
FinTourTask _createAnswerHeader(TaskInfo taskInfo) {
|
||||||
@@ -454,49 +462,53 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
var finTourTask = FinTourTask();
|
var finTourTask = FinTourTask();
|
||||||
finTourTask.sId = taskInfo.task.sId;
|
finTourTask.sId = taskInfo.task.sId;
|
||||||
finTourTask.time = DateTime.now().toIso8601String();
|
finTourTask.time = DateTime.now().toIso8601String();
|
||||||
finTourTask.pos = FinTaskPos();
|
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
|
finTourTask.pos = FinTaskPos();
|
||||||
finTourTask.pos!.lat = position.latitude;
|
finTourTask.pos!.lat = position.latitude;
|
||||||
finTourTask.pos!.long = position.longitude;
|
finTourTask.pos!.long = position.longitude;
|
||||||
finTourTask.pos!.acc = position.accuracy.toInt();
|
finTourTask.pos!.acc = position.accuracy.toInt();
|
||||||
|
} else {
|
||||||
|
finTourTask.pos = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return finTourTask;
|
return finTourTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _sendFinTourMessage() async {
|
_sendFinTourMessage() async {
|
||||||
var message = FinTour();
|
var finTourMessage = FinTourMessage();
|
||||||
message.trId = widget.tour.id;
|
finTourMessage.finTour = FinTour();
|
||||||
message.com = _commisionNumber;
|
finTourMessage.finTour.trId = widget.tour.id;
|
||||||
|
finTourMessage.finTour.com = _commisionNumber;
|
||||||
|
|
||||||
var position = MyApp.currentPosition;
|
var position = MyApp.currentPosition;
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
message.track = Track();
|
finTourMessage.finTour.track = Track();
|
||||||
message.track!.time = DateTime.now().toIso8601String();
|
finTourMessage.finTour.track!.time = DateTime.now().toIso8601String();
|
||||||
message.track!.pos = FinTaskPos();
|
finTourMessage.finTour.track!.pos = FinTaskPos();
|
||||||
message.track!.pos!.lat = position.latitude;
|
finTourMessage.finTour.track!.pos!.lat = position.latitude;
|
||||||
message.track!.pos!.long = position.longitude;
|
finTourMessage.finTour.track!.pos!.long = position.longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.tasks = [];
|
finTourMessage.finTour.tasks = [];
|
||||||
for(var taskInfo in _taskList) {
|
for(var taskInfo in _taskList) {
|
||||||
if (taskInfo.answer != null) {
|
if (taskInfo.answer != null) {
|
||||||
var finTourTask = FinTourTask.fromJson(jsonDecode(taskInfo.answer!));
|
var finTourTask = FinTourTask.fromJson(jsonDecode(taskInfo.answer!));
|
||||||
|
|
||||||
message.tasks.add(finTourTask);
|
finTourMessage.finTour.tasks.add(finTourTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishMessage("fin_tour", jsonEncode(message.toJson()));
|
MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "fin_tour", message: finTourMessage.toJson()));
|
||||||
|
|
||||||
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.put(widget.job);
|
await MyApp.isarInstance.jobs.put(widget.job);
|
||||||
});
|
});
|
||||||
|
|
||||||
_sendImages();
|
_sendImages();
|
||||||
|
|
||||||
checkJobFinished();
|
await _checkJobFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendImages() {
|
_sendImages() {
|
||||||
@@ -519,27 +531,25 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
message.pos!.long = position.longitude;
|
message.pos!.long = position.longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishMessage("pic", jsonEncode(message.toJson()));
|
MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "job", message: message.toJson()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkJobFinished() async {
|
Future<void> _checkJobFinished() async {
|
||||||
var jobFinished = true;
|
var jobFinished = true;
|
||||||
|
|
||||||
for(var tour in widget.job.tours) {
|
for (var tour in widget.job.tours) {
|
||||||
if (tour.state < 1) {
|
if (tour.state == 0) {
|
||||||
jobFinished = false;
|
jobFinished = false;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jobFinished) {
|
if (jobFinished) {
|
||||||
widget.job.state = 2;
|
widget.job.state = 2;
|
||||||
for(var tour in widget.job.tours) {
|
|
||||||
tour.state = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.put(widget.job);
|
await MyApp.isarInstance.jobs.put(widget.job);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ class _TourDetailsPageState extends State<TourDetailsPage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(remark),
|
Expanded(child: SingleChildScrollView(child: Text(remark))),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -130,20 +130,12 @@ class _TourListPageState extends State<TourListPage> {
|
|||||||
JobTour? lastTour;
|
JobTour? lastTour;
|
||||||
|
|
||||||
for (var tour in _tours) {
|
for (var tour in _tours) {
|
||||||
bool tourActive = false;
|
bool tourReadOnly = isTourReadOnly(lastTour, tour);
|
||||||
|
|
||||||
if (lastTour == null) {
|
|
||||||
tourActive = true;
|
|
||||||
} else {
|
|
||||||
if (lastTour.state != 0) {
|
|
||||||
tourActive = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Color color = Colors.transparent;
|
Color color = Colors.transparent;
|
||||||
switch (tour.state) {
|
switch (tour.state) {
|
||||||
case 0:
|
case 0:
|
||||||
color = tourActive ? Colors.white : Colors.grey;
|
color = !tourReadOnly ? Colors.white : Colors.grey;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
@@ -161,11 +153,7 @@ class _TourListPageState extends State<TourListPage> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
contentPadding: const EdgeInsets.all(0),
|
contentPadding: const EdgeInsets.all(0),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (tourActive) {
|
_clicked(tour, tourReadOnly);
|
||||||
_clicked(tour, false);
|
|
||||||
} else {
|
|
||||||
_clicked(tour, true);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
title: Container(
|
title: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -200,6 +188,26 @@ class _TourListPageState extends State<TourListPage> {
|
|||||||
return tourWidgets;
|
return tourWidgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTourReadOnly(JobTour? lastTour, JobTour tour) {
|
||||||
|
bool readOnly;
|
||||||
|
|
||||||
|
if (!widget.readOnly) {
|
||||||
|
readOnly = false;
|
||||||
|
|
||||||
|
if (lastTour == null) {
|
||||||
|
readOnly = tour.state != 0;
|
||||||
|
} else {
|
||||||
|
if (lastTour.state == 0) {
|
||||||
|
readOnly = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
readOnly = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
void _clicked(JobTour tour, bool readOnly) {
|
void _clicked(JobTour tour, bool readOnly) {
|
||||||
MessageService().publish<ContentViewWidget>(Constants.messageTopicPushContentView, arguments: TourDetailsPage(job: widget.job, tour: tour, readOnly: readOnly));
|
MessageService().publish<ContentViewWidget>(Constants.messageTopicPushContentView, arguments: TourDetailsPage(job: widget.job, tour: tour, readOnly: readOnly));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user