Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLaganiere committed Jan 15, 2017
2 parents 962cc9c + 0e51071 commit 9370749
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
Binary file not shown.
10 changes: 7 additions & 3 deletions UCLA Radio/UCLA Radio/data/RadioAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class RadioAPI {
} else {
nowPlaying = nil
}
NotificationCenter.default.post(name: NSNotification.Name(rawValue: NowPlayingUpdatedNotification), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: NowPlayingUpdatedNotification), object: nil)
case .failure:
// no show playing right now
nowPlaying = nil
NotificationCenter.default.post(name: NSNotification.Name(rawValue: NowPlayingUpdatedNotification), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: NowPlayingUpdatedNotification), object: nil)
}
}
}
Expand Down Expand Up @@ -88,7 +88,8 @@ class RadioAPI {
delegate?.failedToFetchData(error)
}
}


static let updatedGiveawaysNotificationName = Notification.Name(rawValue: "DidFetchUpdatedTicketGiveaways")
static func fetchGiveaways(_ delegate: APIFetchDelegate?) {
fetchSomethingCached(giveawaysRoute, key: "events", success: { (result, cached) in
if let eventsMonthsArray = result as? NSArray {
Expand All @@ -98,6 +99,9 @@ class RadioAPI {
}
else {
delegate?.didFetchData(giveaways)
NotificationCenter.default.post(name: updatedGiveawaysNotificationName, object: nil, userInfo: [
"hasGiveaways": (giveaways.count > 0)
])
}
}
else {
Expand Down
34 changes: 27 additions & 7 deletions UCLA Radio/UCLA Radio/menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class MenuItem {
}
}

fileprivate let defaultItems = [
MenuItem(title: "Schedule", storyboardID: ScheduleViewController.storyboardID),
MenuItem(title: "DJs", storyboardID: DJListViewController.storyboardID),
MenuItem(title: "About", storyboardID: AboutViewController.storyboardID)
]

fileprivate let giveawayItem = MenuItem(title: "Tickets", storyboardID: EventsViewController.storyboardID)

class MenuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

fileprivate let items = [
MenuItem(title: "Schedule", storyboardID: ScheduleViewController.storyboardID),
MenuItem(title: "DJs", storyboardID: DJListViewController.storyboardID),
MenuItem(title: "Tickets", storyboardID: EventsViewController.storyboardID),
MenuItem(title: "About", storyboardID: AboutViewController.storyboardID)
]
private var items = [MenuItem]()

var tableView = UITableView(frame: CGRect.zero, style: .grouped)
var triangleView: TrianglifyView!
Expand All @@ -47,6 +49,9 @@ class MenuViewController: UIViewController, UITableViewDataSource, UITableViewDe
triangleView = TrianglifyView()
view.addSubview(triangleView)
triangleView.translatesAutoresizingMaskIntoConstraints = false

items = defaultItems
NotificationCenter.default.addObserver(self, selector: #selector(didUpdateGiveawaysNotification), name: RadioAPI.updatedGiveawaysNotificationName, object: nil)

tableView.dataSource = self
tableView.delegate = self
Expand Down Expand Up @@ -90,6 +95,21 @@ class MenuViewController: UIViewController, UITableViewDataSource, UITableViewDe
navigationController.pushViewController(viewController, animated: true)
}
}

// MARK: - Data

func didUpdateGiveawaysNotification(notification: Notification) {
if let userInfo = notification.userInfo,
let hasGiveaways = userInfo["hasGiveaways"] as? Bool,
hasGiveaways {
// should add tickets row if not already there
items = defaultItems
items.insert(giveawayItem, at: 2)
} else {
items = defaultItems
}
tableView.reloadData()
}

// MARK: - UITableViewDataSource

Expand Down

0 comments on commit 9370749

Please sign in to comment.