Skip to content

Commit 35bb431

Browse files
committed
Merge branch 'main' into dev, accidentally merged PR 564 into main instead of dev
2 parents 86a7825 + 68bb78f commit 35bb431

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

LoopFollow/Settings/SettingsMenuView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct AggregatedStatsViewWrapper: View {
195195
var body: some View {
196196
Group {
197197
if let mainVC = mainViewController {
198-
AggregatedStatsView(viewModel: AggregatedStatsViewModel(mainViewController: mainVC))
198+
AggregatedStatsContentView(mainViewController: mainVC)
199199
} else {
200200
Text("Loading stats...")
201201
.onAppear {

LoopFollow/Stats/AggregatedStatsView.swift

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import UIKit
77
struct AggregatedStatsView: View {
88
@ObservedObject var viewModel: AggregatedStatsViewModel
99
@Environment(\.dismiss) var dismiss
10+
var onDismiss: (() -> Void)?
1011
@State private var showGMI: Bool
1112
@State private var showStdDev: Bool
1213
@State private var startDate: Date
@@ -17,8 +18,9 @@ struct AggregatedStatsView: View {
1718
@State private var loadingTimer: Timer?
1819
@State private var timeoutTimer: Timer?
1920

20-
init(viewModel: AggregatedStatsViewModel) {
21+
init(viewModel: AggregatedStatsViewModel, onDismiss: (() -> Void)? = nil) {
2122
self.viewModel = viewModel
23+
self.onDismiss = onDismiss
2224
_showGMI = State(initialValue: Storage.shared.showGMI.value)
2325
_showStdDev = State(initialValue: Storage.shared.showStdDev.value)
2426

@@ -105,6 +107,11 @@ struct AggregatedStatsView: View {
105107
}
106108
.navigationBarTitleDisplayMode(.inline)
107109
.toolbar {
110+
if let onDismiss {
111+
ToolbarItem(placement: .navigationBarLeading) {
112+
Button("Done", action: onDismiss)
113+
}
114+
}
108115
ToolbarItem(placement: .navigationBarTrailing) {
109116
Button("Refresh") {
110117
loadingError = false
@@ -163,6 +170,38 @@ struct AggregatedStatsView: View {
163170
}
164171
}
165172

173+
struct AggregatedStatsContentView: View {
174+
@StateObject private var viewModel: AggregatedStatsViewModel
175+
private let onDismiss: (() -> Void)?
176+
177+
init(mainViewController: MainViewController?, onDismiss: (() -> Void)? = nil) {
178+
_viewModel = StateObject(wrappedValue: AggregatedStatsViewModel(mainViewController: mainViewController))
179+
self.onDismiss = onDismiss
180+
}
181+
182+
var body: some View {
183+
AggregatedStatsView(viewModel: viewModel, onDismiss: onDismiss)
184+
.preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
185+
}
186+
}
187+
188+
struct AggregatedStatsModalView: View {
189+
@Environment(\.dismiss) private var dismiss
190+
191+
let mainViewController: MainViewController?
192+
193+
var body: some View {
194+
NavigationView {
195+
AggregatedStatsContentView(
196+
mainViewController: mainViewController,
197+
onDismiss: { dismiss() }
198+
)
199+
.navigationBarTitleDisplayMode(.inline)
200+
}
201+
.preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
202+
}
203+
}
204+
166205
struct StatCard: View {
167206
let title: String
168207
let value: String

LoopFollow/ViewControllers/MainViewController.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
200200
updateGraphVisibility()
201201
statsView.isHidden = !Storage.shared.showStats.value
202202

203+
// Tap on stats view to open full statistics screen
204+
let statsTap = UITapGestureRecognizer(target: self, action: #selector(statsViewTapped))
205+
statsView.addGestureRecognizer(statsTap)
206+
203207
BGChart.delegate = self
204208
BGChartFull.delegate = self
205209

@@ -671,7 +675,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
671675
return treatmentsVC
672676

673677
case .stats:
674-
let statsVC = UIHostingController(rootView: AggregatedStatsView(viewModel: AggregatedStatsViewModel(mainViewController: nil)))
678+
let statsVC = UIHostingController(rootView: AggregatedStatsContentView(mainViewController: nil))
675679
let navController = UINavigationController(rootViewController: statsVC)
676680
navController.tabBarItem = UITabBarItem(title: item.displayName, image: UIImage(systemName: item.icon), tag: tag)
677681
return navController
@@ -726,6 +730,22 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
726730
return nil
727731
}
728732

733+
@objc private func statsViewTapped() {
734+
#if !targetEnvironment(macCatalyst)
735+
let position = Storage.shared.position(for: .stats).normalized
736+
if position != .menu, let tabIndex = position.tabIndex, let tbc = tabBarController {
737+
tbc.selectedIndex = tabIndex
738+
return
739+
}
740+
#endif
741+
742+
let statsModalView = AggregatedStatsModalView(mainViewController: self)
743+
let hostingController = UIHostingController(rootView: statsModalView)
744+
hostingController.overrideUserInterfaceStyle = Storage.shared.appearanceMode.value.userInterfaceStyle
745+
hostingController.modalPresentationStyle = .fullScreen
746+
present(hostingController, animated: true)
747+
}
748+
729749
private func createViewController(for item: TabItem, position: TabPosition, storyboard: UIStoryboard) -> UIViewController? {
730750
let tag = position.tabIndex ?? 0
731751

@@ -760,7 +780,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
760780
return treatmentsVC
761781

762782
case .stats:
763-
let statsVC = UIHostingController(rootView: AggregatedStatsView(viewModel: AggregatedStatsViewModel(mainViewController: self)))
783+
let statsVC = UIHostingController(rootView: AggregatedStatsContentView(mainViewController: self))
764784
let navController = UINavigationController(rootViewController: statsVC)
765785
navController.tabBarItem = UITabBarItem(title: item.displayName, image: UIImage(systemName: item.icon), tag: tag)
766786
return navController

LoopFollow/ViewControllers/MoreMenuViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ class MoreMenuViewController: UIViewController {
314314
return
315315
}
316316

317-
let statsVC = UIHostingController(
318-
rootView: AggregatedStatsView(viewModel: AggregatedStatsViewModel(mainViewController: mainVC))
319-
)
317+
let statsView = AggregatedStatsContentView(mainViewController: mainVC)
318+
let statsVC = UIHostingController(rootView: statsView)
320319
statsVC.overrideUserInterfaceStyle = Storage.shared.appearanceMode.value.userInterfaceStyle
321320
navigationController?.pushViewController(statsVC, animated: true)
322321
}

0 commit comments

Comments
 (0)