|
|
|
|
@ -11,29 +11,26 @@ import Intents |
|
|
|
|
|
|
|
|
|
struct Provider: IntentTimelineProvider { |
|
|
|
|
func placeholder(in context: Context) -> SimpleEntry { |
|
|
|
|
SimpleEntry(id: "", name: "Tea", duration: 4 * 60.0, date: Date(), configuration: SelectCountdownIntent()) |
|
|
|
|
SimpleEntry(countdowns: [], date: Date(), configuration: SelectCountdownIntent()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getSnapshot(for configuration: SelectCountdownIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { |
|
|
|
|
|
|
|
|
|
guard let cp = configuration.countdown, |
|
|
|
|
let identifier = cp.identifier, |
|
|
|
|
let countdown = IntentDataProvider.main.countdown(id: identifier) else { |
|
|
|
|
print("WARNING PLACEHOLDER!") |
|
|
|
|
|
|
|
|
|
let entry = SimpleEntry(id: "", |
|
|
|
|
name: "Not found", |
|
|
|
|
duration: 0.0, |
|
|
|
|
date: Date(), |
|
|
|
|
configuration: configuration) |
|
|
|
|
|
|
|
|
|
completion(entry) |
|
|
|
|
guard let cp = configuration.countdown |
|
|
|
|
else { |
|
|
|
|
completion(placeholder(in: context)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let entry = SimpleEntry(id: identifier, |
|
|
|
|
name: countdown.name, |
|
|
|
|
duration: countdown.duration, |
|
|
|
|
let countdowns: [Countdown] = cp.compactMap { |
|
|
|
|
if let id = $0.identifier { |
|
|
|
|
return IntentDataProvider.main.countdown(id: id) |
|
|
|
|
} else { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let entry = SimpleEntry(countdowns: countdowns, |
|
|
|
|
date: Date(), |
|
|
|
|
configuration: configuration) |
|
|
|
|
completion(entry) |
|
|
|
|
@ -51,26 +48,44 @@ struct Provider: IntentTimelineProvider { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct SimpleEntry: TimelineEntry { |
|
|
|
|
let id: String |
|
|
|
|
let name: String? |
|
|
|
|
let duration: Double |
|
|
|
|
|
|
|
|
|
let countdowns: [Countdown] |
|
|
|
|
|
|
|
|
|
// let id: String |
|
|
|
|
// let name: String? |
|
|
|
|
// let duration: Double |
|
|
|
|
|
|
|
|
|
let date: Date |
|
|
|
|
let configuration: SelectCountdownIntent |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct CountdownWidgetView: View { |
|
|
|
|
struct CountdownSimpleWidgetView: View { |
|
|
|
|
|
|
|
|
|
let id: String |
|
|
|
|
let name: String? |
|
|
|
|
let duration: Double |
|
|
|
|
let countdown: Countdown |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
CountdownView(name: name, duration: duration).widgetURL(URL(string: id)) |
|
|
|
|
CountdownView(countdown: countdown) |
|
|
|
|
.widgetURL(countdown.url) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct CountdownMultiWidgetView: View { |
|
|
|
|
|
|
|
|
|
let countdowns: [Countdown] |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
CountdownMultiView(countdowns: countdowns) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct VoidView : View { |
|
|
|
|
var body: some View { |
|
|
|
|
Text("Nothing here") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct LaunchWidgetEntryView : View { |
|
|
|
|
|
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily |
|
|
|
|
@ -80,7 +95,14 @@ struct LaunchWidgetEntryView : View { |
|
|
|
|
@ViewBuilder |
|
|
|
|
var body: some View { |
|
|
|
|
switch family { |
|
|
|
|
case .systemSmall: CountdownWidgetView(id: entry.id, name: entry.name, duration: entry.duration) |
|
|
|
|
case .systemSmall, .accessoryInline, .accessoryRectangular, .accessoryCircular: |
|
|
|
|
if let countdown = entry.countdowns.first { |
|
|
|
|
CountdownSimpleWidgetView(countdown: countdown) |
|
|
|
|
} else { |
|
|
|
|
VoidView() |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
CountdownMultiView(countdowns: entry.countdowns) |
|
|
|
|
|
|
|
|
|
// case .systemMedium: GameStatusWithLastTurnResult(gameStatus) |
|
|
|
|
// case .systemLarge: GameStatusWithStatistics(gameStatus) |
|
|
|
|
@ -88,7 +110,6 @@ struct LaunchWidgetEntryView : View { |
|
|
|
|
// case .accessoryCircular: HealthLevelCircular(selectedCharacter) |
|
|
|
|
// case .accessoryRectangular: HealthLevelRectangular(selectedCharacter) |
|
|
|
|
// case .accessoryInline: HealthLevelInline(selectedCharacter) |
|
|
|
|
default: CountdownWidgetView(id: entry.id, name: entry.name, duration: entry.duration) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -112,10 +133,13 @@ struct LaunchWidget: Widget { |
|
|
|
|
|
|
|
|
|
struct LaunchWidget_Previews: PreviewProvider { |
|
|
|
|
static var previews: some View { |
|
|
|
|
LaunchWidgetEntryView(entry: SimpleEntry(id: "", name: "Tea", duration: 3 * 60.0, date: Date(), configuration: SelectCountdownIntent())) |
|
|
|
|
|
|
|
|
|
let fake = Countdown.fake(context: PersistenceController.preview.container.viewContext) |
|
|
|
|
|
|
|
|
|
LaunchWidgetEntryView(entry: SimpleEntry(countdowns: [fake], date: Date(), configuration: SelectCountdownIntent())) |
|
|
|
|
.previewContext(WidgetPreviewContext(family: .systemSmall)) |
|
|
|
|
LaunchWidgetEntryView(entry: SimpleEntry(id: "", name: "Tea", duration: 3 * 60.0, date: Date(), configuration: SelectCountdownIntent())) |
|
|
|
|
.previewContext(WidgetPreviewContext(family: .accessoryRectangular)) |
|
|
|
|
LaunchWidgetEntryView(entry: SimpleEntry(countdowns: [fake, fake, fake, fake], date: Date(), configuration: SelectCountdownIntent())) |
|
|
|
|
.previewContext(WidgetPreviewContext(family: .systemMedium)) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|