Add feed/group user activities
This commit is contained in:
parent
9d22d4ef35
commit
533bc025f3
|
@ -6,6 +6,8 @@
|
||||||
<array>
|
<array>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-unread</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-unread</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-all</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-all</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-feed</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.read-group</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.preferences</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.preferences</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.add-account</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.add-account</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.activate-account</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.activate-account</string>
|
||||||
|
|
|
@ -122,6 +122,24 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
split.selectHomeItem(.unread)
|
split.selectHomeItem(.unread)
|
||||||
case NSUserActivity.readAllType:
|
case NSUserActivity.readAllType:
|
||||||
split.selectHomeItem(.all)
|
split.selectHomeItem(.all)
|
||||||
|
case NSUserActivity.readFeedType:
|
||||||
|
guard let feedID = activity.feedID() else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
let req = Feed.fetchRequest()
|
||||||
|
req.predicate = NSPredicate(format: "id = %@", feedID)
|
||||||
|
if let feed = try? fervorController.persistentContainer.viewContext.fetch(req).first {
|
||||||
|
split.selectHomeItem(.feed(feed))
|
||||||
|
}
|
||||||
|
case NSUserActivity.readGroupType:
|
||||||
|
guard let groupID = activity.groupID() else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
let req = Group.fetchRequest()
|
||||||
|
req.predicate = NSPredicate(format: "id = %@", groupID)
|
||||||
|
if let group = try? fervorController.persistentContainer.viewContext.fetch(req).first {
|
||||||
|
split.selectHomeItem(.group(group))
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,9 +208,9 @@ class HomeViewController: UIViewController {
|
||||||
case .unread:
|
case .unread:
|
||||||
vc.userActivity = .readUnread(account: fervorController.account!)
|
vc.userActivity = .readUnread(account: fervorController.account!)
|
||||||
case .group(let group):
|
case .group(let group):
|
||||||
break
|
vc.userActivity = .readGroup(group, account: fervorController.account!)
|
||||||
case .feed(let feed):
|
case .feed(let feed):
|
||||||
break
|
vc.userActivity = .readFeed(feed, account: fervorController.account!)
|
||||||
}
|
}
|
||||||
return vc
|
return vc
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ extension NSUserActivity {
|
||||||
static let activateAccountType = "net.shadowfacts.Reader.activity.activate-account"
|
static let activateAccountType = "net.shadowfacts.Reader.activity.activate-account"
|
||||||
static let readUnreadType = "net.shadowfacts.Reader.activity.read-unread"
|
static let readUnreadType = "net.shadowfacts.Reader.activity.read-unread"
|
||||||
static let readAllType = "net.shadowfacts.Reader.activity.read-all"
|
static let readAllType = "net.shadowfacts.Reader.activity.read-all"
|
||||||
|
static let readFeedType = "net.shadowfacts.Reader.activity.read-feed"
|
||||||
|
static let readGroupType = "net.shadowfacts.Reader.activity.read-group"
|
||||||
|
|
||||||
func accountID() -> Data? {
|
func accountID() -> Data? {
|
||||||
let types = [
|
let types = [
|
||||||
|
@ -29,6 +31,22 @@ extension NSUserActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func feedID() -> String? {
|
||||||
|
if activityType == NSUserActivity.readFeedType {
|
||||||
|
return userInfo?["feedID"] as? String
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func groupID() -> String? {
|
||||||
|
if activityType == NSUserActivity.readGroupType {
|
||||||
|
return userInfo?["groupID"] as? String
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static func preferences() -> NSUserActivity {
|
static func preferences() -> NSUserActivity {
|
||||||
return NSUserActivity(activityType: preferencesType)
|
return NSUserActivity(activityType: preferencesType)
|
||||||
}
|
}
|
||||||
|
@ -69,4 +87,30 @@ extension NSUserActivity {
|
||||||
return activity
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func readFeed(_ feed: Feed, account: LocalData.Account) -> NSUserActivity {
|
||||||
|
let activity = NSUserActivity(activityType: readFeedType)
|
||||||
|
activity.isEligibleForHandoff = true
|
||||||
|
activity.isEligibleForPrediction = true
|
||||||
|
activity.title = "Show articles from \(feed.title!)"
|
||||||
|
activity.userInfo = [
|
||||||
|
"accountID": account.id,
|
||||||
|
"feedID": feed.id!
|
||||||
|
]
|
||||||
|
activity.targetContentIdentifier = account.id.base64EncodedString()
|
||||||
|
return activity
|
||||||
|
}
|
||||||
|
|
||||||
|
static func readGroup(_ group: Group, account: LocalData.Account) -> NSUserActivity {
|
||||||
|
let activity = NSUserActivity(activityType: readGroupType)
|
||||||
|
activity.isEligibleForHandoff = true
|
||||||
|
activity.isEligibleForPrediction = true
|
||||||
|
activity.title = "Show articles from \(group.title)"
|
||||||
|
activity.userInfo = [
|
||||||
|
"accountID": account.id,
|
||||||
|
"groupID": group.id!
|
||||||
|
]
|
||||||
|
activity.targetContentIdentifier = account.id.base64EncodedString()
|
||||||
|
return activity
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue