Split the two large widget files (~2000 lines combined) into 10 focused files: - WidgetBundle.swift: Main @main bundle registration - WidgetModels.swift: Shared data models (WatchTimelineView, SimpleEntry, etc.) - WidgetProviders.swift: Timeline providers and TimeLineCreator - WidgetSharedViews.swift: Shared voting views - FeelsTimelineWidget.swift: Timeline widget (small/medium/large) - FeelsVoteWidget.swift: Vote widget with stats views - FeelsIconWidget.swift: Custom icon widget - FeelsGraphicWidget.swift: Graphic mood widget - FeelsMoodControlWidget.swift: Control Center widget - FeelsLiveActivity.swift: Live Activity with proper previews Preserves real-time update architecture (VoteMoodIntent, WidgetCenter, WidgetDataProvider patterns). Adds proper Live Activity preview support with sample content states. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.6 KiB
Swift
95 lines
2.6 KiB
Swift
//
|
|
// FeelsGraphicWidget.swift
|
|
// FeelsWidget
|
|
//
|
|
// Graphic mood widget (small only)
|
|
//
|
|
|
|
import WidgetKit
|
|
import SwiftUI
|
|
import Intents
|
|
|
|
// MARK: - Widget Configuration
|
|
|
|
struct FeelsGraphicWidget: Widget {
|
|
let kind: String = "FeelsGraphicWidget"
|
|
|
|
var body: some WidgetConfiguration {
|
|
IntentConfiguration(kind: kind,
|
|
intent: ConfigurationIntent.self,
|
|
provider: Provider()) { entry in
|
|
FeelsGraphicWidgetEntryView(entry: entry)
|
|
}
|
|
.configurationDisplayName("Mood Graphic")
|
|
.description("")
|
|
.supportedFamilies([.systemSmall])
|
|
.contentMarginsDisabled()
|
|
}
|
|
}
|
|
|
|
// MARK: - Entry View
|
|
|
|
struct FeelsGraphicWidgetEntryView: View {
|
|
@Environment(\.sizeCategory) var sizeCategory
|
|
@Environment(\.widgetFamily) var family
|
|
|
|
var entry: Provider.Entry
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
SmallGraphicWidgetView(entry: entry)
|
|
}
|
|
}
|
|
|
|
// MARK: - Small Graphic Widget View
|
|
|
|
struct SmallGraphicWidgetView: View {
|
|
var entry: Provider.Entry
|
|
var timeLineView: [WatchTimelineView]
|
|
|
|
init(entry: Provider.Entry) {
|
|
self.entry = entry
|
|
let realData = TimeLineCreator.createViews(daysBack: 2)
|
|
// Check if we have any real mood data (not all missing)
|
|
let hasRealData = realData.contains { view in
|
|
let moodTint: MoodTintable.Type = UserDefaultsStore.moodTintable()
|
|
return view.color != moodTint.color(forMood: .missing)
|
|
}
|
|
timeLineView = hasRealData ? realData : TimeLineCreator.createSampleViews(count: 2)
|
|
}
|
|
|
|
private var iconViewModel: IconViewModel {
|
|
if let first = timeLineView.first {
|
|
return IconViewModel(backgroundImage: first.graphic,
|
|
bgColor: first.color,
|
|
bgOverlayColor: first.secondaryColor,
|
|
centerImage: first.graphic,
|
|
innerColor: first.color)
|
|
} else {
|
|
return IconViewModel.great
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
Color.clear
|
|
.containerBackground(for: .widget) {
|
|
IconView(iconViewModel: iconViewModel)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
#Preview("Graphic - Great", as: .systemSmall) {
|
|
FeelsGraphicWidget()
|
|
} timeline: {
|
|
SimpleEntry(
|
|
date: Date(),
|
|
configuration: ConfigurationIntent(),
|
|
timeLineViews: nil,
|
|
hasSubscription: true,
|
|
hasVotedToday: true,
|
|
promptText: ""
|
|
)
|
|
}
|