diff --git a/lib/main.dart b/lib/main.dart index ada5f56..ccdac4a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -122,7 +122,7 @@ class Main extends StatefulWidget { State
createState() => _MainState(); } -class _MainState extends State
{ +class _MainState extends State
with SingleTickerProviderStateMixin { late ContentViewWidget _currentContent; late WidgetStack contentStack = WidgetStack(); @@ -141,10 +141,17 @@ class _MainState extends State
{ final ValueNotifier _connectionLostValueNotifier = ValueNotifier(true); + late AnimationController _animationController; + late Animation _animation; + @override void initState() { super.initState(); + _animationController = AnimationController(vsync: this, duration: const Duration(milliseconds: 1000)); + _animationController.repeat(reverse: true); + _animation = Tween(begin: 0.5, end: 1.0).animate(_animationController); + WidgetsBinding.instance.addPostFrameCallback((_) async { _initMessages(); @@ -269,26 +276,33 @@ class _MainState extends State
{ builder: (context, value, child) { return Visibility( visible: value, - child: Container( - width: MediaQuery.of(context).size.width, - height: 30, - color: Colors.red, - child: const Center( - child: Text( - "*** OFFLINE ***", - style: TextStyle( - color: Colors.white, - fontSize: 15.0, - ), + child: Column( + children: [ + const SizedBox(height: 1), + Container( + width: MediaQuery.of(context).size.width, + height: 40, + color: Constants.colorPrimary, + child: Center( + child: FadeTransition( + opacity: _animation, + child: const Text( + "*** OFFLINE ***", + style: TextStyle( + color: Colors.white, + fontSize: 25.0, + ), + ), + )), ), - ), + ], ), ); }, ), Expanded(child: _currentContent), ], - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ), ), ); diff --git a/lib/popups/infos_popup.dart b/lib/popups/infos_popup.dart index 5f77988..bf125b5 100644 --- a/lib/popups/infos_popup.dart +++ b/lib/popups/infos_popup.dart @@ -1,12 +1,15 @@ import 'package:flutter/material.dart'; import 'package:kumi_popup_window/kumi_popup_window.dart'; +import 'package:stadtbote/main.dart'; import 'package:stadtbote/model/status.dart'; +import 'package:stadtbote/tools/mqtt_core.dart'; import 'package:stadtbote/tools/util.dart'; void showInfosPopup(BuildContext context, Status? status) { var text = "Versionsnummer: a203\n"; - text += "Verbindungsstatus: Unbekannt\n"; - text += "GPS-Status: Unbekannt\n"; + text += "Verbindungsstatus: ${MqttCore.instance.connectionState == ConnectionStateEnum.connected ? "Verbunden" : "NICHT verbunden"}\n"; + text += "GPS-Status: ${MyApp.currentPosition != null ? "Position gefunden" : "Position NICHT gefunden"}\n"; + text += "Version GPS: ${MyApp.currentPosition != null ? MyApp.currentPosition!.timestamp.toString() : "Unbekannt"}\n"; text += "\n"; text += "User Status:\n"; if (status != null) { @@ -16,7 +19,6 @@ void showInfosPopup(BuildContext context, Status? status) { text += "vht_id: ${status.vhtId}\n"; text += "server_version: ${status.serverVersion}\n"; text += "server_instance: ${status.serverInstance}\n"; - text += "Version GPS: Unbekannt"; } else { text += "Keine Informationen gefunden"; } diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index 9869fbe..706a656 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -30,9 +30,16 @@ import '../model/status.dart'; import 'constants.dart'; import 'util.dart'; +enum ConnectionStateEnum { + not_connected, + connected +} + class MqttCore { static late MqttCore instance; + late ConnectionStateEnum connectionState = ConnectionStateEnum.not_connected; + late String _brokerUri; late int _brokerPort; late String _fromServerTopic; @@ -191,6 +198,8 @@ class MqttCore { } void _sessionMessageReceived(payloadData) async { + connectionState = ConnectionStateEnum.connected; + await _sendSyncMessage(); var statusMessage = Status.fromJson(payloadData['status']); @@ -265,6 +274,8 @@ class MqttCore { } void _startReconnectTimer() { + connectionState = ConnectionStateEnum.not_connected; + Util.logInfo("_startReconnectTimer called"); _reconnectDelay = min(_reconnectDelay + 1, 30); @@ -275,6 +286,8 @@ class MqttCore { } void _clientDisconnected() { + connectionState = ConnectionStateEnum.not_connected; + Util.logInfo("_clientDisconnected called"); BroadcastReceiver().publish(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));