mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-08-23 19:32:35 +02:00
add submitted cameras to cache immediately
This commit is contained in:
+30
-6
@@ -6,10 +6,13 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
|
|
||||||
import 'models/camera_profile.dart';
|
import 'models/camera_profile.dart';
|
||||||
import 'models/pending_upload.dart';
|
import 'models/pending_upload.dart';
|
||||||
|
import 'models/osm_camera_node.dart';
|
||||||
import 'services/auth_service.dart';
|
import 'services/auth_service.dart';
|
||||||
import 'services/uploader.dart';
|
import 'services/uploader.dart';
|
||||||
import 'services/profile_service.dart';
|
import 'services/profile_service.dart';
|
||||||
|
import 'services/camera_cache.dart';
|
||||||
import 'widgets/tile_provider_with_cache.dart';
|
import 'widgets/tile_provider_with_cache.dart';
|
||||||
|
import 'widgets/camera_provider_with_cache.dart';
|
||||||
|
|
||||||
// Enum for upload mode (Production, OSM Sandbox, Simulate)
|
// Enum for upload mode (Production, OSM Sandbox, Simulate)
|
||||||
enum UploadMode { production, sandbox, simulate }
|
enum UploadMode { production, sandbox, simulate }
|
||||||
@@ -351,14 +354,35 @@ class AppState extends ChangeNotifier {
|
|||||||
|
|
||||||
void commitSession() {
|
void commitSession() {
|
||||||
if (_session?.target == null) return;
|
if (_session?.target == null) return;
|
||||||
_queue.add(
|
|
||||||
PendingUpload(
|
// Create the pending upload
|
||||||
coord: _session!.target!,
|
final upload = PendingUpload(
|
||||||
direction: _session!.directionDegrees,
|
coord: _session!.target!,
|
||||||
profile: _session!.profile,
|
direction: _session!.directionDegrees,
|
||||||
),
|
profile: _session!.profile,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_queue.add(upload);
|
||||||
_saveQueue();
|
_saveQueue();
|
||||||
|
|
||||||
|
// Add to camera cache immediately so it shows on the map
|
||||||
|
// Create a temporary node with a negative ID (to distinguish from real OSM nodes)
|
||||||
|
// Using timestamp as negative ID to ensure uniqueness
|
||||||
|
final tempId = -DateTime.now().millisecondsSinceEpoch;
|
||||||
|
final tags = Map<String, String>.from(upload.profile.tags);
|
||||||
|
tags['direction'] = upload.direction.toStringAsFixed(0);
|
||||||
|
tags['_pending_upload'] = 'true'; // Mark as pending for potential UI distinction
|
||||||
|
|
||||||
|
final tempNode = OsmCameraNode(
|
||||||
|
id: tempId,
|
||||||
|
coord: upload.coord,
|
||||||
|
tags: tags,
|
||||||
|
);
|
||||||
|
|
||||||
|
CameraCache.instance.addOrUpdate([tempNode]);
|
||||||
|
// Notify camera provider to update the map
|
||||||
|
CameraProviderWithCache.instance.notifyListeners();
|
||||||
|
|
||||||
_session = null;
|
_session = null;
|
||||||
|
|
||||||
// Restart uploader when new items are added
|
// Restart uploader when new items are added
|
||||||
|
|||||||
Reference in New Issue
Block a user