aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Details/DetailsView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp/Details/DetailsView.swift')
-rw-r--r--iosApp/iosApp/Details/DetailsView.swift82
1 files changed, 82 insertions, 0 deletions
diff --git a/iosApp/iosApp/Details/DetailsView.swift b/iosApp/iosApp/Details/DetailsView.swift
new file mode 100644
index 0000000..8e2a6b5
--- /dev/null
+++ b/iosApp/iosApp/Details/DetailsView.swift
@@ -0,0 +1,82 @@
+/**
+ * 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 SwiftUI
+import shared
+
+struct DetailsView: View {
+ @ObservedObject var detailsViewModel = DetailsViewModel()
+
+ @Binding var isPresented: Bool
+ @State var action: DeviceRow.Action
+ var id: Int32
+
+ init(isPresented: Binding<Bool>, action: DeviceRow.Action, forId id: Int32) {
+ self._isPresented = isPresented
+ self.action = action
+ self.id = id
+ detailsViewModel.fetchUnit(id: id)
+ }
+
+ var body: some View {
+ NavigationView {
+ VStack {
+ if let unit = detailsViewModel.unit {
+ switch action {
+ case .details:
+ UnitInformationView(unit: unit)
+ case .reports:
+ UnitReportsView(unit: unit)
+ case .commands:
+ UnitCommandsView(unit: unit)
+ }
+ } else {
+ LoadingView()
+ }
+ }
+ .navigationBarTitleView(
+ Picker(selection: $action) {
+ Text("details").tag(DeviceRow.Action.details)
+ Text("reports").tag(DeviceRow.Action.reports)
+ Text("commands").tag(DeviceRow.Action.commands)
+ } label: {
+ EmptyView()
+ }.pickerStyle(SegmentedPickerStyle())
+ )
+ .navigationTitle(detailsViewModel.unit?.device.name ?? NSLocalizedString("loading", comment: ""))
+ .navigationBarTitleDisplayMode(.large)
+ .toolbar {
+ ToolbarItem(placement: .navigationBarLeading) {
+ if let category = detailsViewModel.unit?.device.category {
+ let type = Marker.companion
+ .categoryToMarkerType(category: category)
+ Image(MarkerTransformations.markerTypeToImageName(markerType: type))
+ } else {
+ EmptyView()
+ }
+ }
+ ToolbarItem(placement: .navigationBarTrailing) {
+ Button {
+ isPresented = false
+ } label: {
+ Text("done").bold()
+ }
+ }
+ }
+ }
+ }
+}