Térképi rétegkezelő lérehozása, track online mentésének előkészítése
This commit is contained in:
+69
-47
@@ -54,6 +54,9 @@ class TrackPoint {
|
||||
|
||||
enum TrackStatus { recording, paused, finished }
|
||||
|
||||
enum TrackSyncMode { localOnly, online }
|
||||
|
||||
enum TrackSyncStatus { pending, synced, error }
|
||||
// ─── Track ───────────────────────────────────────────────────────────────────
|
||||
|
||||
class Track {
|
||||
@@ -68,41 +71,50 @@ class Track {
|
||||
// Statisztikák — ezeket a DB is tárolja a gyors listázáshoz
|
||||
final double distanceMeters;
|
||||
final int pointCount;
|
||||
final TrackSyncMode syncMode;
|
||||
final TrackSyncStatus syncStatus;
|
||||
final String? supabaseId;
|
||||
|
||||
const Track({
|
||||
this.id,
|
||||
this.projectId,
|
||||
required this.name,
|
||||
required this.startTime,
|
||||
this.endTime,
|
||||
this.status = TrackStatus.recording,
|
||||
this.source = 'Telefon GPS',
|
||||
this.distanceMeters = 0,
|
||||
this.pointCount = 0,
|
||||
});
|
||||
const Track(
|
||||
{this.id,
|
||||
this.projectId,
|
||||
required this.name,
|
||||
required this.startTime,
|
||||
this.endTime,
|
||||
this.status = TrackStatus.recording,
|
||||
this.source = 'Telefon GPS',
|
||||
this.distanceMeters = 0,
|
||||
this.pointCount = 0,
|
||||
this.syncMode = TrackSyncMode.online,
|
||||
this.syncStatus = TrackSyncStatus.pending,
|
||||
this.supabaseId});
|
||||
|
||||
Track copyWith({
|
||||
int? id,
|
||||
int? projectId,
|
||||
String? name,
|
||||
DateTime? startTime,
|
||||
DateTime? endTime,
|
||||
TrackStatus? status,
|
||||
String? source,
|
||||
double? distanceMeters,
|
||||
int? pointCount,
|
||||
}) =>
|
||||
Track copyWith(
|
||||
{int? id,
|
||||
int? projectId,
|
||||
String? name,
|
||||
DateTime? startTime,
|
||||
DateTime? endTime,
|
||||
TrackStatus? status,
|
||||
String? source,
|
||||
double? distanceMeters,
|
||||
int? pointCount,
|
||||
TrackSyncMode? syncMode,
|
||||
TrackSyncStatus? syncStatus,
|
||||
String? supabaseId}) =>
|
||||
Track(
|
||||
id: id ?? this.id,
|
||||
projectId: projectId ?? this.projectId,
|
||||
name: name ?? this.name,
|
||||
startTime: startTime ?? this.startTime,
|
||||
endTime: endTime ?? this.endTime,
|
||||
status: status ?? this.status,
|
||||
source: source ?? this.source,
|
||||
distanceMeters: distanceMeters ?? this.distanceMeters,
|
||||
pointCount: pointCount ?? this.pointCount,
|
||||
);
|
||||
id: id ?? this.id,
|
||||
projectId: projectId ?? this.projectId,
|
||||
name: name ?? this.name,
|
||||
startTime: startTime ?? this.startTime,
|
||||
endTime: endTime ?? this.endTime,
|
||||
status: status ?? this.status,
|
||||
source: source ?? this.source,
|
||||
distanceMeters: distanceMeters ?? this.distanceMeters,
|
||||
pointCount: pointCount ?? this.pointCount,
|
||||
syncMode: syncMode ?? this.syncMode,
|
||||
syncStatus: syncStatus ?? this.syncStatus,
|
||||
supabaseId: supabaseId ?? this.supabaseId);
|
||||
|
||||
/// Formázott időtartam (óó:pp:mm)
|
||||
String get durationFormatted {
|
||||
@@ -132,24 +144,34 @@ class Track {
|
||||
'source': source,
|
||||
'distance_m': distanceMeters,
|
||||
'point_count': pointCount,
|
||||
'is_local_only': syncMode == TrackSyncMode.localOnly ? 1 : 0,
|
||||
'sync_status': syncStatus.name,
|
||||
'supabase_id': supabaseId,
|
||||
};
|
||||
|
||||
factory Track.fromMap(Map<String, dynamic> m) => Track(
|
||||
id: m['id'] as int?,
|
||||
projectId: m['project_id'] as int?,
|
||||
name: m['name'] as String,
|
||||
startTime: DateTime.parse(m['start_time'] as String),
|
||||
endTime: m['end_time'] != null
|
||||
? DateTime.parse(m['end_time'] as String)
|
||||
: null,
|
||||
status: TrackStatus.values.firstWhere(
|
||||
(s) => s.name == (m['status'] as String?),
|
||||
orElse: () => TrackStatus.finished,
|
||||
),
|
||||
source: m['source'] as String? ?? 'Telefon GPS',
|
||||
distanceMeters: (m['distance_m'] as num?)?.toDouble() ?? 0,
|
||||
pointCount: m['point_count'] as int? ?? 0,
|
||||
);
|
||||
id: m['id'] as int?,
|
||||
projectId: m['project_id'] as int?,
|
||||
name: m['name'] as String,
|
||||
startTime: DateTime.parse(m['start_time'] as String),
|
||||
endTime: m['end_time'] != null
|
||||
? DateTime.parse(m['end_time'] as String)
|
||||
: null,
|
||||
status: TrackStatus.values.firstWhere(
|
||||
(s) => s.name == (m['status'] as String?),
|
||||
orElse: () => TrackStatus.finished,
|
||||
),
|
||||
source: m['source'] as String? ?? 'Telefon GPS',
|
||||
distanceMeters: (m['distance_m'] as num?)?.toDouble() ?? 0,
|
||||
pointCount: m['point_count'] as int? ?? 0,
|
||||
syncMode: (m['is_local_only'] as int?) == 1
|
||||
? TrackSyncMode.localOnly
|
||||
: TrackSyncMode.online,
|
||||
syncStatus: TrackSyncStatus.values
|
||||
.byName(m['sync_status'] as String? ?? 'pending'),
|
||||
supabaseId: m['supabase_id'] as String?);
|
||||
|
||||
bool get isLocalOnly => syncMode == TrackSyncMode.localOnly;
|
||||
}
|
||||
|
||||
// ─── Segédszámítás: Haversine távolság ───────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user