From 9ab546975901bac64349001b59e05afea601c360 Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 16 Oct 2025 14:25:15 +0200 Subject: [PATCH] feat: Add RX/TX indicators preference with toggle in settings --- lib/screens/home_screen.dart | 188 +++++++++++++++++-------------- lib/screens/settings_screen.dart | 28 +++++ 2 files changed, 133 insertions(+), 83 deletions(-) diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 890d436..7a8360c 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:geolocator/geolocator.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../providers/connection_provider.dart'; import '../providers/app_provider.dart'; import '../providers/messages_provider.dart'; @@ -34,6 +35,7 @@ class _HomeScreenState extends State late TabController _tabController; int _currentIndex = 0; bool _isMapFullscreen = false; + bool _showRxTxIndicators = true; @override void initState() { @@ -48,6 +50,16 @@ class _HomeScreenState extends State } }); }); + _loadRxTxPreference(); + } + + Future _loadRxTxPreference() async { + final prefs = await SharedPreferences.getInstance(); + if (mounted) { + setState(() { + _showRxTxIndicators = prefs.getBool('show_rx_tx_indicators') ?? true; + }); + } } @override @@ -475,8 +487,8 @@ class _HomeScreenState extends State ], ), onTap: () { - Future.delayed(Duration.zero, () { - Navigator.push( + Future.delayed(Duration.zero, () async { + await Navigator.push( context, MaterialPageRoute( builder: (context) => SettingsScreen( @@ -485,6 +497,8 @@ class _HomeScreenState extends State ), ), ); + // Reload preference when returning from settings + _loadRxTxPreference(); }); }, ), @@ -580,34 +594,40 @@ class _HomeScreenState extends State color: deviceInfo.signalRssi != null ? _getSignalColor(deviceInfo.signalRssi!) : Colors.grey, - size: 16, + size: 14, ), - const SizedBox(width: 4), + const SizedBox(width: 3), if (deviceInfo.signalRssi != null) - Text( - '${deviceInfo.signalRssi}dBm', - style: TextStyle( - fontSize: 14, - color: _getSignalColor(deviceInfo.signalRssi!), - fontWeight: FontWeight.w500, + Flexible( + child: Text( + '${deviceInfo.signalRssi}', + style: TextStyle( + fontSize: 12, + color: _getSignalColor(deviceInfo.signalRssi!), + fontWeight: FontWeight.w500, + ), + overflow: TextOverflow.ellipsis, ), ), - const SizedBox(width: 12), + const SizedBox(width: 8), // Battery indicator if (deviceInfo.batteryPercent != null) ...[ Icon( _getBatteryIcon(deviceInfo.batteryPercent!), color: _getBatteryColor(deviceInfo.batteryPercent!), - size: 16, + size: 14, ), - const SizedBox(width: 4), - Text( - '${deviceInfo.batteryPercent!.round()}%', - style: TextStyle( - fontSize: 14, - color: _getBatteryColor( - deviceInfo.batteryPercent!, + const SizedBox(width: 3), + Flexible( + child: Text( + '${deviceInfo.batteryPercent!.round()}%', + style: TextStyle( + fontSize: 12, + color: _getBatteryColor( + deviceInfo.batteryPercent!, + ), ), + overflow: TextOverflow.ellipsis, ), ), ], @@ -687,75 +707,77 @@ class _HomeScreenState extends State ), child: const Icon(Icons.campaign, size: 20), ), - const SizedBox(width: 8), - // RX/TX indicators with long press to open packet log - GestureDetector( - onLongPress: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - PacketLogScreen(bleService: provider.bleService), - ), - ); - }, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // RX indicator - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - width: 8, - height: 8, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: provider.rxActivity - ? Colors.green - : Colors.grey.withOpacity(0.3), + if (_showRxTxIndicators) ...[ + const SizedBox(width: 8), + // RX/TX indicators with long press to open packet log + GestureDetector( + onLongPress: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + PacketLogScreen(bleService: provider.bleService), + ), + ); + }, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // RX indicator + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + width: 8, + height: 8, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: provider.rxActivity + ? Colors.green + : Colors.grey.withOpacity(0.3), + ), ), - ), - const SizedBox(width: 4), - Text( - 'RX:${provider.rxPacketCount}', - style: const TextStyle( - fontSize: 11, - color: Colors.grey, + const SizedBox(width: 4), + Text( + 'RX:${provider.rxPacketCount}', + style: const TextStyle( + fontSize: 11, + color: Colors.grey, + ), ), - ), - ], - ), - const SizedBox(height: 4), - // TX indicator - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - width: 8, - height: 8, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: provider.txActivity - ? Colors.blue - : Colors.grey.withOpacity(0.3), + ], + ), + const SizedBox(height: 4), + // TX indicator + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + width: 8, + height: 8, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: provider.txActivity + ? Colors.blue + : Colors.grey.withOpacity(0.3), + ), ), - ), - const SizedBox(width: 4), - Text( - 'TX:${provider.txPacketCount}', - style: const TextStyle( - fontSize: 11, - color: Colors.grey, + const SizedBox(width: 4), + Text( + 'TX:${provider.txPacketCount}', + style: const TextStyle( + fontSize: 11, + color: Colors.grey, + ), ), - ), - ], - ), - ], + ], + ), + ], + ), ), - ), - const SizedBox(width: 12), + const SizedBox(width: 12), + ], // Settings button (tap for device settings, long press for packet logs) GestureDetector( onTap: () { diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 7dcf136..1805f5f 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -29,6 +29,7 @@ class _SettingsScreenState extends State { late AppThemeMode _selectedTheme; PackageInfo? _packageInfo; bool _isLoadingSampleData = false; + bool _showRxTxIndicators = true; final LocationTrackingService _locationService = LocationTrackingService(); @override @@ -37,6 +38,7 @@ class _SettingsScreenState extends State { _selectedTheme = widget.currentTheme; _loadPackageInfo(); _initializeLocationService(); + _loadRxTxPreference(); } Future _loadPackageInfo() async { @@ -48,6 +50,20 @@ class _SettingsScreenState extends State { } } + Future _loadRxTxPreference() async { + final prefs = await SharedPreferences.getInstance(); + if (mounted) { + setState(() { + _showRxTxIndicators = prefs.getBool('show_rx_tx_indicators') ?? true; + }); + } + } + + Future _saveRxTxPreference(bool value) async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('show_rx_tx_indicators', value); + } + Future _initializeLocationService() async { // Initialize location service with BLE service WidgetsBinding.instance.addPostFrameCallback((_) async { @@ -294,6 +310,18 @@ class _SettingsScreenState extends State { trailing: const Icon(Icons.chevron_right), onTap: () => _showThemeDialog(), ), + SwitchListTile( + secondary: const Icon(Icons.radar), + title: const Text('Show RX/TX Indicators'), + subtitle: const Text('Display packet activity indicators in top bar'), + value: _showRxTxIndicators, + onChanged: (value) async { + setState(() { + _showRxTxIndicators = value; + }); + await _saveRxTxPreference(value); + }, + ), const Divider(), // Location Settings Section