Skip to content

Commit

Permalink
hid invite to stream when not in stream create flow (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfirsht authored and glennrfisher committed Feb 8, 2017
1 parent 335b369 commit 092035c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,31 @@ class InviteStreamViewController: UIViewController {

setupTableView()

// Show skip button when creating a stream
if isCreatingStream {
// Show skip button when creating a stream
let skipButton = UIButton(type: .custom)
skipButton.setTitle("Skip", for: .normal)
skipButton.frame = skipButtonFrame
skipButton.addTarget(self, action: #selector(InviteStreamViewController.doneTapped), for: .touchUpInside)
let skipItem = UIBarButtonItem(customView: skipButton)

navigationItem.setRightBarButtonItems([skipItem], animated: false)
}
viewModel.fetchFriends(callback:{ (error: Error?) -> Void in
DispatchQueue.main.async {
if let error = error {
let alert = UIAlertController(title: "Error Loading Friends", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true)

// Fetch friends to invite
viewModel.fetchFriends(callback:{ (error: Error?) -> Void in
DispatchQueue.main.async {
if let error = error {
let alert = UIAlertController(title: "Error Loading Friends", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true)
}
self.tableView.reloadData()
}
self.tableView.reloadData()
}
})
})
}
else {
navigationItem.title = "Invite to App"
}
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -282,7 +287,7 @@ extension InviteStreamViewController: UITableViewDelegate, UITableViewDataSource
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.numberOfStaticCellsBeforeFriends + viewModel.facebookFriends.count
return viewModel.numberOfRows(ifCreatingStream: isCreatingStream)
}

func numberOfSections(in tableView: UITableView) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class InviteStreamViewModel {
let numberOfStaticCellsBeforeFriends = 3

var selectedFriends: [String: User] = [:]

func numberOfRows(ifCreatingStream creatingStream: Bool) -> Int {
return creatingStream ? numberOfStaticCellsBeforeFriends + facebookFriends.count
: numberOfStaticCellsBeforeFriends - 1
}

func fetchFriends(callback: @escaping (Error?) -> Void) {
let friendIds = FacebookDataManager.sharedInstance.cachedFriendIds
Expand Down

0 comments on commit 092035c

Please sign in to comment.