Skip to content

Commit

Permalink
What's new indicator (mozilla-mobile#538)
Browse files Browse the repository at this point in the history
* What's new indicator

* WhatsNew add protocol

* Move whats new code out of app delegate

* simplify code per pr feedback

* update support url

* Set pref version when user goes through onboarding
  • Loading branch information
joeyg authored and boek committed Oct 23, 2017
1 parent dfd7668 commit 22964a3
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 21 deletions.
24 changes: 22 additions & 2 deletions Blockzilla/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private let browserViewController = BrowserViewController()
private var queuedUrl: URL?
private var queuedString: String?
static let prefWhatsNewDone = "WhatsNewDone"
static let prefWhatsNewCounter = "WhatsNewCounter"

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

Expand Down Expand Up @@ -46,19 +48,37 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
displaySplashAnimation()
KeyboardHelper.defaultHelper.startObserving()

let needToShowFirstRunExperience = UserDefaults.standard.integer(forKey: AppDelegate.prefIntroDone) < AppDelegate.prefIntroVersion
let prefIntroDone = UserDefaults.standard.integer(forKey: AppDelegate.prefIntroDone)

let needToShowFirstRunExperience = prefIntroDone < AppDelegate.prefIntroVersion
if needToShowFirstRunExperience {

// Show the first run UI asynchronously to avoid the "unbalanced calls to begin/end appearance transitions" warning.
DispatchQueue.main.async {
// Set the prefIntroVersion viewed number in the same context as the presentation.
UserDefaults.standard.set(AppDelegate.prefIntroVersion, forKey: AppDelegate.prefIntroDone)
UserDefaults.standard.set(AppInfo.shortVersion, forKey: AppDelegate.prefWhatsNewDone)

let firstRunViewController = FirstRunViewController()
rootViewController.present(firstRunViewController, animated: false, completion: nil)
}
}


// Don't highlight whats new on a fresh install (prefIntroDone == 0 on a fresh install)
if prefIntroDone != 0 && UserDefaults.standard.string(forKey: AppDelegate.prefWhatsNewDone) != AppInfo.shortVersion {

let counter = UserDefaults.standard.integer(forKey: AppDelegate.prefWhatsNewCounter)
switch counter {
case 4:
// Shown three times, remove counter
UserDefaults.standard.set(AppInfo.shortVersion, forKey: AppDelegate.prefWhatsNewDone)
UserDefaults.standard.removeObject(forKey: AppDelegate.prefWhatsNewCounter)
default:
// Show highlight
UserDefaults.standard.set(counter+1, forKey: AppDelegate.prefWhatsNewCounter)
}
}

return true
}

Expand Down
23 changes: 23 additions & 0 deletions Blockzilla/Assets.xcassets/highlight.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "highlights.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "highlights@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "highlights@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Preferences.Updated.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
26 changes: 23 additions & 3 deletions Blockzilla/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BrowserViewController: UIViewController {
self.init(nibName: nil, bundle: nil)
KeyboardHelper.defaultHelper.addDelegate(delegate: self)
}

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -149,7 +149,9 @@ class BrowserViewController: UIViewController {
if userHasSeenIntro && !urlBar.inBrowsingMode {
urlBar.becomeFirstResponder()
}


homeView?.setHighlightWhatsNew(shouldHighlight: shouldShowWhatsNew())

super.viewWillAppear(animated)
}

Expand Down Expand Up @@ -259,7 +261,7 @@ class BrowserViewController: UIViewController {

fileprivate func showSettings() {
urlBar.shouldPresent = false
let settingsViewController = SettingsViewController(searchEngineManager: searchEngineManager)
let settingsViewController = SettingsViewController(searchEngineManager: searchEngineManager, whatsNew: self)
navigationController!.pushViewController(settingsViewController, animated: true)
navigationController!.setNavigationBarHidden(false, animated: true)

Expand Down Expand Up @@ -690,3 +692,21 @@ extension BrowserViewController: KeyboardHelperDelegate {
func keyboardHelper(_ keyboardHelper: KeyboardHelper, keyboardDidHideWithState state: KeyboardState) { }
func keyboardHelper(_ keyboardHelper: KeyboardHelper, keyboardDidShowWithState state: KeyboardState) { }
}

protocol WhatsNewDelegate {
func shouldShowWhatsNew() -> Bool
func didShowWhatsNew() -> Void
}

extension BrowserViewController: WhatsNewDelegate {
func shouldShowWhatsNew() -> Bool {
let counter = UserDefaults.standard.integer(forKey: AppDelegate.prefWhatsNewCounter)
return counter != 0
}

func didShowWhatsNew() {
UserDefaults.standard.set(AppInfo.shortVersion, forKey: AppDelegate.prefWhatsNewDone)
UserDefaults.standard.removeObject(forKey: AppDelegate.prefWhatsNewCounter)
}
}

8 changes: 8 additions & 0 deletions Blockzilla/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ class HomeView: UIView {
@objc private func didPressSettings() {
delegate?.homeViewDidPressSettings(homeView: self)
}

func setHighlightWhatsNew(shouldHighlight: Bool) {
if shouldHighlight {
settingsButton.setImage(UIImage(named: "preferences_updated"), for: .normal)
} else {
settingsButton.setImage(#imageLiteral(resourceName: "icon_settings"), for: .normal)
}
}
}
56 changes: 41 additions & 15 deletions Blockzilla/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi

private var isSafariEnabled = false
private let searchEngineManager: SearchEngineManager

private var highlightsButton: UIBarButtonItem?
private let whatsNew: WhatsNewDelegate

private let toggles = [
BlockerToggle(label: UIConstants.strings.toggleSafari, setting: SettingsToggle.safari),
BlockerToggle(label: UIConstants.strings.labelBlockAds, setting: SettingsToggle.blockAds, subtitle: UIConstants.strings.labelBlockAdsDescription),
Expand All @@ -34,8 +36,9 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
return cell
}()

init(searchEngineManager: SearchEngineManager) {
init(searchEngineManager: SearchEngineManager, whatsNew: WhatsNewDelegate) {
self.searchEngineManager = searchEngineManager
self.whatsNew = whatsNew
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -54,10 +57,14 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
navigationBar.tintColor = UIConstants.colors.navigationButton
navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIConstants.colors.navigationTitle]

let aboutButton = UIBarButtonItem(title: UIConstants.strings.aboutTitle, style: .plain, target: self, action: #selector(aboutClicked))
aboutButton.image = #imageLiteral(resourceName: "about_icon")
aboutButton.accessibilityIdentifier = "SettingsViewController.aboutButton"
navigationItem.rightBarButtonItem = aboutButton
highlightsButton = UIBarButtonItem(title: UIConstants.strings.whatsNewTitle, style: .plain, target: self, action: #selector(whatsNewClicked))
highlightsButton?.image = UIImage(named: "highlight")
highlightsButton?.accessibilityIdentifier = "SettingsViewController.whatsNewButton"
navigationItem.rightBarButtonItem = highlightsButton

if whatsNew.shouldShowWhatsNew() {
highlightsButton?.tintColor = UIConstants.colors.settingsLink
}

view.addSubview(tableView)
tableView.snp.makeConstraints { make in
Expand Down Expand Up @@ -154,14 +161,19 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
backgroundColorView.backgroundColor = UIConstants.colors.cellSelected
cell.selectedBackgroundView = backgroundColorView
default:
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "toggleCell")
let toggle = toggleForIndexPath(indexPath)
cell.textLabel?.text = toggle.label
cell.textLabel?.numberOfLines = 0
cell.accessoryView = PaddedSwitch(switchView: toggle.toggle)
cell.detailTextLabel?.text = toggle.subtitle
cell.detailTextLabel?.numberOfLines = 0
cell.selectionStyle = .none
if indexPath.section == 4 && indexPath.row == 1 {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "aboutCell")
cell.textLabel?.text = UIConstants.strings.aboutTitle
} else {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "toggleCell")
let toggle = toggleForIndexPath(indexPath)
cell.textLabel?.text = toggle.label
cell.textLabel?.numberOfLines = 0
cell.accessoryView = PaddedSwitch(switchView: toggle.toggle)
cell.detailTextLabel?.text = toggle.subtitle
cell.detailTextLabel?.numberOfLines = 0
cell.selectionStyle = .none
}
}

cell.backgroundColor = UIConstants.colors.background
Expand All @@ -178,7 +190,7 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
case 1: return 1 // Integration.
case 2: return 4 // Privacy.
case 3: return 1 // Performance.
case 4: return 1 // Mozilla.
case 4: return 2 // Mozilla.
default:
assertionFailure("Invalid section")
return 0
Expand Down Expand Up @@ -278,6 +290,11 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
let searchSettingsViewController = SearchSettingsViewController(searchEngineManager: searchEngineManager)
searchSettingsViewController.delegate = self
navigationController?.pushViewController(searchSettingsViewController, animated: true)
break
case 4:
if indexPath.row == 1 {
aboutClicked()
}
default: break
}
}
Expand All @@ -297,6 +314,15 @@ class SettingsViewController: UIViewController, UITableViewDataSource, UITableVi
@objc private func aboutClicked() {
navigationController!.pushViewController(AboutViewController(), animated: true)
}

@objc private func whatsNewClicked() {
highlightsButton?.tintColor = UIColor.white

guard let url = SupportUtils.URLForTopic(topic: "whats-new-focus-ios-3") else { return }
navigationController?.pushViewController(AboutContentViewController(url: url), animated: true)

whatsNew.didShowWhatsNew()
}

@objc private func toggleSwitched(_ sender: UISwitch) {
let toggle = toggles.filter { $0.toggle == sender }.first!
Expand Down
3 changes: 2 additions & 1 deletion Blockzilla/UIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ struct UIConstants {
static let aboutSafariBulletHeader = NSLocalizedString("About.safariBulletHeader", value: "Use it as a Safari extension:", comment: "Label on About screen")
static let aboutSafariBullet1 = NSLocalizedString("About.safariBullet1", value: "Block trackers for improved privacy", comment: "Label on About screen")
static let aboutSafariBullet2 = NSLocalizedString("About.safariBullet2", value: "Block Web fonts to reduce page size", comment: "Label on About screen")
static let aboutTitle = NSLocalizedString("About.screenTitle", value: "About", comment: "Title for the About screen")
static let aboutTitle = NSLocalizedString("About.screenTitle", value: "About Firefox Focus", comment: "Title for the About screen")
static let whatsNewTitle = NSLocalizedString("Settings.whatsNewTitle", value: "What's New", comment: "Title for What's new screen")
static let aboutTopLabel = NSLocalizedString("About.topLabel", value: "%@ puts you in control.", comment: "Label on About screen")
static let browserBack = NSLocalizedString("Browser.backLabel", value: "Back", comment: "Accessibility label for the back button")
static let browserForward = NSLocalizedString("Browser.forwardLabel", value: "Forward", comment: "Accessibility label for the forward button")
Expand Down

0 comments on commit 22964a3

Please sign in to comment.