more cameras -> nodes

This commit is contained in:
stopflock
2025-08-29 18:20:42 -05:00
parent eeedbd7da7
commit a8ac237317
17 changed files with 127 additions and 126 deletions
+18 -18
View File
@@ -1,33 +1,33 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/camera_profile.dart';
import '../models/node_profile.dart';
import '../services/profile_service.dart';
class ProfileState extends ChangeNotifier {
static const String _enabledPrefsKey = 'enabled_profiles';
final List<CameraProfile> _profiles = [];
final Set<CameraProfile> _enabled = {};
final List<NodeProfile> _profiles = [];
final Set<NodeProfile> _enabled = {};
// Getters
List<CameraProfile> get profiles => List.unmodifiable(_profiles);
bool isEnabled(CameraProfile p) => _enabled.contains(p);
List<CameraProfile> get enabledProfiles =>
List<NodeProfile> get profiles => List.unmodifiable(_profiles);
bool isEnabled(NodeProfile p) => _enabled.contains(p);
List<NodeProfile> get enabledProfiles =>
_profiles.where(isEnabled).toList(growable: false);
// Initialize profiles from built-in and custom sources
Future<void> init() async {
// Initialize profiles: built-in + custom
_profiles.add(CameraProfile.genericAlpr());
_profiles.add(CameraProfile.flock());
_profiles.add(CameraProfile.motorola());
_profiles.add(CameraProfile.genetec());
_profiles.add(CameraProfile.leonardo());
_profiles.add(CameraProfile.neology());
_profiles.add(CameraProfile.genericGunshotDetector());
_profiles.add(CameraProfile.shotspotter());
_profiles.add(CameraProfile.flockRaven());
_profiles.add(NodeProfile.genericAlpr());
_profiles.add(NodeProfile.flock());
_profiles.add(NodeProfile.motorola());
_profiles.add(NodeProfile.genetec());
_profiles.add(NodeProfile.leonardo());
_profiles.add(NodeProfile.neology());
_profiles.add(NodeProfile.genericGunshotDetector());
_profiles.add(NodeProfile.shotspotter());
_profiles.add(NodeProfile.flockRaven());
_profiles.addAll(await ProfileService().load());
// Load enabled profile IDs from prefs
@@ -42,7 +42,7 @@ class ProfileState extends ChangeNotifier {
}
}
void toggleProfile(CameraProfile p, bool e) {
void toggleProfile(NodeProfile p, bool e) {
if (e) {
_enabled.add(p);
} else {
@@ -57,7 +57,7 @@ class ProfileState extends ChangeNotifier {
notifyListeners();
}
void addOrUpdateProfile(CameraProfile p) {
void addOrUpdateProfile(NodeProfile p) {
final idx = _profiles.indexWhere((x) => x.id == p.id);
if (idx >= 0) {
_profiles[idx] = p;
@@ -70,7 +70,7 @@ class ProfileState extends ChangeNotifier {
notifyListeners();
}
void deleteProfile(CameraProfile p) {
void deleteProfile(NodeProfile p) {
if (!p.editable) return;
_enabled.remove(p);
_profiles.removeWhere((x) => x.id == p.id);
+9 -9
View File
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import '../models/camera_profile.dart';
import '../models/node_profile.dart';
import '../models/operator_profile.dart';
import '../models/osm_camera_node.dart';
// ------------------ AddNodeSession ------------------
class AddNodeSession {
AddNodeSession({required this.profile, this.directionDegrees = 0});
CameraProfile profile;
NodeProfile profile;
OperatorProfile? operatorProfile;
double directionDegrees;
LatLng? target;
@@ -24,7 +24,7 @@ class EditNodeSession {
});
final OsmCameraNode originalNode; // The original node being edited
CameraProfile profile;
NodeProfile profile;
OperatorProfile? operatorProfile;
double directionDegrees;
LatLng target; // Current position (can be dragged)
@@ -38,7 +38,7 @@ class SessionState extends ChangeNotifier {
AddNodeSession? get session => _session;
EditNodeSession? get editSession => _editSession;
void startAddSession(List<CameraProfile> enabledProfiles) {
void startAddSession(List<NodeProfile> enabledProfiles) {
final submittableProfiles = enabledProfiles.where((p) => p.isSubmittable).toList();
final defaultProfile = submittableProfiles.isNotEmpty
? submittableProfiles.first
@@ -48,11 +48,11 @@ class SessionState extends ChangeNotifier {
notifyListeners();
}
void startEditSession(OsmCameraNode node, List<CameraProfile> enabledProfiles) {
void startEditSession(OsmCameraNode node, List<NodeProfile> enabledProfiles) {
final submittableProfiles = enabledProfiles.where((p) => p.isSubmittable).toList();
// Try to find a matching profile based on the node's tags
CameraProfile matchingProfile = submittableProfiles.isNotEmpty
NodeProfile matchingProfile = submittableProfiles.isNotEmpty
? submittableProfiles.first
: enabledProfiles.first;
@@ -74,7 +74,7 @@ class SessionState extends ChangeNotifier {
notifyListeners();
}
bool _profileMatchesTags(CameraProfile profile, Map<String, String> tags) {
bool _profileMatchesTags(NodeProfile profile, Map<String, String> tags) {
// Simple matching: check if all profile tags are present in node tags
for (final entry in profile.tags.entries) {
if (tags[entry.key] != entry.value) {
@@ -86,7 +86,7 @@ class SessionState extends ChangeNotifier {
void updateSession({
double? directionDeg,
CameraProfile? profile,
NodeProfile? profile,
OperatorProfile? operatorProfile,
LatLng? target,
}) {
@@ -114,7 +114,7 @@ class SessionState extends ChangeNotifier {
void updateEditSession({
double? directionDeg,
CameraProfile? profile,
NodeProfile? profile,
OperatorProfile? operatorProfile,
LatLng? target,
}) {