forked from shadowfacts/Tusker
Add NSUserActivity for checking mentions
This commit is contained in:
parent
9f818328ee
commit
d08789bfab
|
@ -6,6 +6,7 @@
|
|||
<array>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.show-timeline</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-notifications</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-mentions</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.new-post</string>
|
||||
</array>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
|
|
|
@ -46,6 +46,16 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
navigationController.presentationController?.delegate = compose
|
||||
present(navigationController, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension MainTabBarViewController {
|
||||
enum Tab: Int {
|
||||
case timelines
|
||||
case notifications
|
||||
case compose
|
||||
case search
|
||||
case myProfile
|
||||
}
|
||||
|
||||
func select(tab: Tab) {
|
||||
if tab == .compose {
|
||||
|
@ -62,15 +72,4 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
return viewControllers![tab.rawValue]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MainTabBarViewController {
|
||||
enum Tab: Int {
|
||||
case timelines
|
||||
case notifications
|
||||
case compose
|
||||
case search
|
||||
case myProfile
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ class NotificationsPageViewController: SegmentedPageViewController {
|
|||
init() {
|
||||
let notifications = NotificationsTableViewController(allowedTypes: Pachyderm.Notification.Kind.allCases)
|
||||
notifications.title = notificationsTitle
|
||||
notifications.userActivity = UserActivityManager.checkNotificationsActivity()
|
||||
|
||||
let mentions = NotificationsTableViewController(allowedTypes: [.mention])
|
||||
mentions.title = mentionsTitle
|
||||
mentions.userActivity = UserActivityManager.checkMentionsActivity()
|
||||
|
||||
super.init(titles: [
|
||||
notificationsTitle,
|
||||
|
@ -40,8 +42,12 @@ class NotificationsPageViewController: SegmentedPageViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
selectMode(Preferences.shared.defaultNotificationsMode)
|
||||
}
|
||||
|
||||
func selectMode(_ mode: NotificationsMode) {
|
||||
let index: Int
|
||||
switch Preferences.shared.defaultNotificationsMode {
|
||||
switch mode {
|
||||
case .allNotifications:
|
||||
index = 0
|
||||
case .mentionsOnly:
|
||||
|
|
|
@ -69,8 +69,6 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
|||
self.newer = pagination?.newer
|
||||
self.older = pagination?.older
|
||||
}
|
||||
|
||||
userActivity = UserActivityManager.checkNotificationsActivity()
|
||||
}
|
||||
|
||||
// MARK: - Table view data source
|
||||
|
|
|
@ -15,14 +15,14 @@ class UserActivityManager {
|
|||
private static let encoder = PropertyListEncoder()
|
||||
private static let decoder = PropertyListDecoder()
|
||||
|
||||
private static func present(_ vc: UIViewController, animated: Bool = true) {
|
||||
UIApplication.shared.delegate?.window??.rootViewController?.present(vc, animated: animated)
|
||||
}
|
||||
|
||||
private static func getMainTabBarController() -> MainTabBarViewController {
|
||||
return (UIApplication.shared.delegate! as! AppDelegate).window!.rootViewController as! MainTabBarViewController
|
||||
}
|
||||
|
||||
private static func present(_ vc: UIViewController, animated: Bool = true) {
|
||||
getMainTabBarController().present(vc, animated: animated)
|
||||
}
|
||||
|
||||
// MARK: - New Post
|
||||
static func newPostActivity(mentioning: Account? = nil) -> NSUserActivity {
|
||||
let activity = NSUserActivity(type: .newPost)
|
||||
|
@ -49,13 +49,38 @@ class UserActivityManager {
|
|||
static func checkNotificationsActivity() -> NSUserActivity {
|
||||
let activity = NSUserActivity(type: .checkNotifications)
|
||||
activity.isEligibleForPrediction = true
|
||||
activity.title = "Check Notifications"
|
||||
activity.suggestedInvocationPhrase = "Check my Tusker notifications"
|
||||
activity.title = NSLocalizedString("Check Notifications", comment: "check notifications shortcut title")
|
||||
activity.suggestedInvocationPhrase = NSLocalizedString("Check my Tusker notifications", comment: "check notifications shortcut invocation phrase")
|
||||
return activity
|
||||
}
|
||||
|
||||
static func handleCheckNotifications(activity: NSUserActivity) {
|
||||
getMainTabBarController().select(tab: .notifications)
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .notifications)
|
||||
if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
|
||||
navController.popToRootViewController(animated: false)
|
||||
notificationsPageController.selectMode(.allNotifications)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Check Mentions
|
||||
static func checkMentionsActivity() -> NSUserActivity {
|
||||
let activity = NSUserActivity(type: .checkMentions)
|
||||
activity.isEligibleForPrediction = true
|
||||
activity.title = NSLocalizedString("Check Mentions", comment: "check mentions shortcut title")
|
||||
activity.suggestedInvocationPhrase = NSLocalizedString("Check my mentions", comment: "check mentions shortcut invocation phrase")
|
||||
return activity
|
||||
}
|
||||
|
||||
static func handleCheckMentions(activity: NSUserActivity) {
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .notifications)
|
||||
if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
|
||||
navController.popToRootViewController(animated: false)
|
||||
notificationsPageController.selectMode(.mentionsOnly)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Show Timeline
|
||||
|
|
|
@ -11,6 +11,7 @@ import Foundation
|
|||
enum UserActivityType: String {
|
||||
case newPost = "net.shadowfacts.Tusker.activity.new-post"
|
||||
case checkNotifications = "net.shadowfacts.Tusker.activity.check-notifications"
|
||||
case checkMentions = "net.shadowfacts.Tusker.activity.check-mentions"
|
||||
case showTimeline = "net.shadowfacts.Tusker.activity.show-timeline"
|
||||
}
|
||||
|
||||
|
@ -21,6 +22,8 @@ extension UserActivityType {
|
|||
return UserActivityManager.handleNewPost
|
||||
case .checkNotifications:
|
||||
return UserActivityManager.handleCheckNotifications
|
||||
case .checkMentions:
|
||||
return UserActivityManager.handleCheckMentions
|
||||
case .showTimeline:
|
||||
return UserActivityManager.handleShowTimeline
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue