Update graphic for article reading user activities
This commit is contained in:
parent
3d343eb91d
commit
c1460d3df3
|
@ -18,6 +18,7 @@ class ActivityManager {
|
||||||
private var nextUnreadActivity: NSUserActivity?
|
private var nextUnreadActivity: NSUserActivity?
|
||||||
private var selectingActivity: NSUserActivity?
|
private var selectingActivity: NSUserActivity?
|
||||||
private var readingActivity: NSUserActivity?
|
private var readingActivity: NSUserActivity?
|
||||||
|
private var readingArticle: Article?
|
||||||
|
|
||||||
var stateRestorationActivity: NSUserActivity? {
|
var stateRestorationActivity: NSUserActivity? {
|
||||||
if readingActivity != nil {
|
if readingActivity != nil {
|
||||||
|
@ -103,14 +104,21 @@ class ActivityManager {
|
||||||
func reading(_ article: Article?) {
|
func reading(_ article: Article?) {
|
||||||
invalidateReading()
|
invalidateReading()
|
||||||
invalidateNextUnread()
|
invalidateNextUnread()
|
||||||
|
|
||||||
guard let article = article else { return }
|
guard let article = article else { return }
|
||||||
readingActivity = makeReadArticleActivity(article)
|
readingActivity = makeReadArticleActivity(article)
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
updateReadArticleSearchAttributes(with: article)
|
||||||
|
#endif
|
||||||
|
|
||||||
readingActivity?.becomeCurrent()
|
readingActivity?.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func invalidateReading() {
|
func invalidateReading() {
|
||||||
readingActivity?.invalidate()
|
readingActivity?.invalidate()
|
||||||
readingActivity = nil
|
readingActivity = nil
|
||||||
|
readingArticle = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
@ -150,6 +158,11 @@ class ActivityManager {
|
||||||
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed, let activityFeedId = selectingActivity?.userInfo?[DeepLinkKey.feedID.rawValue] as? String else {
|
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed, let activityFeedId = selectingActivity?.userInfo?[DeepLinkKey.feedID.rawValue] as? String else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let article = readingArticle, activityFeedId == article.feedID {
|
||||||
|
updateReadArticleSearchAttributes(with: article)
|
||||||
|
}
|
||||||
|
|
||||||
if activityFeedId == feed.feedID {
|
if activityFeedId == feed.feedID {
|
||||||
updateSelectingActivityFeedSearchAttributes(with: feed)
|
updateSelectingActivityFeedSearchAttributes(with: feed)
|
||||||
}
|
}
|
||||||
|
@ -183,30 +196,38 @@ private extension ActivityManager {
|
||||||
activity.isEligibleForHandoff = true
|
activity.isEligibleForHandoff = true
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
activity.keywords = Set(makeKeywords(article))
|
||||||
let feedNameKeywords = makeKeywords(article.feed?.nameForDisplay)
|
|
||||||
let articleTitleKeywords = makeKeywords(article.title)
|
|
||||||
let keywords = feedNameKeywords + articleTitleKeywords
|
|
||||||
activity.keywords = Set(keywords)
|
|
||||||
|
|
||||||
activity.isEligibleForSearch = true
|
activity.isEligibleForSearch = true
|
||||||
activity.isEligibleForPrediction = false
|
activity.isEligibleForPrediction = false
|
||||||
activity.persistentIdentifier = ActivityManager.identifer(for: article)
|
activity.persistentIdentifier = ActivityManager.identifer(for: article)
|
||||||
|
updateReadArticleSearchAttributes(with: article)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
readingArticle = article
|
||||||
|
|
||||||
|
return activity
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateReadArticleSearchAttributes(with article: Article) {
|
||||||
|
|
||||||
// CoreSpotlight
|
|
||||||
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeCompositeContent as String)
|
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeCompositeContent as String)
|
||||||
attributeSet.title = article.title
|
attributeSet.title = article.title
|
||||||
attributeSet.contentDescription = article.summary
|
attributeSet.contentDescription = article.summary
|
||||||
attributeSet.keywords = keywords
|
attributeSet.keywords = makeKeywords(article)
|
||||||
|
|
||||||
if let image = article.avatarImage() {
|
if let image = article.avatarImage() {
|
||||||
attributeSet.thumbnailData = image.pngData()
|
attributeSet.thumbnailData = image.pngData()
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.contentAttributeSet = attributeSet
|
readingActivity?.contentAttributeSet = attributeSet
|
||||||
#endif
|
readingActivity?.needsSave = true
|
||||||
|
|
||||||
return activity
|
}
|
||||||
|
|
||||||
|
func makeKeywords(_ article: Article) -> [String] {
|
||||||
|
let feedNameKeywords = makeKeywords(article.feed?.nameForDisplay)
|
||||||
|
let articleTitleKeywords = makeKeywords(article.title)
|
||||||
|
return feedNameKeywords + articleTitleKeywords
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeKeywords(_ value: String?) -> [String] {
|
func makeKeywords(_ value: String?) -> [String] {
|
||||||
|
|
Loading…
Reference in New Issue