Skip to content

Commit

Permalink
Removed YoshiMenuType from YoshiMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCampbell committed Jan 5, 2016
1 parent e93634d commit 6ee1213
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
8 changes: 3 additions & 5 deletions Example/YoshiExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let menuItemQA = MenuItem(name: "QA")
let environmentItems = [menuItemProd, menuItemStaging, menuItemQA].map { $0 as YoshiTableViewMenuItem }

let tableViewMenu = TableViewMenu(debugMenuName: "Environment", menuType: .TableView, displayItems: environmentItems, didSelectDisplayItem: { (displayItem) in
print(displayItem.displayText())
let tableViewMenu = TableViewMenu(debugMenuName: "Environment", displayItems: environmentItems, didSelectDisplayItem: { (displayItem) in
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.EnvironmentUpdatedNotification, object: displayItem.displayText())
})

// YoshiMenuType.DateSelector
let dateSelector = DateSelector(debugMenuName: "Environment Date", menuType: .DateSelector, didUpdateDate: { (dateSelected) in
print("dateSelected = \(dateSelected)")
let dateSelector = DateSelector(debugMenuName: "Environment Date", didUpdateDate: { (dateSelected) in
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.EnvironmentDateUpdatedNotification, object: dateSelected)
})

Expand All @@ -53,7 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("completed")
}

let customMenu = CustomMenu(debugMenuName: "Custom", menuType: .CustomMenu, setup: setup, completion: completion)
let customMenu = CustomMenu(debugMenuName: "Custom", setup: setup, completion: completion)

DebugMenu.setupDebugMenu([tableViewMenu, dateSelector, customMenu])
}
Expand Down
5 changes: 1 addition & 4 deletions Example/YoshiExample/MenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ struct MenuItem: YoshiTableViewMenuItem {
}
}

struct TableViewMenu: YoshiMenu, YoshiTableViewMenu {
struct TableViewMenu: YoshiTableViewMenu {
var debugMenuName: String
var menuType: YoshiMenuType
var displayItems: [YoshiTableViewMenuItem]
var didSelectDisplayItem: (displayItem: YoshiTableViewMenuItem) -> ()
}

struct CustomMenu: YoshiCustomMenu {
var debugMenuName: String
var menuType: YoshiMenuType
var setup: () -> ()
var completion: () -> ()
}

struct DateSelector: YoshiDateSelectorMenu {
var debugMenuName: String
var menuType: YoshiMenuType
var didUpdateDate: (dateSelected: NSDate) -> ()
}
31 changes: 15 additions & 16 deletions Yoshi/Yoshi/DebugConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ internal class DebugConfigurationManager {
var inDebugMenu: Bool = false
let debugAlertController = UIAlertController(title: AppBundleUtility.appVersionText(), message: nil, preferredStyle: .ActionSheet)
var yoshiMenuItems = [YoshiMenu]()
var presentingViewController: UIViewController?
var rootViewController: UIViewController?

func setupDebugMenuOptions(menuItems: [YoshiMenu]) {
self.yoshiMenuItems = menuItems

for menu in self.yoshiMenuItems {
switch menu.menuType {
case .TableView:
guard let tableViewAction = self.tableViewAction(menu) else { continue }
switch menu {
case let menuType as YoshiTableViewMenu:
guard let tableViewAction = self.tableViewAction(menuType) else { continue }
self.debugAlertController.addAction(tableViewAction)
case .DateSelector:
guard let datePickerAction = self.dateSelectorAction(menu) else { continue }
case let menuType as YoshiDateSelectorMenu:
guard let datePickerAction = self.dateSelectorAction(menuType) else { continue }
self.debugAlertController.addAction(datePickerAction)
case .CustomMenu:
guard let customMenuAction = self.customMenuAction(menu) else { continue }
case let menuType as YoshiCustomMenu:
guard let customMenuAction = self.customMenuAction(menuType) else { continue }
self.debugAlertController.addAction(customMenuAction)
default:
continue
}
}

Expand All @@ -42,15 +44,15 @@ internal class DebugConfigurationManager {
}

func showDebugActionSheetFromViewController(viewController: UIViewController) {
self.presentingViewController = viewController
self.rootViewController = viewController
viewController.presentViewController(self.debugAlertController, animated: true, completion: nil)
self.inDebugMenu = true
}

// MARK: Private Methods

private func presentViewController(viewControllerToDisplay: UIViewController) {
guard let presentingViewController = self.presentingViewController else { return }
guard let presentingViewController = self.rootViewController else { return }
presentingViewController.presentViewController(viewControllerToDisplay, animated: true, completion: { () -> Void in
self.inDebugMenu = false
})
Expand All @@ -62,8 +64,7 @@ internal class DebugConfigurationManager {
}
}

private func tableViewAction(menu: YoshiMenu) -> UIAlertAction? {
guard let menu = menu as? YoshiTableViewMenu else { return nil }
private func tableViewAction(menu: YoshiTableViewMenu) -> UIAlertAction? {
return UIAlertAction(title: menu.debugMenuName, style: .Default) { (_) -> Void in
let bundle = NSBundle(forClass: DebugConfigurationManager.self)
let tableViewController = DebugTableViewController(nibName: DebugTableViewController.nibName(), bundle: bundle)
Expand All @@ -74,8 +75,7 @@ internal class DebugConfigurationManager {
}
}

private func dateSelectorAction(menu: YoshiMenu) -> UIAlertAction? {
guard let menu = menu as? YoshiDateSelectorMenu else { return nil }
private func dateSelectorAction(menu: YoshiDateSelectorMenu) -> UIAlertAction? {
return UIAlertAction(title: menu.debugMenuName, style: .Default, handler: { (_) -> Void in
let bundle = NSBundle(forClass: DebugConfigurationManager.self)
let datePickerViewController = DebugDatePickerViewController(nibName: DebugDatePickerViewController.nibName(), bundle: bundle)
Expand All @@ -86,8 +86,7 @@ internal class DebugConfigurationManager {
})
}

private func customMenuAction(menu: YoshiMenu) -> UIAlertAction? {
guard let menu = menu as? YoshiCustomMenu else { return nil }
private func customMenuAction(menu: YoshiCustomMenu) -> UIAlertAction? {
menu.setup()
return UIAlertAction(title: menu.debugMenuName, style: .Default) { (_) -> Void in
menu.completion()
Expand Down
4 changes: 2 additions & 2 deletions Yoshi/Yoshi/DebugMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DebugMenu {
}

/**
Should be called when a motion action is recieved. This will handle showing the hidden debug menu.
Should be called when a motion action is received. This will handle showing the hidden debug menu.

- parameter motion: (UIEventSubtype) the motion captured by the original motionBegan call
- parameter event: (UIEvent) the event captured by the original motionBegan call
Expand All @@ -32,7 +32,7 @@ public class DebugMenu {
}

/**
Should be called when touches are recieved. This will handle showing the hidden debug menu.
Should be called when touches are received. This will handle showing the hidden debug menu.

- parameter touches: Set<UITouch> the touches received by the origininal touchesBegan
- parameter event: (UIEvent) the event captured by the original motionBegan call
Expand Down
7 changes: 0 additions & 7 deletions Yoshi/Yoshi/Yoshi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
// Copyright © 2015 Prolific Interactive. All rights reserved.
//

public enum YoshiMenuType {
case TableView
case DateSelector
case CustomMenu
}

public protocol YoshiMenu {
var debugMenuName: String { get }
var menuType: YoshiMenuType { get }
}

public protocol YoshiTableViewMenuItem {
Expand Down

0 comments on commit 6ee1213

Please sign in to comment.