closed #27
This commit is contained in:
BIN
FeelsWidget/Assets.xcassets/AverageGraphic.imageset/AverageGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/AverageGraphic.imageset/AverageGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 208 KiB |
21
FeelsWidget/Assets.xcassets/AverageGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/AverageGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
FeelsWidget/Assets.xcassets/BadGraphic.imageset/BadGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/BadGraphic.imageset/BadGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
21
FeelsWidget/Assets.xcassets/BadGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/BadGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
21
FeelsWidget/Assets.xcassets/GoodGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/GoodGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
FeelsWidget/Assets.xcassets/GoodGraphic.imageset/GoodGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/GoodGraphic.imageset/GoodGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
21
FeelsWidget/Assets.xcassets/GreatGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/GreatGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
FeelsWidget/Assets.xcassets/GreatGraphic.imageset/GreatGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/GreatGraphic.imageset/GreatGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
21
FeelsWidget/Assets.xcassets/HorribleGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/HorribleGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
FeelsWidget/Assets.xcassets/HorribleGraphic.imageset/HorribleGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/HorribleGraphic.imageset/HorribleGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 212 KiB |
21
FeelsWidget/Assets.xcassets/MissingGraphic.imageset/Contents.json
vendored
Normal file
21
FeelsWidget/Assets.xcassets/MissingGraphic.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
FeelsWidget/Assets.xcassets/MissingGraphic.imageset/MissingGraphic.png
vendored
Normal file
BIN
FeelsWidget/Assets.xcassets/MissingGraphic.imageset/MissingGraphic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 236 KiB |
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user