Add navigation support for Folder and Feed view activities
This commit is contained in:
parent
d641223536
commit
ba9f7ac426
@ -13,4 +13,5 @@ enum ActivityID: String {
|
|||||||
case accountName = "accountName"
|
case accountName = "accountName"
|
||||||
case feedID = "feedID"
|
case feedID = "feedID"
|
||||||
case articleID = "articleID"
|
case articleID = "articleID"
|
||||||
|
case folderName = "folderName"
|
||||||
}
|
}
|
||||||
|
@ -42,14 +42,27 @@ class ActivityManager {
|
|||||||
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Folder")
|
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Folder")
|
||||||
let title = NSString.localizedStringWithFormat(localizedText as NSString, folder.nameForDisplay) as String
|
let title = NSString.localizedStringWithFormat(localizedText as NSString, folder.nameForDisplay) as String
|
||||||
selectingActivity = makeSelectingActivity(type: ActivityType.selectFolder, title: title, identifier: "folder.\(folder.nameForDisplay)")
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectFolder, title: title, identifier: "folder.\(folder.nameForDisplay)")
|
||||||
selectingActivity!.becomeCurrent()
|
|
||||||
|
|
||||||
|
selectingActivity!.userInfo = [
|
||||||
|
ActivityID.accountID.rawValue: folder.account?.accountID ?? "",
|
||||||
|
ActivityID.accountName.rawValue: folder.account?.name ?? "",
|
||||||
|
ActivityID.folderName.rawValue: folder.nameForDisplay
|
||||||
|
]
|
||||||
|
|
||||||
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectingFeed(_ feed: Feed) {
|
func selectingFeed(_ feed: Feed) {
|
||||||
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Feed")
|
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Feed")
|
||||||
let title = NSString.localizedStringWithFormat(localizedText as NSString, feed.nameForDisplay) as String
|
let title = NSString.localizedStringWithFormat(localizedText as NSString, feed.nameForDisplay) as String
|
||||||
selectingActivity = makeSelectingActivity(type: ActivityType.selectFeed, title: title, identifier: feed.url)
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectFeed, title: title, identifier: feed.url)
|
||||||
|
|
||||||
|
selectingActivity!.userInfo = [
|
||||||
|
ActivityID.accountID.rawValue: feed.account?.accountID ?? "",
|
||||||
|
ActivityID.accountName.rawValue: feed.account?.name ?? "",
|
||||||
|
ActivityID.feedID.rawValue: feed.feedID
|
||||||
|
]
|
||||||
|
|
||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,9 +254,9 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
case .selectStarred:
|
case .selectStarred:
|
||||||
handleSelectStarred()
|
handleSelectStarred()
|
||||||
case .selectFolder:
|
case .selectFolder:
|
||||||
print("folder selected")
|
handleSelectFolder(activity)
|
||||||
case .selectFeed:
|
case .selectFeed:
|
||||||
print("feed selected")
|
handleSelectFeed(activity)
|
||||||
case .readArticle:
|
case .readArticle:
|
||||||
handleReadArticle(activity)
|
handleReadArticle(activity)
|
||||||
}
|
}
|
||||||
@ -1224,12 +1224,30 @@ private extension AppCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleSelectFolder(_ activity: NSUserActivity) {
|
||||||
|
guard let accountNode = findAccountNode(for: activity), let folderNode = findFolderNode(for: activity, beginningAt: accountNode) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if let indexPath = indexPathFor(folderNode) {
|
||||||
|
selectFeed(indexPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleSelectFeed(_ activity: NSUserActivity) {
|
||||||
|
guard let accountNode = findAccountNode(for: activity), let feedNode = findFeedNode(for: activity, beginningAt: accountNode) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if let feed = feedNode.representedObject as? Feed {
|
||||||
|
discloseFeed(feed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handleReadArticle(_ activity: NSUserActivity) {
|
func handleReadArticle(_ activity: NSUserActivity) {
|
||||||
guard let accountNode = findAccountNode(for: activity), let feedNode = findFeedNode(for: activity, beginningAt: accountNode) else {
|
guard let accountNode = findAccountNode(for: activity), let feedNode = findFeedNode(for: activity, beginningAt: accountNode) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
masterFeedViewController.discloseFeed(feedNode.representedObject as! Feed)
|
discloseFeed(feedNode.representedObject as! Feed)
|
||||||
|
|
||||||
guard let articleID = activity.userInfo?[ActivityID.articleID.rawValue] as? String else { return }
|
guard let articleID = activity.userInfo?[ActivityID.articleID.rawValue] as? String else { return }
|
||||||
|
|
||||||
@ -1261,6 +1279,16 @@ private extension AppCoordinator {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findFolderNode(for activity: NSUserActivity, beginningAt startingNode: Node) -> Node? {
|
||||||
|
guard let folderName = activity.userInfo?[ActivityID.folderName.rawValue] as? String else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if let node = startingNode.descendantNode(where: { ($0.representedObject as? Folder)?.nameForDisplay == folderName }) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func findFeedNode(for activity: NSUserActivity, beginningAt startingNode: Node) -> Node? {
|
func findFeedNode(for activity: NSUserActivity, beginningAt startingNode: Node) -> Node? {
|
||||||
guard let feedID = activity.userInfo?[ActivityID.feedID.rawValue] as? String else {
|
guard let feedID = activity.userInfo?[ActivityID.feedID.rawValue] as? String else {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user