This commit is contained in:
Nedifinita
2025-11-23 21:43:47 +08:00
parent fe2769f479
commit a47c6a5745
20 changed files with 88 additions and 209 deletions

View File

@@ -3,7 +3,6 @@ import 'dart:io';
import 'dart:ui';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:lbjconsole/services/ble_service.dart';
@@ -107,7 +106,7 @@ class BackgroundService {
_notificationId,
'LBJ Console',
'蓝牙连接监控中',
NotificationDetails(
const NotificationDetails(
android: AndroidNotificationDetails(
_notificationChannelId,
_notificationChannelName,
@@ -146,7 +145,7 @@ class BackgroundService {
_notificationId,
'LBJ Console',
isConnected ? '蓝牙已连接 - $deviceStatus' : '蓝牙未连接 - 自动重连中',
NotificationDetails(
const NotificationDetails(
android: AndroidNotificationDetails(
_notificationChannelId,
_notificationChannelName,

View File

@@ -145,7 +145,9 @@ class BLEService {
if (isConnected ||
_isConnecting ||
_isManualDisconnect ||
_isAutoConnectBlocked) return;
_isAutoConnectBlocked) {
return;
}
for (var device in allFoundDevices) {
if (_shouldAutoConnectTo(device)) {
@@ -168,10 +170,13 @@ class BLEService {
final deviceAddress = device.remoteId.str;
if (_targetDeviceName.isNotEmpty &&
deviceName.toLowerCase() == _targetDeviceName.toLowerCase())
deviceName.toLowerCase() == _targetDeviceName.toLowerCase()) {
return true;
}
if (_lastKnownDeviceAddress != null &&
_lastKnownDeviceAddress == deviceAddress) return true;
_lastKnownDeviceAddress == deviceAddress) {
return true;
}
return false;
}

View File

@@ -27,7 +27,7 @@ class DatabaseService {
}
_database = await _initDatabase();
return _database!;
} catch (e, stackTrace) {
} catch (e) {
rethrow;
}
}
@@ -38,8 +38,6 @@ class DatabaseService {
return false;
}
final db = await database;
final result = await db.rawQuery('SELECT 1');
return true;
} catch (e) {
return false;
@@ -59,7 +57,7 @@ class DatabaseService {
);
return db;
} catch (e, stackTrace) {
} catch (e) {
rethrow;
}
}
@@ -206,7 +204,7 @@ class DatabaseService {
final records =
result.map((json) => TrainRecord.fromDatabaseJson(json)).toList();
return records;
} catch (e, stackTrace) {
} catch (e) {
rethrow;
}
}
@@ -239,7 +237,7 @@ class DatabaseService {
final records =
result.map((json) => TrainRecord.fromDatabaseJson(json)).toList();
return records;
} catch (e, stackTrace) {
} catch (e) {
rethrow;
}
}

View File

@@ -1,4 +1,3 @@
import 'package:lbjconsole/util/loco_type_util.dart';
class LocoTypeService {
static final LocoTypeService _instance = LocoTypeService._internal();

View File

@@ -111,7 +111,7 @@ class MergeService {
}
});
final reusedRecords = _reuseDiscardedRecords(
_reuseDiscardedRecords(
discardedRecords, mergedRecordIds, settings.groupBy);
final singleRecords = filteredRecords
@@ -283,100 +283,4 @@ class MergeService {
return result;
}
static List<Object> _groupByTrainOrLoco(List<TrainRecord> records) {
final List<MergedTrainRecord> mergedRecords = [];
final List<TrainRecord> singleRecords = [];
final Set<String> usedRecordIds = {};
for (int i = 0; i < records.length; i++) {
final record = records[i];
if (usedRecordIds.contains(record.uniqueId)) continue;
final group = <TrainRecord>[record];
for (int j = i + 1; j < records.length; j++) {
final otherRecord = records[j];
if (usedRecordIds.contains(otherRecord.uniqueId)) continue;
final recordTrain = record.train.trim();
final otherTrain = otherRecord.train.trim();
final recordLoco = record.loco.trim();
final otherLoco = otherRecord.loco.trim();
final trainMatch = recordTrain.isNotEmpty &&
recordTrain != "<NUL>" &&
!recordTrain.contains("-----") &&
otherTrain.isNotEmpty &&
otherTrain != "<NUL>" &&
!otherTrain.contains("-----") &&
recordTrain == otherTrain;
final locoMatch = recordLoco.isNotEmpty &&
recordLoco != "<NUL>" &&
otherLoco.isNotEmpty &&
otherLoco != "<NUL>" &&
recordLoco == otherLoco;
final bothTrainEmpty = (recordTrain.isEmpty ||
recordTrain == "<NUL>" ||
recordTrain.contains("----")) &&
(otherTrain.isEmpty ||
otherTrain == "<NUL>" ||
otherTrain.contains("----"));
if (trainMatch || locoMatch || (bothTrainEmpty && locoMatch)) {
group.add(otherRecord);
}
}
if (group.length >= 2) {
for (final record in group) {
usedRecordIds.add(record.uniqueId);
}
final firstRecord = group.first;
final train = firstRecord.train.trim();
final loco = firstRecord.loco.trim();
String uniqueGroupKey;
if (train.isNotEmpty &&
train != "<NUL>" &&
!train.contains("-----") &&
loco.isNotEmpty &&
loco != "<NUL>") {
uniqueGroupKey = "train_or_loco:${train}_$loco";
} else if (train.isNotEmpty &&
train != "<NUL>" &&
!train.contains("-----")) {
uniqueGroupKey = "train_or_loco:train:$train";
} else if (loco.isNotEmpty && loco != "<NUL>") {
uniqueGroupKey = "train_or_loco:loco:$loco";
} else {
uniqueGroupKey = "train_or_loco:group_${mergedRecords.length}";
}
mergedRecords.add(MergedTrainRecord(
groupKey: uniqueGroupKey,
records: group,
latestRecord: group.first,
));
} else {
singleRecords.add(record);
usedRecordIds.add(record.uniqueId);
}
}
final List<Object> result = [...mergedRecords, ...singleRecords];
result.sort((a, b) {
final aTime = a is MergedTrainRecord
? a.latestRecord.receivedTimestamp
: (a as TrainRecord).receivedTimestamp;
final bTime = b is MergedTrainRecord
? b.latestRecord.receivedTimestamp
: (b as TrainRecord).receivedTimestamp;
return bTime.compareTo(aTime);
});
return result;
}
}

View File

@@ -20,7 +20,7 @@ class NotificationService {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
final InitializationSettings initializationSettings =
const InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
);
@@ -61,7 +61,7 @@ class NotificationService {
return;
}
final String title = '列车信息';
const String title = '列车信息';
final String body = _buildNotificationContent(record);
final AndroidNotificationDetails androidPlatformChannelSpecifics =

View File

@@ -149,8 +149,9 @@ class _LbJState {
break;
case _lbjSyncAddr:
if (numeric.length >= 5)
if (numeric.length >= 5) {
time = "${numeric.substring(1, 3)}:${numeric.substring(3, 5)}";
}
break;
}
}
@@ -167,11 +168,11 @@ class _LbJState {
String gpsPosition = "";
if (posLatDeg.isNotEmpty && posLatMin.isNotEmpty) {
gpsPosition = "${posLatDeg}°${posLatMin}";
gpsPosition = "$posLatDeg°$posLatMin";
}
if (posLonDeg.isNotEmpty && posLonMin.isNotEmpty) {
gpsPosition +=
(gpsPosition.isEmpty ? "" : " ") + "${posLonDeg}°${posLonMin}";
"${gpsPosition.isEmpty ? "" : " "}$posLonDeg°$posLonMin";
}
String kmPosition = positionKm.replaceAll(' <NUL>', '');