everything changed
This commit is contained in:
@@ -16,12 +16,14 @@ class WatchTimelineView: Identifiable {
|
||||
let graphic: Image
|
||||
let date: Date
|
||||
let color: Color
|
||||
let secondaryColor: Color
|
||||
|
||||
init(image: Image, date: Date, color: Color, graphic: Image) {
|
||||
init(image: Image, graphic: Image, date: Date, color: Color, secondaryColor: Color) {
|
||||
self.image = image
|
||||
self.date = date
|
||||
self.color = color
|
||||
self.graphic = graphic
|
||||
self.secondaryColor = secondaryColor
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,17 +41,21 @@ struct TimeLineCreator {
|
||||
|
||||
let dayStart = Calendar.current.startOfDay(for: day)
|
||||
let dayEnd = Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: dayStart)!
|
||||
let moodTint: MoodTintable.Type = UserDefaultsStore.moodTintable()
|
||||
let moodImages: MoodImagable.Type = UserDefaultsStore.moodMoodImagable()
|
||||
|
||||
if let todayEntry = PersistenceController.shared.getData(startDate: dayStart, endDate: dayEnd, includedDays: []).first {
|
||||
timeLineView.append(WatchTimelineView(image: todayEntry.mood.icon,
|
||||
date: dayStart,
|
||||
color: todayEntry.mood.color,
|
||||
graphic: todayEntry.mood.graphic))
|
||||
timeLineView.append(WatchTimelineView(image: moodImages.icon(forMood: todayEntry.mood),
|
||||
graphic: moodImages.icon(forMood: todayEntry.mood),
|
||||
date: dayStart,
|
||||
color: moodTint.color(forMood: todayEntry.mood),
|
||||
secondaryColor: moodTint.secondary(forMood: todayEntry.mood)))
|
||||
} else {
|
||||
timeLineView.append(WatchTimelineView(image: Mood.missing.icon,
|
||||
date: dayStart,
|
||||
color: Mood.missing.color,
|
||||
graphic: Mood.missing.graphic))
|
||||
timeLineView.append(WatchTimelineView(image: moodImages.icon(forMood: .missing),
|
||||
graphic: moodImages.icon(forMood: .missing),
|
||||
date: Date(),
|
||||
color: moodTint.color(forMood: .missing),
|
||||
secondaryColor: moodTint.secondary(forMood: .missing)))
|
||||
}
|
||||
}
|
||||
timeLineView = timeLineView.sorted(by: { $0.date > $1.date })
|
||||
@@ -72,7 +78,7 @@ struct Provider: IntentTimelineProvider {
|
||||
|
||||
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
|
||||
let entry = SimpleEntry(date: Date(),
|
||||
configuration: ConfigurationIntent(),
|
||||
configuration: ConfigurationIntent(),
|
||||
timeLineViews: Array(TimeLineCreator.createViews(daysBack: 11).prefix(10)))
|
||||
completion(entry)
|
||||
}
|
||||
@@ -83,8 +89,8 @@ struct Provider: IntentTimelineProvider {
|
||||
timeLineViews: nil)
|
||||
|
||||
let midNightEntry = SimpleEntry(date: Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: Date())!,
|
||||
configuration: ConfigurationIntent(),
|
||||
timeLineViews: nil)
|
||||
configuration: ConfigurationIntent(),
|
||||
timeLineViews: nil)
|
||||
|
||||
let date = Calendar.current.date(byAdding: .second, value: 10, to: Date())!
|
||||
let timeline = Timeline(entries: [entry, midNightEntry], policy: .after(date))
|
||||
@@ -164,7 +170,7 @@ struct SmallWidgetView: View {
|
||||
struct MediumWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
var timeLineView = [WatchTimelineView]()
|
||||
|
||||
|
||||
init(entry: Provider.Entry) {
|
||||
self.entry = entry
|
||||
timeLineView = Array(TimeLineCreator.createViews(daysBack: 6).prefix(5))
|
||||
@@ -191,7 +197,7 @@ struct MediumWidgetView: View {
|
||||
struct LargeWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
var timeLineView = [WatchTimelineView]()
|
||||
|
||||
|
||||
init(entry: Provider.Entry) {
|
||||
self.entry = entry
|
||||
timeLineView = Array(TimeLineCreator.createViews(daysBack: 11).prefix(10))
|
||||
@@ -241,26 +247,31 @@ struct FeelsGraphicWidgetEntryView : View {
|
||||
var body: some View {
|
||||
SmallGraphicWidgetView(entry: entry)
|
||||
.onReceive(NotificationCenter.default.publisher(for: .NSPersistentStoreRemoteChange)) { _ in
|
||||
// make sure you don't call this too often
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
// make sure you don't call this too often
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SmallGraphicWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
var timeLineView = [WatchTimelineView]()
|
||||
var timeLineView: [WatchTimelineView]
|
||||
|
||||
init(entry: Provider.Entry) {
|
||||
self.entry = entry
|
||||
timeLineView = [TimeLineCreator.createViews(daysBack: 2).first!]
|
||||
timeLineView = TimeLineCreator.createViews(daysBack: 2)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geo in
|
||||
timeLineView.first!.graphic
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
if let first = timeLineView.first {
|
||||
IconView(iconViewModel: IconViewModel(backgroundImage: first.graphic,
|
||||
bgColor: first.color,
|
||||
bgOverlayColor: first.secondaryColor,
|
||||
centerImage: first.graphic),
|
||||
isPreview: true)
|
||||
} else {
|
||||
IconView(iconViewModel: IconViewModel.great,
|
||||
isPreview: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,23 +418,49 @@ struct FeelsGraphicWidget: Widget {
|
||||
struct FeelsWidget_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
// FeelsWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
// configuration: ConfigurationIntent(),
|
||||
// timeLineViews: FeelsWidget_Previews.data))
|
||||
// .previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
// .environment(\.sizeCategory, .small)
|
||||
//
|
||||
// FeelsWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
// configuration: ConfigurationIntent(),
|
||||
// timeLineViews: FeelsWidget_Previews.data))
|
||||
// .previewContext(WidgetPreviewContext(family: .systemMedium))
|
||||
// .environment(\.sizeCategory, .medium)
|
||||
//
|
||||
// FeelsWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
// configuration: ConfigurationIntent(),
|
||||
// timeLineViews: FeelsWidget_Previews.data))
|
||||
// .previewContext(WidgetPreviewContext(family: .systemLarge))
|
||||
// .environment(\.sizeCategory, .large)
|
||||
FeelsGraphicWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
configuration: ConfigurationIntent(),
|
||||
timeLineViews: [WatchTimelineView(image: HandEmojiMoodImages.icon(forMood: .great),
|
||||
graphic: HandEmojiMoodImages.icon(forMood: .great),
|
||||
date: Date(),
|
||||
color: MoodTints.Neon.color(forMood: .great),
|
||||
|
||||
secondaryColor: .white),
|
||||
WatchTimelineView(image: HandEmojiMoodImages.icon(forMood: .great),
|
||||
graphic: HandEmojiMoodImages.icon(forMood: .great),
|
||||
date: Date(),
|
||||
color: MoodTints.Neon.color(forMood: .great),
|
||||
|
||||
secondaryColor: .white)]))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
FeelsGraphicWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
configuration: ConfigurationIntent(),
|
||||
timeLineViews: [WatchTimelineView(image: HandEmojiMoodImages.icon(forMood: .horrible),
|
||||
graphic: HandEmojiMoodImages.icon(forMood: .horrible),
|
||||
date: Date(),
|
||||
color: MoodTints.Neon.color(forMood: .horrible),
|
||||
|
||||
secondaryColor: .white),
|
||||
WatchTimelineView(image: HandEmojiMoodImages.icon(forMood: .horrible),
|
||||
graphic: HandEmojiMoodImages.icon(forMood: .horrible),
|
||||
date: Date(),
|
||||
color: MoodTints.Neon.color(forMood: .horrible),
|
||||
|
||||
secondaryColor: .white)]))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
// FeelsWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
// configuration: ConfigurationIntent(),
|
||||
// timeLineViews: FeelsWidget_Previews.data))
|
||||
// .previewContext(WidgetPreviewContext(family: .systemMedium))
|
||||
// .environment(\.sizeCategory, .medium)
|
||||
//
|
||||
// FeelsWidgetEntryView(entry: SimpleEntry(date: Date(),
|
||||
// configuration: ConfigurationIntent(),
|
||||
// timeLineViews: FeelsWidget_Previews.data))
|
||||
// .previewContext(WidgetPreviewContext(family: .systemLarge))
|
||||
// .environment(\.sizeCategory, .large)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user