Update user activity if a feed has been selected and its best icon has been downloaded
This commit is contained in:
parent
9c66f6160e
commit
5aba61ea04
@ -20,6 +20,10 @@ class ActivityManager {
|
|||||||
private var selectingActivity: NSUserActivity? = nil
|
private var selectingActivity: NSUserActivity? = nil
|
||||||
private var readingActivity: NSUserActivity? = nil
|
private var readingActivity: NSUserActivity? = nil
|
||||||
|
|
||||||
|
init() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .FeedIconDidBecomeAvailable, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
func selectingToday() {
|
func selectingToday() {
|
||||||
let title = NSLocalizedString("See articles for Today", comment: "Today")
|
let title = NSLocalizedString("See articles for Today", comment: "Today")
|
||||||
selectingActivity = makeSelectingActivity(type: ActivityType.selectToday, title: title, identifier: "smartfeed.today")
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectToday, title: title, identifier: "smartfeed.today")
|
||||||
@ -62,16 +66,8 @@ class ActivityManager {
|
|||||||
ActivityID.accountName.rawValue: feed.account?.name ?? "",
|
ActivityID.accountName.rawValue: feed.account?.name ?? "",
|
||||||
ActivityID.feedID.rawValue: feed.feedID
|
ActivityID.feedID.rawValue: feed.feedID
|
||||||
]
|
]
|
||||||
|
selectingActivity!.requiredUserInfoKeys = [ActivityID.accountID.rawValue, ActivityID.accountName.rawValue, ActivityID.feedID.rawValue]
|
||||||
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
|
updateSelectingActivityFeedSearchAttributes(with: feed)
|
||||||
attributeSet.title = feed.nameForDisplay
|
|
||||||
attributeSet.keywords = makeKeywords(feed.nameForDisplay)
|
|
||||||
if let image = appDelegate.feedIconDownloader.icon(for: feed) {
|
|
||||||
attributeSet.thumbnailData = image.pngData()
|
|
||||||
} else if let image = appDelegate.faviconDownloader.faviconAsAvatar(for: feed) {
|
|
||||||
attributeSet.thumbnailData = image.pngData()
|
|
||||||
}
|
|
||||||
selectingActivity!.contentAttributeSet = attributeSet
|
|
||||||
|
|
||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
@ -115,6 +111,15 @@ class ActivityManager {
|
|||||||
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: identifers(for: feed)) {}
|
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: identifers(for: feed)) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
||||||
|
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed, let activityFeedId = selectingActivity?.userInfo?[ActivityID.feedID.rawValue] as? String else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if activityFeedId == feed.feedID {
|
||||||
|
updateSelectingActivityFeedSearchAttributes(with: feed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
@ -195,4 +200,20 @@ private extension ActivityManager {
|
|||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateSelectingActivityFeedSearchAttributes(with feed: Feed) {
|
||||||
|
|
||||||
|
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
|
||||||
|
attributeSet.title = feed.nameForDisplay
|
||||||
|
attributeSet.keywords = makeKeywords(feed.nameForDisplay)
|
||||||
|
if let image = appDelegate.feedIconDownloader.icon(for: feed) {
|
||||||
|
attributeSet.thumbnailData = image.pngData()
|
||||||
|
} else if let image = appDelegate.faviconDownloader.faviconAsAvatar(for: feed) {
|
||||||
|
attributeSet.thumbnailData = image.pngData()
|
||||||
|
}
|
||||||
|
|
||||||
|
selectingActivity!.contentAttributeSet = attributeSet
|
||||||
|
selectingActivity!.needsSave = true
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user