aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp')
-rw-r--r--iosApp/iosApp/Details/Commands/UnitCommandsView.swift25
-rw-r--r--iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift46
-rw-r--r--iosApp/iosApp/Details/Information/UnitInformationView.swift146
-rw-r--r--iosApp/iosApp/Localizable.strings4
-rw-r--r--iosApp/iosApp/Shared/Utils.swift7
-rw-r--r--iosApp/iosApp/iOSApp.swift6
6 files changed, 167 insertions, 67 deletions
diff --git a/iosApp/iosApp/Details/Commands/UnitCommandsView.swift b/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
index fade29b..9e4b280 100644
--- a/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
+++ b/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
@@ -19,10 +19,31 @@ import SwiftUI
import shared
struct UnitCommandsView: View {
+ @ObservedObject var unitCommandsViewModel = UnitCommandsViewModel()
+
var unit: UnitInformation
+ init(unit: UnitInformation) {
+ self.unit = unit
+ unitCommandsViewModel.fetchCommands(id: unit.device.id)
+ }
+
var body: some View {
-
- Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+ VStack {
+ List {
+ Picker("commands", selection: $unitCommandsViewModel.selectedId) {
+ ForEach(unitCommandsViewModel.commands, id: \.id) { command in
+ Text(command.description_ ?? "\(command.id!)")
+ .tag(Int(truncating: command.id!))
+ }
+ }.pickerStyle(InlinePickerStyle())
+
+ Button {
+ unitCommandsViewModel.sendCommand()
+ } label: {
+ Label("send-command", systemImage: "paperplane")
+ }
+ }
+ }
}
}
diff --git a/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift b/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift
new file mode 100644
index 0000000..aac82c9
--- /dev/null
+++ b/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift
@@ -0,0 +1,46 @@
+/**
+ * TrackerMap
+ * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import Foundation
+import shared
+
+class UnitCommandsViewModel: ObservableObject {
+ @Inject var commandsController: CommandsController
+
+ @Published var commands = [Command]()
+ @Published var selected: Command?
+ @Published var selectedId: Int = 0 {
+ didSet {
+ selected = commands.first(where: {
+ Int(truncating: $0.id!) == selectedId
+ })
+ }
+ }
+
+ func fetchCommands(id: Int32) {
+ commandsController.fetchCommands(deviceId: id) { commands, error in
+ print("We've got the commands! \(commands ?? [])")
+ self.commands = commands ?? []
+ }
+ }
+
+ func sendCommand() {
+ if let command = selected {
+ commandsController.sendCommand(command: command) { _, error in }
+ }
+ }
+}
diff --git a/iosApp/iosApp/Details/Information/UnitInformationView.swift b/iosApp/iosApp/Details/Information/UnitInformationView.swift
index 3a52b84..f713ab4 100644
--- a/iosApp/iosApp/Details/Information/UnitInformationView.swift
+++ b/iosApp/iosApp/Details/Information/UnitInformationView.swift
@@ -23,80 +23,96 @@ struct UnitInformationView: View {
var body: some View {
List {
- // MARK: - Contact
- if let contact = unit.device.contact {
- HStack {
- Text("contact")
- Spacer()
- Text(contact).foregroundColor(.secondaryLabel)
+ Section {
+ // MARK: - Contact
+ if let contact = unit.device.contact {
+ HStack {
+ Text("contact")
+ Spacer()
+ Text(contact).foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Unique ID
- if let uniqueId = unit.device.uniqueId {
- HStack {
- Text("unique-id")
- Spacer()
- Text(uniqueId).foregroundColor(.secondaryLabel)
+ // MARK: - Unique ID
+ if let uniqueId = unit.device.uniqueId {
+ HStack {
+ Text("unique-id")
+ Spacer()
+ Text(uniqueId).foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Date time
- if let datetime = unit.position?.fixTime {
- HStack {
- Text("datetime")
- Spacer()
- Text(Formatter.companion.formatDate(str: datetime))
- .foregroundColor(.secondaryLabel)
+ // MARK: - Date time
+ if let datetime = unit.position?.fixTime {
+ HStack {
+ Text("datetime")
+ Spacer()
+ Text(Formatter.companion.formatDate(str: datetime))
+ .foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Latitude
- if let latitude = unit.position?.latitude {
- HStack {
- Text("latitude")
- Spacer()
- Text("\(latitude)").foregroundColor(.secondaryLabel)
+ // MARK: - Latitude
+ if let latitude = unit.position?.latitude {
+ HStack {
+ Text("latitude")
+ Spacer()
+ Text("\(latitude)").foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Longitude
- if let longitude = unit.position?.longitude {
- HStack {
- Text("longitude")
- Spacer()
- Text("\(longitude)").foregroundColor(.secondaryLabel)
+ // MARK: - Longitude
+ if let longitude = unit.position?.longitude {
+ HStack {
+ Text("longitude")
+ Spacer()
+ Text("\(longitude)").foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Speed
- if let speed = unit.position?.speed {
- HStack {
- Text("speed")
- Spacer()
- Text(Formatter.companion.formatSpeed(
- speed: Double(truncating: speed), unit: .kmh))
- .foregroundColor(.secondaryLabel)
+ // MARK: - Speed
+ if let speed = unit.position?.speed {
+ HStack {
+ Text("speed")
+ Spacer()
+ Text(Formatter.companion.formatSpeed(
+ speed: Double(truncating: speed), unit: .kmh))
+ .foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Address
- if let address = unit.position?.address {
- HStack {
- Text("address")
- Spacer()
- Text(address).foregroundColor(.secondaryLabel)
+ // MARK: - Address
+ if let address = unit.position?.address {
+ HStack {
+ Text("address")
+ Spacer()
+ Text(address).foregroundColor(.secondaryLabel)
+ }
}
- }
- // MARK: - Hours
- if let hours = unit.getHourmeter() {
- HStack {
- Text("hourmeter")
- Spacer()
- Text(Formatter.companion.formatHours(millis: Int64(truncating: hours)))
- .foregroundColor(.secondaryLabel)
+ // MARK: - Hours
+ if let hours = unit.getHourmeter() {
+ HStack {
+ Text("hourmeter")
+ Spacer()
+ Text(Formatter.companion.formatHours(millis: Int64(truncating: hours)))
+ .foregroundColor(.secondaryLabel)
+ }
+ }
+ // MARK: - Protocol
+ if let protocol_ = unit.position?.protocol {
+ HStack {
+ Text("protocol")
+ Spacer()
+ Text(protocol_).foregroundColor(.secondaryLabel)
+ }
}
}
- // MARK: - Protocol
- if let protocol_ = unit.position?.protocol {
- HStack {
- Text("protocol")
- Spacer()
- Text(protocol_).foregroundColor(.secondaryLabel)
+ Section {
+ Button {
+ if let longitude = unit.position?.longitude,
+ let latitude = unit.position?.latitude,
+ let url = Utils.getMapsURL(longitude: Float(truncating: longitude),
+ latitude: Float(truncating: latitude)) {
+ if UIApplication.shared.canOpenURL(url) {
+ UIApplication.shared.open(url, options: [:])
+ }
+ }
+ } label: {
+ Label("open-location-browser", systemImage: "globe")
}
}
}
diff --git a/iosApp/iosApp/Localizable.strings b/iosApp/iosApp/Localizable.strings
index 9013574..4d1e1f2 100644
--- a/iosApp/iosApp/Localizable.strings
+++ b/iosApp/iosApp/Localizable.strings
@@ -48,3 +48,7 @@
"address" = "Address";
"hourmeter" = "Hourmeter";
"protocol" = "Protocol";
+"open-location-browser" = "Open location in browser";
+"maps-url-template" = "https://www.google.com/maps/place/{y},{x}?z=19";
+
+"send-command" = "Send command";
diff --git a/iosApp/iosApp/Shared/Utils.swift b/iosApp/iosApp/Shared/Utils.swift
index 9b473a5..61a8f90 100644
--- a/iosApp/iosApp/Shared/Utils.swift
+++ b/iosApp/iosApp/Shared/Utils.swift
@@ -38,4 +38,11 @@ class Utils {
tileInfo.cacheDir = thisCacheDir
return tileInfo
}
+
+ static func getMapsURL(longitude: Float, latitude: Float) -> URL? {
+ let template = NSLocalizedString("maps-url-template", comment: "")
+ return URL(string: template
+ .replacingOccurrences(of: "{x}", with: "\(latitude)")
+ .replacingOccurrences(of: "{y}", with: "\(longitude)"))
+ }
}
diff --git a/iosApp/iosApp/iOSApp.swift b/iosApp/iosApp/iOSApp.swift
index 6bf6710..338c06b 100644
--- a/iosApp/iosApp/iOSApp.swift
+++ b/iosApp/iosApp/iOSApp.swift
@@ -49,6 +49,9 @@ struct iOSApp: App {
Resolver.shared.add(GeofencesApi.self) { resolver in
return GeofencesApi(sessionManager: resolver.resolve())
}
+ Resolver.shared.add(CommandsApi.self) { resolver in
+ return CommandsApi(sessionManager: resolver.resolve())
+ }
Resolver.shared.add(SessionController.self) { resolver in
return SessionController(sessionApi: resolver.resolve(), usersApi: resolver.resolve())
}
@@ -61,6 +64,9 @@ struct iOSApp: App {
Resolver.shared.add(ReportController.self) { resolver in
return ReportController(reportsApi: resolver.resolve(), geofencesApi: resolver.resolve())
}
+ Resolver.shared.add(CommandsController.self) { resolver in
+ return CommandsController(commandsApi: resolver.resolve())
+ }
}
var body: some Scene {