mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-27 14:06:38 +10:00
reimplement location aware snr-indikator after alpha7
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import 'package:latlong2/latlong.dart';
|
||||||
|
|
||||||
|
import '../connector/meshcore_protocol.dart';
|
||||||
import '../models/contact.dart';
|
import '../models/contact.dart';
|
||||||
|
|
||||||
export 'contact_filter_types.dart';
|
export 'contact_filter_types.dart';
|
||||||
@@ -43,3 +46,55 @@ String? _extractHexPrefix(String query) {
|
|||||||
if (!RegExp(r'^[0-9a-f]+$').hasMatch(cleaned)) return null;
|
if (!RegExp(r'^[0-9a-f]+$').hasMatch(cleaned)) return null;
|
||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Contact? getRepeaterPrefixMatchNearLocation(
|
||||||
|
List<Contact> contacts,
|
||||||
|
int pubkeyFirstByte, {
|
||||||
|
LatLng? searchPoint,
|
||||||
|
bool preferFavorites = false,
|
||||||
|
}) {
|
||||||
|
final candidates = contacts
|
||||||
|
.where(
|
||||||
|
(c) =>
|
||||||
|
c.publicKey.isNotEmpty &&
|
||||||
|
c.publicKey.first == pubkeyFirstByte &&
|
||||||
|
(c.type == advTypeRepeater || c.type == advTypeRoom),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (candidates.isEmpty) return null;
|
||||||
|
|
||||||
|
candidates.sort((a, b) {
|
||||||
|
if (preferFavorites) {
|
||||||
|
final favA = a.isFavorite ? 1 : 0;
|
||||||
|
final favB = b.isFavorite ? 1 : 0;
|
||||||
|
final favCompare = favB.compareTo(favA);
|
||||||
|
if (favCompare != 0) return favCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
final seenCompare = b.lastSeen.compareTo(a.lastSeen);
|
||||||
|
if (seenCompare != 0) return seenCompare;
|
||||||
|
|
||||||
|
return a.publicKeyHex.compareTo(b.publicKeyHex);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (searchPoint == null) {
|
||||||
|
return candidates.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
final distance = Distance();
|
||||||
|
Contact best = candidates.first;
|
||||||
|
var bestDistance = double.infinity;
|
||||||
|
|
||||||
|
for (final c in candidates) {
|
||||||
|
if (c.hasLocation) {
|
||||||
|
final d = distance(searchPoint, LatLng(c.latitude!, c.longitude!));
|
||||||
|
if (d < bestDistance) {
|
||||||
|
bestDistance = d;
|
||||||
|
best = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:latlong2/latlong.dart';
|
||||||
|
|
||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
|
import '../utils/contact_search.dart';
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
import 'signal_ui.dart';
|
import 'signal_ui.dart';
|
||||||
|
|
||||||
@@ -158,10 +161,23 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
|||||||
widget.connector.currentSf,
|
widget.connector.currentSf,
|
||||||
);
|
);
|
||||||
final allContacts = widget.connector.allContacts;
|
final allContacts = widget.connector.allContacts;
|
||||||
final name = allContacts
|
|
||||||
.where((c) => c.publicKey.first == repeater.pubkeyFirstByte)
|
final selfLat = widget.connector.selfLatitude;
|
||||||
.map((c) => c.name)
|
final selfLon = widget.connector.selfLongitude;
|
||||||
.firstOrNull;
|
|
||||||
|
LatLng? selfPoint;
|
||||||
|
if (selfLat != null && selfLon != null) {
|
||||||
|
selfPoint = LatLng(selfLat, selfLon);
|
||||||
|
}
|
||||||
|
|
||||||
|
final contact = getRepeaterPrefixMatchNearLocation(
|
||||||
|
allContacts,
|
||||||
|
repeater.pubkeyFirstByte,
|
||||||
|
searchPoint: selfPoint,
|
||||||
|
preferFavorites: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
final name = contact?.name;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import flutter_blue_plus_darwin
|
|||||||
import flutter_local_notifications
|
import flutter_local_notifications
|
||||||
import mobile_scanner
|
import mobile_scanner
|
||||||
import package_info_plus
|
import package_info_plus
|
||||||
|
import path_provider_foundation
|
||||||
import share_plus
|
import share_plus
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
import sqflite_darwin
|
import sqflite_darwin
|
||||||
@@ -20,6 +21,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
|||||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||||
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
|
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
|
||||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||||
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||||
|
|||||||
Reference in New Issue
Block a user