Add AI-powered mental wellness features: Reflection Companion, Pattern Tags, Weekly Digest
Three new Foundation Models features to deepen user engagement with mental wellness: 1. AI Reflection Companion — personalized feedback after completing guided reflections, referencing the user's actual words with personality-pack-adapted tone 2. Mood Pattern Tags — auto-extracts theme tags (work, family, stress, etc.) from notes and reflections, displayed as colored pills on entries 3. Weekly Emotional Digest — BGTask-scheduled Sunday digest with headline, summary, highlight, and intention; shown as card in Insights tab with notification All features: on-device (zero cost), premium-gated, iOS 26+ with graceful degradation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,8 @@ struct InsightsView: View {
|
||||
@EnvironmentObject var iapManager: IAPManager
|
||||
@State private var showSubscriptionStore = false
|
||||
@State private var selectedTab: InsightsTab = .insights
|
||||
@State private var weeklyDigest: WeeklyDigest?
|
||||
@State private var showDigest = true
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
@@ -94,15 +96,34 @@ struct InsightsView: View {
|
||||
.onAppear {
|
||||
AnalyticsManager.shared.trackScreen(.insights)
|
||||
viewModel.generateInsights()
|
||||
loadWeeklyDigest()
|
||||
}
|
||||
.padding(.top)
|
||||
}
|
||||
|
||||
// MARK: - Insights Content
|
||||
|
||||
private func loadWeeklyDigest() {
|
||||
if #available(iOS 26, *), !iapManager.shouldShowPaywall {
|
||||
if let digest = FoundationModelsDigestService.shared.loadLatestDigest(),
|
||||
digest.isFromCurrentWeek,
|
||||
!WeeklyDigest.isDismissed(for: digest) {
|
||||
weeklyDigest = digest
|
||||
showDigest = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var insightsContent: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 20) {
|
||||
// Weekly Digest Card
|
||||
if showDigest, let digest = weeklyDigest {
|
||||
WeeklyDigestCardView(digest: digest) {
|
||||
showDigest = false
|
||||
}
|
||||
}
|
||||
|
||||
// This Month Section
|
||||
InsightsSectionView(
|
||||
title: "This Month",
|
||||
|
||||
130
Shared/Views/InsightsView/WeeklyDigestCardView.swift
Normal file
130
Shared/Views/InsightsView/WeeklyDigestCardView.swift
Normal file
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// WeeklyDigestCardView.swift
|
||||
// Reflect
|
||||
//
|
||||
// Displays the AI-generated weekly emotional digest card in the Insights tab.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WeeklyDigestCardView: View {
|
||||
|
||||
let digest: WeeklyDigest
|
||||
let onDismiss: () -> Void
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
|
||||
private var textColor: Color { theme.currentTheme.labelColor }
|
||||
private var accentColor: Color { moodTint.color(forMood: .good) }
|
||||
|
||||
@State private var appeared = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
// Header
|
||||
HStack {
|
||||
Image(systemName: digest.iconName)
|
||||
.font(.title2)
|
||||
.foregroundStyle(accentColor)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(String(localized: "Weekly Digest"))
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.secondary)
|
||||
.textCase(.uppercase)
|
||||
|
||||
Text(digest.headline)
|
||||
.font(.headline)
|
||||
.foregroundColor(textColor)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
WeeklyDigest.markDismissed()
|
||||
withAnimation(.easeInOut(duration: 0.3)) {
|
||||
onDismiss()
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.font(.title3)
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
.accessibilityLabel(String(localized: "Dismiss digest"))
|
||||
.accessibilityIdentifier(AccessibilityID.WeeklyDigest.dismissButton)
|
||||
}
|
||||
|
||||
// Summary
|
||||
Text(digest.summary)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(textColor)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
Divider()
|
||||
|
||||
// Highlight
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
Image(systemName: "star.fill")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.yellow)
|
||||
.padding(.top, 2)
|
||||
|
||||
Text(digest.highlight)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(textColor)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
|
||||
// Intention
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
Image(systemName: "arrow.right.circle.fill")
|
||||
.font(.caption)
|
||||
.foregroundStyle(accentColor)
|
||||
.padding(.top, 2)
|
||||
|
||||
Text(digest.intention)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
|
||||
// Date range
|
||||
Text(dateRangeString)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
.padding(20)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 20)
|
||||
.fill(Color(.secondarySystemBackground))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 20)
|
||||
.stroke(
|
||||
LinearGradient(
|
||||
colors: [accentColor.opacity(0.3), .purple.opacity(0.2)],
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
),
|
||||
lineWidth: 1
|
||||
)
|
||||
)
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.opacity(appeared ? 1 : 0)
|
||||
.offset(y: appeared ? 0 : 10)
|
||||
.onAppear {
|
||||
withAnimation(.easeOut(duration: 0.4)) {
|
||||
appeared = true
|
||||
}
|
||||
}
|
||||
.accessibilityIdentifier(AccessibilityID.WeeklyDigest.card)
|
||||
}
|
||||
|
||||
private var dateRangeString: String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
return "\(formatter.string(from: digest.weekStartDate)) - \(formatter.string(from: digest.weekEndDate))"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user