Adding some context actions for audio records
This commit is contained in:
parent
d2dcdbff9d
commit
ecf64d3280
@ -17,6 +17,7 @@ struct AudioRecordViewModel: Identifiable {
|
||||
var number: String?
|
||||
var date: String
|
||||
var onPlay: () -> Void
|
||||
var url: URL?
|
||||
|
||||
init(dto: AudioRecordDto, isPlaying: Bool = false, onPlay: @escaping () -> Void) {
|
||||
|
||||
@ -28,5 +29,6 @@ struct AudioRecordViewModel: Identifiable {
|
||||
)
|
||||
self.isPlaying = isPlaying
|
||||
self.onPlay = onPlay
|
||||
self.url = try? FileManager.default.url(for: dto.path, in: Constants.audioRecordsFolder)
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,8 @@ final class RecordsCoordinator {
|
||||
recordPlayer: resolver.resolve(RecordPlayerServiceProtocol.self)
|
||||
)
|
||||
|
||||
viewModel.coordinator = self
|
||||
|
||||
let view = RecordsScreen(viewModel: viewModel)
|
||||
let controller = UIHostingController(rootView: view)
|
||||
|
||||
@ -31,4 +33,12 @@ final class RecordsCoordinator {
|
||||
self.navController = navController
|
||||
return navController
|
||||
}
|
||||
|
||||
func showOnMap(event: VehicleEventDto) {
|
||||
|
||||
let controller = ShowEventController()
|
||||
controller.event = event
|
||||
controller.hidesBottomBarWhenPushed = true
|
||||
navController.pushViewController(controller, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,14 @@ struct RecordsScreen: View {
|
||||
@ViewBuilder
|
||||
func makeActions(for record: AudioRecordViewModel, useLabels: Bool = false) -> some View {
|
||||
|
||||
if useLabels {
|
||||
makeMenuActions(for: record)
|
||||
}
|
||||
|
||||
if let url = record.url {
|
||||
ShareLink(item: url)
|
||||
}
|
||||
|
||||
Button {
|
||||
selectedRecordId = record.id
|
||||
numberText = record.number ?? ""
|
||||
@ -77,4 +85,20 @@ struct RecordsScreen: View {
|
||||
Label(useLabels ? "Delete" : "", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func makeMenuActions(for record: AudioRecordViewModel) -> some View {
|
||||
|
||||
Button {
|
||||
viewModel.showRawRecognizedText(id: record.id)
|
||||
} label: {
|
||||
Label("Show recognized text", systemImage: "textformat")
|
||||
}
|
||||
|
||||
Button {
|
||||
viewModel.showOnMap(id: record.id)
|
||||
} label: {
|
||||
Label("Show on map", systemImage: "map")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ final class RecordsViewModel: ACHudContainer {
|
||||
let recordService: VehicleRecordServiceProtocol
|
||||
let storageService: StorageServiceProtocol
|
||||
let recordPlayer: RecordPlayerServiceProtocol
|
||||
var coordinator: RecordsCoordinator?
|
||||
|
||||
var hud: ACHud?
|
||||
var showRecordingAlert: Bool = false
|
||||
@ -103,4 +104,22 @@ final class RecordsViewModel: ACHudContainer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func showRawRecognizedText(id: String) {
|
||||
guard let record = records.first(where: { $0.id == id }) else {
|
||||
return
|
||||
}
|
||||
|
||||
hud = .message(record.rawText)
|
||||
}
|
||||
|
||||
func showOnMap(id: String) {
|
||||
guard let record = records.first(where: { $0.id == id }),
|
||||
let event = record.event
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
coordinator?.showOnMap(event: event)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user