- Replace Core Data with SwiftData for iOS 18+ - Create MoodEntryModel as @Model class replacing MoodEntry entity - Create SharedModelContainer for App Group container sharing - Create DataController with CRUD extensions replacing PersistenceController - Update all views and view models to use MoodEntryModel - Update widget extension to use SwiftData - Remove old Core Data files (Persistence*.swift, .xcdatamodeld) - Add EntryType enum with all entry type cases - Fix widget label truncation with proper spacing and text scaling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
347 lines
13 KiB
Swift
347 lines
13 KiB
Swift
//
|
|
// HomeViewTwo.swift
|
|
// Feels (iOS)
|
|
//
|
|
// Created by Trey Tartt on 2/18/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MonthView: View {
|
|
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
|
|
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
|
|
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
|
|
@AppStorage(UserDefaultsStore.Keys.moodImages.rawValue, store: GroupUserDefaults.groupDefaults) private var imagePack: MoodImages = .FontAwesome
|
|
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
|
|
|
@AppStorage(UserDefaultsStore.Keys.shape.rawValue, store: GroupUserDefaults.groupDefaults) private var shape: BGShape = .circle
|
|
|
|
@StateObject private var shareImage = StupidAssShareObservableObject()
|
|
|
|
// store a value that gets changed when user updates custom colors to update the view since the moodTint doesn't change
|
|
@AppStorage(UserDefaultsStore.Keys.customMoodTintUpdateNumber.rawValue, store: GroupUserDefaults.groupDefaults) private var customMoodTintUpdateNumber: Int = 0
|
|
|
|
@EnvironmentObject var iapManager: IAPManager
|
|
@StateObject private var selectedDetail = StupidAssDetailViewObservableObject()
|
|
@State private var showingSheet = false
|
|
@StateObject private var onboardingData = OnboardingDataDataManager.shared
|
|
@StateObject private var filteredDays = DaysFilterClass.shared
|
|
|
|
class StupidAssDetailViewObservableObject: ObservableObject {
|
|
@Published var fuckingWrapped: MonthDetailView? = nil
|
|
@Published var showFuckingSheet = false
|
|
}
|
|
|
|
// Heatmap-style grid with tight spacing
|
|
private let heatmapColumns = Array(repeating: GridItem(.flexible(), spacing: 2), count: 7)
|
|
|
|
private let weekdayLabels = ["S", "M", "T", "W", "T", "F", "S"]
|
|
|
|
@ObservedObject var viewModel: DayViewViewModel
|
|
@State private var trialWarningHidden = false
|
|
@State private var showSubscriptionStore = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if viewModel.hasNoData {
|
|
EmptyHomeView(showVote: false, viewModel: nil)
|
|
.padding()
|
|
} else {
|
|
ScrollView {
|
|
VStack(spacing: 16) {
|
|
ForEach(viewModel.grouped.sorted(by: { $0.key > $1.key }), id: \.key) { year, months in
|
|
// for each month
|
|
ForEach(months.sorted(by: { $0.key > $1.key }), id: \.key) { month, entries in
|
|
MonthCard(
|
|
month: month,
|
|
year: year,
|
|
entries: entries,
|
|
moodTint: moodTint,
|
|
imagePack: imagePack,
|
|
textColor: textColor,
|
|
theme: theme,
|
|
filteredDays: filteredDays.currentFilters,
|
|
onTap: {
|
|
let detailView = MonthDetailView(
|
|
monthInt: month,
|
|
yearInt: year,
|
|
entries: entries,
|
|
parentViewModel: viewModel
|
|
)
|
|
selectedDetail.fuckingWrapped = detailView
|
|
selectedDetail.showFuckingSheet = true
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
.padding(.bottom, 100)
|
|
.background(
|
|
GeometryReader { proxy in
|
|
let offset = proxy.frame(in: .named("scroll")).minY
|
|
Color.clear.preference(key: ViewOffsetKey.self, value: offset)
|
|
}
|
|
)
|
|
}
|
|
.disabled(iapManager.shouldShowPaywall)
|
|
}
|
|
|
|
// Hidden text to trigger updates when custom tint changes
|
|
Text(String(customMoodTintUpdateNumber))
|
|
.hidden()
|
|
|
|
if iapManager.shouldShowPaywall {
|
|
// Paywall overlay - tap to show subscription store
|
|
Color.black.opacity(0.3)
|
|
.ignoresSafeArea()
|
|
.onTapGesture {
|
|
showSubscriptionStore = true
|
|
}
|
|
|
|
VStack {
|
|
Spacer()
|
|
Button {
|
|
showSubscriptionStore = true
|
|
} label: {
|
|
Text(String(localized: "subscription_required_button"))
|
|
.font(.headline)
|
|
.foregroundColor(.white)
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(RoundedRectangle(cornerRadius: 10).fill(Color.pink))
|
|
}
|
|
.padding()
|
|
}
|
|
} else if iapManager.shouldShowTrialWarning {
|
|
VStack {
|
|
Spacer()
|
|
if !trialWarningHidden {
|
|
IAPWarningView(iapManager: iapManager)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.sheet(isPresented: $showSubscriptionStore) {
|
|
FeelsSubscriptionStoreView()
|
|
}
|
|
.onAppear(perform: {
|
|
EventLogger.log(event: "show_month_view")
|
|
})
|
|
.padding([.top])
|
|
.background(
|
|
theme.currentTheme.bg
|
|
.edgesIgnoringSafeArea(.all)
|
|
)
|
|
.sheet(isPresented: $selectedDetail.showFuckingSheet,
|
|
onDismiss: didDismiss) {
|
|
selectedDetail.fuckingWrapped
|
|
}
|
|
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
|
|
if let uiImage = self.shareImage.fuckingWrappedShrable {
|
|
ShareSheet(photo: uiImage)
|
|
}
|
|
}
|
|
.onPreferenceChange(ViewOffsetKey.self) { value in
|
|
withAnimation {
|
|
trialWarningHidden = value < 0
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func didDismiss() {
|
|
selectedDetail.showFuckingSheet = false
|
|
selectedDetail.fuckingWrapped = nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Month Card Component
|
|
struct MonthCard: View {
|
|
let month: Int
|
|
let year: Int
|
|
let entries: [MoodEntryModel]
|
|
let moodTint: MoodTints
|
|
let imagePack: MoodImages
|
|
let textColor: Color
|
|
let theme: Theme
|
|
let filteredDays: [Int]
|
|
let onTap: () -> Void
|
|
|
|
@State private var showStats = true
|
|
|
|
private let weekdayLabels = ["S", "M", "T", "W", "T", "F", "S"]
|
|
private let heatmapColumns = Array(repeating: GridItem(.flexible(), spacing: 2), count: 7)
|
|
|
|
private var metrics: [MoodMetrics] {
|
|
let (startDate, endDate) = Date.dateRange(monthInt: month, yearInt: year)
|
|
let monthEntries = DataController.shared.getData(startDate: startDate, endDate: endDate, includedDays: [1,2,3,4,5,6,7])
|
|
return Random.createTotalPerc(fromEntries: monthEntries)
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
// Month Header
|
|
Button(action: { withAnimation(.easeInOut(duration: 0.2)) { showStats.toggle() } }) {
|
|
HStack {
|
|
Text("\(Random.monthName(fromMonthInt: month)) \(String(year))")
|
|
.font(.title3.bold())
|
|
.foregroundColor(textColor)
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: showStats ? "chevron.up" : "chevron.down")
|
|
.font(.caption.weight(.semibold))
|
|
.foregroundColor(textColor.opacity(0.5))
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 12)
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
// Weekday Labels
|
|
HStack(spacing: 2) {
|
|
ForEach(weekdayLabels, id: \.self) { day in
|
|
Text(day)
|
|
.font(.caption2.weight(.medium))
|
|
.foregroundColor(textColor.opacity(0.5))
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.bottom, 6)
|
|
|
|
// Heatmap Grid
|
|
LazyVGrid(columns: heatmapColumns, spacing: 2) {
|
|
ForEach(entries, id: \.self) { entry in
|
|
HeatmapCell(
|
|
entry: entry,
|
|
moodTint: moodTint,
|
|
isFiltered: filteredDays.contains(Int(entry.weekDay))
|
|
)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.bottom, 12)
|
|
|
|
// Bar Chart Stats (collapsible)
|
|
if showStats {
|
|
Divider()
|
|
.padding(.horizontal, 16)
|
|
|
|
MoodBarChart(metrics: metrics, moodTint: moodTint, imagePack: imagePack)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 12)
|
|
.transition(.opacity.combined(with: .move(edge: .top)))
|
|
}
|
|
}
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 16)
|
|
.fill(theme.currentTheme.secondaryBGColor)
|
|
)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
onTap()
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Heatmap Cell
|
|
struct HeatmapCell: View {
|
|
let entry: MoodEntryModel
|
|
let moodTint: MoodTints
|
|
let isFiltered: Bool
|
|
|
|
var body: some View {
|
|
RoundedRectangle(cornerRadius: 4)
|
|
.fill(cellColor)
|
|
.aspectRatio(1, contentMode: .fit)
|
|
}
|
|
|
|
private var cellColor: Color {
|
|
if entry.mood == .placeholder {
|
|
return Color.gray.opacity(0.1)
|
|
} else if entry.mood == .missing {
|
|
return Color.gray.opacity(0.25)
|
|
} else if !isFiltered {
|
|
return Color.gray.opacity(0.1)
|
|
} else {
|
|
return moodTint.color(forMood: entry.mood)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Mini Bar Chart
|
|
struct MoodBarChart: View {
|
|
let metrics: [MoodMetrics]
|
|
let moodTint: MoodTints
|
|
let imagePack: MoodImages
|
|
|
|
var body: some View {
|
|
VStack(spacing: 8) {
|
|
ForEach(metrics.filter { $0.total > 0 }) { metric in
|
|
HStack(spacing: 10) {
|
|
// Mood icon
|
|
imagePack.icon(forMood: metric.mood)
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.frame(width: 18, height: 18)
|
|
.foregroundColor(moodTint.color(forMood: metric.mood))
|
|
|
|
// Bar
|
|
GeometryReader { geo in
|
|
ZStack(alignment: .leading) {
|
|
// Background track
|
|
RoundedRectangle(cornerRadius: 4)
|
|
.fill(Color.gray.opacity(0.15))
|
|
|
|
// Filled bar
|
|
RoundedRectangle(cornerRadius: 4)
|
|
.fill(moodTint.color(forMood: metric.mood))
|
|
.frame(width: max(4, geo.size.width * CGFloat(metric.percent / 100)))
|
|
}
|
|
}
|
|
.frame(height: 10)
|
|
|
|
// Count and percentage
|
|
Text("\(metric.total)")
|
|
.font(.caption.weight(.semibold))
|
|
.foregroundColor(moodTint.color(forMood: metric.mood))
|
|
.frame(width: 28, alignment: .trailing)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Legacy support for settings button
|
|
extension MonthView {
|
|
private var settingsButtonView: some View {
|
|
HStack {
|
|
Spacer()
|
|
VStack {
|
|
Button(action: {
|
|
showingSheet.toggle()
|
|
}, label: {
|
|
Image(systemName: "gear")
|
|
.foregroundColor(Color(UIColor.darkGray))
|
|
.font(.system(size: 20))
|
|
}).sheet(isPresented: $showingSheet) {
|
|
SettingsView()
|
|
}
|
|
.padding(.top, 60)
|
|
.padding(.trailing)
|
|
Spacer()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MonthView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MonthView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: true))
|
|
}
|
|
}
|