Ivan Valkou 5 lat temu
rodzic
commit
e0d186fa03

+ 1 - 12
FreeAPS/Sources/Modules/AuthotizedRoot/AuthotizedRootDataFlow.swift

@@ -1,18 +1,7 @@
 import SwiftUI
 
 enum AuthotizedRoot {
-    enum Config {
-        static let initialTab = 0
-    }
-
-    struct Tab: Identifiable {
-        let rootScreen: Screen
-        let view: AnyView
-        let image: Image
-        let text: Text
-
-        var id: Int { rootScreen.id }
-    }
+    enum Config {}
 }
 
 protocol AuthotizedRootProvider: Provider {}

+ 3 - 17
FreeAPS/Sources/Modules/AuthotizedRoot/AuthotizedRootViewModel.swift

@@ -3,24 +3,10 @@ import Swinject
 
 extension AuthotizedRoot {
     class ViewModel<Provider>: BaseViewModel<Provider>, ObservableObject where Provider: AuthotizedRootProvider {
-        @Published private(set) var tabs: [Tab] = []
-        @Published var selectedTab = Config.initialTab
-        @Published private(set) var isAuthotized = true
+        override func subscribe() {}
 
-        required init(provider: Provider, resolver: Resolver) {
-            super.init(provider: provider, resolver: resolver)
-            setupTabs()
-        }
-
-        private func setupTabs() {
-            tabs = router.tabs.map { $0.tab(resolver: self.resolver) }
-        }
-
-        override func subscribe() {
-            router.selectTab
-                .receive(on: RunLoop.main)
-                .assign(to: \.selectedTab, on: self)
-                .store(in: &lifetime)
+        var rootView: some View {
+            router.view(for: .home)
         }
     }
 }

+ 2 - 13
FreeAPS/Sources/Modules/AuthotizedRoot/View/AuthotizedRootRootView.swift

@@ -5,19 +5,8 @@ extension AuthotizedRoot {
         @EnvironmentObject var viewModel: ViewModel<Provider>
 
         var body: some View {
-            TabView(selection: $viewModel.selectedTab) {
-                ForEach(viewModel.tabs) { tab in
-                    NavigationView {
-                        tab.view
-                    }
-                    .tabItem {
-                        VStack {
-                            tab.image
-                            tab.text
-                        }
-                    }
-                    .tag(tab.id)
-                }
+            NavigationView {
+                viewModel.rootView
             }
         }
     }

+ 0 - 1
FreeAPS/Sources/Modules/BasalProfileEditor/View/BasalProfileEditorRootView.swift

@@ -40,7 +40,6 @@ extension BasalProfileEditor {
             .navigationTitle("Basal Profile")
             .navigationBarTitleDisplayMode(.automatic)
             .navigationBarItems(
-                leading: Button("Close", action: viewModel.hideModal),
                 trailing: EditButton()
             )
             .environment(\.editMode, $editMode)

+ 2 - 2
FreeAPS/Sources/Modules/Base/BaseViewModel.swift

@@ -29,10 +29,10 @@ class BaseViewModel<Provider>: ViewModel, Injectable where Provider: FreeAPS.Pro
     }
 
     func showModal(for screen: Screen?) {
-        router.modalScreen.send(screen)
+        router.mainModalScreen.send(screen)
     }
 
     func hideModal() {
-        router.modalScreen.send(nil)
+        router.mainModalScreen.send(nil)
     }
 }

+ 0 - 1
FreeAPS/Sources/Modules/CREditor/View/CREditorRootView.swift

@@ -35,7 +35,6 @@ extension CREditor {
             .navigationTitle("Carb Ratios")
             .navigationBarTitleDisplayMode(.automatic)
             .navigationBarItems(
-                leading: Button("Close", action: viewModel.hideModal),
                 trailing: EditButton()
             )
             .environment(\.editMode, $editMode)

+ 0 - 1
FreeAPS/Sources/Modules/ConfigEditor/View/ConfigEditorRootView.swift

@@ -22,7 +22,6 @@ extension ConfigEditor {
                     }
                 }
                 .navigationBarItems(
-                    leading: Button("Close", action: viewModel.hideModal),
                     trailing: Button("Save", action: viewModel.save)
                 )
                 .sheet(isPresented: $showShareSheet) {

+ 4 - 0
FreeAPS/Sources/Modules/Home/HomeViewModel.swift

@@ -34,6 +34,10 @@ extension Home {
         func bolus() {
             showModal(for: .bolus)
         }
+
+        func settings() {
+            showModal(for: .settings)
+        }
     }
 }
 

+ 48 - 19
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -5,26 +5,55 @@ extension Home {
         @EnvironmentObject var viewModel: ViewModel<Provider>
 
         var body: some View {
-            Form {
-                GlucoseChartView(glucose: $viewModel.glucose, suggestion: $viewModel.suggestion).frame(height: 150)
-                if let reason = viewModel.suggestion?.reason {
-                    Text(reason).font(.caption)
-                }
-                Button(action: viewModel.addCarbs) {
-                    Text("Add carbs")
-                }
-                Button(action: viewModel.addTempTarget) {
-                    Text("Add temp target")
-                }
-                Button(action: viewModel.bolus) {
-                    Text("Bolus")
-                }
-                Button(action: viewModel.manualTampBasal) {
-                    Text("Manual temp basal")
-                }
-                Button(action: viewModel.runLoop) {
-                    Text("Run loop now")
+            GeometryReader { geo in
+                VStack {
+                    Group {
+                        Text("Header")
+                    }
+                    ScrollView(.vertical, showsIndicators: false) {
+                        GlucoseChartView(glucose: $viewModel.glucose, suggestion: $viewModel.suggestion).frame(height: 150)
+                        if let reason = viewModel.suggestion?.reason {
+                            Text(reason).font(.caption).padding()
+                        }
+                        Button(action: viewModel.runLoop) {
+                            Text("Run loop now").buttonBackground().padding()
+                        }.foregroundColor(.white)
+                    }
+
+                    ZStack {
+                        Rectangle().fill(Color.gray.opacity(0.2)).frame(height: 50 + geo.safeAreaInsets.bottom)
+
+                        HStack {
+                            Button { viewModel.showModal(for: .addCarbs) }
+                            label: {
+                                Image(systemName: "circlebadge.2.fill")
+                            }.foregroundColor(.green)
+                            Spacer()
+                            Button { viewModel.showModal(for: .addTempTarget) }
+                            label: {
+                                Image(systemName: "target")
+                            }.foregroundColor(.green)
+                            Spacer()
+                            Button { viewModel.showModal(for: .bolus) }
+                            label: {
+                                Image(systemName: "drop.fill")
+                            }.foregroundColor(.orange)
+                            Spacer()
+                            Button { viewModel.showModal(for: .manualTempBasal) }
+                            label: {
+                                Image(systemName: "circle.bottomhalf.fill")
+                            }.foregroundColor(.blue)
+                            Spacer()
+                            Button { viewModel.showModal(for: .settings) }
+                            label: {
+                                Image(systemName: "gearshape")
+                            }.foregroundColor(.gray)
+                        }
+                        .padding(.horizontal, 24)
+                        .padding(.bottom, geo.safeAreaInsets.bottom)
+                    }
                 }
+                .edgesIgnoringSafeArea(.bottom)
             }
             .navigationTitle("Home")
             .navigationBarHidden(true)

+ 0 - 1
FreeAPS/Sources/Modules/ISFEditor/View/ISFEditorRootView.swift

@@ -35,7 +35,6 @@ extension ISFEditor {
             .navigationTitle("Insulin Sensitivities")
             .navigationBarTitleDisplayMode(.automatic)
             .navigationBarItems(
-                leading: Button("Close", action: viewModel.hideModal),
                 trailing: EditButton()
             )
             .environment(\.editMode, $editMode)

+ 2 - 2
FreeAPS/Sources/Modules/Main/MainViewModel.swift

@@ -16,7 +16,7 @@ extension Main {
         }
 
         override func subscribe() {
-            router.modalScreen
+            router.mainModalScreen
                 .map { $0?.modal(resolver: self.resolver) }
                 .removeDuplicates { $0?.id == $1?.id }
                 .receive(on: RunLoop.main)
@@ -41,7 +41,7 @@ extension Main {
             $isModalPresented
                 .filter { !$0 }
                 .sink { _ in
-                    self.router.modalScreen.send(nil)
+                    self.router.mainModalScreen.send(nil)
                 }
                 .store(in: &lifetime)
         }

+ 0 - 1
FreeAPS/Sources/Modules/NightscoutConfig/View/NightscoutConfigRootView.swift

@@ -36,7 +36,6 @@ extension NightscoutConfig {
                 }
             }
             .navigationBarTitle("Nightscout Config", displayMode: .automatic)
-            .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
         }
     }
 }

+ 0 - 1
FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift

@@ -40,7 +40,6 @@ extension PreferencesEditor {
             }
             .navigationTitle("Preferences")
             .navigationBarTitleDisplayMode(.automatic)
-            .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
         }
     }
 }

+ 0 - 1
FreeAPS/Sources/Modules/PumpConfig/View/PumpConfigRootView.swift

@@ -25,7 +25,6 @@ extension PumpConfig {
             }
             .navigationTitle("Pump config")
             .navigationBarTitleDisplayMode(.automatic)
-            .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
             .popover(isPresented: $viewModel.setupPump) {
                 if let pumpManager = viewModel.provider.apsManager.pumpManager {
                     PumpSettingsView(pumpManager: pumpManager, completionDelegate: viewModel)

+ 0 - 1
FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift

@@ -45,7 +45,6 @@ extension PumpSettingsEditor {
             }
             .navigationTitle("Pump Settings")
             .navigationBarTitleDisplayMode(.automatic)
-            .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
         }
     }
 }

+ 31 - 25
FreeAPS/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -11,59 +11,65 @@ extension Settings {
                 }
 
                 Section(header: Text("Devices")) {
-                    Text("Pump").chevronCell().modal(for: .pumpConfig, from: self)
+                    Text("Pump").chevronCell().navigationLink(to: .pumpConfig, from: self)
                 }
 
                 Section(header: Text("Services")) {
-                    Text("Nightscout").chevronCell().modal(for: .nighscoutConfig, from: self)
+                    Text("Nightscout").chevronCell().navigationLink(to: .nighscoutConfig, from: self)
                 }
 
                 Section(header: Text("Configuration")) {
-                    Text("Pump Settings").chevronCell().modal(for: .pumpSettingsEditor, from: self)
-                    Text("Basal Profile").chevronCell().modal(for: .basalProfileEditor, from: self)
-                    Text("Insulin Sensitivities").chevronCell().modal(for: .isfEditor, from: self)
-                    Text("Carb Ratios").chevronCell().modal(for: .crEditor, from: self)
-                    Text("Target Ranges").chevronCell().modal(for: .targetsEditor, from: self)
-                    Text("Preferences").chevronCell().modal(for: .preferencesEditor, from: self)
+                    Text("Pump Settings").chevronCell().navigationLink(to: .pumpSettingsEditor, from: self)
+                    Text("Basal Profile").chevronCell().navigationLink(to: .basalProfileEditor, from: self)
+                    Text("Insulin Sensitivities").chevronCell().navigationLink(to: .isfEditor, from: self)
+                    Text("Carb Ratios").chevronCell().navigationLink(to: .crEditor, from: self)
+                    Text("Target Ranges").chevronCell().navigationLink(to: .targetsEditor, from: self)
+                    Text("Preferences").chevronCell().navigationLink(to: .preferencesEditor, from: self)
                 }
 
                 Section(header: Text("Config files")) {
                     Group {
                         Text("Preferences").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.preferences), from: self)
-                        Text("Pump Settings").chevronCell().modal(for: .configEditor(file: OpenAPS.Settings.settings), from: self)
-                        Text("Autosense").chevronCell().modal(for: .configEditor(file: OpenAPS.Settings.autosense), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
+                        Text("Pump Settings").chevronCell()
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
+                        Text("Autosense").chevronCell()
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
                         Text("Pump History").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
                         Text("Basal profile").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
                         Text("Targets ranges").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
-                        Text("Carb ratios").chevronCell().modal(for: .configEditor(file: OpenAPS.Settings.carbRatios), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
+                        Text("Carb ratios").chevronCell()
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.carbRatios), from: self)
                         Text("Insulin sensitivities").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.insulinSensitivities), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.insulinSensitivities), from: self)
                         Text("Temp targets").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
                     }
 
                     Group {
                         Text("Pump profile").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
-                        Text("Profile").chevronCell().modal(for: .configEditor(file: OpenAPS.Settings.profile), from: self)
-                        Text("Glucose").chevronCell().modal(for: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
-                        Text("Carbs").chevronCell().modal(for: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
+                        Text("Profile").chevronCell()
+                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
+                        Text("Glucose").chevronCell().navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
+                        Text("Carbs").chevronCell()
+                            .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
                         Text("Suggested").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Enact.suggested), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Enact.suggested), from: self)
                         Text("Enacted").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.Enact.enacted), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
                         Text("Announcements").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
                         Text("Enacted announcements").chevronCell()
-                            .modal(for: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
+                            .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
                     }
                 }
             }
             .navigationTitle("Settings")
+            .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
             .navigationBarTitleDisplayMode(.automatic)
         }
     }

+ 0 - 1
FreeAPS/Sources/Modules/TargetsEditor/View/TargetsEditorRootView.swift

@@ -35,7 +35,6 @@ extension TargetsEditor {
             .navigationTitle("Target Ranges")
             .navigationBarTitleDisplayMode(.automatic)
             .navigationBarItems(
-                leading: Button("Close", action: viewModel.hideModal),
                 trailing: EditButton()
             )
             .environment(\.editMode, $editMode)

+ 2 - 10
FreeAPS/Sources/Router/Router.swift

@@ -3,23 +3,15 @@ import SwiftUI
 import Swinject
 
 protocol Router {
-    var selectTab: PassthroughSubject<Int, Never> { get }
-    var modalScreen: CurrentValueSubject<Screen?, Never> { get }
-    var tabs: [Screen] { get }
+    var mainModalScreen: CurrentValueSubject<Screen?, Never> { get }
     func view(for screen: Screen) -> AnyView
 }
 
 final class BaseRouter: Router {
-    let selectTab = PassthroughSubject<Int, Never>()
-    let modalScreen = CurrentValueSubject<Screen?, Never>(nil)
+    let mainModalScreen = CurrentValueSubject<Screen?, Never>(nil)
 
     private let resolver: Resolver
 
-    let tabs: [Screen] = [
-        .home,
-        .settings
-    ]
-
     private var screens: [Screen.ID: AnyView] = [:]
 
     init(resolver: Resolver) {

+ 0 - 22
FreeAPS/Sources/Router/Screen.swift

@@ -69,28 +69,6 @@ extension Screen {
         }
     }
 
-    func tab(resolver: Resolver) -> AuthotizedRoot.Tab {
-        let tabView = view(resolver: resolver)
-        switch self {
-        case .home:
-            return .init(
-                rootScreen: self,
-                view: tabView,
-                image: Image(systemName: "house"),
-                text: Text("Home")
-            )
-        case .settings:
-            return .init(
-                rootScreen: self,
-                view: tabView,
-                image: Image(systemName: "gear"),
-                text: Text("Settings")
-            )
-        default:
-            fatalError("Tab for this screen \(self) did not specified")
-        }
-    }
-
     func modal(resolver: Resolver) -> Main.Modal {
         .init(screen: self, view: view(resolver: resolver))
     }