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:
Trey t
2025-12-13 12:22:06 -06:00
parent 6c92cf4ec3
commit 920aaee35c
26 changed files with 4295 additions and 99 deletions

View File

@@ -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{