[AltWidget] Refactors previous widgets to use AppsTimelineProvider

This commit is contained in:
Riley Testut
2023-09-01 13:30:19 -05:00
committed by Magesh K
parent ea2600aba9
commit 2aaa7761fc
4 changed files with 46 additions and 25 deletions

View File

@@ -200,3 +200,28 @@ extension AppsTimelineProvider: TimelineProvider
}
}
}
extension AppsTimelineProvider: IntentTimelineProvider
{
typealias Intent = ViewAppIntent
func getSnapshot(for intent: Intent, in context: Context, completion: @escaping (AppsEntry) -> Void)
{
Task<Void, Never> {
let bundleIDs = [intent.identifier ?? StoreApp.altstoreAppID]
let snapshot = await self.snapshot(for: bundleIDs)
completion(snapshot)
}
}
func getTimeline(for intent: Intent, in context: Context, completion: @escaping (Timeline<AppsEntry>) -> Void)
{
Task<Void, Never> {
let bundleIDs = [intent.identifier ?? StoreApp.altstoreAppID]
let timeline = await self.timeline(for: bundleIDs)
completion(timeline)
}
}
}

View File

@@ -18,7 +18,7 @@ struct AppDetailWidget: Widget
public var body: some WidgetConfiguration {
let configuration = IntentConfiguration(kind: kind,
intent: ViewAppIntent.self,
provider: Provider()) { (entry) in
provider: AppsTimelineProvider()) { (entry) in
AppDetailWidgetView(entry: entry)
}
.supportedFamilies([.systemSmall])
@@ -39,11 +39,11 @@ struct AppDetailWidget: Widget
private struct AppDetailWidgetView: View
{
var entry: AppEntry
var entry: AppsEntry
var body: some View {
Group {
if let app = self.entry.app
if let app = self.entry.apps.first
{
let daysRemaining = app.expirationDate.numberOfCalendarDays(since: self.entry.date)
@@ -130,7 +130,7 @@ private struct AppDetailWidgetView: View
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
.widgetBackground(backgroundView(icon: entry.app?.icon, tintColor: entry.app?.tintColor))
.widgetBackground(backgroundView(icon: entry.apps.first?.icon, tintColor: entry.apps.first?.tintColor))
}
}
@@ -202,19 +202,19 @@ struct WidgetView_Previews: PreviewProvider {
icon: UIImage(named: "Delta"))
return Group {
AppDetailWidgetView(entry: AppEntry(date: Date(), app: altstore))
AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [altstore]))
.previewContext(WidgetPreviewContext(family: .systemSmall))
AppDetailWidgetView(entry: AppEntry(date: Date(), app: delta))
AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [delta]))
.previewContext(WidgetPreviewContext(family: .systemSmall))
AppDetailWidgetView(entry: AppEntry(date: Date(), app: expiredDelta))
AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [expiredDelta]))
.previewContext(WidgetPreviewContext(family: .systemSmall))
AppDetailWidgetView(entry: AppEntry(date: Date(), app: nil))
AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: []))
.previewContext(WidgetPreviewContext(family: .systemSmall))
AppDetailWidgetView(entry: AppEntry(date: Date(), app: nil, isPlaceholder: true))
AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [], isPlaceholder: true))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}

View File

@@ -20,7 +20,7 @@ struct TextLockScreenWidget: Widget
{
return IntentConfiguration(kind: kind,
intent: ViewAppIntent.self,
provider: Provider()) { (entry) in
provider: AppsTimelineProvider()) { (entry) in
ComplicationView(entry: entry, style: .text)
}
.supportedFamilies([.accessoryCircular])
@@ -43,7 +43,7 @@ struct IconLockScreenWidget: Widget
{
return IntentConfiguration(kind: kind,
intent: ViewAppIntent.self,
provider: Provider()) { (entry) in
provider: AppsTimelineProvider()) { (entry) in
ComplicationView(entry: entry, style: .icon)
}
.supportedFamilies([.accessoryCircular])
@@ -70,12 +70,12 @@ extension ComplicationView
@available(iOS 16, *)
private struct ComplicationView: View
{
let entry: AppEntry
let entry: AppsEntry
let style: Style
var body: some View {
let refreshedDate = self.entry.app?.refreshedDate ?? .now
let expirationDate = self.entry.app?.expirationDate ?? .now
let refreshedDate = self.entry.apps.first?.refreshedDate ?? .now
let expirationDate = self.entry.apps.first?.expirationDate ?? .now
let totalDays = expirationDate.numberOfCalendarDays(since: refreshedDate)
let daysRemaining = expirationDate.numberOfCalendarDays(since: self.entry.date)
@@ -160,23 +160,23 @@ struct ComplicationView_Previews: PreviewProvider {
icon: UIImage(named: "AltStore"))
return Group {
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .icon)
ComplicationView(entry: AppsEntry(date: Date(), apps: [weekAltstore]), style: .icon)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .icon)
ComplicationView(entry: AppsEntry(date: expiredDate, apps: [weekAltstore]), style: .icon)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .icon)
ComplicationView(entry: AppsEntry(date: longRefreshedDate, apps: [yearAltstore]), style: .icon)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .text)
ComplicationView(entry: AppsEntry(date: Date(), apps: [weekAltstore]), style: .text)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .text)
ComplicationView(entry: AppsEntry(date: expiredDate, apps: [weekAltstore]), style: .text)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .text)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
ComplicationView(entry: AppsEntry(date: longRefreshedDate, apps: [yearAltstore]), style: .text)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
}
}
}