Updated gps setting to follow state of companion.

This commit is contained in:
Winston Lowe
2026-01-19 16:56:32 -08:00
parent 2becbb342c
commit 98fc2d6e0a
17 changed files with 174 additions and 113 deletions
+4 -4
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "Ще излезе скоро",
"channels_enterHashtag": "Въведете хаштаг",
"channels_hashtagHint": "напр. #отбор",
"settings_locationIntervalSec": "Интервал (Секунди)",
"settings_locationGPSEnableSubtitle": "Активирайте GPS, за автоматично изпращане на данни за местоположението (ако е поддържано).",
"settings_locationIntervalInvalid": "Интервалът трябва да бъде поне 60 секунди и по-малко от 86400 секунди.",
"settings_locationGPSEnable": "Активиране на GPS"
"settings_locationIntervalSec": "Интервал за GPS (Секунди)",
"settings_locationGPSEnable": "Активиране на GPS",
"settings_locationGPSEnableSubtitle": "Активирайте автоматичното актуализиране на местоположението чрез GPS.",
"settings_locationIntervalInvalid": "Интервалът трябва да бъде поне 60 секунди и по-малко от 86400 секунди."
}
+3 -3
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Gib Hashtag ein",
"channels_hashtagHint": "z.B. #team",
"settings_locationGPSEnable": "GPS aktivieren",
"settings_locationGPSEnableSubtitle": "Aktivieren Sie GPS, um Standortdaten automatisch zu senden (falls unterstützt).",
"settings_locationIntervalSec": "Zeitintervall (Sekunden)",
"settings_locationIntervalInvalid": "Der Zeitraum muss mindestens 60 Sekunden betragen und weniger als 86400 Sekunden sein."
"settings_locationGPSEnableSubtitle": "Aktivieren Sie die automatische Aktualisierung der Standortdaten per GPS.",
"settings_locationIntervalInvalid": "Der Zeitraum muss mindestens 60 Sekunden betragen und weniger als 86400 Sekunden sein.",
"settings_locationIntervalSec": "Zeitintervall für GPS (Sekunden)"
}
+2 -2
View File
@@ -87,8 +87,8 @@
"settings_locationBothRequired": "Enter both latitude and longitude.",
"settings_locationInvalid": "Invalid latitude or longitude.",
"settings_locationGPSEnable": "GPS Enable",
"settings_locationGPSEnableSubtitle": "Enable GPS to automatically send location data (if supported)",
"settings_locationIntervalSec": "Interval (Seconds)",
"settings_locationGPSEnableSubtitle": "Enables GPS to automatically update location.",
"settings_locationIntervalSec": "Interval for GPS (Seconds)",
"settings_locationIntervalInvalid": "Interval must be at least 60 seconds, and less than 86400 seconds.",
"settings_locationUpdated": "GPS settings updated.",
"settings_latitude": "Latitude",
+2 -2
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "Próximamente",
"channels_enterHashtag": "Introducir hashtag",
"channels_hashtagHint": "ej. #equipo",
"settings_locationGPSEnableSubtitle": "Habilitar GPS para enviar automáticamente datos de ubicación (si está disponible).",
"settings_locationGPSEnable": "Habilitar GPS",
"settings_locationIntervalSec": "Intervalo (Segundos)",
"settings_locationGPSEnableSubtitle": "Habilita la actualización automática de la ubicación mediante GPS.",
"settings_locationIntervalSec": "Intervalo para GPS (Segundos)",
"settings_locationIntervalInvalid": "El intervalo debe ser de al menos 60 segundos y menor que 86400 segundos."
}
+3 -3
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "Bientôt disponible",
"channels_enterHashtag": "Entrez le hashtag",
"channels_hashtagHint": "ex. #équipe",
"settings_locationGPSEnableSubtitle": "Activer la mise à jour automatique de la position grâce au GPS.",
"settings_locationIntervalInvalid": "L'intervalle doit être dau moins 60 secondes et inférieur à 86400 secondes.",
"settings_locationGPSEnable": "Activer le GPS",
"settings_locationGPSEnableSubtitle": "Activer le GPS pour envoyer automatiquement les données de localisation (si pris en charge).",
"settings_locationIntervalSec": "Intervalle (Secondes)",
"settings_locationIntervalInvalid": "L'intervalle doit être d'au moins 60 secondes et inférieur à 86400 secondes."
"settings_locationIntervalSec": "Intervalle GPS (Secondes)"
}
+2 -2
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "Arriverà presto",
"channels_enterHashtag": "Inserisci hashtag",
"channels_hashtagHint": "es. #team",
"settings_locationGPSEnableSubtitle": "Abilita il GPS per inviare automaticamente i dati di posizione (se supportato).",
"settings_locationGPSEnable": "Abilita GPS",
"settings_locationIntervalSec": "Intervallo (Secondi)",
"settings_locationGPSEnableSubtitle": "Abilita l'aggiornamento automatico della posizione tramite GPS.",
"settings_locationIntervalSec": "Intervallo GPS (Secondi)",
"settings_locationIntervalInvalid": "L'intervallo deve essere di almeno 60 secondi e inferiore a 86400 secondi."
}
+2 -2
View File
@@ -489,13 +489,13 @@ abstract class AppLocalizations {
/// No description provided for @settings_locationGPSEnableSubtitle.
///
/// In en, this message translates to:
/// **'Enable GPS to automatically send location data (if supported)'**
/// **'Enables GPS to automatically send location data (if supported)'**
String get settings_locationGPSEnableSubtitle;
/// No description provided for @settings_locationIntervalSec.
///
/// In en, this message translates to:
/// **'Interval (Seconds)'**
/// **'Interval for GPS (Seconds)'**
String get settings_locationIntervalSec;
/// No description provided for @settings_locationIntervalInvalid.
+2 -2
View File
@@ -204,10 +204,10 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get settings_locationGPSEnableSubtitle =>
'Enable GPS to automatically send location data (if supported)';
'Enables GPS to automatically send location data (if supported)';
@override
String get settings_locationIntervalSec => 'Interval (Seconds)';
String get settings_locationIntervalSec => 'Interval for GPS (Seconds)';
@override
String get settings_locationIntervalInvalid =>
+2 -2
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Voer hashtag in",
"channels_hashtagHint": "bijv. #team",
"settings_locationGPSEnable": "GPS inschakelen",
"settings_locationGPSEnableSubtitle": "Zijze GPS inschakelen om locatiegegevens automatisch te verzenden (indien ondersteund).",
"settings_locationIntervalSec": "Interval voor GPS (Seconden)",
"settings_locationIntervalInvalid": "De intervallen moeten minstens 60 seconden zijn en minder dan 86400 seconden.",
"settings_locationIntervalSec": "Interval (Seconden)"
"settings_locationGPSEnableSubtitle": "Activeer automatisch locatieupdates via GPS."
}
+2 -2
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Wprowadź hashtag",
"channels_hashtagHint": "np. #zespół",
"settings_locationGPSEnable": "Włącz GPS",
"settings_locationGPSEnableSubtitle": "Włącz GPS, aby automatycznie wysyłać dane o lokalizacji (jeśli jest obsługiwane).",
"settings_locationIntervalSec": "Interwał (Sekundy)",
"settings_locationIntervalSec": "Interwał dla GPS (Sekundy)",
"settings_locationGPSEnableSubtitle": "Włącza automatyczne aktualizowanie pozycji za pomocą GPS.",
"settings_locationIntervalInvalid": "Interwał musi wynosić co najmniej 60 sekund i mniej niż 86400 sekund."
}
+3 -3
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Insira hashtag",
"channels_hashtagHint": "ex. #equipe",
"settings_locationGPSEnable": "Ativar GPS",
"settings_locationGPSEnableSubtitle": "Habilite o GPS para enviar dados de localização automaticamente (se suportado).",
"settings_locationIntervalSec": "Intervalo (Segundos)",
"settings_locationIntervalInvalid": "O intervalo deve ser de pelo menos 60 segundos e inferior a 86400 segundos."
"settings_locationGPSEnableSubtitle": "Habilita a atualização automática da localização via GPS.",
"settings_locationIntervalInvalid": "O intervalo deve ser de pelo menos 60 segundos e inferior a 86400 segundos.",
"settings_locationIntervalSec": "Intervalo para GPS (Segundos)"
}
+2 -2
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Zadajte hashtag",
"channels_hashtagHint": "napr. #tím",
"settings_locationGPSEnable": "Aktivovať GPS",
"settings_locationGPSEnableSubtitle": "Zapnite GPS na automatické posielanie dát o polohe (ak je podporované).",
"settings_locationIntervalSec": "Interval (Sekundy)",
"settings_locationGPSEnableSubtitle": "Povolí automatické aktualizovanie polohy pomocou GPS.",
"settings_locationIntervalSec": "Interval pre GPS (Sekundy)",
"settings_locationIntervalInvalid": "Interval musí byť aspoň 60 sekúnd a menej ako 86400 sekúnd."
}
+3 -3
View File
@@ -1350,7 +1350,7 @@
"channels_enterHashtag": "Vnesite hashtag",
"channels_hashtagHint": "npr. #ekipa",
"settings_locationGPSEnable": "Omogoči GPS",
"settings_locationGPSEnableSubtitle": "Omogoči GPS za samodejno pošiljanje podatkov o lokaciji (če je podprto).",
"settings_locationIntervalSec": "Interval (Sekunde)",
"settings_locationIntervalInvalid": "Intervallo mora biti vsaj 60 sekund in manj kot 86400 sekund."
"settings_locationGPSEnableSubtitle": "Omogoči samodejno posodabljanje lokacije z GPS-jem.",
"settings_locationIntervalInvalid": "Intervallo mora biti vsaj 60 sekund in manj kot 86400 sekund.",
"settings_locationIntervalSec": "Interval za GPS (Sekunde)"
}
+2 -2
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "Kommer snart",
"channels_enterHashtag": "Ange hashtag",
"channels_hashtagHint": "t.ex. #team",
"settings_locationGPSEnableSubtitle": "Aktiverar automatiska uppdateringar av platsen med hjälp av GPS.",
"settings_locationGPSEnable": "Aktivera GPS",
"settings_locationIntervalSec": "Tidsintervall (Sekunder)",
"settings_locationGPSEnableSubtitle": "Aktivera GPS för att automatiskt skicka platsdata (om det stöds).",
"settings_locationIntervalSec": "Interval för GPS (Sekunder)",
"settings_locationIntervalInvalid": "Intervalet måste vara minst 60 sekunder och mindre än 86400 sekunder."
}
+2 -2
View File
@@ -1349,8 +1349,8 @@
"channels_scanQrCodeComingSoon": "即将到来",
"channels_enterHashtag": "输入标签",
"channels_hashtagHint": "例如 #团队",
"settings_locationGPSEnableSubtitle": "启用GPS自动发送位置数据(如果支持)。",
"settings_locationGPSEnable": "启用GPS",
"settings_locationIntervalSec": "时间间隔(秒)",
"settings_locationGPSEnableSubtitle": "启用GPS自动更新位置。",
"settings_locationIntervalSec": "GPS 间隔(秒)",
"settings_locationIntervalInvalid": "时间间隔必须至少为60秒,且小于86400秒。"
}
+79 -77
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:meshcore_open/widgets/elements_ui.dart';
import 'package:provider/provider.dart';
import 'package:package_info_plus/package_info_plus.dart';
@@ -435,7 +436,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
intervalController.text = "900";
latController.text = connector.selfLatitude?.toStringAsFixed(6) ?? '';
lonController.text = connector.selfLongitude?.toStringAsFixed(6) ?? '';
bool isGPSEnabled = false;
bool hasGPS = connector.currentCustomVars!.isNotEmpty
? connector.currentCustomVars!.containsKey("gps")
: false;
bool isGPSEnabled = hasGPS
? connector.currentCustomVars!["gps"] == "1"
: false;
showDialog(
context: context,
@@ -445,48 +452,30 @@ class _SettingsScreenState extends State<SettingsScreen> {
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (!isGPSEnabled) ...[
TextField(
controller: latController,
decoration: InputDecoration(
labelText: l10n.settings_latitude,
border: const OutlineInputBorder(),
),
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
signed: true,
),
TextField(
controller: latController,
decoration: InputDecoration(
labelText: l10n.settings_latitude,
border: const OutlineInputBorder(),
),
const SizedBox(height: 16),
TextField(
controller: lonController,
decoration: InputDecoration(
labelText: l10n.settings_longitude,
border: const OutlineInputBorder(),
),
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
signed: true,
),
),
],
const SizedBox(height: 16),
CheckboxListTile(
value: isGPSEnabled,
enabled: true,
onChanged: (v) =>
setDialogState(() => isGPSEnabled = v ?? false),
//controlAffinity: ListTileControlAffinity.leading,
title: Text(
l10n.settings_locationGPSEnable,
style: TextStyle(fontSize: 12),
),
subtitle: Text(
l10n.settings_locationGPSEnableSubtitle,
style: TextStyle(fontSize: 10),
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
signed: true,
),
),
if (isGPSEnabled) ...{
const SizedBox(height: 16),
TextField(
controller: lonController,
decoration: InputDecoration(
labelText: l10n.settings_longitude,
border: const OutlineInputBorder(),
),
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
signed: true,
),
),
if (hasGPS) ...[
const SizedBox(height: 16),
TextField(
controller: intervalController,
@@ -499,7 +488,21 @@ class _SettingsScreenState extends State<SettingsScreen> {
signed: false,
),
),
},
const SizedBox(height: 16),
FeatureToggleRow(
title: l10n.settings_locationGPSEnable,
subtitle: l10n.settings_locationGPSEnableSubtitle,
value: isGPSEnabled,
onChanged: (value) async {
setDialogState(() => isGPSEnabled = value);
if (value) {
await connector.setCustomVar("gps:1");
} else {
await connector.setCustomVar("gps:0");
}
},
),
],
],
),
actions: [
@@ -510,11 +513,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
TextButton(
onPressed: () async {
Navigator.pop(context);
if (isGPSEnabled) {
if (hasGPS) {
final intervalText = intervalController.text.trim();
if (intervalText.isEmpty) {
return;
}
final interval = int.tryParse(intervalText);
if (interval == null || interval < 60) {
if (!context.mounted) return;
@@ -525,53 +530,50 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
return;
}
await connector.setCustomVar("gps:1");
await connector.setCustomVar("gps_interval:$interval");
await connector.refreshDeviceInfo();
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.settings_locationUpdated)),
);
} else {
final latText = latController.text.trim();
final lonText = lonController.text.trim();
if (latText.isEmpty && lonText.isEmpty) {
return;
}
}
final currentLat = connector.selfLatitude;
final currentLon = connector.selfLongitude;
final lat = latText.isNotEmpty
? double.tryParse(latText)
: currentLat;
final lon = lonText.isNotEmpty
? double.tryParse(lonText)
: currentLon;
if (lat == null || lon == null) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(l10n.settings_locationBothRequired),
),
);
return;
}
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.settings_locationInvalid)),
);
return;
}
final latText = latController.text.trim();
final lonText = lonController.text.trim();
if (latText.isEmpty && lonText.isEmpty) {
return;
}
await connector.setCustomVar("gps:0");
await connector.setNodeLocation(lat: lat, lon: lon);
await connector.refreshDeviceInfo();
final currentLat = connector.selfLatitude;
final currentLon = connector.selfLongitude;
final lat = latText.isNotEmpty
? double.tryParse(latText)
: currentLat;
final lon = lonText.isNotEmpty
? double.tryParse(lonText)
: currentLon;
if (lat == null || lon == null) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.settings_locationUpdated)),
SnackBar(content: Text(l10n.settings_locationBothRequired)),
);
return;
}
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.settings_locationInvalid)),
);
return;
}
await connector.setNodeLocation(lat: lat, lon: lon);
await connector.refreshDeviceInfo();
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.settings_locationUpdated)),
);
},
child: Text(l10n.common_save),
),
+59
View File
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
class FeatureToggleRow extends StatefulWidget {
final String title;
final String subtitle;
final bool value;
final bool hasRefreshing;
final bool isRefreshing;
final ValueChanged<bool>? onChanged;
final VoidCallback? onRefresh;
final String? refreshTooltip;
const FeatureToggleRow({
super.key,
required this.title,
required this.subtitle,
required this.value,
this.hasRefreshing = false,
this.isRefreshing = false,
this.onChanged,
this.onRefresh,
this.refreshTooltip,
});
@override
State<FeatureToggleRow> createState() => _FeatureToggleRow();
}
class _FeatureToggleRow extends State<FeatureToggleRow> {
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: SwitchListTile(
title: Text(widget.title),
subtitle: Text(widget.subtitle),
value: widget.value,
onChanged: widget.onChanged,
contentPadding: EdgeInsets.zero,
),
),
if (widget.hasRefreshing)
IconButton(
icon: widget.isRefreshing
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.refresh, size: 20),
onPressed: widget.isRefreshing ? null : widget.onRefresh,
tooltip: widget.refreshTooltip,
visualDensity: VisualDensity.compact,
),
],
);
}
}