From 96544ca9244f0882ed4a5ba09a0cee9903bbe46a Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Wed, 11 Sep 2024 09:37:02 +0200 Subject: [PATCH] #700 --- android/app/src/debug/AndroidManifest.xml | 1 + android/app/src/main/AndroidManifest.xml | 5 +- android/app/src/profile/AndroidManifest.xml | 1 + lib/content_views/accepted_jobs_page.dart | 108 +++++- lib/content_views/approach_area_page.dart | 108 +++++- lib/content_views/assigned_jobs_page.dart | 108 +++++- lib/content_views/finished_jobs_page.dart | 108 +++++- lib/content_views/main_page.dart | 332 +++++++++++++----- lib/content_views/messages_page.dart | 108 +++++- lib/content_views/task_list_page.dart | 107 +++++- lib/content_views/tour_details_page.dart | 108 +++++- lib/content_views/tour_list_page.dart | 108 +++++- .../utils/content_view_widget.dart | 4 +- lib/content_views/utils/header_info.dart | 11 - lib/main.dart | 156 ++------ lib/popups/accept_jobs_popup.dart | 9 + .../tasks_popups/receipt_giver_popup.dart | 2 +- lib/tools/constants.dart | 2 +- lib/tools/messages/remove_job_message.dart | 6 + lib/tools/mqtt_core.dart | 11 +- lib/tools/util.dart | 2 +- pubspec.yaml | 2 +- 22 files changed, 1026 insertions(+), 381 deletions(-) delete mode 100644 lib/content_views/utils/header_info.dart create mode 100644 lib/tools/messages/remove_job_message.dart diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 94667a6..5f3eebf 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -5,4 +5,5 @@ to allow setting breakpoints, to provide hot reload, etc. --> + diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 4acfd4e..e97cfd1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,12 @@ + + android:icon="@mipmap/launcher_icon" + android:requestLegacyExternalStorage="true"> + + diff --git a/lib/content_views/accepted_jobs_page.dart b/lib/content_views/accepted_jobs_page.dart index ed9f7f2..b669c09 100644 --- a/lib/content_views/accepted_jobs_page.dart +++ b/lib/content_views/accepted_jobs_page.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:isar/isar.dart'; import 'package:stadtbote/content_views/tour_list_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:intl/intl.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/tools/message_service.dart'; import '../main.dart'; @@ -18,21 +18,10 @@ class AcceptedJobsPage extends ContentViewWidget { State createState() => _AcceptedJobsPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Angenommene Aufträge', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: false, - rightButtonVisible: false, - rightButtonImage: null, - rightButtonOnPressed: () async { - //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -146,3 +135,90 @@ class _AcceptedJobsPageState extends State { await MessageService().publish(Constants.messageTopicPushContentView, arguments: TourListPage(job: job)); } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Angenommene Aufträge", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/content_views/approach_area_page.dart b/lib/content_views/approach_area_page.dart index 14c02ba..2fbc0f7 100644 --- a/lib/content_views/approach_area_page.dart +++ b/lib/content_views/approach_area_page.dart @@ -3,8 +3,8 @@ import 'package:flutter/material.dart'; import 'package:isar/isar.dart'; import 'package:mqtt5_client/mqtt5_client.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:stadtbote/main.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/rank.dart'; import 'package:stadtbote/popups/tasks_popups/zip_popup.dart'; import 'package:stadtbote/protocoll_messages/zip_message.dart'; @@ -23,21 +23,10 @@ class ApproachAreaPage extends ContentViewWidget { State createState() => _ApproachAreaPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Anfahrtsbereich', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: true, - rightButtonVisible: true, - rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.help_outline, size: 20.0, color: Colors.white)), - rightButtonOnPressed: () async { - await Util.startBrowser('https://app.assecutor.de/help/sb/app/context/001/index.html'); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -222,4 +211,91 @@ class _ApproachAreaPageState extends State { setState(() {}); }); } +} + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Anfahrtsbereich", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } } \ No newline at end of file diff --git a/lib/content_views/assigned_jobs_page.dart b/lib/content_views/assigned_jobs_page.dart index a445077..8e27ee8 100644 --- a/lib/content_views/assigned_jobs_page.dart +++ b/lib/content_views/assigned_jobs_page.dart @@ -4,9 +4,9 @@ import 'package:flutter/material.dart'; import 'package:isar/isar.dart'; import 'package:mqtt5_client/mqtt5_client.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:intl/intl.dart'; import 'package:badges/badges.dart' as badges; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/protocoll_messages/accept_job_message.dart'; import 'package:stadtbote/protocoll_messages/fin_task_message.dart'; import 'package:stadtbote/tools/message_service.dart'; @@ -25,21 +25,10 @@ class AssignedJobsPage extends ContentViewWidget { State createState() => _AssignedJobsPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Zugewiesene Aufträge', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: false, - rightButtonVisible: false, - rightButtonImage: null, - rightButtonOnPressed: () async { - //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -215,3 +204,90 @@ class _AssignedJobsPageState extends State { void _initMessages() {} } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Zugewiesene Aufträge", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/content_views/finished_jobs_page.dart b/lib/content_views/finished_jobs_page.dart index 401e056..53ba54f 100644 --- a/lib/content_views/finished_jobs_page.dart +++ b/lib/content_views/finished_jobs_page.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:isar/isar.dart'; import 'package:stadtbote/content_views/tour_list_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:intl/intl.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/tools/message_service.dart'; import '../main.dart'; @@ -18,21 +18,10 @@ class FinishedJobsPage extends ContentViewWidget { State createState() => _FinishedJobsPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Erledigte Aufträge', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: false, - rightButtonVisible: false, - rightButtonImage: null, - rightButtonOnPressed: () async { - //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -134,3 +123,90 @@ class _FinishedJobsPageState extends State { await MessageService().publish(Constants.messageTopicPushContentView, arguments: TourListPage(job: job, readOnly: true,)); } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Erledigte Aufträge", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/content_views/main_page.dart b/lib/content_views/main_page.dart index 5ab0980..47e761e 100644 --- a/lib/content_views/main_page.dart +++ b/lib/content_views/main_page.dart @@ -7,78 +7,38 @@ import 'package:stadtbote/content_views/assigned_jobs_page.dart'; import 'package:stadtbote/content_views/finished_jobs_page.dart'; import 'package:stadtbote/content_views/messages_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; +import 'package:stadtbote/main.dart'; import 'package:stadtbote/model/job.dart'; +import 'package:stadtbote/model/location_status.dart'; import 'package:stadtbote/model/message.dart'; import 'package:stadtbote/model/session_status.dart'; -import 'package:stadtbote/model/location_status.dart'; import 'package:stadtbote/popups/infos_popup.dart'; import 'package:stadtbote/protocoll_messages/logout_message.dart'; +import 'package:stadtbote/tools/constants.dart'; import 'package:stadtbote/tools/message_service.dart'; -import 'package:stadtbote/tools/messages/publish_payload_message.dart'; -import 'package:stadtbote/tools/messages/connect_client_message.dart'; -import 'package:stadtbote/tools/messages/disconnect_client_message.dart'; import 'package:stadtbote/tools/messages/job_deleted_message.dart'; import 'package:stadtbote/tools/messages/job_received_message.dart'; import 'package:stadtbote/tools/messages/message_message.dart'; +import 'package:stadtbote/tools/messages/publish_payload_message.dart'; +import 'package:stadtbote/tools/messages/connect_client_message.dart'; +import 'package:stadtbote/tools/messages/disconnect_client_message.dart'; +import 'package:stadtbote/tools/messages/refresh_badges_message.dart'; import 'package:stadtbote/tools/messages/session_info_update.dart'; import 'package:badges/badges.dart' as badges; import 'package:stadtbote/tools/messages/status_info_update.dart'; -import 'package:stadtbote/tools/messages/refresh_badges_message.dart'; - -import '../main.dart'; -import '../tools/constants.dart'; -import '../tools/util.dart'; +import 'package:stadtbote/tools/util.dart'; class MainPage extends ContentViewWidget { - final ValueNotifier _zipValueNotifier = ValueNotifier("-----"); - final ValueNotifier sidValueNotifier = ValueNotifier("-----"); - - MainPage({super.key}); + const MainPage({super.key}); @override State createState() => _MainPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: Container( - height: 100, - padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), - child: Column(children: [ - ValueListenableBuilder( - valueListenable: _zipValueNotifier, - builder: (context, value, child) { - return Text( - value, - style: const TextStyle( - color: Colors.white, - fontSize: 25.0, - ), - ); - }, - ), - const SizedBox(height: 5), - ValueListenableBuilder( - valueListenable: sidValueNotifier, - builder: (context, value, child) { - return Text( - value, - style: const TextStyle( - color: Colors.white, - fontSize: 25.0, - ), - ); - }, - ), - ]), - ), - rightButtonEnabled: true, - rightButtonVisible: true, - rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.info_outline, size: 20.0, color: Colors.white)), - rightButtonOnPressed: () async { - showInfosPopup(await MyApp.isarInstance.sessionStatus.where().findFirst()); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -93,8 +53,6 @@ class _MainPageState extends State { void initState() { super.initState(); - _updateHeader(); - _refreshBadges(); _initMessages(); @@ -144,7 +102,8 @@ class _MainPageState extends State { 'Zugewiesene Aufträge', image: Image.asset('assets/zugewiesene_auftraege.png', width: 30, height: 30), () async => { - await MessageService().publish(Constants.messageTopicPushContentView, arguments: const AssignedJobsPage()) + await MessageService() + .publish(Constants.messageTopicPushContentView, arguments: const AssignedJobsPage()) }), ); }, @@ -177,7 +136,8 @@ class _MainPageState extends State { 'Angenommene Aufträge', image: Image.asset('assets/angenommene_auftraege.png', width: 30, height: 30), () async => { - await MessageService().publish(Constants.messageTopicPushContentView, arguments: const AcceptedJobsPage()) + await MessageService() + .publish(Constants.messageTopicPushContentView, arguments: const AcceptedJobsPage()) })); }, ), @@ -188,7 +148,10 @@ class _MainPageState extends State { child: getDefaultButton( 'Erledigte Aufträge', image: Image.asset('assets/erledigte_auftraege.png', width: 30, height: 30), - () async => {await MessageService().publish(Constants.messageTopicPushContentView, arguments: const FinishedJobsPage())}), + () async => { + await MessageService() + .publish(Constants.messageTopicPushContentView, arguments: const FinishedJobsPage()) + }), ), SizedBox(height: _loggedOut == true ? 0 : 20), Visibility( @@ -216,8 +179,10 @@ class _MainPageState extends State { child: getDefaultButton( 'Nachrichten', image: Image.asset('assets/nachrichten.png', width: 30, height: 30), - () async => - {await MessageService().publish(Constants.messageTopicPushContentView, arguments: const MessagesPage())})); + () async => { + await MessageService() + .publish(Constants.messageTopicPushContentView, arguments: const MessagesPage()) + })); }, ), ), @@ -227,15 +192,16 @@ class _MainPageState extends State { child: getDefaultButton( 'Anfahrtsbereich', image: Image.asset('assets/anfahrtsbereich.png', width: 30, height: 30), - () async => {await MessageService().publish(Constants.messageTopicPushContentView, arguments: const ApproachAreaPage())}), + () async => { + await MessageService() + .publish(Constants.messageTopicPushContentView, arguments: const ApproachAreaPage()) + }), ), SizedBox(height: _loggedOut == true ? 0 : 20), - getDefaultButton( - _loggedOut ? 'Anmelden' : 'Abmelden', - image: Image.asset(_loggedOut ? 'assets/anmelden.png' : 'assets/abmelden.png', width: 30, height: 30), - () async { - _logout(context); - }), + getDefaultButton(_loggedOut ? 'Anmelden' : 'Abmelden', + image: Image.asset(_loggedOut ? 'assets/anmelden.png' : 'assets/abmelden.png', width: 30, height: 30), () async { + _logout(context); + }), Expanded( child: Container( decoration: BoxDecoration( @@ -260,14 +226,6 @@ class _MainPageState extends State { } _initMessages() { - MessageService().subscribe(Constants.messageTopicSessionStatusInfoUpdate, this, (sessionStatusInfoUpdateMessage) { - widget.sidValueNotifier.value = sessionStatusInfoUpdateMessage.status.sid; - }); - - MessageService().subscribe(Constants.messageTopicLocationStatusUpdated, this, (statusInfoUpdateMessage) { - _updateHeader(); - }); - MessageService().subscribe(Constants.messageTopicJobReceived, this, (JobReceivedMessage jobReceivedMessage) { _jobReceived(jobReceivedMessage.job); }); @@ -286,9 +244,7 @@ class _MainPageState extends State { } void _exitMessages() { - MessageService().unsubscribe(Constants.messageTopicSessionStatusInfoUpdate, this); - - MessageService().unsubscribe(Constants.messageTopicJobReceived, this); + MessageService().unsubscribeAll(this); } void _refreshBadges() async { @@ -301,19 +257,6 @@ class _MainPageState extends State { _refreshBadges(); } - void _updateHeader() async { - var status = await MyApp.isarInstance.locationStatus.where().findFirst(); - var sessionStatus = await MyApp.isarInstance.sessionStatus.where().findFirst(); - - if (status != null) { - widget._zipValueNotifier.value = '${status.zip} (${status.zipReal})'; - } else if (sessionStatus != null) { - widget._zipValueNotifier.value = sessionStatus.locZip; - } else { - widget._zipValueNotifier.value = "---"; - } - } - _logout(context) async { if (!_loggedOut) { showLogoutAlertDialog(context); @@ -341,7 +284,6 @@ class _MainPageState extends State { await MessageService().publish(Constants.messageTopicDisconnectClient, arguments: DisconnectClientMessage()); Future.delayed(const Duration(seconds: 5), () async { - Navigator.of(context).pop(); setState(() {}); @@ -361,7 +303,8 @@ class _MainPageState extends State { title: const Text("Warnung"), content: const Text("Wollen Sie sich wirklich abmelden?"), actions: [ - yesButton, noButton, + yesButton, + noButton, ], ); @@ -386,6 +329,207 @@ class _MainPageState extends State { logoutMessage.pos!.acc = position.accuracy.toInt(); } - await MessageService().publish(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "logout", message: logoutMessage.toJson(), qos: MqttQos.exactlyOnce)); + await MessageService().publish(Constants.messageTopicPublishPayload, + arguments: PublishPayloadMessage(topic: "logout", message: logoutMessage.toJson(), qos: MqttQos.exactlyOnce)); + } +} + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + final ValueNotifier _zipValueNotifier = ValueNotifier("-----"); + final ValueNotifier _zipRealValueNotifier = ValueNotifier("-----"); + final ValueNotifier _sidValueNotifier = ValueNotifier("-----"); + + @override + void initState() { + super.initState(); + + _updateHeader(); + + _initMessages(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + var sessionStatus = await MyApp.isarInstance.sessionStatus.where().findFirst(); + + showInfosPopup(sessionStatus); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, // Verteilt die Texte gleichmäßig in der Zeile + children: [ + SizedBox( + width: cellWidth, + child: const Text( + 'Meldung', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 11, color: Colors.white), + ), + ), + SizedBox( + width: cellWidth, + child: const Text( + 'Ortung', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 11, color: Colors.white), + ), + ), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, // Verteilt die Texte gleichmäßig in der Zeile + children: [ + SizedBox( + width: cellWidth, + child: ValueListenableBuilder( + valueListenable: _zipValueNotifier, + builder: (context, value, child) { + return Text( + textAlign: TextAlign.center, + value, + style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ); + }, + ) + ), + SizedBox( + width: cellWidth, + child: ValueListenableBuilder( + valueListenable: _zipRealValueNotifier, + builder: (context, value, child) { + return Text( + textAlign: TextAlign.center, + value, + style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ); + }, + ), + ), + ], + ), + Column( + children: [ + const Text( + 'Kurierkennung', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 11, color: Colors.white), + ), + ValueListenableBuilder( + valueListenable: _sidValueNotifier, + builder: (context, value, child) { + return Text( + textAlign: TextAlign.center, + value, + style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ); + }, + ), + ], + ) + ], + ), + ), + ], + ), + ); + } + + _initMessages() { + MessageService().subscribe(Constants.messageTopicSessionStatusInfoUpdate, this, (sessionStatusInfoUpdateMessage) { + _updateHeader(); + }); + + MessageService().subscribe(Constants.messageTopicLocationStatusUpdated, this, (statusInfoUpdateMessage) { + _updateHeader(); + }); + } + + _updateHeader() async { + var status = await MyApp.isarInstance.locationStatus.where().findFirst(); + var sessionStatus = await MyApp.isarInstance.sessionStatus.where().findFirst(); + + if (status != null) { + _zipValueNotifier.value = status.zip; + _zipRealValueNotifier.value = status.zipReal; + } else if (sessionStatus != null) { + _zipValueNotifier.value = sessionStatus.locZip; + _zipRealValueNotifier.value = '---'; + } else { + _zipValueNotifier.value = '---'; + _zipRealValueNotifier.value = '---'; + } + if (sessionStatus != null) { + _sidValueNotifier.value = sessionStatus.sid; + } + + /* + rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.info_outline, size: 20.0, color: Colors.white)), + rightButtonOnPressed: () async { + showInfosPopup(await MyApp.isarInstance.sessionStatus.where().findFirst()); + }); + */ } } diff --git a/lib/content_views/messages_page.dart b/lib/content_views/messages_page.dart index bb06101..fe282a3 100644 --- a/lib/content_views/messages_page.dart +++ b/lib/content_views/messages_page.dart @@ -5,8 +5,8 @@ import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import 'package:isar/isar.dart'; import 'package:mqtt5_client/mqtt5_client.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:stadtbote/main.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/message.dart' as sbmessage; import 'package:stadtbote/model/message.dart'; import 'package:stadtbote/model/session_status.dart'; @@ -23,21 +23,10 @@ class MessagesPage extends ContentViewWidget { State createState() => _MessagesPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Nachrichten', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: true, - rightButtonVisible: true, - rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.help_outline, size: 20.0, color: Colors.white)), - rightButtonOnPressed: () async { - await Util.startBrowser('https://app.assecutor.de/help/sb/app/context/003/index.html'); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -197,3 +186,90 @@ class _MessagesPageState extends State { }); } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Nachrichten", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/content_views/task_list_page.dart b/lib/content_views/task_list_page.dart index 6c960f4..6e476ff 100644 --- a/lib/content_views/task_list_page.dart +++ b/lib/content_views/task_list_page.dart @@ -6,7 +6,6 @@ import 'package:intl/intl.dart'; import 'package:isar/isar.dart'; import 'package:mqtt5_client/mqtt5_client.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/job.dart'; import 'package:stadtbote/model/job_tour.dart'; @@ -44,21 +43,10 @@ class TaskListPage extends ContentViewWidget { State createState() => _TaskListPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Liste der Aufgaben', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: true, - rightButtonVisible: true, - rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.help_outline, size: 20.0, color: Colors.white)), - rightButtonOnPressed: () async { - await Util.startBrowser('https://app.assecutor.de/help/sb/app/context/002/index.html'); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -581,3 +569,90 @@ class _TaskListPageState extends State { } } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Liste der Aufgaben", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/content_views/tour_details_page.dart b/lib/content_views/tour_details_page.dart index d5f7f97..c8a1a31 100644 --- a/lib/content_views/tour_details_page.dart +++ b/lib/content_views/tour_details_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:stadtbote/content_views/task_list_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/job_tour.dart'; import 'package:stadtbote/tools/message_service.dart'; @@ -23,21 +23,10 @@ class TourDetailsPage extends ContentViewWidget { State createState() => _TourDetailsPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Details der Station', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: false, - rightButtonVisible: false, - rightButtonImage: null, - rightButtonOnPressed: () async { - //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -151,3 +140,90 @@ class _TourDetailsPageState extends State { ); } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Details der Station", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/content_views/tour_list_page.dart b/lib/content_views/tour_list_page.dart index 71c4566..676f070 100644 --- a/lib/content_views/tour_list_page.dart +++ b/lib/content_views/tour_list_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:stadtbote/content_views/tour_details_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; +import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/job_tour.dart'; import 'package:stadtbote/popups/map_popup.dart'; import 'package:stadtbote/tools/message_service.dart'; @@ -21,21 +21,10 @@ class TourListPage extends ContentViewWidget { State createState() => _TourListPageState(); @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Liste der Stationen', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - ), - ), - rightButtonEnabled: true, - rightButtonVisible: true, - rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.help_outline, size: 20.0, color: Colors.white)), - rightButtonOnPressed: () async { - await Util.startBrowser('https://app.assecutor.de/help/sb/app/context/004/index.html'); - }); + Future getHeaderWidget(BuildContext context) async { + await Future.delayed(const Duration(microseconds: 0)); + + return _HeaderWidget(); } } @@ -212,3 +201,90 @@ class _TourListPageState extends State { await MessageService().publish(Constants.messageTopicPushContentView, arguments: TourDetailsPage(job: widget.job, tour: tour, readOnly: readOnly)); } } + +class _HeaderWidget extends StatefulWidget { + @override + State<_HeaderWidget> createState() => _HeaderWidgetState(); +} + +class _HeaderWidgetState extends State<_HeaderWidget> { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2; + + return Padding( + padding: const EdgeInsets.all(8), + child: Stack( + alignment: Alignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Visibility( + visible: true, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + radius: 10, + backgroundColor: Constants.colorPrimary, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)), + ), + ), + ), + ), + ), + Visibility( + visible: false, + child: Container( + width: 60, + height: 60, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + ), + child: FittedBox( + child: GestureDetector( + onTap: () async { + await MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1)); + }, + child: const CircleAvatar( + backgroundColor: Constants.colorPrimary, + radius: 10, + child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))), + ), + ), + ), + ), + ], + ), + SizedBox( + height: 100, + width: cellWidth * 2, + child: const Center( + child: Text( + textAlign: TextAlign.center, + "Liste der Stationen", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white), + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/content_views/utils/content_view_widget.dart b/lib/content_views/utils/content_view_widget.dart index ab1c854..4369640 100644 --- a/lib/content_views/utils/content_view_widget.dart +++ b/lib/content_views/utils/content_view_widget.dart @@ -1,11 +1,9 @@ import 'package:flutter/cupertino.dart'; -import 'header_info.dart'; - abstract class ContentViewWidget extends StatefulWidget { const ContentViewWidget({super.key}); - Future getHeaderInfo(BuildContext context); + Future getHeaderWidget(BuildContext context); void close() { close(); diff --git a/lib/content_views/utils/header_info.dart b/lib/content_views/utils/header_info.dart deleted file mode 100644 index bcb435b..0000000 --- a/lib/content_views/utils/header_info.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:flutter/material.dart'; - -class HeaderInfo { - late Widget titleWidget; - late bool rightButtonEnabled; - late bool rightButtonVisible; - late Future? rightButtonImage; - late Function rightButtonOnPressed; - - HeaderInfo({required this.titleWidget, required this.rightButtonEnabled, required this.rightButtonVisible, this.rightButtonImage, required this.rightButtonOnPressed}); -} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 5929236..59fee15 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,11 +1,9 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:isar/isar.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:permission_handler/permission_handler.dart'; import 'package:shared_map/shared_map.dart'; import 'package:stadtbote/messages/pop_content_view_message.dart'; import 'package:stadtbote/model/enqueued_message.dart'; @@ -22,6 +20,8 @@ import 'package:stadtbote/tools/connection_status.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/messages/refresh_badges_message.dart'; +import 'package:stadtbote/tools/messages/remove_job_message.dart'; import 'package:stadtbote/tools/mqtt_core.dart'; import 'content_views/main_page.dart'; @@ -48,8 +48,6 @@ Future main() async { PictureSchema ], directory: dir.path, name: "database_v1"); - var status = await Permission.storage.request(); - await _clearLog(); runApp(const MyApp()); @@ -169,15 +167,6 @@ class _MainState extends State
with SingleTickerProviderStateMixin { late Widget _currentTitleWidget; - late Widget _leftIconButton; - late Widget _rightIconButton; - - late bool _leftButtonVisible = false; - late bool _rightButtonVisible = false; - - late Function _rightButtonOnPressed; - late Function _leftButtonOnPressed; - bool _initCompleted = false; final ValueNotifier _connectionLostValueNotifier = ValueNotifier(true); @@ -207,22 +196,9 @@ class _MainState extends State
with SingleTickerProviderStateMixin { _startCheckForNewState0JobsJobsTimer(); - _currentContent = MainPage(); + _currentContent = const MainPage(); - var headerInfo = await _currentContent.getHeaderInfo(MyApp.appNavigatorKey.currentContext!); - _currentTitleWidget = headerInfo.titleWidget; - - _leftButtonVisible = false; - _leftIconButton = const Icon(Icons.arrow_back, size: 20.0, color: Colors.white); - _leftButtonOnPressed = () { - _popContentView(1); - }; - - _rightButtonVisible = headerInfo.rightButtonVisible; - _rightButtonOnPressed = headerInfo.rightButtonOnPressed; - if (headerInfo.rightButtonEnabled) { - _rightIconButton = await headerInfo.rightButtonImage as Widget; - } + _currentTitleWidget = await _currentContent.getHeaderWidget(MyApp.appNavigatorKey.currentContext!); _initCompleted = true; @@ -256,66 +232,11 @@ class _MainState extends State
with SingleTickerProviderStateMixin { child: SizedBox( height: 100, child: Padding( - padding: const EdgeInsets.all(8), + padding: const EdgeInsets.all(0), child: Stack( alignment: Alignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Visibility( - visible: _leftButtonVisible, - child: Container( - width: 60, - height: 60, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - ), - child: FittedBox( - child: GestureDetector( - onTap: () async { - _leftButtonOnPressed(); - }, - child: CircleAvatar( - radius: 15, - backgroundColor: Constants.colorPrimary, - child: Padding(padding: const EdgeInsets.all(1.0), child: _leftIconButton), - ), - ), - ), - ), - ), - Visibility( - visible: _rightButtonVisible, - child: Container( - width: 60, - height: 60, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: Colors.red, - ), - child: FittedBox( - child: GestureDetector( - onTap: () async { - _rightButtonOnPressed(); - }, - child: CircleAvatar( - backgroundColor: Constants.colorPrimary, - radius: 15, - child: Padding(padding: const EdgeInsets.all(1.0), child: _rightIconButton), - ), - ), - ), - ), - ), - ], - ), - SizedBox( - height: 100, - width: 300, - child: Center(heightFactor: 1, child: _currentTitleWidget), - ), + Center(heightFactor: 1, child: _currentTitleWidget), ], ), ), @@ -361,29 +282,34 @@ class _MainState extends State
with SingleTickerProviderStateMixin { } void _initMessages() { - MessageService().unsubscribe(Constants.messageTopicPushContentView, this); - MessageService().unsubscribe(Constants.messageTopicPopContentView, this); - MessageService().unsubscribe(Constants.messageTopicReplaceContentView, this); - MessageService().unsubscribe(Constants.messageTopicHideRightButton, this); - MessageService().unsubscribe(Constants.messageTopicConnectionStatusChanged, this); - MessageService().unsubscribe(Constants.messageTopicJobReceived, this); + MessageService().unsubscribeAll(this); MessageService().subscribe(Constants.messageTopicPushContentView, this, (ContentViewWidget widget) { _pushContentView(widget); }); + MessageService().subscribe(Constants.messageTopicPopContentView, this, (PopContentViewMessage message) { _popContentView(message.count); }); + MessageService().subscribe(Constants.messageTopicReplaceContentView, this, (ContentViewWidget widget) { _replaceContentView(widget); }); - MessageService().subscribe(Constants.messageTopicHideRightButton, this, (hideButton) { - _hideRightButton(hideButton); - }); + MessageService().subscribe(Constants.messageTopicConnectionStatusChanged, this, (ConnectionStatus connectionStatus) { _connectionStatusChanged(connectionStatus); }); + MessageService().subscribe(Constants.messageTopicRemoveJob, this, (RemoveJobMessage job) async { + await MyApp.isarInstance.writeTxn(() async { + await MyApp.isarInstance.jobs.where().filter().idEqualTo(job.id).deleteAll(); + }); + + await MessageService().publish(Constants.messageTopicJobDeleted, arguments: JobDeletedMessage(id: job.id)); + + await MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage()); + }); + MessageService().subscribe(Constants.messageTopicJobReceived, this, (JobReceivedMessage jobReceivedMessage) async { if (jobReceivedMessage.job.state == 0) { await _jobMap!.put(jobReceivedMessage.job.id, jobReceivedMessage.job); @@ -403,16 +329,7 @@ class _MainState extends State
with SingleTickerProviderStateMixin { _currentContent = widget; }); - var headerInfo = await _currentContent.getHeaderInfo(context); - _currentTitleWidget = headerInfo.titleWidget; - _rightButtonVisible = headerInfo.rightButtonVisible; - _rightButtonOnPressed = headerInfo.rightButtonOnPressed; - - if (headerInfo.rightButtonEnabled) { - _rightIconButton = await headerInfo.rightButtonImage as Widget; - } - - _leftButtonVisible = false; + _currentTitleWidget = await _currentContent.getHeaderWidget(context); setState(() {}); }); @@ -428,18 +345,7 @@ class _MainState extends State
with SingleTickerProviderStateMixin { _currentContent = previousContentView; - var headerInfo = await _currentContent.getHeaderInfo(context); - _currentTitleWidget = headerInfo.titleWidget; - _rightButtonVisible = headerInfo.rightButtonVisible; - _rightButtonOnPressed = headerInfo.rightButtonOnPressed; - - if (headerInfo.rightButtonEnabled) { - _rightIconButton = await headerInfo.rightButtonImage as Widget; - } - - if (contentStack.isEmpty) { - _leftButtonVisible = false; - } + _currentTitleWidget = await _currentContent.getHeaderWidget(context); setState(() {}); }); @@ -451,28 +357,12 @@ class _MainState extends State
with SingleTickerProviderStateMixin { _currentContent = widget; - var headerInfo = await _currentContent.getHeaderInfo(context); - - _currentTitleWidget = headerInfo.titleWidget; - _rightButtonVisible = headerInfo.rightButtonVisible; - _rightButtonOnPressed = headerInfo.rightButtonOnPressed; - - if (headerInfo.rightButtonEnabled) { - _rightIconButton = await headerInfo.rightButtonImage as Widget; - } - - _leftButtonVisible = true; + _currentTitleWidget = await _currentContent.getHeaderWidget(context); setState(() {}); }); } - void _hideRightButton(bool hideButton) { - setState(() { - _rightButtonVisible = !hideButton; - }); - } - void _connectionStatusChanged(ConnectionStatus newConnectionStatus) { var currentConnectionStatus = newConnectionStatus.status; diff --git a/lib/popups/accept_jobs_popup.dart b/lib/popups/accept_jobs_popup.dart index 3c3361e..a484e23 100644 --- a/lib/popups/accept_jobs_popup.dart +++ b/lib/popups/accept_jobs_popup.dart @@ -13,6 +13,7 @@ import 'package:stadtbote/protocoll_messages/fin_task_message.dart'; import 'package:stadtbote/tools/constants.dart'; import 'package:stadtbote/tools/message_service.dart'; import 'package:stadtbote/tools/messages/refresh_badges_message.dart'; +import 'package:stadtbote/tools/messages/remove_job_message.dart'; import 'package:stadtbote/tools/util.dart'; import 'package:badges/badges.dart' as badges; @@ -230,6 +231,10 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini jobMap.remove(job.id); + MessageService().publish(Constants.messageTopicRemoveJob, arguments: RemoveJobMessage(id: job.id)); + + setState(() {}); + if (jobMap.length() == 0) { Navigator.of(context).pop(); @@ -250,6 +255,10 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini jobMap.remove(job.id); + MessageService().publish(Constants.messageTopicRemoveJob, arguments: RemoveJobMessage(id: job.id)); + + setState(() {}); + if (jobMap.length() == 0) { Navigator.of(context).pop(); diff --git a/lib/popups/tasks_popups/receipt_giver_popup.dart b/lib/popups/tasks_popups/receipt_giver_popup.dart index 10b347c..c71f0e6 100644 --- a/lib/popups/tasks_popups/receipt_giver_popup.dart +++ b/lib/popups/tasks_popups/receipt_giver_popup.dart @@ -42,7 +42,7 @@ showReceiptGiverPopup(BuildContext context, TaskInfo taskInfo, Function(String) textInputType: TextInputType.text, formatter: [FilteringTextInputFormatter.singleLineFormatter], controller: textEditingController, - maxLength: 50, + maxLength: 40, autofocus: true), const SizedBox(height: 20), getDefaultButton('Übernehmen', () { diff --git a/lib/tools/constants.dart b/lib/tools/constants.dart index 41ace80..6e4cca5 100644 --- a/lib/tools/constants.dart +++ b/lib/tools/constants.dart @@ -12,12 +12,12 @@ class Constants { static const String messageTopicRankingUpdated = "ranking_updated"; static const String messageTopicJobReceived = "job_received"; static const String messageTopicJobDeleted = "job_deleted"; + static const String messageTopicRemoveJob = "remove_job"; static const String messageTopicUpdateBadges = "update_badges"; static const String messageTopicMessageReceived = "message_received"; static const String messageTopicPushContentView = "push_content_view"; static const String messageTopicPopContentView = "pop_content_view"; static const String messageTopicReplaceContentView = "replace_content_view"; - static const String messageTopicHideRightButton = "hide_right_button"; static const String messageTopicPublishPayload = "publish_payload_message"; static const String messageTopicConnectClient = "connect_client"; static const String messageTopicDisconnectClient = "disconnect_client"; diff --git a/lib/tools/messages/remove_job_message.dart b/lib/tools/messages/remove_job_message.dart new file mode 100644 index 0000000..abcaff5 --- /dev/null +++ b/lib/tools/messages/remove_job_message.dart @@ -0,0 +1,6 @@ + +class RemoveJobMessage { + final int id; + + RemoveJobMessage({required this.id}); +} \ No newline at end of file diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index 0273e50..201e758 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -332,14 +332,11 @@ class MqttCore { void _jobDeleteReceived(payloadData) async { var jobDelMessage = JobDelMessage.fromJson(payloadData); - var foundJobs = await MyApp.isarInstance.jobs.where().filter().idEqualTo(jobDelMessage.id).findAll(); - if (foundJobs.isNotEmpty) { - await MyApp.isarInstance.writeTxn(() async { - await MyApp.isarInstance.jobs.delete(jobDelMessage.id); - }); + await MyApp.isarInstance.writeTxn(() async { + await MyApp.isarInstance.jobs.where().filter().idEqualTo(jobDelMessage.id).deleteAll(); + }); - await MessageService().publish(Constants.messageTopicJobDeleted, arguments: JobDeletedMessage(id: jobDelMessage.id)); - } + await MessageService().publish(Constants.messageTopicJobDeleted, arguments: JobDeletedMessage(id: jobDelMessage.id)); } void _syncRequestReceived(payloadData) async { diff --git a/lib/tools/util.dart b/lib/tools/util.dart index 10f300d..05d2c2e 100644 --- a/lib/tools/util.dart +++ b/lib/tools/util.dart @@ -374,7 +374,7 @@ String mapTourMode(String mode) { text += "/ Auslieferung"; break; - case "pudel": + case "pu/del": text += "/ Abholung/Auslieferung"; break; } diff --git a/pubspec.yaml b/pubspec.yaml index 642e370..84729c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 # 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. -version: 321.0.0+321 +version: 322.0.0+322 environment: sdk: '>=2.19.6 <3.0.0'