forked from shadowfacts/Tusker
Add NSUserActivity for search
This commit is contained in:
parent
d08789bfab
commit
bc2e3c37a0
|
@ -8,6 +8,7 @@
|
|||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-notifications</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.check-mentions</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.new-post</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.search</string>
|
||||
</array>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
|
|
|
@ -83,6 +83,8 @@ class SearchTableViewController: EnhancedTableViewController {
|
|||
.map { $0?.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
.filter { $0 != self.currentQuery }
|
||||
.sink(receiveValue: performSearch(query:))
|
||||
|
||||
userActivity = UserActivityManager.searchActivity()
|
||||
}
|
||||
|
||||
func performSearch(query: String?) {
|
||||
|
|
|
@ -57,9 +57,9 @@ class UserActivityManager {
|
|||
static func handleCheckNotifications(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)
|
||||
if let navigationController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let notificationsPageController = navigationController.viewControllers.first as? NotificationsPageViewController {
|
||||
navigationController.popToRootViewController(animated: false)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ enum UserActivityType: String {
|
|||
case checkNotifications = "net.shadowfacts.Tusker.activity.check-notifications"
|
||||
case checkMentions = "net.shadowfacts.Tusker.activity.check-mentions"
|
||||
case showTimeline = "net.shadowfacts.Tusker.activity.show-timeline"
|
||||
case search = "net.shadowfacts.Tusker.activity.search"
|
||||
}
|
||||
|
||||
extension UserActivityType {
|
||||
|
@ -26,6 +27,8 @@ extension UserActivityType {
|
|||
return UserActivityManager.handleCheckMentions
|
||||
case .showTimeline:
|
||||
return UserActivityManager.handleShowTimeline
|
||||
case .search:
|
||||
return UserActivityManager.handleSearch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue