Skip to content

Commit

Permalink
[LOOP-5056] Presets Homepage Updates - Part 2 (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camji55 authored Dec 16, 2024
1 parent 3a1144c commit 6003381
Show file tree
Hide file tree
Showing 11 changed files with 458 additions and 344 deletions.
4 changes: 4 additions & 0 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
84E8BBD02CCA279B0078E6CF /* Image+Exists.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E8BBCF2CCA27960078E6CF /* Image+Exists.swift */; };
84EC162E2C9115CA00D220C5 /* DIYLoopUnitTestPlan.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = 84EC162D2C9115CA00D220C5 /* DIYLoopUnitTestPlan.xctestplan */; };
84F20DFB2D0A56CB0089DF02 /* PresetStatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F20DFA2D0A56CB0089DF02 /* PresetStatsView.swift */; };
84F20DFD2D0B9C3A0089DF02 /* EditOverrideDurationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F20DFC2D0B9C3A0089DF02 /* EditOverrideDurationView.swift */; };
84FA9D332CF7FD0D004162B4 /* PresetsHistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FA9D322CF7FD0D004162B4 /* PresetsHistoryView.swift */; };
891B508524342BE1005DA578 /* CarbAndBolusFlowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891B508424342BE1005DA578 /* CarbAndBolusFlowViewModel.swift */; };
892A5D59222F0A27008961AB /* Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892A5D58222F0A27008961AB /* Debug.swift */; };
Expand Down Expand Up @@ -1152,6 +1153,7 @@
84E8BBCF2CCA27960078E6CF /* Image+Exists.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Image+Exists.swift"; sourceTree = "<group>"; };
84EC162D2C9115CA00D220C5 /* DIYLoopUnitTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = DIYLoopUnitTestPlan.xctestplan; sourceTree = "<group>"; };
84F20DFA2D0A56CB0089DF02 /* PresetStatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetStatsView.swift; sourceTree = "<group>"; };
84F20DFC2D0B9C3A0089DF02 /* EditOverrideDurationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditOverrideDurationView.swift; sourceTree = "<group>"; };
84FA9D322CF7FD0D004162B4 /* PresetsHistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetsHistoryView.swift; sourceTree = "<group>"; };
891B508424342BE1005DA578 /* CarbAndBolusFlowViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbAndBolusFlowViewModel.swift; sourceTree = "<group>"; };
892A5D29222EF60A008961AB /* MockKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MockKit.framework; path = Carthage/Build/iOS/MockKit.framework; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -2524,6 +2526,7 @@
84C170EE2CCA37680098E52F /* PresetCard.swift */,
84D1F1A82D09800700CB271F /* PresetDetentView.swift */,
84F20DFA2D0A56CB0089DF02 /* PresetStatsView.swift */,
84F20DFC2D0B9C3A0089DF02 /* EditOverrideDurationView.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -3530,6 +3533,7 @@
439A7942211F631C0041B75F /* RootNavigationController.swift in Sources */,
149A28BD2A853E6C00052EDF /* CarbEntryView.swift in Sources */,
4F11D3C020DCBEEC006E072C /* GlucoseBackfillRequestUserInfo.swift in Sources */,
84F20DFD2D0B9C3A0089DF02 /* EditOverrideDurationView.swift in Sources */,
89E267FC2292456700A3F2AF /* FeatureFlags.swift in Sources */,
43A567691C94880B00334FAC /* LoopDataManager.swift in Sources */,
C152B9F52C9C7D4A00ACBC06 /* AutomationHistoryEntry.swift in Sources */,
Expand Down
75 changes: 70 additions & 5 deletions Loop/Managers/LoopAppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import Intents
import BackgroundTasks
import Combine
import LoopTestingKit
import LoopKit
import LoopKitUI
import MockKit
Expand Down Expand Up @@ -540,13 +541,69 @@ class LoopAppManager: NSObject {
}
}
}

private lazy var settingsViewModel: SettingsViewModel = {
let deletePumpDataFunc: () -> PumpManagerViewModel.DeleteTestingDataFunc? = { [weak self] in
(self?.deviceDataManager.pumpManager is TestingPumpManager) ? {
Task { [weak self] in try? await self?.deviceDataManager.deleteTestingPumpData()
}} : nil
}
let deleteCGMDataFunc: () -> CGMManagerViewModel.DeleteTestingDataFunc? = { [weak self] in
(self?.deviceDataManager.cgmManager is TestingCGMManager) ? {
Task { [weak self] in try? await self?.deviceDataManager.deleteTestingCGMData()
}} : nil
}
let pumpViewModel = PumpManagerViewModel(
image: { [weak self] in (self?.deviceDataManager.pumpManager as? PumpManagerUI)?.smallImage },
name: { [weak self] in self?.deviceDataManager.pumpManager?.localizedTitle ?? "" },
isSetUp: { [weak self] in self?.deviceDataManager.pumpManager?.isOnboarded == true },
availableDevices: deviceDataManager.availablePumpManagers,
deleteTestingDataFunc: deletePumpDataFunc
)

let cgmViewModel = CGMManagerViewModel(
image: {[weak self] in (self?.deviceDataManager.cgmManager as? DeviceManagerUI)?.smallImage },
name: {[weak self] in self?.deviceDataManager.cgmManager?.localizedTitle ?? "" },
isSetUp: {[weak self] in self?.deviceDataManager.cgmManager?.isOnboarded == true },
availableDevices: deviceDataManager.availableCGMManagers,
deleteTestingDataFunc: deleteCGMDataFunc
)
let servicesViewModel = ServicesViewModel(showServices: FeatureFlags.includeServicesInSettingsEnabled,
availableServices: { [weak self] in self?.servicesManager.availableServices ?? [] },
activeServices: { [weak self] in self?.servicesManager.activeServices ?? [] })
let versionUpdateViewModel = VersionUpdateViewModel(supportManager: supportManager, guidanceColors: .default)

let viewModel = SettingsViewModel(alertPermissionsChecker: alertPermissionsChecker,
alertMuter: alertManager.alertMuter,
versionUpdateViewModel: versionUpdateViewModel,
pumpManagerSettingsViewModel: pumpViewModel,
cgmManagerSettingsViewModel: cgmViewModel,
servicesViewModel: servicesViewModel,
criticalEventLogExportViewModel: CriticalEventLogExportViewModel(exporterFactory: criticalEventLogExportManager),
therapySettings: { [weak self] in self?.settingsManager.therapySettings ?? TherapySettings() },
sensitivityOverridesEnabled: FeatureFlags.sensitivityOverridesEnabled,
initialDosingEnabled: self.settingsManager.settings.dosingEnabled, automaticDosingStatus: self.automaticDosingStatus,
automaticDosingStrategy: self.settingsManager.settings.automaticDosingStrategy,
lastLoopCompletion: loopDataManager.$lastLoopCompleted,
mostRecentGlucoseDataDate: loopDataManager.$publishedMostRecentGlucoseDataDate,
mostRecentPumpDataDate: loopDataManager.$publishedMostRecentPumpDataDate,
availableSupports: supportManager.availableSupports,
isOnboardingComplete: onboardingManager.isComplete,
therapySettingsViewModelDelegate: deviceDataManager,
presetHistory: temporaryPresetsManager.overrideHistory,
temporaryPresetsManager: temporaryPresetsManager
)

viewModel.favoriteFoodInsightsDelegate = loopDataManager

return viewModel
}()

private func launchHomeScreen() async {
dispatchPrecondition(condition: .onQueue(.main))
precondition(state == .launchHomeScreen)

let statusTableView = StatusTableView(
displayGlucosePreference: displayGlucosePreference,

let viewModel = StatusTableViewModel(
alertPermissionsChecker: alertPermissionsChecker,
alertMuter: alertManager.alertMuter,
automaticDosingStatus: automaticDosingStatus,
Expand All @@ -564,8 +621,16 @@ class LoopAppManager: NSObject {
carbStore: carbStore,
doseStore: doseStore,
criticalEventLogExportManager: criticalEventLogExportManager,
bluetoothStateManager: bluetoothStateManager
).edgesIgnoringSafeArea(.top)
bluetoothStateManager: bluetoothStateManager,
settingsViewModel: settingsViewModel
)

let statusTableView = StatusTableView(viewModel: viewModel)
.environmentObject(deviceDataManager.displayGlucosePreference)
.environment(\.appName, Bundle.main.bundleDisplayName)
.environment(\.isInvestigationalDevice, FeatureFlags.isInvestigationalDevice)
.environment(\.loopStatusColorPalette, .loopStatus)
.edgesIgnoringSafeArea(.top)

var rootNavigationController = rootViewController as? RootNavigationController
if rootNavigationController == nil {
Expand Down
Loading

0 comments on commit 6003381

Please sign in to comment.