Skip to content

Instantly share code, notes, and snippets.

@frosty
Created April 26, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosty/988ff3658b9780d4f9f75c47e117de10 to your computer and use it in GitHub Desktop.
Save frosty/988ff3658b9780d4f9f75c47e117de10 to your computer and use it in GitHub Desktop.
diff --git a/WordPress/Classes/Utility/InteractiveNotificationsManager.swift b/WordPress/Classes/Utility/InteractiveNotificationsManager.swift
index 4a6e95a02d..2d6b80f9a4 100644
--- a/WordPress/Classes/Utility/InteractiveNotificationsManager.swift
+++ b/WordPress/Classes/Utility/InteractiveNotificationsManager.swift
@@ -441,6 +441,11 @@ extension InteractiveNotificationsManager: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) {
+ if notification.request.content.categoryIdentifier == NotificationRemindersHelper.RequestKeys.category {
+ completionHandler(.alert)
+ return
+ }
+
let userInfo = notification.request.content.userInfo as NSDictionary
// If the app is open, and a Zendesk view is being shown, Zendesk will display an alert allowing the user to view the updated ticket.
diff --git a/WordPress/Classes/Utility/NotificationRemindersHelper.swift b/WordPress/Classes/Utility/NotificationRemindersHelper.swift
index 7be45a5f2e..db0a8b1fd0 100644
--- a/WordPress/Classes/Utility/NotificationRemindersHelper.swift
+++ b/WordPress/Classes/Utility/NotificationRemindersHelper.swift
@@ -181,7 +181,7 @@ struct NotificationRemindersHelper {
static let reminderIds = "notification-reminder-ids"
}
- private enum RequestKeys {
+ enum RequestKeys {
static let category = "notification-reminder"
static let notificationId = "note_id"
static let type = "type"
diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController.swift
index 05404121d3..750173525b 100644
--- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController.swift
+++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController.swift
@@ -5,6 +5,7 @@ import MGSwipeTableCell
import WordPressShared
import WordPressAuthenticator
import Gridicons
+import UserNotifications
/// The purpose of this class is to render the collection of Notifications, associated to the main
/// WordPress.com account.
@@ -1091,14 +1092,100 @@ private extension NotificationsViewController {
}
func showMoreAlertController(for note: Notification) {
+ let style: UIAlertController.Style = WPDeviceIdentification.isiPhone() || splitViewControllerIsHorizontallyCompact ? .actionSheet : .alert
+ let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
+
+ controller.addActionWithTitle(NSLocalizedString("Remind me...", comment: "Button title. Allows the user to pick a time to schedule a reminder."),
+ style: .default,
+ handler: { [weak self] action in
+ self?.showReminderAlert(for: note)
+ })
+
+ controller.addActionWithTitle(NSLocalizedString("Share...", comment: "Button title. Allows the user to share the content of a notification."),
+ style: .default,
+ handler: { [weak self] action in
+ self?.showActivityController(for: note)
+ })
+
+ controller.addCancelActionWithTitle(NSLocalizedString("Cancel", comment: "Button title. Dismisses an action sheet."))
+
+ if let indexPath = tableViewHandler.resultsController.indexPath(forObject: note),
+ let cell = tableView.cellForRow(at: indexPath) {
+ controller.popoverPresentationController?.sourceView = self.view
+ controller.popoverPresentationController?.sourceRect = cell.frame
+ controller.popoverPresentationController?.permittedArrowDirections = .left
+ }
+
+ present(controller, animated: true, completion: nil)
}
+
+ func showActivityController(for note: Notification) {
+ guard let url = note.url else {
+ return
}
+ var activityItems = [Any]()
+ if let subject = note.renderSubject() {
+ activityItems.append(subject as Any)
+ }
+ activityItems.append(url)
+ let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
+ if let indexPath = tableViewHandler.resultsController.indexPath(forObject: note),
+ let cell = tableView.cellForRow(at: indexPath) {
+ controller.popoverPresentationController?.sourceView = self.view
+ controller.popoverPresentationController?.sourceRect = cell.frame
+ }
+ present(controller, animated: true, completion: nil)
}
}
+// MARK: - Reminders
+//
+private extension NotificationsViewController {
+
+ @objc func didTapRemindersButton() {
+ let vc = NotificationRemindersViewController()
+ let nav = UINavigationController(rootViewController: vc)
+ nav.modalPresentationStyle = .formSheet
+ present(nav, animated: true, completion: nil)
+ }
+
+ func showReminderAlert(for note: Notification) {
+ let remind: ((NotificationReminderPeriod) -> Void) = { period in
+ let helper = NotificationRemindersHelper()
+ helper.remindMe(in: period, about: note, completion: { [weak self] _ in
+ self?.updateNotificationRemindersButton()
+ })
+ }
+
+ let title = NSLocalizedString("When would you like to be reminded?",
+ comment: "Title of an alert that asks the user when they would like to set a reminder for.")
+
+ let style: UIAlertController.Style = WPDeviceIdentification.isiPhone() || splitViewControllerIsHorizontallyCompact ? .actionSheet : .alert
+ let controller = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
+
+ if let indexPath = tableViewHandler.resultsController.indexPath(forObject: note),
+ let cell = tableView.cellForRow(at: indexPath) {
+ controller.popoverPresentationController?.sourceView = self.view
+ controller.popoverPresentationController?.sourceRect = cell.frame
+ controller.popoverPresentationController?.permittedArrowDirections = .left
+ }
+
+ for period in NotificationReminderPeriod.allCases {
+ controller.addActionWithTitle(period.displayTitle,
+ style: .default,
+ handler: { _ in
+ remind(period)
+ })
+ }
+
+ controller.addCancelActionWithTitle(NSLocalizedString("Cancel", comment: "Button title. Dismisses an action sheet"))
+
+ present(controller, animated: true, completion: nil)
+ }
+}
// MARK: - Filter Helpers
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment