|
| 1 | +import UIKit |
| 2 | + |
| 3 | +class OnboardingEnableNotificationsViewController: UIViewController { |
| 4 | + @IBOutlet weak var titleLabel: UILabel! |
| 5 | + @IBOutlet weak var subTitleLabel: UILabel! |
| 6 | + @IBOutlet weak var detailView: UIView! |
| 7 | + |
| 8 | + let option: OnboardingOption |
| 9 | + let coordinator: OnboardingQuestionsCoordinator |
| 10 | + |
| 11 | + init(with coordinator: OnboardingQuestionsCoordinator, option: OnboardingOption) { |
| 12 | + self.coordinator = coordinator |
| 13 | + self.option = option |
| 14 | + |
| 15 | + super.init(nibName: nil, bundle: nil) |
| 16 | + } |
| 17 | + |
| 18 | + required convenience init?(coder: NSCoder) { |
| 19 | + self.init(with: OnboardingQuestionsCoordinator(), option: .notifications) |
| 20 | + } |
| 21 | + |
| 22 | + override func viewDidLoad() { |
| 23 | + super.viewDidLoad() |
| 24 | + |
| 25 | + navigationController?.navigationBar.isHidden = true |
| 26 | + navigationController?.delegate = self |
| 27 | + |
| 28 | + applyStyles() |
| 29 | + updateContent() |
| 30 | + |
| 31 | + coordinator.notificationsDisplayed(option: option) |
| 32 | + } |
| 33 | + |
| 34 | + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { |
| 35 | + return [.portrait, .portraitUpsideDown] |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// MARK: - IBAction's |
| 40 | +extension OnboardingEnableNotificationsViewController { |
| 41 | + @IBAction func enableButtonTapped(_ sender: Any) { |
| 42 | + coordinator.notificationsEnabledTapped(selection: option) |
| 43 | + } |
| 44 | + |
| 45 | + @IBAction func skipButtonTapped(_ sender: Any) { |
| 46 | + coordinator.notificationsSkipped(selection: option) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +// MARK: - Trait Collection Handling |
| 51 | +extension OnboardingEnableNotificationsViewController { |
| 52 | + func updateContent(for traitCollection: UITraitCollection) { |
| 53 | + let contentSize = traitCollection.preferredContentSizeCategory |
| 54 | + |
| 55 | + // Hide the detail image if the text is too large |
| 56 | + detailView.isHidden = contentSize.isAccessibilityCategory |
| 57 | + } |
| 58 | + |
| 59 | + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { |
| 60 | + super.traitCollectionDidChange(previousTraitCollection) |
| 61 | + |
| 62 | + updateContent(for: traitCollection) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// MARK: - UINavigation Controller Delegate |
| 67 | +extension OnboardingEnableNotificationsViewController: UINavigationControllerDelegate { |
| 68 | + func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask { |
| 69 | + return supportedInterfaceOrientations |
| 70 | + } |
| 71 | + |
| 72 | + func navigationControllerPreferredInterfaceOrientationForPresentation(_ navigationController: UINavigationController) -> UIInterfaceOrientation { |
| 73 | + return .portrait |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +// MARK: - Private Helpers |
| 78 | +private extension OnboardingEnableNotificationsViewController { |
| 79 | + func applyStyles() { |
| 80 | + navigationController?.navigationBar.isHidden = true |
| 81 | + |
| 82 | + titleLabel.font = WPStyleGuide.serifFontForTextStyle(.title1, fontWeight: .semibold) |
| 83 | + titleLabel.textColor = .text |
| 84 | + |
| 85 | + subTitleLabel.font = .preferredFont(forTextStyle: .title3) |
| 86 | + subTitleLabel.textColor = .secondaryLabel |
| 87 | + } |
| 88 | + |
| 89 | + func updateContent() { |
| 90 | + let text: String |
| 91 | + let notificationContent: UnifiedPrologueNotificationsContent? |
| 92 | + |
| 93 | + switch option { |
| 94 | + case .stats: |
| 95 | + text = StatsStrings.subTitle |
| 96 | + notificationContent = .init(topElementTitle: StatsStrings.notificationTopTitle, |
| 97 | + middleElementTitle: StatsStrings.notificationMiddleTitle, |
| 98 | + bottomElementTitle: StatsStrings.notificationBottomTitle, |
| 99 | + topImage: "view-milestone-1k", |
| 100 | + middleImage: "traffic-surge-icon") |
| 101 | + case .writing: |
| 102 | + text = WritingStrings.subTitle |
| 103 | + notificationContent = nil |
| 104 | + |
| 105 | + case .notifications, .showMeAround, .skip: |
| 106 | + text = DefaultStrings.subTitle |
| 107 | + notificationContent = nil |
| 108 | + |
| 109 | + case .reader: |
| 110 | + text = ReaderStrings.subTitle |
| 111 | + notificationContent = .init(topElementTitle: ReaderStrings.notificationTopTitle, |
| 112 | + middleElementTitle: ReaderStrings.notificationMiddleTitle, |
| 113 | + bottomElementTitle: ReaderStrings.notificationBottomTitle) |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + subTitleLabel.text = text |
| 118 | + |
| 119 | + // Convert the image view to a UIView and embed it |
| 120 | + let imageView = UIView.embedSwiftUIView(UnifiedPrologueNotificationsContentView(notificationContent)) |
| 121 | + imageView.frame.size.width = detailView.frame.width |
| 122 | + detailView.addSubview(imageView) |
| 123 | + imageView.pinSubviewToAllEdges(detailView) |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +// MARK: - Constants / Strings |
| 128 | +private struct StatsStrings { |
| 129 | + static let subTitle = NSLocalizedString("Know when your site is getting more traffic, new followers, or when it passes a new milestone!", comment: "Subtitle giving the user more context about why to enable notifications.") |
| 130 | + |
| 131 | + static let notificationTopTitle = NSLocalizedString("Congratulations! Your site passed *1000 all-time* views!", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 132 | + static let notificationMiddleTitle = NSLocalizedString("Your site appears to be getting *more traffic* than usual!", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 133 | + static let notificationBottomTitle = NSLocalizedString("*Johann Brandt* is now following your site!", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 134 | +} |
| 135 | + |
| 136 | +private struct WritingStrings { |
| 137 | + static let subTitle = NSLocalizedString("Stay in touch with your audience with like and comment notifications.", comment: "Subtitle giving the user more context about why to enable notifications.") |
| 138 | +} |
| 139 | + |
| 140 | +private struct DefaultStrings { |
| 141 | + static let subTitle = NSLocalizedString("Stay in touch with like and comment notifications.", comment: "Subtitle giving the user more context about why to enable notifications.") |
| 142 | +} |
| 143 | + |
| 144 | +private struct ReaderStrings { |
| 145 | + static let subTitle = NSLocalizedString("Know when your favorite authors post new content.", comment: "Subtitle giving the user more context about why to enable notifications.") |
| 146 | + static let notificationTopTitle = NSLocalizedString("*Madison Ruiz* added a new post to their site", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 147 | + static let notificationMiddleTitle = NSLocalizedString("You received *50 likes* on your comment", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 148 | + static let notificationBottomTitle = NSLocalizedString("*Johann Brandt* responded to your comment", comment: "Example notification content displayed on the Enable Notifications prompt that is personalized based on a users selection. Words marked between * characters will be displayed as bold text.") |
| 149 | +} |
0 commit comments