- Wrap 30+ production print() statements in #if DEBUG guards across 18 files - Add VoiceOver labels, hints, and traits to Watch app, Live Activities, widgets - Add .accessibilityAddTraits(.isButton) to 15+ onTapGesture views - Add text alternatives for color-only indicators (progress dots, mood circles) - Localize raw string literals in NoteEditorView, EntryDetailView, widgets - Replace 25+ silent try? with do/catch + AppLogger error logging - Replace hardcoded font sizes with semantic Dynamic Type fonts - Fix FIXME in IconPickerView (log icon change errors) - Extract magic animation delays to named constants across 8 files - Add widget empty state "Log your first mood!" messaging - Hide decorative images from VoiceOver, add labels to ColorPickers - Remove stale TODO in Color+Codable (alpha change deferred for migration) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
238 lines
8.9 KiB
Swift
238 lines
8.9 KiB
Swift
//
|
|
// MonthDetailView.swift
|
|
// Reflect (iOS)
|
|
//
|
|
// Created by Trey Tartt on 2/18/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MonthDetailView: View {
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
|
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
|
|
|
|
private var textColor: Color { theme.currentTheme.labelColor }
|
|
|
|
@StateObject private var shareImage = ShareImageStateViewModel()
|
|
|
|
@State private var showingSheet = false
|
|
@State private var selectedEntry: MoodEntryModel?
|
|
@State private var showingUpdateEntryAlert = false
|
|
@State private var showUpdateEntryAlert = false
|
|
|
|
let monthInt: Int
|
|
let yearInt: Int
|
|
@State var entries: [MoodEntryModel]
|
|
var parentViewModel: DayViewViewModel
|
|
|
|
let columns = [
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500)),
|
|
GridItem(.flexible(minimum: 5, maximum: 500))
|
|
]
|
|
|
|
var image: UIImage {
|
|
let image = shareView.asImage(size: CGSize(width: 666, height: 1190))
|
|
return image
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
HStack {
|
|
Text("\(Random.monthName(fromMonthInt: monthInt)) \(String(yearInt))")
|
|
.font(.title)
|
|
.foregroundColor(textColor)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding()
|
|
|
|
|
|
Image(systemName: "square.and.arrow.up")
|
|
.foregroundColor(textColor)
|
|
.padding(.trailing)
|
|
.accessibilityIdentifier(AccessibilityID.MonthDetail.shareButton)
|
|
.onTapGesture {
|
|
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
|
|
impactMed.impactOccurred()
|
|
|
|
let _image = self.image
|
|
self.shareImage.showSheet = true
|
|
self.shareImage.selectedShareImage = _image
|
|
}
|
|
.accessibilityAddTraits(.isButton)
|
|
.accessibilityLabel(String(localized: "Share month"))
|
|
}
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
|
|
createListView()
|
|
.padding([.leading, .trailing])
|
|
|
|
monthDetails
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
}
|
|
.onAppear(perform: {
|
|
AnalyticsManager.shared.trackScreen(.monthDetail)
|
|
})
|
|
.background(
|
|
theme.currentTheme.bg
|
|
)
|
|
.sheet(isPresented: self.$shareImage.showSheet) {
|
|
if let uiImage = self.shareImage.selectedShareImage {
|
|
ShareSheet(photo: uiImage)
|
|
}
|
|
}
|
|
.alert(DayViewViewModel.updateTitleHeader(forEntry: selectedEntry), isPresented: $showUpdateEntryAlert) {
|
|
ForEach(Mood.allValues) { mood in
|
|
Button(mood.strValue, action: {
|
|
if let selectedEntry = selectedEntry {
|
|
parentViewModel.update(entry: selectedEntry, toMood: mood)
|
|
}
|
|
updateEntries()
|
|
showUpdateEntryAlert = false
|
|
selectedEntry = nil
|
|
})
|
|
.accessibilityIdentifier(AccessibilityID.MonthDetail.moodButton(mood.strValue))
|
|
}
|
|
|
|
if let selectedEntry = selectedEntry,
|
|
deleteEnabled,
|
|
selectedEntry.mood != .missing {
|
|
Button(String(localized: "content_view_delete_entry"), action: {
|
|
parentViewModel.update(entry: selectedEntry, toMood: .missing)
|
|
updateEntries()
|
|
showUpdateEntryAlert = false
|
|
})
|
|
.accessibilityIdentifier(AccessibilityID.MonthDetail.deleteButton)
|
|
}
|
|
|
|
Button(String(localized: "content_view_fill_in_missing_entry_cancel"), role: .cancel, action: {
|
|
updateEntries()
|
|
selectedEntry = nil
|
|
showUpdateEntryAlert = false
|
|
})
|
|
.accessibilityIdentifier(AccessibilityID.MonthDetail.cancelButton)
|
|
}
|
|
}
|
|
|
|
private var shareView: some View {
|
|
VStack {
|
|
HStack {
|
|
Text("\(Random.monthName(fromMonthInt: monthInt)) \(String(yearInt))")
|
|
.font(.title)
|
|
.foregroundColor(textColor)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding()
|
|
}
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
|
|
createListView()
|
|
.padding([.leading, .trailing])
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
|
|
monthDetails
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
}
|
|
.background(
|
|
theme.currentTheme.bg
|
|
)
|
|
}
|
|
|
|
private func createListView() -> some View {
|
|
ScrollView {
|
|
LazyVGrid(columns: columns, spacing: 25) {
|
|
ForEach(entries, id: \.self) { entry in
|
|
listViewEntry(forEntry: entry)
|
|
.accessibilityIdentifier(AccessibilityID.MonthDetail.entryCell(DateFormattingCache.shared.string(for: entry.forDate, format: .dateMedium)))
|
|
.onTapGesture(perform: {
|
|
if entry.canEdit {
|
|
selectedEntry = entry
|
|
showUpdateEntryAlert = true
|
|
}
|
|
})
|
|
.accessibilityAddTraits(.isButton)
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func listViewEntry(forEntry entry: MoodEntryModel) -> some View {
|
|
VStack {
|
|
if entry.mood == .placeholder {
|
|
Text(" ")
|
|
.font(.title3)
|
|
.foregroundColor(Mood.placeholder.color)
|
|
|
|
Circle()
|
|
.frame(minWidth: 5,
|
|
maxWidth: 50,
|
|
minHeight: 5,
|
|
maxHeight: 50,
|
|
alignment: .center)
|
|
.foregroundColor(moodTint.color(forMood: entry.mood))
|
|
} else {
|
|
Text(entry.forDate,
|
|
format: Date.FormatStyle().day())
|
|
.font(.title3)
|
|
.foregroundColor(textColor)
|
|
|
|
entry.mood.icon
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(minWidth: 5,
|
|
maxWidth: 50,
|
|
minHeight: 5,
|
|
maxHeight: 50,
|
|
alignment: .center)
|
|
.foregroundColor(moodTint.color(forMood: entry.mood))
|
|
}
|
|
}
|
|
}
|
|
|
|
private func updateEntries() {
|
|
parentViewModel.updateData()
|
|
let (startDate, endDate) = Date.dateRange(monthInt: monthInt, yearInt: yearInt)
|
|
let updatedEntries = DataController.shared.getData(startDate: startDate, endDate: endDate, includedDays: [1,2,3,4,5,6,7])
|
|
let padded = MoodEntryFunctions.padMoodEntriesMonth(monthEntries: updatedEntries)
|
|
entries = padded
|
|
}
|
|
|
|
private var monthDetails: some View {
|
|
VStack {
|
|
SmallRollUpHeaderView(entries: entries,
|
|
viewType: .constant(.total))
|
|
.frame(minHeight: 0, maxHeight: 100)
|
|
|
|
SmallRollUpHeaderView(entries: entries,
|
|
viewType: .constant(.percentageShape))
|
|
.frame(minHeight: 0, maxHeight: 100)
|
|
.padding(.top, -20)
|
|
}
|
|
.frame(minHeight: 0, maxHeight: 200)
|
|
.padding()
|
|
}
|
|
}
|
|
|
|
struct MonthDetailView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MonthDetailView(monthInt: 5, yearInt: 2022, entries:
|
|
DataController.shared.randomEntries(count: 30).sorted(by: {
|
|
$0.forDate < $1.forDate
|
|
}), parentViewModel: DayViewViewModel(addMonthStartWeekdayPadding: true))
|
|
}
|
|
}
|