Add next unread as a user activity and more aggressively invalidate user activities
This commit is contained in:
parent
e6a4338a86
commit
5cb099aee6
@ -15,8 +15,9 @@ import Intents
|
|||||||
|
|
||||||
class ActivityManager {
|
class ActivityManager {
|
||||||
|
|
||||||
private var selectingActivity: NSUserActivity? = nil
|
private var nextUnreadActivity: NSUserActivity?
|
||||||
private var readingActivity: NSUserActivity? = nil
|
private var selectingActivity: NSUserActivity?
|
||||||
|
private var readingActivity: NSUserActivity?
|
||||||
|
|
||||||
var stateRestorationActivity: NSUserActivity? {
|
var stateRestorationActivity: NSUserActivity? {
|
||||||
if readingActivity != nil {
|
if readingActivity != nil {
|
||||||
@ -30,31 +31,38 @@ class ActivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func invalidateCurrentActivities() {
|
func invalidateCurrentActivities() {
|
||||||
readingActivity?.invalidate()
|
invalidateReading()
|
||||||
readingActivity = nil
|
invalidateSelecting()
|
||||||
selectingActivity?.invalidate()
|
invalidateNextUnread()
|
||||||
selectingActivity = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectingToday() {
|
func selectingToday() {
|
||||||
let title = NSLocalizedString("See articles for Today", comment: "Today")
|
invalidateCurrentActivities()
|
||||||
|
|
||||||
|
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")
|
||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectingAllUnread() {
|
func selectingAllUnread() {
|
||||||
let title = NSLocalizedString("See articles in All Unread", comment: "All Unread")
|
invalidateCurrentActivities()
|
||||||
|
|
||||||
|
let title = NSLocalizedString("See articles in “All Unread”", comment: "All Unread")
|
||||||
selectingActivity = makeSelectingActivity(type: ActivityType.selectAllUnread, title: title, identifier: "smartfeed.allUnread")
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectAllUnread, title: title, identifier: "smartfeed.allUnread")
|
||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectingStarred() {
|
func selectingStarred() {
|
||||||
let title = NSLocalizedString("See articles in Starred", comment: "Starred")
|
invalidateCurrentActivities()
|
||||||
|
|
||||||
|
let title = NSLocalizedString("See articles in “Starred”", comment: "Starred")
|
||||||
selectingActivity = makeSelectingActivity(type: ActivityType.selectStarred, title: title, identifier: "smartfeed.starred")
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectStarred, title: title, identifier: "smartfeed.starred")
|
||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectingFolder(_ folder: Folder) {
|
func selectingFolder(_ folder: Folder) {
|
||||||
|
invalidateCurrentActivities()
|
||||||
|
|
||||||
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: ActivityManager.identifer(for: folder))
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectFolder, title: title, identifier: ActivityManager.identifer(for: folder))
|
||||||
@ -69,6 +77,8 @@ class ActivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func selectingFeed(_ feed: Feed) {
|
func selectingFeed(_ feed: Feed) {
|
||||||
|
invalidateCurrentActivities()
|
||||||
|
|
||||||
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: ActivityManager.identifer(for: feed))
|
selectingActivity = makeSelectingActivity(type: ActivityType.selectFeed, title: title, identifier: ActivityManager.identifer(for: feed))
|
||||||
@ -83,14 +93,36 @@ class ActivityManager {
|
|||||||
selectingActivity!.becomeCurrent()
|
selectingActivity!.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func invalidateSelecting() {
|
||||||
|
selectingActivity?.invalidate()
|
||||||
|
selectingActivity = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectingNextUnread() {
|
||||||
|
guard nextUnreadActivity == nil else { return }
|
||||||
|
let title = NSLocalizedString("See first unread article", comment: "First Unread")
|
||||||
|
nextUnreadActivity = makeSelectingActivity(type: ActivityType.nextUnread, title: title, identifier: "action.nextUnread")
|
||||||
|
nextUnreadActivity!.becomeCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
|
func invalidateNextUnread() {
|
||||||
|
nextUnreadActivity?.invalidate()
|
||||||
|
nextUnreadActivity = nil
|
||||||
|
}
|
||||||
|
|
||||||
func reading(_ article: Article?) {
|
func reading(_ article: Article?) {
|
||||||
readingActivity?.invalidate()
|
invalidateReading()
|
||||||
readingActivity = nil
|
invalidateNextUnread()
|
||||||
guard let article = article else { return }
|
guard let article = article else { return }
|
||||||
readingActivity = makeReadArticleActivity(article)
|
readingActivity = makeReadArticleActivity(article)
|
||||||
readingActivity?.becomeCurrent()
|
readingActivity?.becomeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func invalidateReading() {
|
||||||
|
nextUnreadActivity?.invalidate()
|
||||||
|
nextUnreadActivity = nil
|
||||||
|
}
|
||||||
|
|
||||||
static func cleanUp(_ account: Account) {
|
static func cleanUp(_ account: Account) {
|
||||||
var ids = [String]()
|
var ids = [String]()
|
||||||
|
|
||||||
|
@ -14,5 +14,6 @@ enum ActivityType: String {
|
|||||||
case selectStarred = "com.ranchero.NetNewsWire.SelectStarred"
|
case selectStarred = "com.ranchero.NetNewsWire.SelectStarred"
|
||||||
case selectFolder = "com.ranchero.NetNewsWire.SelectFolder"
|
case selectFolder = "com.ranchero.NetNewsWire.SelectFolder"
|
||||||
case selectFeed = "com.ranchero.NetNewsWire.SelectFeed"
|
case selectFeed = "com.ranchero.NetNewsWire.SelectFeed"
|
||||||
|
case nextUnread = "com.ranchero.NetNewsWire.NextUnread"
|
||||||
case readArticle = "com.ranchero.NetNewsWire.ReadArticle"
|
case readArticle = "com.ranchero.NetNewsWire.ReadArticle"
|
||||||
}
|
}
|
||||||
|
@ -269,6 +269,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
handleSelectFolder(activity)
|
handleSelectFolder(activity)
|
||||||
case .selectFeed:
|
case .selectFeed:
|
||||||
handleSelectFeed(activity)
|
handleSelectFeed(activity)
|
||||||
|
case .nextUnread:
|
||||||
|
selectFirstUnreadInAllUnread()
|
||||||
case .readArticle:
|
case .readArticle:
|
||||||
handleReadArticle(activity)
|
handleReadArticle(activity)
|
||||||
}
|
}
|
||||||
@ -609,7 +611,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func selectFirstUnread() {
|
func selectFirstUnread() {
|
||||||
selectFirstUnreadArticleInTimeline()
|
if selectFirstUnreadArticleInTimeline() {
|
||||||
|
activityManager.selectingNextUnread()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectNextUnread() {
|
func selectNextUnread() {
|
||||||
@ -621,11 +625,14 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if selectNextUnreadArticleInTimeline() {
|
if selectNextUnreadArticleInTimeline() {
|
||||||
|
activityManager.selectingNextUnread()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNextUnreadFeedFetcher()
|
selectNextUnreadFeedFetcher()
|
||||||
selectNextUnreadArticleInTimeline()
|
if selectNextUnreadArticleInTimeline() {
|
||||||
|
activityManager.selectingNextUnread()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user