feat(Widget): Reorganize and rename FollowersCountWidget code

This commit is contained in:
Marcus Kida 2023-01-31 11:43:45 +01:00
parent e2fe1263a4
commit e05a8602d5
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
5 changed files with 252 additions and 33 deletions

View File

@ -31,7 +31,7 @@
2A33063929880835001D4C51 /* CurvedChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33063329880834001D4C51 /* CurvedChart.swift */; };
2A33063A29880835001D4C51 /* LightChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33063429880834001D4C51 /* LightChart.swift */; };
2A33063B29880835001D4C51 /* ChartType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33063529880834001D4C51 /* ChartType.swift */; };
2A33AB662982C4AF008A7FB1 /* FollowCountWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33AB652982C4AF008A7FB1 /* FollowCountWidgetView.swift */; };
2A33AB662982C4AF008A7FB1 /* FollowersCountWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A33AB652982C4AF008A7FB1 /* FollowersCountWidgetView.swift */; };
2A3F6FE3292ECB5E002E6DA7 /* FollowedTagsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3F6FE2292ECB5E002E6DA7 /* FollowedTagsViewModel.swift */; };
2A3F6FE5292F6E44002E6DA7 /* FollowedTagsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3F6FE4292F6E44002E6DA7 /* FollowedTagsTableViewCell.swift */; };
2A506CF4292CD85800059C37 /* FollowedTagsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A506CF3292CD85800059C37 /* FollowedTagsViewController.swift */; };
@ -44,7 +44,7 @@
2A728122297EA9D7004138C5 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A728121297EA9D7004138C5 /* WidgetKit.framework */; };
2A728124297EA9D7004138C5 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A728123297EA9D7004138C5 /* SwiftUI.framework */; };
2A728127297EA9D7004138C5 /* WidgetExtensionBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A728126297EA9D7004138C5 /* WidgetExtensionBundle.swift */; };
2A72812B297EA9D7004138C5 /* FollowersWidgetExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A72812A297EA9D7004138C5 /* FollowersWidgetExtension.swift */; };
2A72812B297EA9D7004138C5 /* FollowersCountWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A72812A297EA9D7004138C5 /* FollowersCountWidget.swift */; };
2A72812E297EA9D8004138C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2A72812D297EA9D8004138C5 /* Assets.xcassets */; };
2A728130297EA9D8004138C5 /* WidgetExtension.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 2A72812C297EA9D7004138C5 /* WidgetExtension.intentdefinition */; };
2A728131297EA9D8004138C5 /* WidgetExtension.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 2A72812C297EA9D7004138C5 /* WidgetExtension.intentdefinition */; };
@ -620,7 +620,7 @@
2A33063429880834001D4C51 /* LightChart.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LightChart.swift; sourceTree = "<group>"; };
2A33063529880834001D4C51 /* ChartType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartType.swift; sourceTree = "<group>"; };
2A33625329759B4200481A90 /* OpenInActionExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OpenInActionExtension.entitlements; sourceTree = "<group>"; };
2A33AB652982C4AF008A7FB1 /* FollowCountWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowCountWidgetView.swift; sourceTree = "<group>"; };
2A33AB652982C4AF008A7FB1 /* FollowersCountWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowersCountWidgetView.swift; sourceTree = "<group>"; };
2A3F6FE2292ECB5E002E6DA7 /* FollowedTagsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowedTagsViewModel.swift; sourceTree = "<group>"; };
2A3F6FE4292F6E44002E6DA7 /* FollowedTagsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowedTagsTableViewCell.swift; sourceTree = "<group>"; };
2A506CF3292CD85800059C37 /* FollowedTagsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowedTagsViewController.swift; sourceTree = "<group>"; };
@ -635,7 +635,7 @@
2A728121297EA9D7004138C5 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
2A728123297EA9D7004138C5 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
2A728126297EA9D7004138C5 /* WidgetExtensionBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetExtensionBundle.swift; sourceTree = "<group>"; };
2A72812A297EA9D7004138C5 /* FollowersWidgetExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowersWidgetExtension.swift; sourceTree = "<group>"; };
2A72812A297EA9D7004138C5 /* FollowersCountWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowersCountWidget.swift; sourceTree = "<group>"; };
2A72812C297EA9D7004138C5 /* WidgetExtension.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = WidgetExtension.intentdefinition; sourceTree = "<group>"; };
2A72812D297EA9D8004138C5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2A72812F297EA9D8004138C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -1409,14 +1409,6 @@
path = Charts;
sourceTree = "<group>";
};
2A33AB642982C4A3008A7FB1 /* WidgetViews */ = {
isa = PBXGroup;
children = (
2A33AB652982C4AF008A7FB1 /* FollowCountWidgetView.swift */,
);
path = WidgetViews;
sourceTree = "<group>";
};
2A506CF2292CD83B00059C37 /* FollowedTags */ = {
isa = PBXGroup;
children = (
@ -1444,11 +1436,10 @@
isa = PBXGroup;
children = (
2A33062E29880834001D4C51 /* LightChart */,
2A33AB642982C4A3008A7FB1 /* WidgetViews */,
2A86A14329892700007F1062 /* Variants */,
2AE202A9297FDDF500F66E55 /* WidgetExtension.entitlements */,
2A72813E297EC762004138C5 /* WidgetExtension.swift */,
2A728126297EA9D7004138C5 /* WidgetExtensionBundle.swift */,
2A72812A297EA9D7004138C5 /* FollowersWidgetExtension.swift */,
2A33062C2987DBFA001D4C51 /* FollowersCountHistory.swift */,
2A72812C297EA9D7004138C5 /* WidgetExtension.intentdefinition */,
2A72812D297EA9D8004138C5 /* Assets.xcassets */,
@ -1457,6 +1448,23 @@
path = WidgetExtension;
sourceTree = "<group>";
};
2A86A14329892700007F1062 /* Variants */ = {
isa = PBXGroup;
children = (
2A86A14429892709007F1062 /* FollowersCount */,
);
path = Variants;
sourceTree = "<group>";
};
2A86A14429892709007F1062 /* FollowersCount */ = {
isa = PBXGroup;
children = (
2A72812A297EA9D7004138C5 /* FollowersCountWidget.swift */,
2A33AB652982C4AF008A7FB1 /* FollowersCountWidgetView.swift */,
);
path = FollowersCount;
sourceTree = "<group>";
};
2D152A8A25C295B8009AA50C /* Content */ = {
isa = PBXGroup;
children = (
@ -3481,9 +3489,9 @@
2A33063A29880835001D4C51 /* LightChart.swift in Sources */,
2A33063B29880835001D4C51 /* ChartType.swift in Sources */,
2A33063629880835001D4C51 /* Math.swift in Sources */,
2A33AB662982C4AF008A7FB1 /* FollowCountWidgetView.swift in Sources */,
2A33AB662982C4AF008A7FB1 /* FollowersCountWidgetView.swift in Sources */,
2A728127297EA9D7004138C5 /* WidgetExtensionBundle.swift in Sources */,
2A72812B297EA9D7004138C5 /* FollowersWidgetExtension.swift in Sources */,
2A72812B297EA9D7004138C5 /* FollowersCountWidget.swift in Sources */,
2A33063929880835001D4C51 /* CurvedChart.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -5,34 +5,34 @@ import SwiftUI
import Intents
import MastodonSDK
struct FollowersProvider: IntentTimelineProvider {
struct FollowersCountWidgetProvider: IntentTimelineProvider {
private let followersHistory = FollowersCountHistory.shared
func placeholder(in context: Context) -> FollowersEntry {
func placeholder(in context: Context) -> FollowersCountEntry {
.placeholder
}
func getSnapshot(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersEntry) -> ()) {
func getSnapshot(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersCountEntry) -> ()) {
guard !context.isPreview else {
return completion(.placeholder)
}
loadCurrentEntry(for: configuration, in: context, completion: completion)
}
func getTimeline(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (Timeline<FollowersEntry>) -> ()) {
func getTimeline(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (Timeline<FollowersCountEntry>) -> ()) {
loadCurrentEntry(for: configuration, in: context) { entry in
completion(Timeline(entries: [entry], policy: .after(.now)))
}
}
}
struct FollowersEntry: TimelineEntry {
struct FollowersCountEntry: TimelineEntry {
let date: Date
let account: FollowersEntryAccountable?
let configuration: FollowersCountIntent
static var placeholder: Self {
FollowersEntry(
FollowersCountEntry(
date: .now,
account: FollowersEntryAccount(
followersCount: 99_900,
@ -46,7 +46,7 @@ struct FollowersEntry: TimelineEntry {
}
static var unconfigured: Self {
FollowersEntry(
FollowersCountEntry(
date: .now,
account: nil,
configuration: FollowersCountIntent()
@ -54,7 +54,7 @@ struct FollowersEntry: TimelineEntry {
}
}
struct FollowersWidgetExtension: Widget {
struct FollowersCountWidget: Widget {
private var availableFamilies: [WidgetFamily] {
if #available(iOS 16, *) {
return [.systemSmall, .accessoryRectangular, .accessoryCircular]
@ -63,8 +63,8 @@ struct FollowersWidgetExtension: Widget {
}
var body: some WidgetConfiguration {
IntentConfiguration(kind: "Followers", intent: FollowersCountIntent.self, provider: FollowersProvider()) { entry in
FollowCountWidgetView(entry: entry)
IntentConfiguration(kind: "Followers", intent: FollowersCountIntent.self, provider: FollowersCountWidgetProvider()) { entry in
FollowersCountWidgetView(entry: entry)
}
.configurationDisplayName("Followers")
.description("Show number of followers.")
@ -72,8 +72,8 @@ struct FollowersWidgetExtension: Widget {
}
}
private extension FollowersProvider {
func loadCurrentEntry(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersEntry) -> Void) {
private extension FollowersCountWidgetProvider {
func loadCurrentEntry(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersCountEntry) -> Void) {
Task {
guard
let authBox = WidgetExtension.appContext
@ -102,7 +102,7 @@ private extension FollowersProvider {
let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0
let entry = FollowersEntry(
let entry = FollowersCountEntry(
date: Date(),
account: FollowersEntryAccount.from(
mastodonAccount: resultingAccount,

View File

@ -4,12 +4,12 @@ import SwiftUI
import WidgetKit
import MastodonAsset
struct FollowCountWidgetView: View {
struct FollowersCountWidgetView: View {
private let followersHistory = FollowersCountHistory.shared
@Environment(\.widgetFamily) var family
var entry: FollowersProvider.Entry
var entry: FollowersCountWidgetProvider.Entry
var body: some View {
if let account = entry.account {

View File

@ -174,8 +174,219 @@
<key>INIntentVerb</key>
<string>View</string>
</dict>
<dict>
<key>INIntentCategory</key>
<string>information</string>
<key>INIntentDescriptionID</key>
<string>B9KyhZ</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentLastParameterTag</key>
<integer>5</integer>
<key>INIntentName</key>
<string>MultiFollowCountSmall</string>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterArraySizes</key>
<array>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>3</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>Small</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>6</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>Medium</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>6</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>Large</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>6</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>ExtraLarge</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>1</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>AccessoryInline</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>1</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>AccessoryCorner</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>1</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>AccessoryCircular</string>
</dict>
<dict>
<key>INIntentParameterArraySizeSize</key>
<integer>1</integer>
<key>INIntentParameterArraySizeSizeClass</key>
<string>AccessoryRectangular</string>
</dict>
</array>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Accounts</string>
<key>INIntentParameterDisplayNameID</key>
<string>fovmPX</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterFixedSizeArray</key>
<integer>1</integer>
<key>INIntentParameterName</key>
<string>accounts</string>
<key>INIntentParameterObjectType</key>
<string>MultiFollowAccountsSmall</string>
<key>INIntentParameterObjectTypeNamespace</key>
<string>88xZPY</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsMultipleValues</key>
<true/>
<key>INIntentParameterTag</key>
<integer>5</integer>
<key>INIntentParameterType</key>
<string>Object</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Multi Follow Count Small</string>
<key>INIntentTitleID</key>
<string>e0W2wo</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>View</string>
</dict>
</array>
<key>INTypes</key>
<array/>
<array>
<dict>
<key>INTypeDisplayName</key>
<string>Account</string>
<key>INTypeDisplayNameID</key>
<string>LUrJ3D</string>
<key>INTypeLastPropertyTag</key>
<integer>101</integer>
<key>INTypeName</key>
<string>MultiFollowAccountsSmall</string>
<key>INTypeProperties</key>
<array>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>1</integer>
<key>INTypePropertyName</key>
<string>identifier</string>
<key>INTypePropertyTag</key>
<integer>1</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>2</integer>
<key>INTypePropertyName</key>
<string>displayString</string>
<key>INTypePropertyTag</key>
<integer>2</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>3</integer>
<key>INTypePropertyName</key>
<string>pronunciationHint</string>
<key>INTypePropertyTag</key>
<integer>3</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>4</integer>
<key>INTypePropertyName</key>
<string>alternativeSpeakableMatches</string>
<key>INTypePropertySupportsMultipleValues</key>
<true/>
<key>INTypePropertyTag</key>
<integer>4</integer>
<key>INTypePropertyType</key>
<string>SpeakableString</string>
</dict>
<dict>
<key>INTypePropertyDisplayName</key>
<string>username</string>
<key>INTypePropertyDisplayNameID</key>
<string>TQNJZz</string>
<key>INTypePropertyDisplayPriority</key>
<integer>5</integer>
<key>INTypePropertyName</key>
<string>property</string>
<key>INTypePropertySupportsMultipleValues</key>
<true/>
<key>INTypePropertyTag</key>
<integer>101</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
</array>
</dict>
</array>
</dict>
</plist>

View File

@ -6,6 +6,6 @@ import SwiftUI
@main
struct WidgetExtensionBundle: WidgetBundle {
var body: some Widget {
FollowersWidgetExtension()
FollowersCountWidget()
}
}