Widget Features: - Add inline voting to timeline widget when no entry exists for today - Show random prompt from notification strings in voting mode - Update vote widget to use simple icon style for selection - Make stats bar full width in voted state view - Add Localizable.strings to widget extension target Bug Fixes: - Fix inverted date calculation in InsightsViewModel streak logic - Replace force unwraps with safe optional handling in widgets - Replace fatalError calls with graceful error handling - Fix CSV import safety in SettingsView Warning Fixes: - Add @retroactive to Color and Date extension conformances - Update deprecated onChange(of:perform:) to new syntax - Replace deprecated applicationIconBadgeNumber with setBadgeCount - Replace deprecated UIApplication.shared.windows API - Add @preconcurrency for Swift 6 protocol conformances - Add missing widget family cases to switch statement - Remove unused variables and #warning directives 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
229 lines
7.9 KiB
Swift
229 lines
7.9 KiB
Swift
//
|
|
// AllMoods.swift
|
|
// Feels (iOS)
|
|
//
|
|
// Created by Trey Tartt on 2/6/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct AllMoodsTotalTemplate: View, SharingTemplate {
|
|
static var description: String {
|
|
"All Time Count"
|
|
}
|
|
|
|
var isPreview: Bool
|
|
var startDate: Date
|
|
var endDate: Date
|
|
var totalEntryCount: Int = 0
|
|
|
|
@Environment(\.presentationMode) var presentationMode
|
|
@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
|
|
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = .white
|
|
|
|
@StateObject private var shareImage = StupidAssShareObservableObject()
|
|
private var entries = [MoodMetrics]()
|
|
|
|
@MainActor
|
|
init(isPreview: Bool, startDate: Date, endDate: Date, fakeData: Bool) {
|
|
self.isPreview = isPreview
|
|
self.startDate = startDate
|
|
self.endDate = endDate
|
|
|
|
var moodEntries: [MoodEntryModel]?
|
|
|
|
if fakeData {
|
|
moodEntries = DataController.shared.randomEntries(count: 10)
|
|
} else {
|
|
moodEntries = DataController.shared.getData(startDate:startDate,
|
|
endDate: endDate,
|
|
includedDays: [1,2,3,4,5,6,7])
|
|
}
|
|
|
|
totalEntryCount = moodEntries?.count ?? 0
|
|
|
|
if let moodEntries = moodEntries {
|
|
entries = Random.createTotalPerc(fromEntries: moodEntries)
|
|
entries = entries.sorted(by: {
|
|
$0.percent > $1.percent
|
|
})
|
|
} else {
|
|
entries = []
|
|
}
|
|
}
|
|
|
|
var image: UIImage {
|
|
let image = shareView.asImage(size: CGSize(width: 666, height: 1190))
|
|
return image
|
|
}
|
|
|
|
var preview: some View {
|
|
circularViews
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.frame(height: 100)
|
|
}
|
|
|
|
private var circularViews: some View {
|
|
VStack {
|
|
VStack {
|
|
HStack {
|
|
ForEach(entries.prefix(2), id: \.mood) { model in
|
|
ZStack {
|
|
Circle().fill(moodTint.color(forMood: model.mood))
|
|
|
|
Text("\(model.percent, specifier: "%.0f")%")
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
.scaledToFill()
|
|
.minimumScaleFactor(0.5)
|
|
.lineLimit(1)
|
|
.foregroundColor(textColor)
|
|
.padding(2)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
|
|
HStack {
|
|
ForEach(entries.suffix(3), id: \.mood) { model in
|
|
ZStack {
|
|
Circle().fill(moodTint.color(forMood: model.mood))
|
|
|
|
Text("\(model.percent, specifier: "%.0f")%")
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
.scaledToFill()
|
|
.minimumScaleFactor(0.5)
|
|
.lineLimit(1)
|
|
.foregroundColor(textColor)
|
|
.padding(2)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
}
|
|
.padding(.top, 30)
|
|
|
|
HStack {
|
|
ForEach(entries, id: \.mood) { model in
|
|
ZStack {
|
|
Circle().fill(moodTint.color(forMood: model.mood))
|
|
|
|
Text("\(model.total)")
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
.scaledToFill()
|
|
.minimumScaleFactor(0.5)
|
|
.lineLimit(1)
|
|
.foregroundColor(textColor)
|
|
.padding(2)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var shareView: some View {
|
|
VStack {
|
|
Text(String(format: String(localized: "share_view_all_moods_total_template_title"), totalEntryCount))
|
|
.font(.title)
|
|
.foregroundColor(textColor)
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.padding()
|
|
|
|
HStack {
|
|
ForEach(Mood.allValues, id: \.self) { mood in
|
|
Circle()
|
|
.frame(minWidth: 10, idealWidth: 70, maxWidth: 100, minHeight: 10, idealHeight: 70, maxHeight: 100)
|
|
.aspectRatio(contentMode: .fit)
|
|
.foregroundColor(moodTint.color(forMood: mood))
|
|
.overlay(
|
|
mood.icon
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.padding(9)
|
|
.foregroundColor(textColor)
|
|
)
|
|
}
|
|
}
|
|
.padding()
|
|
|
|
circularViews
|
|
.padding()
|
|
|
|
Spacer()
|
|
}
|
|
.background(Color(UIColor.secondarySystemBackground))
|
|
.cornerRadius(10)
|
|
.padding()
|
|
}
|
|
|
|
var mainView: some View {
|
|
VStack {
|
|
shareView
|
|
|
|
HStack(alignment: .center) {
|
|
Button(action: {
|
|
let _image = self.image
|
|
self.shareImage.showFuckingSheet = true
|
|
self.shareImage.fuckingWrappedShrable = _image
|
|
}, label: {
|
|
Text("Share")
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
.foregroundColor(Color.white)
|
|
.padding(.top, 20)
|
|
})
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.background(
|
|
Color.green
|
|
)
|
|
.padding(.trailing, -5)
|
|
|
|
Button(action: {
|
|
presentationMode.wrappedValue.dismiss()
|
|
}, label: {
|
|
Text("Exit")
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
.foregroundColor(Color.white)
|
|
.padding(.top, 20)
|
|
})
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.background(
|
|
Color.red
|
|
)
|
|
.padding(.leading, -5)
|
|
}
|
|
.padding([.leading, .trailing], -20)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
if isPreview {
|
|
shareView
|
|
.scaleEffect(2)
|
|
} else {
|
|
mainView
|
|
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
|
|
if let uiImage = self.shareImage.fuckingWrappedShrable {
|
|
ShareSheet(photo: uiImage)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct AllMoodsSharingTemplate_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
|
|
|
|
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
|
|
|
|
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true).shareView
|
|
}
|
|
}
|
|
}
|