Add premium features and reorganize Settings tab
Premium Features: - Journal notes and photo attachments for mood entries - Data export (CSV and PDF reports) - Privacy lock with Face ID/Touch ID - Apple Health integration for mood correlation - 4 new personality packs (Motivational Coach, Zen Master, Best Friend, Data Analyst) Settings Tab Reorganization: - Combined Customize and Settings into single tab with segmented control - Added upgrade banner with trial countdown above segment - "Why Upgrade?" sheet showing all premium benefits - Subscribe button opens improved StoreKit 2 subscription view UI Improvements: - Enhanced subscription store with feature highlights - Entry detail view for viewing/editing notes and photos - Removed duplicate subscription banners from tab content 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
304
Shared/Views/SettingsView/SettingsTabView.swift
Normal file
304
Shared/Views/SettingsView/SettingsTabView.swift
Normal file
@@ -0,0 +1,304 @@
|
||||
//
|
||||
// SettingsTabView.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 12/13/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import StoreKit
|
||||
|
||||
enum SettingsTab: String, CaseIterable {
|
||||
case customize = "Customize"
|
||||
case settings = "Settings"
|
||||
}
|
||||
|
||||
struct SettingsTabView: View {
|
||||
@State private var selectedTab: SettingsTab = .customize
|
||||
@State private var showWhyUpgrade = false
|
||||
@State private var showSubscriptionStore = false
|
||||
|
||||
@EnvironmentObject var authManager: BiometricAuthManager
|
||||
@EnvironmentObject var iapManager: IAPManager
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
// Header
|
||||
Text("Settings")
|
||||
.font(.system(size: 28, weight: .bold, design: .rounded))
|
||||
.foregroundColor(textColor)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 8)
|
||||
|
||||
// Upgrade Banner (only show if not subscribed)
|
||||
if !iapManager.isSubscribed {
|
||||
UpgradeBannerView(
|
||||
showWhyUpgrade: $showWhyUpgrade,
|
||||
showSubscriptionStore: $showSubscriptionStore,
|
||||
trialExpirationDate: iapManager.trialExpirationDate
|
||||
)
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 12)
|
||||
}
|
||||
|
||||
// Segmented control
|
||||
Picker("", selection: $selectedTab) {
|
||||
ForEach(SettingsTab.allCases, id: \.self) { tab in
|
||||
Text(tab.rawValue).tag(tab)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 12)
|
||||
.padding(.bottom, 16)
|
||||
|
||||
// Content based on selected tab
|
||||
if selectedTab == .customize {
|
||||
CustomizeContentView()
|
||||
} else {
|
||||
SettingsContentView()
|
||||
.environmentObject(authManager)
|
||||
}
|
||||
}
|
||||
.background(
|
||||
theme.currentTheme.bg
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
)
|
||||
.sheet(isPresented: $showWhyUpgrade) {
|
||||
WhyUpgradeView()
|
||||
}
|
||||
.sheet(isPresented: $showSubscriptionStore) {
|
||||
FeelsSubscriptionStoreView()
|
||||
.environmentObject(iapManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Upgrade Banner View
|
||||
struct UpgradeBannerView: View {
|
||||
@Binding var showWhyUpgrade: Bool
|
||||
@Binding var showSubscriptionStore: Bool
|
||||
let trialExpirationDate: Date?
|
||||
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 12) {
|
||||
// Countdown timer
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "clock")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundColor(.orange)
|
||||
|
||||
if let expirationDate = trialExpirationDate {
|
||||
Text("Trial expires in ")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundColor(textColor.opacity(0.8))
|
||||
+
|
||||
Text(expirationDate, style: .relative)
|
||||
.font(.system(size: 14, weight: .bold))
|
||||
.foregroundColor(.orange)
|
||||
} else {
|
||||
Text("Trial expired")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundColor(.orange)
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons in HStack
|
||||
HStack(spacing: 12) {
|
||||
// Why Upgrade button
|
||||
Button {
|
||||
showWhyUpgrade = true
|
||||
} label: {
|
||||
Text("Why Upgrade?")
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.accentColor, lineWidth: 1.5)
|
||||
)
|
||||
}
|
||||
|
||||
// Subscribe button
|
||||
Button {
|
||||
showSubscriptionStore = true
|
||||
} label: {
|
||||
Text("Subscribe")
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundColor(.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.pink)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(14)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 14)
|
||||
.fill(colorScheme == .dark ? Color(.systemGray6) : Color(.systemGray6).opacity(0.5))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Why Upgrade View
|
||||
struct WhyUpgradeView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ScrollView {
|
||||
VStack(spacing: 24) {
|
||||
// Header
|
||||
VStack(spacing: 12) {
|
||||
Image(systemName: "star.fill")
|
||||
.font(.system(size: 50))
|
||||
.foregroundStyle(
|
||||
LinearGradient(
|
||||
colors: [.orange, .pink],
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
)
|
||||
|
||||
Text("Unlock Premium")
|
||||
.font(.system(size: 28, weight: .bold))
|
||||
|
||||
Text("Get the most out of your mood tracking journey")
|
||||
.font(.body)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.padding(.top, 20)
|
||||
|
||||
// Benefits list
|
||||
VStack(spacing: 16) {
|
||||
PremiumBenefitRow(
|
||||
icon: "calendar",
|
||||
iconColor: .blue,
|
||||
title: "Month View",
|
||||
description: "See your mood patterns across entire months at a glance"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "chart.bar.fill",
|
||||
iconColor: .green,
|
||||
title: "Year View",
|
||||
description: "Track long-term trends and see how your mood evolves over time"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "lightbulb.fill",
|
||||
iconColor: .yellow,
|
||||
title: "AI Insights",
|
||||
description: "Get personalized insights and patterns discovered by AI"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "note.text",
|
||||
iconColor: .purple,
|
||||
title: "Journal Notes",
|
||||
description: "Add notes and context to your mood entries"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "photo.fill",
|
||||
iconColor: .pink,
|
||||
title: "Photo Attachments",
|
||||
description: "Capture moments with photos attached to entries"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "heart.fill",
|
||||
iconColor: .red,
|
||||
title: "Health Integration",
|
||||
description: "Correlate mood with steps, sleep, and exercise data"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "square.and.arrow.up",
|
||||
iconColor: .orange,
|
||||
title: "Export Data",
|
||||
description: "Export your data as CSV or beautiful PDF reports"
|
||||
)
|
||||
|
||||
PremiumBenefitRow(
|
||||
icon: "faceid",
|
||||
iconColor: .gray,
|
||||
title: "Privacy Lock",
|
||||
description: "Protect your data with Face ID or Touch ID"
|
||||
)
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
.padding(.bottom, 40)
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Premium Benefit Row
|
||||
struct PremiumBenefitRow: View {
|
||||
let icon: String
|
||||
let iconColor: Color
|
||||
let title: String
|
||||
let description: String
|
||||
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 14) {
|
||||
Image(systemName: icon)
|
||||
.font(.system(size: 22))
|
||||
.foregroundColor(iconColor)
|
||||
.frame(width: 44, height: 44)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(iconColor.opacity(0.15))
|
||||
)
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title)
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
|
||||
Text(description)
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(14)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(colorScheme == .dark ? Color(.systemGray6) : .white)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsTabView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsTabView()
|
||||
.environmentObject(BiometricAuthManager())
|
||||
.environmentObject(IAPManager())
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,332 @@ import CloudKitSyncMonitor
|
||||
import UniformTypeIdentifiers
|
||||
import StoreKit
|
||||
|
||||
// MARK: - Settings Content View (for use in SettingsTabView)
|
||||
struct SettingsContentView: View {
|
||||
@EnvironmentObject var authManager: BiometricAuthManager
|
||||
|
||||
@State private var showOnboarding = false
|
||||
@State private var showExportView = false
|
||||
@StateObject private var healthService = HealthService.shared
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack {
|
||||
// Features section
|
||||
featuresSectionHeader
|
||||
privacyLockToggle
|
||||
healthKitToggle
|
||||
exportDataButton
|
||||
|
||||
// Settings section
|
||||
settingsSectionHeader
|
||||
canDelete
|
||||
showOnboardingButton
|
||||
|
||||
// Legal section
|
||||
legalSectionHeader
|
||||
eulaButton
|
||||
privacyButton
|
||||
|
||||
Spacer()
|
||||
.frame(height: 20)
|
||||
|
||||
Text("\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))")
|
||||
.font(.body)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.sheet(isPresented: $showOnboarding) {
|
||||
OnboardingMain(onboardingData: UserDefaultsStore.getOnboarding(),
|
||||
updateBoardingDataClosure: { onboardingData in
|
||||
OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData)
|
||||
showOnboarding = false
|
||||
})
|
||||
}
|
||||
.sheet(isPresented: $showExportView) {
|
||||
ExportView(entries: DataController.shared.getData(
|
||||
startDate: Date(timeIntervalSince1970: 0),
|
||||
endDate: Date(),
|
||||
includedDays: []
|
||||
))
|
||||
}
|
||||
.onAppear(perform: {
|
||||
EventLogger.log(event: "show_settings_view")
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Section Headers
|
||||
|
||||
private var featuresSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Features")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var settingsSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Settings")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var legalSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Legal")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
// MARK: - Privacy Lock Toggle
|
||||
|
||||
@ViewBuilder
|
||||
private var privacyLockToggle: some View {
|
||||
if authManager.canUseBiometrics {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: authManager.biometricIcon)
|
||||
.font(.title2)
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Privacy Lock")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("Require \(authManager.biometricName) to open app")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Toggle("", isOn: Binding(
|
||||
get: { authManager.isLockEnabled },
|
||||
set: { newValue in
|
||||
Task {
|
||||
if newValue {
|
||||
let success = await authManager.enableLock()
|
||||
if !success {
|
||||
EventLogger.log(event: "privacy_lock_enable_failed")
|
||||
}
|
||||
} else {
|
||||
authManager.disableLock()
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
.labelsHidden()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Health Kit Toggle
|
||||
|
||||
private var healthKitToggle: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "heart.fill")
|
||||
.font(.title2)
|
||||
.foregroundColor(.red)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Apple Health")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("Correlate mood with health data")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if healthService.isAvailable {
|
||||
Toggle("", isOn: Binding(
|
||||
get: { healthService.isEnabled },
|
||||
set: { newValue in
|
||||
if newValue {
|
||||
Task {
|
||||
let success = await healthService.requestAuthorization()
|
||||
if !success {
|
||||
EventLogger.log(event: "healthkit_enable_failed")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
healthService.isEnabled = false
|
||||
EventLogger.log(event: "healthkit_disabled")
|
||||
}
|
||||
}
|
||||
))
|
||||
.labelsHidden()
|
||||
} else {
|
||||
Text("Not Available")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
// MARK: - Export Data Button
|
||||
|
||||
private var exportDataButton: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
EventLogger.log(event: "tap_export_data")
|
||||
showExportView = true
|
||||
}, label: {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.font(.title2)
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Export Data")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("CSV or PDF report")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
.padding()
|
||||
})
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var showOnboardingButton: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
EventLogger.log(event: "tap_show_onboarding")
|
||||
showOnboarding.toggle()
|
||||
}, label: {
|
||||
Text(String(localized: "settings_view_show_onboarding"))
|
||||
.foregroundColor(textColor)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var canDelete: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
VStack {
|
||||
Toggle(String(localized: "settings_use_delete_enable"),
|
||||
isOn: $deleteEnabled)
|
||||
.onChange(of: deleteEnabled) { _, newValue in
|
||||
EventLogger.log(event: "toggle_can_delete", withData: ["value": newValue])
|
||||
}
|
||||
.foregroundColor(textColor)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var eulaButton: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
EventLogger.log(event: "show_eula")
|
||||
if let url = URL(string: "https://ifeels.app/eula.html") {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}, label: {
|
||||
Text(String(localized: "settings_view_show_eula"))
|
||||
.foregroundColor(textColor)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var privacyButton: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
EventLogger.log(event: "show_privacy")
|
||||
if let url = URL(string: "https://ifeels.app/privacy.html") {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}, label: {
|
||||
Text(String(localized: "settings_view_show_privacy"))
|
||||
.foregroundColor(textColor)
|
||||
})
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Legacy SettingsView (sheet presentation with close button)
|
||||
struct SettingsView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@Environment(\.openURL) var openURL
|
||||
@EnvironmentObject var iapManager: IAPManager
|
||||
|
||||
@EnvironmentObject var authManager: BiometricAuthManager
|
||||
|
||||
@State private var showingExporter = false
|
||||
@State private var showingImporter = false
|
||||
@State private var importContent = ""
|
||||
|
||||
|
||||
@State private var showOnboarding = false
|
||||
|
||||
@State private var showExportView = false
|
||||
|
||||
@State private var showSpecialThanks = false
|
||||
@State private var showWhyBGMode = false
|
||||
@ObservedObject var syncMonitor = SyncMonitor.shared
|
||||
|
||||
@StateObject private var healthService = HealthService.shared
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false
|
||||
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
@AppStorage(UserDefaultsStore.Keys.firstLaunchDate.rawValue, store: GroupUserDefaults.groupDefaults) private var firstLaunchDate = Date()
|
||||
@AppStorage(UserDefaultsStore.Keys.privacyLockEnabled.rawValue, store: GroupUserDefaults.groupDefaults) private var privacyLockEnabled = false
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
@@ -37,11 +343,23 @@ struct SettingsView: View {
|
||||
Group {
|
||||
closeButtonView
|
||||
.padding()
|
||||
|
||||
|
||||
// cloudKitEnable
|
||||
subscriptionInfoView
|
||||
|
||||
// Features section
|
||||
featuresSectionHeader
|
||||
privacyLockToggle
|
||||
healthKitToggle
|
||||
exportDataButton
|
||||
|
||||
// Settings section
|
||||
settingsSectionHeader
|
||||
canDelete
|
||||
showOnboardingButton
|
||||
|
||||
// Legal section
|
||||
legalSectionHeader
|
||||
eulaButton
|
||||
privacyButton
|
||||
// specialThanksCell
|
||||
@@ -78,6 +396,13 @@ struct SettingsView: View {
|
||||
showOnboarding = false
|
||||
})
|
||||
}
|
||||
.sheet(isPresented: $showExportView) {
|
||||
ExportView(entries: DataController.shared.getData(
|
||||
startDate: Date(timeIntervalSince1970: 0),
|
||||
endDate: Date(),
|
||||
includedDays: []
|
||||
))
|
||||
}
|
||||
.onAppear(perform: {
|
||||
EventLogger.log(event: "show_settings_view")
|
||||
})
|
||||
@@ -146,6 +471,178 @@ struct SettingsView: View {
|
||||
private var subscriptionInfoView: some View {
|
||||
PurchaseButtonView(iapManager: iapManager)
|
||||
}
|
||||
|
||||
// MARK: - Section Headers
|
||||
|
||||
private var featuresSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Features")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var settingsSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Settings")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
private var legalSectionHeader: some View {
|
||||
HStack {
|
||||
Text("Legal")
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 20)
|
||||
.padding(.horizontal, 4)
|
||||
}
|
||||
|
||||
// MARK: - Privacy Lock Toggle
|
||||
|
||||
@ViewBuilder
|
||||
private var privacyLockToggle: some View {
|
||||
if authManager.canUseBiometrics {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: authManager.biometricIcon)
|
||||
.font(.title2)
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Privacy Lock")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("Require \(authManager.biometricName) to open app")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Toggle("", isOn: Binding(
|
||||
get: { authManager.isLockEnabled },
|
||||
set: { newValue in
|
||||
Task {
|
||||
if newValue {
|
||||
let success = await authManager.enableLock()
|
||||
if !success {
|
||||
EventLogger.log(event: "privacy_lock_enable_failed")
|
||||
}
|
||||
} else {
|
||||
authManager.disableLock()
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
.labelsHidden()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Health Kit Toggle
|
||||
|
||||
private var healthKitToggle: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "heart.fill")
|
||||
.font(.title2)
|
||||
.foregroundColor(.red)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Apple Health")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("Correlate mood with health data")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if healthService.isAvailable {
|
||||
Toggle("", isOn: Binding(
|
||||
get: { healthService.isEnabled },
|
||||
set: { newValue in
|
||||
if newValue {
|
||||
Task {
|
||||
let success = await healthService.requestAuthorization()
|
||||
if !success {
|
||||
EventLogger.log(event: "healthkit_enable_failed")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
healthService.isEnabled = false
|
||||
EventLogger.log(event: "healthkit_disabled")
|
||||
}
|
||||
}
|
||||
))
|
||||
.labelsHidden()
|
||||
} else {
|
||||
Text("Not Available")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
// MARK: - Export Data Button
|
||||
|
||||
private var exportDataButton: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
EventLogger.log(event: "tap_export_data")
|
||||
showExportView = true
|
||||
}, label: {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.font(.title2)
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Export Data")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Text("CSV or PDF report")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
.padding()
|
||||
})
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var closeButtonView: some View {
|
||||
HStack{
|
||||
|
||||
Reference in New Issue
Block a user