113 lines
3.6 KiB
Swift
113 lines
3.6 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var iapService: IAPService
|
|
@EnvironmentObject var adMobService: AdMobService
|
|
@EnvironmentObject var tabSelection: TabSelectionStore
|
|
@AppStorage("onboardingCompleted") private var onboardingCompleted = false
|
|
@AppStorage("faceIdEnabled") private var faceIdEnabled = false
|
|
@AppStorage("pinEnabled") private var pinEnabled = false
|
|
@AppStorage("lockOnLaunch") private var lockOnLaunch = true
|
|
@AppStorage("lockOnBackground") private var lockOnBackground = false
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
@State private var isUnlocked = false
|
|
|
|
private var lockEnabled: Bool {
|
|
faceIdEnabled || pinEnabled
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Group {
|
|
if !onboardingCompleted {
|
|
OnboardingView(onboardingCompleted: $onboardingCompleted)
|
|
} else {
|
|
mainContent
|
|
}
|
|
}
|
|
|
|
if onboardingCompleted && lockEnabled && !isUnlocked {
|
|
AppLockView(isUnlocked: $isUnlocked)
|
|
}
|
|
}
|
|
.onAppear {
|
|
if !lockEnabled {
|
|
isUnlocked = true
|
|
} else {
|
|
isUnlocked = !lockOnLaunch
|
|
}
|
|
}
|
|
.onChange(of: lockEnabled) { _, enabled in
|
|
if !enabled {
|
|
isUnlocked = true
|
|
} else {
|
|
isUnlocked = !lockOnLaunch
|
|
}
|
|
}
|
|
.onChange(of: onboardingCompleted) { _, completed in
|
|
if completed && lockEnabled {
|
|
isUnlocked = !lockOnLaunch
|
|
}
|
|
}
|
|
.onChange(of: scenePhase) { _, phase in
|
|
guard onboardingCompleted, lockEnabled else { return }
|
|
if phase == .background && lockOnBackground {
|
|
isUnlocked = false
|
|
}
|
|
}
|
|
}
|
|
|
|
private var mainContent: some View {
|
|
ZStack {
|
|
TabView(selection: $tabSelection.selectedTab) {
|
|
DashboardView()
|
|
.tabItem {
|
|
Label("Home", systemImage: "house.fill")
|
|
}
|
|
.tag(0)
|
|
|
|
SourceListView(iapService: iapService)
|
|
.tabItem {
|
|
Label("Sources", systemImage: "list.bullet")
|
|
}
|
|
.tag(1)
|
|
|
|
ChartsContainerView(iapService: iapService)
|
|
.tabItem {
|
|
Label("Charts", systemImage: "chart.xyaxis.line")
|
|
}
|
|
.tag(2)
|
|
|
|
JournalView()
|
|
.tabItem {
|
|
Label("Journal", systemImage: "book.closed")
|
|
}
|
|
.tag(3)
|
|
|
|
SettingsView()
|
|
.tabItem {
|
|
Label("Settings", systemImage: "gearshape.fill")
|
|
}
|
|
.tag(4)
|
|
}
|
|
}
|
|
// Banner ad at bottom for free users
|
|
.safeAreaInset(edge: .bottom, spacing: 0) {
|
|
if !iapService.isPremium {
|
|
BannerAdView()
|
|
.frame(height: AppConstants.UI.bannerAdHeight)
|
|
.frame(maxWidth: .infinity)
|
|
.background(Color(.systemBackground))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ContentView()
|
|
.environmentObject(IAPService())
|
|
.environmentObject(AdMobService())
|
|
.environmentObject(AccountStore(iapService: IAPService()))
|
|
.environmentObject(TabSelectionStore())
|
|
}
|