Add NSUserActivity for search

This commit is contained in:
Shadowfacts 2019-09-15 21:20:50 -04:00
parent d08789bfab
commit bc2e3c37a0
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 27 additions and 3 deletions

View File

@ -8,6 +8,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-notifications</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-notifications</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-mentions</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-mentions</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.new-post</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.new-post</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.search</string>
</array> </array>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>

View File

@ -83,6 +83,8 @@ class SearchTableViewController: EnhancedTableViewController {
.map { $0?.trimmingCharacters(in: .whitespacesAndNewlines) } .map { $0?.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { $0 != self.currentQuery } .filter { $0 != self.currentQuery }
.sink(receiveValue: performSearch(query:)) .sink(receiveValue: performSearch(query:))
userActivity = UserActivityManager.searchActivity()
} }
func performSearch(query: String?) { func performSearch(query: String?) {

View File

@ -57,9 +57,9 @@ class UserActivityManager {
static func handleCheckNotifications(activity: NSUserActivity) { static func handleCheckNotifications(activity: NSUserActivity) {
let tabBarController = getMainTabBarController() let tabBarController = getMainTabBarController()
tabBarController.select(tab: .notifications) tabBarController.select(tab: .notifications)
if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController, if let navigationController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController { let notificationsPageController = navigationController.viewControllers.first as? NotificationsPageViewController {
navController.popToRootViewController(animated: false) navigationController.popToRootViewController(animated: false)
notificationsPageController.selectMode(.allNotifications) notificationsPageController.selectMode(.allNotifications)
} }
} }
@ -145,4 +145,22 @@ class UserActivityManager {
} }
} }
// MARK: - Search
static func searchActivity() -> NSUserActivity {
let activity = NSUserActivity(type: .search)
activity.isEligibleForPrediction = true
activity.title = NSLocalizedString("Search", comment: "search shortcut title")
activity.suggestedInvocationPhrase = NSLocalizedString("Search the fediverse", comment: "search shortcut invocation phrase")
return activity
}
static func handleSearch(activity: NSUserActivity) {
let tabBarController = getMainTabBarController()
tabBarController.select(tab: .search)
if let navigationController = tabBarController.getTabController(tab: .search) as? UINavigationController {
navigationController.popToRootViewController(animated: false)
}
}
} }

View File

@ -13,6 +13,7 @@ enum UserActivityType: String {
case checkNotifications = "net.shadowfacts.Tusker.activity.check-notifications" case checkNotifications = "net.shadowfacts.Tusker.activity.check-notifications"
case checkMentions = "net.shadowfacts.Tusker.activity.check-mentions" case checkMentions = "net.shadowfacts.Tusker.activity.check-mentions"
case showTimeline = "net.shadowfacts.Tusker.activity.show-timeline" case showTimeline = "net.shadowfacts.Tusker.activity.show-timeline"
case search = "net.shadowfacts.Tusker.activity.search"
} }
extension UserActivityType { extension UserActivityType {
@ -26,6 +27,8 @@ extension UserActivityType {
return UserActivityManager.handleCheckMentions return UserActivityManager.handleCheckMentions
case .showTimeline: case .showTimeline:
return UserActivityManager.handleShowTimeline return UserActivityManager.handleShowTimeline
case .search:
return UserActivityManager.handleSearch
} }
} }
} }