Compare commits

..

No commits in common. 'f9f548183b8cad9aa921f5dc0dd6ccda33af3d47' and '1dd9520257eaa490ec33c3784703944b6933fac5' have entirely different histories.

  1. 8
      JustOneThing.xcodeproj/project.pbxproj
  2. 64
      WidgetShared/JustOneThingProvider.swift
  3. 14
      WidgetShared/JustOneThingWidget.swift
  4. 15
      WidgetShared/Thing.swift

@ -37,9 +37,6 @@
5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
54EB3C202A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
54EB3C212A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -131,7 +128,6 @@
54928C462A35F8CB00095445 /* WatchWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WatchWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingWidget.swift; sourceTree = "<group>"; };
5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingProvider.swift; sourceTree = "<group>"; };
54EB3C1E2A5434A30082B059 /* Thing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Thing.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -200,7 +196,6 @@
5472018B2A3655E4005B2FCC /* WidgetShared */ = {
isa = PBXGroup;
children = (
54EB3C1E2A5434A30082B059 /* Thing.swift */,
54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */,
5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */,
54928C372A35F8B800095445 /* WidgetAssets.xcassets */,
@ -490,7 +485,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */,
54928C212A35F89A00095445 /* Widget.intentdefinition in Sources */,
5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
547201972A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */,
@ -501,7 +495,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54EB3C202A5434A30082B059 /* Thing.swift in Sources */,
547201962A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */,
5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
5472018E2A36563B005B2FCC /* Widget.intentdefinition in Sources */,
@ -512,7 +505,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54EB3C212A5434A30082B059 /* Thing.swift in Sources */,
547201902A36563C005B2FCC /* Widget.intentdefinition in Sources */,
5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
54928C4B2A35F8CB00095445 /* JustOneThingWidget.swift in Sources */,

@ -9,51 +9,31 @@ import WidgetKit
import SwiftUI
import Intents
struct ThingDataStore {
public var things:[Thing] = [
Thing(text: "The First Thing", createdAt: Date()),
Thing(text: "The Second Thing", createdAt: Date()),
Thing(text: "The Third Thing", createdAt: Date()),
Thing(text: "The Fourth Thing", createdAt: Date()),
Thing(text: "The Fifth Thing", createdAt: Date()),
Thing(text: "The Sixth Thing", createdAt: Date()),
]
public var shuffledThings:[Thing] {
things.shuffled()
struct Provider: IntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), configuration: ConfigurationIntent())
}
}
extension Date {
mutating public func withAddedMinutes(_ minutes:Double) -> Date {
self.addTimeInterval(minutes*60)
return self
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), configuration: configuration)
completion(entry)
}
}
struct ThingProvider: IntentTimelineProvider {
var thingStore:ThingDataStore = ThingDataStore()
func placeholder(in context: Context) -> ThingEntry {
ThingEntry(thing: .placeholder)
}
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (ThingEntry) -> ()) {
completion(ThingEntry(thing: .placeholder, config: configuration))
}
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> ()) {
var entries: [SimpleEntry] = []
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<ThingEntry>) -> ()) {
var timestamp = Date.now
let entries = thingStore.shuffledThings.map {
ThingEntry(thing: $0,
timelineDate: timestamp.withAddedMinutes(15),
config: configuration)
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate, configuration: configuration)
entries.append(entry)
}
completion(Timeline(entries: entries, policy: .atEnd))
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
extension ThingProvider {
func recommendations() -> [IntentRecommendation<ConfigurationIntent>] {
return [
IntentRecommendation(intent: ConfigurationIntent(), description: "My Intent Widget")
@ -61,15 +41,7 @@ extension ThingProvider {
}
}
struct ThingEntry: TimelineEntry {
struct SimpleEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationIntent
let thing: Thing
public init(thing:Thing, timelineDate:Date = .now, config:ConfigurationIntent = ConfigurationIntent()) {
self.thing = thing
self.date = timelineDate
self.configuration = config
}
}

@ -17,11 +17,11 @@ struct JustOneThingWidgetBundle: WidgetBundle {
}
struct ThingEntryView : View {
var entry: ThingEntry
struct JustOneThingWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
Text(entry.thing.text)
Text(entry.date, style: .time)
}
}
@ -29,10 +29,8 @@ struct JustOneThingWidget: Widget {
let kind: String = "JustOneThingWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind,
intent: ConfigurationIntent.self,
provider: ThingProvider()) { entry in
ThingEntryView(entry: entry)
IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
JustOneThingWidgetEntryView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
@ -41,7 +39,7 @@ struct JustOneThingWidget: Widget {
struct Widget_Previews: PreviewProvider {
static var previews: some View {
ThingEntryView(entry: ThingEntry(thing: .placeholder))
JustOneThingWidgetEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent()))
#if os(watchOS)
.previewContext(WidgetPreviewContext(family: .accessoryRectangular))
#else

@ -1,15 +0,0 @@
//
// Thing.swift
// JustOneThing
//
// Created by Alan Francis on 04/07/2023.
//
import Foundation
struct Thing {
let text: String
let createdAt: Date
static let placeholder: Thing = Thing(text: "placeholder", createdAt: Date.now)
}
Loading…
Cancel
Save