From 61ce0a0653ca89cffb9f221c584750475a9b7a4a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 9 May 2025 07:56:34 -0700 Subject: [PATCH] Update status screen --- lib/l10n/app_en.arb | 1 + lib/main_screen.dart | 4 ++-- lib/preferences.dart | 4 +++- lib/status_screen.dart | 34 +++++++++++++++------------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index fb4547c..719cd42 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2,6 +2,7 @@ "mainTitle": "Traccar Client", "trackingTitle": "Tracking", "settingsTitle": "Settings", + "statusTitle": "Logs", "saveButton": "Save", "cancelButton": "Cancel", "locationButton": "Send location", diff --git a/lib/main_screen.dart b/lib/main_screen.dart index bc6c5fd..61d0521 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -80,8 +80,8 @@ class _MainScreenState extends State { FilledButton.tonal( onPressed: () async { try { - await bg.BackgroundGeolocation.getCurrentPosition(samples: 1); - await bg.BackgroundGeolocation.sync(); + await bg.BackgroundGeolocation.getCurrentPosition(samples: 1); + await bg.BackgroundGeolocation.sync(); } catch (error) { developer.log('Failed to fetch location', error: error); } diff --git a/lib/preferences.dart b/lib/preferences.dart index d1ad931..3987e9a 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -43,8 +43,10 @@ class Preferences { "device_id": preferences.getString(id), }, distanceFilter: preferences.getInt(distance)?.toDouble(), - locationUpdateInterval: preferences.getInt(interval), + locationUpdateInterval: (preferences.getInt(interval) ?? 0) * 1000, maxRecordsToPersist: preferences.getBool(buffer) != false ? -1 : 0, + logLevel: bg.Config.LOG_LEVEL_INFO, + logMaxDays: 1, ); } diff --git a/lib/status_screen.dart b/lib/status_screen.dart index 38ad990..e85e249 100644 --- a/lib/status_screen.dart +++ b/lib/status_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class StatusScreen extends StatefulWidget { const StatusScreen({super.key}); @@ -14,14 +15,14 @@ class _StatusScreenState extends State { @override void initState() { super.initState(); - _loadLogs(); + _refreshLogs(); } - Future _loadLogs() async { - final logs = await bg.Logger.getLog(); // Fetch logs + Future _refreshLogs() async { + final logs = await bg.Logger.getLog(); setState(() { _logs.clear(); - _logs.addAll(logs.split('\n').reversed); // Latest logs first + _logs.addAll(logs.split('\n')); }); } @@ -34,11 +35,11 @@ class _StatusScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Background Geolocation Logs'), + title: Text(AppLocalizations.of(context)!.statusTitle), actions: [ IconButton( icon: const Icon(Icons.refresh), - onPressed: _loadLogs, + onPressed: _refreshLogs, ), IconButton( icon: const Icon(Icons.delete), @@ -46,19 +47,14 @@ class _StatusScreenState extends State { ), ], ), - body: _logs.isEmpty - ? const Center(child: Text('No logs available.')) - : ListView.builder( - itemCount: _logs.length, - itemBuilder: (_, index) => Padding( - padding: const EdgeInsets.symmetric( - vertical: 2.0, horizontal: 8.0), - child: Text( - _logs[index], - style: const TextStyle(fontSize: 12.0), - ), - ), - ), + body: ListView.builder( + reverse: true, + itemCount: _logs.length, + itemBuilder: (_, index) => Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Text(_logs[index]), + ), + ), ); } }