Erweiterungen
This commit is contained in:
1 parent
41d086e13e
commit
7015d83fd1
20 files changed
+182
-158
No files matched your search
+45
-32
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_map/shared_map.dart';
|
||||
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
||||
import 'package:stadtbote/model/enqueued_message.dart';
|
||||
import 'package:stadtbote/model/log_entry.dart';
|
||||
@@ -17,6 +18,7 @@ import 'package:stadtbote/tools/colored_safe_area.dart';
|
||||
import 'package:stadtbote/model/session_status.dart';
|
||||
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/mqtt_core.dart';
|
||||
@@ -29,28 +31,28 @@ import 'tools/constants.dart';
|
||||
import 'tools/util.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
MyApp.isarInstance = await Isar.open([
|
||||
SessionStatusSchema,
|
||||
LocationStatusSchema,
|
||||
JobSchema,
|
||||
TaskInfoSchema,
|
||||
MessageSchema,
|
||||
EnqueuedMessageSchema,
|
||||
LogEntrySchema,
|
||||
RankingSchema,
|
||||
PictureSchema
|
||||
], directory: dir.path, name: "database_v1");
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
MyApp.isarInstance = await Isar.open([
|
||||
SessionStatusSchema,
|
||||
LocationStatusSchema,
|
||||
JobSchema,
|
||||
TaskInfoSchema,
|
||||
MessageSchema,
|
||||
EnqueuedMessageSchema,
|
||||
LogEntrySchema,
|
||||
RankingSchema,
|
||||
PictureSchema
|
||||
], directory: dir.path, name: "database_v1");
|
||||
|
||||
await _clearLog();
|
||||
await _clearLog();
|
||||
|
||||
runZonedGuarded(() {}, (error, stackTrace) {
|
||||
runApp(MyApp());
|
||||
}, (error, stackTrace) {
|
||||
_traceUncaughtExceptions(error, stackTrace);
|
||||
});
|
||||
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
Future<void> _clearLog() async {
|
||||
@@ -177,8 +179,12 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
|
||||
Timer? _checkForNewState0JobsJobsTimer;
|
||||
|
||||
bool _dialogOpened = false;
|
||||
|
||||
late SharedMap<int, Job>? _jobMap;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -188,8 +194,13 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
_animation = Tween<double>(begin: 0.5, end: 1.0).animate(_animationController);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
var store1 = SharedStore('jobs');
|
||||
_jobMap = await store1.getSharedMap<int, Job>('m1');
|
||||
|
||||
_initMessages();
|
||||
|
||||
_startCheckForNewState0JobsJobsTimer();
|
||||
|
||||
_currentContent = MainPage();
|
||||
|
||||
var headerInfo = await _currentContent.getHeaderInfo(context);
|
||||
@@ -366,8 +377,15 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
MessageService().subscribe<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, this, (ConnectionStatus connectionStatus) {
|
||||
_connectionStatusChanged(connectionStatus);
|
||||
});
|
||||
MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, this, (JobReceivedMessage jobReceivedMessage) {
|
||||
_jobReceived(jobReceivedMessage.job);
|
||||
|
||||
MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, this, (JobReceivedMessage jobReceivedMessage) async {
|
||||
if (jobReceivedMessage.job.state == 0) {
|
||||
await _jobMap!.put(jobReceivedMessage.job.id, jobReceivedMessage.job);
|
||||
}
|
||||
});
|
||||
|
||||
MessageService().subscribe<JobDeletedMessage>(Constants.messageTopicJobDeleted, this, (JobDeletedMessage jobDeletedMessage) async {
|
||||
await _jobMap!.remove(jobDeletedMessage.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -457,19 +475,14 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
||||
_connectionLostValueNotifier.value = newConnectionStatus.status == ConnectionStatusEnum.notConnected;
|
||||
}
|
||||
|
||||
void _jobReceived(Job job) async {
|
||||
if (!MyApp.suppressAcceptDialog) {
|
||||
if (job.state == 0) {
|
||||
if (!_dialogOpened) {
|
||||
_dialogOpened = true;
|
||||
|
||||
await showAcceptJobsPopup(context, await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll(), () {
|
||||
_dialogOpened = false;
|
||||
|
||||
MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage());
|
||||
});
|
||||
}
|
||||
void _startCheckForNewState0JobsJobsTimer() {
|
||||
_checkForNewState0JobsJobsTimer ??= Timer.periodic(const Duration(seconds: 5), (Timer t) async {
|
||||
if (await _jobMap!.length() > 0 && !_dialogOpened) {
|
||||
_dialogOpened = true;
|
||||
await showAcceptJobsPopup(context, _jobMap!.sharedReference(), () async {
|
||||
_dialogOpened = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user