diff --git a/AltWidget/AltWidget.swift b/AltWidget/AltWidget.swift index 87666400..62696399 100644 --- a/AltWidget/AltWidget.swift +++ b/AltWidget/AltWidget.swift @@ -189,9 +189,9 @@ struct HomeScreenWidget: Widget } } -struct LockScreenWidget: Widget +struct TextLockScreenWidget: Widget { - private let kind: String = "LockAppDetail" + private let kind: String = "TextLockAppDetail" public var body: some WidgetConfiguration { if #available(iOSApplicationExtension 16, *) @@ -199,10 +199,10 @@ struct LockScreenWidget: Widget return IntentConfiguration(kind: kind, intent: ViewAppIntent.self, provider: Provider()) { (entry) in - ComplicationView(entry: entry) + ComplicationView(entry: entry, style: .text) } .supportedFamilies([.accessoryCircular]) - .configurationDisplayName("AltWidget") + .configurationDisplayName("AltWidget (Text)") .description("View remaining days until SideStore expires.") } else @@ -212,11 +212,58 @@ struct LockScreenWidget: Widget } } +struct IconLockScreenWidget: Widget +{ + private let kind: String = "IconLockAppDetail" + + public var body: some WidgetConfiguration { + if #available(iOSApplicationExtension 16, *) + { + return IntentConfiguration(kind: kind, + intent: ViewAppIntent.self, + provider: Provider()) { (entry) in + ComplicationView(entry: entry, style: .icon) + } + .supportedFamilies([.accessoryCircular]) + .configurationDisplayName("AltWidget (Icon)") + .description("View remaining days until SideStore expires.") + } + else + { + return EmptyWidgetConfiguration() + } + } +} +// +//struct LockScreenWidget: Widget +//{ +// private let kind: String = "LockAppDetail" +// +// public var body: some WidgetConfiguration { +// if #available(iOSApplicationExtension 16, *) +// { +// return IntentConfiguration(kind: kind, +// intent: ViewAppIntent.self, +// provider: Provider()) { (entry) in +// ComplicationView(entry: entry, style: .icon) +// } +// .supportedFamilies([.accessoryCircular]) +// .configurationDisplayName("AltWidget") +// .description("View remaining days until SideStore expires.") +// } +// else +// { +// return EmptyWidgetConfiguration() +// } +// } +//} + @main struct AltWidgets: WidgetBundle { var body: some Widget { HomeScreenWidget() - LockScreenWidget() + IconLockScreenWidget() + TextLockScreenWidget() } } diff --git a/AltWidget/Assets.xcassets/SmallIcon.imageset/Contents.json b/AltWidget/Assets.xcassets/SmallIcon.imageset/Contents.json new file mode 100644 index 00000000..84d8b8f9 --- /dev/null +++ b/AltWidget/Assets.xcassets/SmallIcon.imageset/Contents.json @@ -0,0 +1,16 @@ +{ + "images" : [ + { + "filename" : "altminicon.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true, + "template-rendering-intent" : "template" + } +} diff --git a/AltWidget/Assets.xcassets/SmallIcon.imageset/altminicon.pdf b/AltWidget/Assets.xcassets/SmallIcon.imageset/altminicon.pdf new file mode 100644 index 00000000..cdddd470 Binary files /dev/null and b/AltWidget/Assets.xcassets/SmallIcon.imageset/altminicon.pdf differ diff --git a/AltWidget/ComplicationView.swift b/AltWidget/ComplicationView.swift index 08ccd62d..98142c41 100644 --- a/AltWidget/ComplicationView.swift +++ b/AltWidget/ComplicationView.swift @@ -9,10 +9,21 @@ import SwiftUI import WidgetKit +@available(iOS 16, *) +extension ComplicationView +{ + enum Style + { + case text + case icon + } +} + @available(iOS 16, *) struct ComplicationView: View { let entry: AppEntry + let style: Style var body: some View { let refreshedDate = self.entry.app?.refreshedDate ?? .now @@ -31,16 +42,42 @@ struct ComplicationView: View } else { - VStack(spacing: -1) { - let fontSize = daysRemaining > 99 ? 18.0 : 20.0 - Text("\(daysRemaining)") - .font(.system(size: fontSize, weight: .bold, design: .rounded)) + switch self.style + { + case .text: + VStack(spacing: -1) { + let fontSize = daysRemaining > 99 ? 18.0 : 20.0 + Text("\(daysRemaining)") + .font(.system(size: fontSize, weight: .bold, design: .rounded)) + + Text(daysRemaining == 1 ? "DAY" : "DAYS") + .font(.caption) + } + .fixedSize() + .offset(y: -1) - Text(daysRemaining == 1 ? "DAY" : "DAYS") - .font(.caption) + case .icon: + ZStack { + // Destination + Image("SmallIcon") + .resizable() + .aspectRatio(1.0, contentMode: .fill) + .scaleEffect(x: 0.8, y: 0.8) + + // Source + ( + daysRemaining > 7 ? + Text("7+") + .font(.system(size: 18, weight: .bold, design: .rounded)) + .kerning(-2) : + + Text("\(daysRemaining)") + .font(.system(size: 20, weight: .bold, design: .rounded)) + ) + .foregroundColor(Color.black) + .blendMode(.destinationOut) // Clip text out of image. + } } - .fixedSize() - .offset(y: -1) } } .gaugeStyle(.accessoryCircularCapacity) @@ -74,14 +111,23 @@ struct ComplicationView_Previews: PreviewProvider { icon: UIImage(named: "AltStore")) return Group { - ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore)) + ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .icon) .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore)) + ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .icon) .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore)) + ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .icon) .previewContext(WidgetPreviewContext(family: .accessoryCircular)) + + ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .text) + .previewContext(WidgetPreviewContext(family: .accessoryCircular)) + + ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .text) + .previewContext(WidgetPreviewContext(family: .accessoryCircular)) + + ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .text) + .previewContext(WidgetPreviewContext(family: .accessoryCircular)) } } }