2019-08-24 21:57:51 +02:00
|
|
|
//
|
2019-08-25 21:43:11 +02:00
|
|
|
// ActivityManager.swift
|
2019-08-24 21:57:51 +02:00
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 8/23/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreSpotlight
|
|
|
|
import CoreServices
|
|
|
|
import Articles
|
|
|
|
|
2019-08-25 21:43:11 +02:00
|
|
|
class ActivityManager {
|
2019-08-24 21:57:51 +02:00
|
|
|
|
2019-08-25 21:43:11 +02:00
|
|
|
public static var shared = ActivityManager()
|
|
|
|
|
|
|
|
func makeReadArticleActivity(_ article: Article) -> NSUserActivity {
|
2019-08-25 02:31:29 +02:00
|
|
|
let activity = NSUserActivity(activityType: ActivityType.readArticle.rawValue)
|
2019-08-24 21:57:51 +02:00
|
|
|
|
|
|
|
activity.title = article.title
|
|
|
|
|
|
|
|
let feedNameKeywords = article.feed?.nameForDisplay.components(separatedBy: " ").filter { $0.count > 2 } ?? []
|
|
|
|
let articleTitleKeywords = article.title?.components(separatedBy: " ").filter { $0.count > 2 } ?? []
|
|
|
|
let keywords = feedNameKeywords + articleTitleKeywords
|
|
|
|
activity.keywords = Set(keywords)
|
|
|
|
|
|
|
|
activity.userInfo = [
|
|
|
|
ActivityID.accountID.rawValue: article.accountID,
|
2019-08-25 02:31:29 +02:00
|
|
|
ActivityID.accountName.rawValue: article.account?.name ?? "",
|
2019-08-24 21:57:51 +02:00
|
|
|
ActivityID.feedID.rawValue: article.feedID,
|
|
|
|
ActivityID.articleID.rawValue: article.articleID
|
|
|
|
]
|
|
|
|
activity.isEligibleForSearch = true
|
|
|
|
activity.isEligibleForPrediction = false
|
|
|
|
activity.isEligibleForHandoff = true
|
|
|
|
|
|
|
|
// CoreSpotlight
|
|
|
|
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeCompositeContent as String)
|
|
|
|
attributeSet.title = article.title
|
|
|
|
attributeSet.contentDescription = article.summary
|
|
|
|
attributeSet.keywords = keywords
|
2019-08-25 18:51:08 +02:00
|
|
|
attributeSet.relatedUniqueIdentifier = article.url
|
2019-08-24 21:57:51 +02:00
|
|
|
|
|
|
|
if let image = article.avatarImage() {
|
|
|
|
attributeSet.thumbnailData = image.pngData()
|
|
|
|
}
|
|
|
|
|
|
|
|
activity.contentAttributeSet = attributeSet
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|