This commit is contained in:
Trey t
2022-01-19 09:54:52 -06:00
parent 031de0c933
commit d68db75f87
53 changed files with 567 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "AverageGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "BadGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "GoodGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "GreatGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "HorribleGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "MissingGraphic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

View File

@@ -13,13 +13,15 @@ import CoreData
class WatchTimelineView: Identifiable {
let id = UUID()
let image: Image
let graphic: Image
let date: Date
let color: Color
init(image: Image, date: Date, color: Color) {
init(image: Image, date: Date, color: Color, graphic: Image) {
self.image = image
self.date = date
self.color = color
self.graphic = graphic
}
}
@@ -51,13 +53,20 @@ struct TimeLineCreator {
return day == entryDay && month == entryMonth && year == entryYear
}).first {
let timeLineView = WatchTimelineView(image: item.mood.icon, date: pastDate, color: item.mood.color)
let timeLineView = WatchTimelineView(image: item.mood.icon,
date: pastDate,
color: item.mood.color,
graphic: item.mood.graphic)
returnViews.append(timeLineView)
} else {
let timeLineView = WatchTimelineView(image: Mood.missing.icon, date: pastDate, color: Mood.missing.color)
let timeLineView = WatchTimelineView(image: Mood.missing.icon,
date: pastDate,
color: Mood.missing.color,
graphic: Mood.missing.graphic)
returnViews.append(timeLineView)
}
}
returnViews = returnViews.sorted(by: { $0.date > $1.date })
return returnViews
}
}
@@ -72,7 +81,7 @@ struct Provider: IntentTimelineProvider {
for pastDay in 0...10 {
let pastDate = Calendar.current.date(byAdding: .day, value: -pastDay, to: Date())!
let mood = Mood.allValues.randomElement()!
sampleViews.append( WatchTimelineView(image: mood.icon, date: pastDate, color: mood.color) )
sampleViews.append(WatchTimelineView(image: mood.icon, date: pastDate, color: mood.color, graphic: mood.graphic))
}
return SimpleEntry(date: Date(), configuration: ConfigurationIntent(), timeLineViews: sampleViews)
}
@@ -84,7 +93,7 @@ struct Provider: IntentTimelineProvider {
for pastDay in 0...10 {
let pastDate = Calendar.current.date(byAdding: .day, value: -pastDay, to: Date())!
let mood = Mood.allValues.randomElement()!
timeLineViews.append( WatchTimelineView(image: mood.icon, date: pastDate, color: mood.color) )
timeLineViews.append( WatchTimelineView(image: mood.icon, date: pastDate, color: mood.color, graphic: mood.graphic))
}
} else {
let data = TimeLineCreator.getData()
@@ -148,6 +157,22 @@ struct FeelsWidgetEntryView : View {
}
}
struct FeelsGraphicWidgetEntryView : View {
@Environment(\.sizeCategory) var sizeCategory
@Environment(\.widgetFamily) var family
var entry: Provider.Entry
@ViewBuilder
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()
}
}
}
struct SmallWidgetView: View {
var entry: Provider.Entry
@@ -167,6 +192,18 @@ struct SmallWidgetView: View {
}
}
struct SmallGraphicWidgetView: View {
var entry: Provider.Entry
var body: some View {
GeometryReader { geo in
entry.timeLineViews.first!.graphic
.resizable()
.scaledToFit()
}
}
}
struct TimeHeaderView: View {
let startDate: Date
let endDate: Date
@@ -275,6 +312,13 @@ struct EntryCard: View {
}
@main
struct FeelsBundle: WidgetBundle {
var body: some Widget {
FeelsWidget()
FeelsGraphicWidget()
}
}
struct FeelsWidget: Widget {
let kind: String = "FeelsWidget"
@@ -290,6 +334,21 @@ struct FeelsWidget: Widget {
}
}
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("Feels")
.description("")
.supportedFamilies([.systemSmall])
}
}
struct FeelsWidget_Previews: PreviewProvider {
static var data: [WatchTimelineView] {
var data = PersistenceController.shared.randomEntries(count: 10)