mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Implement Feed protocol.
This commit is contained in:
@@ -38,13 +38,13 @@ class ActivityManager {
|
||||
invalidateNextUnread()
|
||||
}
|
||||
|
||||
func selecting(fetcher: ArticleFetcher) {
|
||||
func selecting(feed: Feed) {
|
||||
invalidateCurrentActivities()
|
||||
|
||||
selectingActivity = makeSelectFeedActivity(fetcher: fetcher)
|
||||
selectingActivity = makeSelectFeedActivity(feed: feed)
|
||||
|
||||
if let feed = fetcher as? WebFeed {
|
||||
updateSelectingActivityFeedSearchAttributes(with: feed)
|
||||
if let webFeed = feed as? WebFeed {
|
||||
updateSelectingActivityFeedSearchAttributes(with: webFeed)
|
||||
}
|
||||
|
||||
donate(selectingActivity!)
|
||||
@@ -76,12 +76,12 @@ class ActivityManager {
|
||||
nextUnreadActivity = nil
|
||||
}
|
||||
|
||||
func reading(fetcher: ArticleFetcher?, article: Article?) {
|
||||
func reading(feed: Feed?, article: Article?) {
|
||||
invalidateReading()
|
||||
invalidateNextUnread()
|
||||
|
||||
guard let article = article else { return }
|
||||
readingActivity = makeReadArticleActivity(fetcher: fetcher, article: article)
|
||||
readingActivity = makeReadArticleActivity(feed: feed, article: article)
|
||||
|
||||
#if os(iOS)
|
||||
updateReadArticleSearchAttributes(with: article)
|
||||
@@ -151,37 +151,36 @@ class ActivityManager {
|
||||
|
||||
private extension ActivityManager {
|
||||
|
||||
func makeSelectFeedActivity(fetcher: ArticleFetcher) -> NSUserActivity {
|
||||
func makeSelectFeedActivity(feed: Feed) -> NSUserActivity {
|
||||
let activity = NSUserActivity(activityType: ActivityType.selectFeed.rawValue)
|
||||
|
||||
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Folder")
|
||||
let displayName = (fetcher as? DisplayNameProvider)?.nameForDisplay ?? ""
|
||||
let title = NSString.localizedStringWithFormat(localizedText as NSString, displayName) as String
|
||||
let title = NSString.localizedStringWithFormat(localizedText as NSString, feed.nameForDisplay) as String
|
||||
activity.title = title
|
||||
|
||||
activity.keywords = Set(makeKeywords(title))
|
||||
activity.isEligibleForSearch = true
|
||||
|
||||
let articleFetcherIdentifierUserInfo = fetcher.articleFetcherType?.userInfo ?? [AnyHashable: Any]()
|
||||
let articleFetcherIdentifierUserInfo = feed.feedID?.userInfo ?? [AnyHashable: Any]()
|
||||
activity.userInfo = [UserInfoKey.feedIdentifier: articleFetcherIdentifierUserInfo]
|
||||
activity.requiredUserInfoKeys = Set(activity.userInfo!.keys.map { $0 as! String })
|
||||
|
||||
#if os(iOS)
|
||||
activity.suggestedInvocationPhrase = title
|
||||
activity.isEligibleForPrediction = true
|
||||
activity.persistentIdentifier = fetcher.articleFetcherType?.description ?? ""
|
||||
activity.contentAttributeSet?.relatedUniqueIdentifier = fetcher.articleFetcherType?.description ?? ""
|
||||
activity.persistentIdentifier = feed.feedID?.description ?? ""
|
||||
activity.contentAttributeSet?.relatedUniqueIdentifier = feed.feedID?.description ?? ""
|
||||
#endif
|
||||
|
||||
return activity
|
||||
}
|
||||
|
||||
func makeReadArticleActivity(fetcher: ArticleFetcher?, article: Article) -> NSUserActivity {
|
||||
func makeReadArticleActivity(feed: Feed?, article: Article) -> NSUserActivity {
|
||||
let activity = NSUserActivity(activityType: ActivityType.readArticle.rawValue)
|
||||
activity.title = ArticleStringFormatter.truncatedTitle(article)
|
||||
|
||||
if let fetcher = fetcher {
|
||||
let articleFetcherIdentifierUserInfo = fetcher.articleFetcherType?.userInfo ?? [AnyHashable: Any]()
|
||||
if let feed = feed {
|
||||
let articleFetcherIdentifierUserInfo = feed.feedID?.userInfo ?? [AnyHashable: Any]()
|
||||
let articlePathUserInfo = article.pathUserInfo
|
||||
activity.userInfo = [UserInfoKey.feedIdentifier: articleFetcherIdentifierUserInfo, UserInfoKey.articlePath: articlePathUserInfo]
|
||||
} else {
|
||||
|
||||
@@ -13,12 +13,11 @@ import Articles
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
protocol PseudoFeed: class, DisplayNameProvider, UnreadCountProvider, SmallIconProvider, PasteboardWriterOwner {
|
||||
protocol PseudoFeed: class, Feed, SmallIconProvider, PasteboardWriterOwner {
|
||||
|
||||
}
|
||||
|
||||
private var smartFeedIcon: RSImage = {
|
||||
|
||||
return RSImage(named: NSImage.smartBadgeTemplateName)!
|
||||
}()
|
||||
|
||||
@@ -35,7 +34,7 @@ import Articles
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
protocol PseudoFeed: class, DisplayNameProvider, UnreadCountProvider, SmallIconProvider {
|
||||
protocol PseudoFeed: class, Feed, SmallIconProvider {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import Articles
|
||||
|
||||
struct SearchFeedDelegate: SmartFeedDelegate {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
return ArticleFetcherType.smartFeed(String(describing: SearchFeedDelegate.self))
|
||||
var feedID: FeedIdentifier? {
|
||||
return FeedIdentifier.smartFeed(String(describing: SearchFeedDelegate.self))
|
||||
}
|
||||
|
||||
var nameForDisplay: String {
|
||||
|
||||
@@ -13,8 +13,8 @@ import Articles
|
||||
|
||||
struct SearchTimelineFeedDelegate: SmartFeedDelegate {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
return ArticleFetcherType.smartFeed(String(describing: SearchTimelineFeedDelegate.self))
|
||||
var feedID: FeedIdentifier? {
|
||||
return FeedIdentifier.smartFeed(String(describing: SearchTimelineFeedDelegate.self))
|
||||
}
|
||||
|
||||
var nameForDisplay: String {
|
||||
|
||||
@@ -13,6 +13,10 @@ import Account
|
||||
|
||||
final class SmartFeed: PseudoFeed {
|
||||
|
||||
var feedID: FeedIdentifier? {
|
||||
delegate.feedID
|
||||
}
|
||||
|
||||
var nameForDisplay: String {
|
||||
return delegate.nameForDisplay
|
||||
}
|
||||
@@ -71,10 +75,6 @@ final class SmartFeed: PseudoFeed {
|
||||
}
|
||||
|
||||
extension SmartFeed: ArticleFetcher {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
delegate.articleFetcherType
|
||||
}
|
||||
|
||||
func fetchArticles() -> Set<Article> {
|
||||
return delegate.fetchArticles()
|
||||
|
||||
@@ -11,10 +11,8 @@ import Account
|
||||
import Articles
|
||||
import RSCore
|
||||
|
||||
protocol SmartFeedDelegate: DisplayNameProvider, ArticleFetcher, SmallIconProvider {
|
||||
|
||||
protocol SmartFeedDelegate: FeedIdentifiable, DisplayNameProvider, ArticleFetcher, SmallIconProvider {
|
||||
var fetchType: FetchType { get }
|
||||
|
||||
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import Account
|
||||
|
||||
struct StarredFeedDelegate: SmartFeedDelegate {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
return ArticleFetcherType.smartFeed(String(describing: StarredFeedDelegate.self))
|
||||
var feedID: FeedIdentifier? {
|
||||
return FeedIdentifier.smartFeed(String(describing: StarredFeedDelegate.self))
|
||||
}
|
||||
|
||||
let nameForDisplay = NSLocalizedString("Starred", comment: "Starred pseudo-feed title")
|
||||
|
||||
@@ -13,8 +13,8 @@ import Account
|
||||
|
||||
struct TodayFeedDelegate: SmartFeedDelegate {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
return ArticleFetcherType.smartFeed(String(describing: TodayFeedDelegate.self))
|
||||
var feedID: FeedIdentifier? {
|
||||
return FeedIdentifier.smartFeed(String(describing: TodayFeedDelegate.self))
|
||||
}
|
||||
|
||||
let nameForDisplay = NSLocalizedString("Today", comment: "Today pseudo-feed title")
|
||||
|
||||
@@ -19,6 +19,10 @@ import Articles
|
||||
|
||||
final class UnreadFeed: PseudoFeed {
|
||||
|
||||
var feedID: FeedIdentifier? {
|
||||
return FeedIdentifier.smartFeed(String(describing: UnreadFeed.self))
|
||||
}
|
||||
|
||||
let nameForDisplay = NSLocalizedString("All Unread", comment: "All Unread pseudo-feed title")
|
||||
let fetchType = FetchType.unread
|
||||
|
||||
@@ -53,10 +57,6 @@ final class UnreadFeed: PseudoFeed {
|
||||
|
||||
extension UnreadFeed: ArticleFetcher {
|
||||
|
||||
var articleFetcherType: ArticleFetcherType? {
|
||||
return ArticleFetcherType.smartFeed(String(describing: UnreadFeed.self))
|
||||
}
|
||||
|
||||
func fetchArticles() -> Set<Article> {
|
||||
return fetchUnreadArticles()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user