Displaying events on map and list
This commit is contained in:
parent
bf96c0cc4f
commit
b0718aadf1
@ -116,6 +116,8 @@
|
|||||||
7A71580C2C44453200852088 /* AdsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71580B2C44453200852088 /* AdsScreen.swift */; };
|
7A71580C2C44453200852088 /* AdsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71580B2C44453200852088 /* AdsScreen.swift */; };
|
||||||
7A71580E2C4445A200852088 /* AdsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71580D2C4445A200852088 /* AdsCoordinator.swift */; };
|
7A71580E2C4445A200852088 /* AdsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71580D2C4445A200852088 /* AdsCoordinator.swift */; };
|
||||||
7A7158122C444A6400852088 /* AdsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7158112C444A6400852088 /* AdsViewModel.swift */; };
|
7A7158122C444A6400852088 /* AdsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7158112C444A6400852088 /* AdsViewModel.swift */; };
|
||||||
|
7A71EF552D0A208F00943129 /* MarkerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71EF542D0A208F00943129 /* MarkerModel.swift */; };
|
||||||
|
7A71EF572D0A26B200943129 /* EventModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A71EF562D0A26B200943129 /* EventModel.swift */; };
|
||||||
7A7547E024032CB6004E8406 /* VehiclePhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */; };
|
7A7547E024032CB6004E8406 /* VehiclePhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */; };
|
||||||
7A761C042677F18E0005F28F /* ApiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A11474323FF06CA00B424AF /* ApiService.swift */; };
|
7A761C042677F18E0005F28F /* ApiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A11474323FF06CA00B424AF /* ApiService.swift */; };
|
||||||
7A761C052677F1BC0005F28F /* CocoaError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A27ADF824A09CAD0035F39E /* CocoaError.swift */; };
|
7A761C052677F1BC0005F28F /* CocoaError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A27ADF824A09CAD0035F39E /* CocoaError.swift */; };
|
||||||
@ -391,6 +393,8 @@
|
|||||||
7A71580B2C44453200852088 /* AdsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsScreen.swift; sourceTree = "<group>"; };
|
7A71580B2C44453200852088 /* AdsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsScreen.swift; sourceTree = "<group>"; };
|
||||||
7A71580D2C4445A200852088 /* AdsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsCoordinator.swift; sourceTree = "<group>"; };
|
7A71580D2C4445A200852088 /* AdsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsCoordinator.swift; sourceTree = "<group>"; };
|
||||||
7A7158112C444A6400852088 /* AdsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsViewModel.swift; sourceTree = "<group>"; };
|
7A7158112C444A6400852088 /* AdsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsViewModel.swift; sourceTree = "<group>"; };
|
||||||
|
7A71EF542D0A208F00943129 /* MarkerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkerModel.swift; sourceTree = "<group>"; };
|
||||||
|
7A71EF562D0A26B200943129 /* EventModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventModel.swift; sourceTree = "<group>"; };
|
||||||
7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclePhotoCell.swift; sourceTree = "<group>"; };
|
7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclePhotoCell.swift; sourceTree = "<group>"; };
|
||||||
7A761C0A267E8FF90005F28F /* Error.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
7A761C0A267E8FF90005F28F /* Error.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
||||||
7A813DBD2506A57100CC93B9 /* AuthenticationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AuthenticationServices.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AuthenticationServices.framework; sourceTree = DEVELOPER_DIR; };
|
7A813DBD2506A57100CC93B9 /* AuthenticationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AuthenticationServices.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AuthenticationServices.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
@ -987,6 +991,8 @@
|
|||||||
7AB9FE252D08C2D7005DE374 /* EventsCoordinator.swift */,
|
7AB9FE252D08C2D7005DE374 /* EventsCoordinator.swift */,
|
||||||
7AB9FE272D08C2F4005DE374 /* EventsViewModel.swift */,
|
7AB9FE272D08C2F4005DE374 /* EventsViewModel.swift */,
|
||||||
7AB9FE292D08CF35005DE374 /* EventsScreenMode.swift */,
|
7AB9FE292D08CF35005DE374 /* EventsScreenMode.swift */,
|
||||||
|
7A71EF542D0A208F00943129 /* MarkerModel.swift */,
|
||||||
|
7A71EF562D0A26B200943129 /* EventModel.swift */,
|
||||||
);
|
);
|
||||||
path = EventsScreen;
|
path = EventsScreen;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1361,6 +1367,7 @@
|
|||||||
7A659B5B24A3768A0043A0F2 /* Substrings.swift in Sources */,
|
7A659B5B24A3768A0043A0F2 /* Substrings.swift in Sources */,
|
||||||
7A71580E2C4445A200852088 /* AdsCoordinator.swift in Sources */,
|
7A71580E2C4445A200852088 /* AdsCoordinator.swift in Sources */,
|
||||||
7AFBE8CA2C3081C7003C491D /* ACProgressHud+Modifiers.swift in Sources */,
|
7AFBE8CA2C3081C7003C491D /* ACProgressHud+Modifiers.swift in Sources */,
|
||||||
|
7A71EF572D0A26B200943129 /* EventModel.swift in Sources */,
|
||||||
7AABBE3B2CF9F85600346588 /* Binding+Map.swift in Sources */,
|
7AABBE3B2CF9F85600346588 /* Binding+Map.swift in Sources */,
|
||||||
7A27ADF7249FEF690035F39E /* Recorder.swift in Sources */,
|
7A27ADF7249FEF690035F39E /* Recorder.swift in Sources */,
|
||||||
7A1E78F62CE900330004B740 /* ReportScreen.swift in Sources */,
|
7A1E78F62CE900330004B740 /* ReportScreen.swift in Sources */,
|
||||||
@ -1412,6 +1419,7 @@
|
|||||||
7ABD1B472D044A3200B43213 /* GalleryScreen.swift in Sources */,
|
7ABD1B472D044A3200B43213 /* GalleryScreen.swift in Sources */,
|
||||||
7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */,
|
7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */,
|
||||||
7A71580C2C44453200852088 /* AdsScreen.swift in Sources */,
|
7A71580C2C44453200852088 /* AdsScreen.swift in Sources */,
|
||||||
|
7A71EF552D0A208F00943129 /* MarkerModel.swift in Sources */,
|
||||||
7A06E0B02C7065D8005731AC /* SettingsCoordinator.swift in Sources */,
|
7A06E0B02C7065D8005731AC /* SettingsCoordinator.swift in Sources */,
|
||||||
7A91894F29A2BD8700519C74 /* GestureRecognizers.swift in Sources */,
|
7A91894F29A2BD8700519C74 /* GestureRecognizers.swift in Sources */,
|
||||||
7AFBE8CC2C3085C6003C491D /* ACProgressView.swift in Sources */,
|
7AFBE8CC2C3085C6003C491D /* ACProgressView.swift in Sources */,
|
||||||
|
|||||||
17
AutoCat/Screens/EventsScreen/EventModel.swift
Normal file
17
AutoCat/Screens/EventsScreen/EventModel.swift
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// EventModel.swift
|
||||||
|
// AutoCat
|
||||||
|
//
|
||||||
|
// Created by Selim Mustafaev on 11.12.2024.
|
||||||
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct EventModel: Identifiable {
|
||||||
|
|
||||||
|
let id = UUID()
|
||||||
|
var address: String
|
||||||
|
var marker: MarkerModel
|
||||||
|
var isMe: Bool
|
||||||
|
}
|
||||||
@ -36,11 +36,33 @@ struct EventsScreen: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var map: some View {
|
var map: some View {
|
||||||
Map {}
|
Map {
|
||||||
|
ForEach(viewModel.events.map(\.marker)) {
|
||||||
|
Marker($0.date, coordinate: $0.coordinate)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var list: some View {
|
var list: some View {
|
||||||
List {}
|
List {
|
||||||
|
ForEach(viewModel.events) { event in
|
||||||
|
makeEventCell(for: event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.listStyle(.inset)
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeEventCell(for event: EventModel) -> some View {
|
||||||
|
HStack {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(event.address)
|
||||||
|
Text(event.marker.date)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: event.isMe ? "person.fill" : "person")
|
||||||
|
.foregroundStyle(event.isMe ? Color.accentColor : .secondary)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import AutoCatCore
|
import AutoCatCore
|
||||||
|
import CoreLocation
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
@Observable
|
@Observable
|
||||||
@ -15,13 +16,37 @@ class EventsViewModel {
|
|||||||
|
|
||||||
@ObservationIgnored @Service var api: ApiServiceProtocol
|
@ObservationIgnored @Service var api: ApiServiceProtocol
|
||||||
@ObservationIgnored @Service var storageService: StorageServiceProtocol
|
@ObservationIgnored @Service var storageService: StorageServiceProtocol
|
||||||
|
@ObservationIgnored @Service var settingsService: SettingsServiceProtocol
|
||||||
|
|
||||||
|
var hud: ACHud?
|
||||||
|
|
||||||
var vehicle: VehicleDto
|
var vehicle: VehicleDto
|
||||||
var mode: EventsScreenMode = .map
|
var mode: EventsScreenMode = .map
|
||||||
var hud: ACHud?
|
var events: [EventModel] = []
|
||||||
|
|
||||||
init(vehicle: VehicleDto) {
|
init(vehicle: VehicleDto) {
|
||||||
|
|
||||||
self.vehicle = vehicle
|
self.vehicle = vehicle
|
||||||
|
updateEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateEvents() {
|
||||||
|
|
||||||
|
events = vehicle.events.map { event in
|
||||||
|
|
||||||
|
EventModel(
|
||||||
|
address: event.address ?? "Lat: \(event.latitude), Lon: \(event.longitude)",
|
||||||
|
marker: makeMarkerModel(from: event),
|
||||||
|
isMe: event.addedBy == settingsService.user.email
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeMarkerModel(from event: VehicleEventDto) -> MarkerModel {
|
||||||
|
|
||||||
|
let date = Date(timeIntervalSince1970: event.date)
|
||||||
|
let dateString = Formatters.marker.string(from: date)
|
||||||
|
let coordinate = CLLocationCoordinate2DMake(event.latitude, event.longitude)
|
||||||
|
return MarkerModel(date: dateString, coordinate: coordinate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
AutoCat/Screens/EventsScreen/MarkerModel.swift
Normal file
16
AutoCat/Screens/EventsScreen/MarkerModel.swift
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// MarkerModel.swift
|
||||||
|
// AutoCat
|
||||||
|
//
|
||||||
|
// Created by Selim Mustafaev on 11.12.2024.
|
||||||
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import CoreLocation
|
||||||
|
|
||||||
|
struct MarkerModel: Identifiable {
|
||||||
|
|
||||||
|
let id = UUID()
|
||||||
|
var date: String
|
||||||
|
var coordinate: CLLocationCoordinate2D
|
||||||
|
}
|
||||||
@ -16,4 +16,11 @@ struct Formatters {
|
|||||||
formatter.timeStyle = .medium
|
formatter.timeStyle = .medium
|
||||||
return formatter
|
return formatter
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
static let marker: DateFormatter = {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateStyle = .medium
|
||||||
|
formatter.timeStyle = .short
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user