Skip to content

Commit

Permalink
Loading error states (#288)
Browse files Browse the repository at this point in the history
* added default image for home screen nav bar

* added default images and proper default texts to views

* added error alerts
  • Loading branch information
dfirsht authored and glennrfisher committed Feb 8, 2017
1 parent eed421b commit 89993b2
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class AddVideosViewController: UIViewController {

viewModel.fetchTrendingVideos() {[weak self] error, videos in
DispatchQueue.main.async {
if let error = error {
self?.showVideoAlert(with: error)
}
self?.searchTableView.reloadData()
}
}
Expand Down Expand Up @@ -68,6 +71,12 @@ class AddVideosViewController: UIViewController {
// Dispose of any resources that can be recreated.
}

fileprivate func showVideoAlert(with error: Error) {
let alert = UIAlertController(title: "Error Loading Videos", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)
}

private func setupSearchBar() {
searchTextField.leftViewMode = .always
searchTextField.leftView = UIView(frame: searchSpacerFrame)
Expand Down Expand Up @@ -125,6 +134,9 @@ class AddVideosViewController: UIViewController {
searchTextField.resignFirstResponder()
viewModel.fetchTrendingVideos() {[weak self] error, videos in
DispatchQueue.main.async {
if let error = error {
self?.showVideoAlert(with: error)
}
self?.searchTableView.reloadData()
}
}
Expand Down Expand Up @@ -155,14 +167,20 @@ extension AddVideosViewController: UITextFieldDelegate {
if query.characters.count > 0 {
viewModel.searchForVideos(withQuery: query) {[weak self] error, videos in
DispatchQueue.main.async {
if let error = error {
self?.showVideoAlert(with: error)
}
self?.searchTableView.reloadData()
self?.searchTableView.setContentOffset(CGPoint.zero, animated: true)
}
self?.searchTableView.setContentOffset(CGPoint.zero, animated: true)
}
}
else {
viewModel.fetchTrendingVideos {[weak self] error, videos in
DispatchQueue.main.async {
if let error = error {
self?.showVideoAlert(with: error)
}
self?.searchTableView.reloadData()
}
}
Expand Down
20 changes: 16 additions & 4 deletions iOS/Stormtrooper/Stormtrooper/Controllers/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ class HomeViewController: UIViewController {
let profileButton = UIButton(type: .custom)
profileButton.frame = profileButtonFrame
FacebookDataManager.sharedInstance.fetchProfilePictureForCurrentUser() {error, image in
if let image = image {
DispatchQueue.main.async {
DispatchQueue.main.async {
if let image = image {
profileButton.setImage(image, for: .normal)
profileButton.layer.cornerRadius = profileButton.frame.width / 2
profileButton.clipsToBounds = true
}
else {
profileButton.setImage(#imageLiteral(resourceName: "Profile_50"), for: .normal)
}
}
}

Expand Down Expand Up @@ -104,8 +107,17 @@ class HomeViewController: UIViewController {
func refreshStreams(callback: ((Void) -> Void)? = nil) {
viewModel.refreshStreams { error, streams in
DispatchQueue.main.async {
self.streamsTableView.reloadData()
callback?()
if let error = error {
let alert = UIAlertController(title: "Error Loading Streams", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true) {
callback?()
}
}
else {
self.streamsTableView.reloadData()
callback?()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ class InviteStreamViewController: UIViewController {
navigationItem.setRightBarButtonItems([skipItem], animated: false)
}
viewModel.fetchFriends(callback:{ (error: Error?) -> Void in
if error == nil {
DispatchQueue.main.async {
self.tableView.reloadData()
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()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,19 @@ class StreamViewController: UIViewController {

fileprivate func updateView(forVideoWithID id: String) {
viewModel.getVideo(withID: id) {[weak self] error, video in
if let video = video {
DispatchQueue.main.async {
DispatchQueue.main.async {
if let video = video {
self?.videoTitleLabel.text = video.title
var subtitle = video.channelTitle
if let viewCount = video.viewCount {
subtitle += " - \(viewCount) views"
}
self?.videoSubtitleLabel.text = subtitle
}
else {
self?.videoTitleLabel.text = "-"
self?.videoSubtitleLabel.text = "-"
}
}
}
}
Expand Down Expand Up @@ -809,7 +813,9 @@ extension StreamViewController: YTPlayerViewDelegate {
}

func playerView(_ playerView: YTPlayerView, receivedError error: YTPlayerError) {
//error received
let alert = UIAlertController(title: "Recieved Error from Player", message: "\(error)", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)
}

func playerView(_ playerView: YTPlayerView, didChangeTo quality: YTPlaybackQuality) {
Expand Down
9 changes: 6 additions & 3 deletions iOS/Stormtrooper/Stormtrooper/Storyboards/Stream.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -15,6 +15,9 @@
<array key="OpenSans-Semibold.ttf">
<string>OpenSans-Semibold</string>
</array>
<array key="WorkSans-Medium.ttf">
<string>WorkSans-Medium</string>
</array>
<array key="WorkSans-SemiBold.ttf">
<string>WorkSans-SemiBold</string>
</array>
Expand Down Expand Up @@ -131,7 +134,7 @@
<color key="textColor" red="0.84705882349999995" green="0.25490196079999999" blue="0.023529411760000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oTw-lu-Z7R">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oTw-lu-Z7R">
<rect key="frame" x="15" y="34" width="318" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="NWF-Dc-a8W"/>
Expand All @@ -140,7 +143,7 @@
<color key="textColor" red="0.96470588235294119" green="0.96470588235294119" blue="0.96470588235294119" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="knW-fA-GaK">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="knW-fA-GaK">
<rect key="frame" x="15" y="53" width="325" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="CmU-FD-BFk"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class AddVideosViewModel {
youtubeDataManager.fetchTrendingVideos() {error, videos in
if let videos = videos {
self.videos = videos
callback(error, videos)
}
callback(error, videos)
}
}

func searchForVideos(withQuery query: String, callback: @escaping (Error?, [Video]?) -> Void) {
youtubeDataManager.searchForVideos(withQuery: query) {error, videos in
if let videos = videos {
self.videos = videos
callback(error, videos)
}
callback(error, videos)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class HomeViewModel {
// return
accountDataManager.retrieveInvites {[weak self] error, streams in
if let error = error {
print(error)
callback(error, nil)
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="55"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Zt3-P9-Heg">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Profile_50" translatesAutoresizingMaskIntoConstraints="NO" id="Zt3-P9-Heg">
<rect key="frame" x="17" y="13" width="30" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="LnA-hw-uMk"/>
Expand Down Expand Up @@ -76,4 +76,7 @@
<point key="canvasLocation" x="-12.5" y="249"/>
</tableViewCell>
</objects>
<resources>
<image name="Profile_50" width="50" height="50"/>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="nG4-Pk-zlc">
<rect key="frame" x="16" y="12" width="120" height="67.5"/>
<color key="backgroundColor" red="0.2196078431372549" green="0.2196078431372549" blue="0.2196078431372549" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="67.5" id="3N3-Lu-WXb"/>
<constraint firstAttribute="width" constant="120" id="mjg-pB-4O5"/>
Expand Down Expand Up @@ -65,7 +66,6 @@
<constraints>
<constraint firstItem="zzU-0G-chd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="rQa-ge-4Pm" secondAttribute="trailing" constant="18" id="8JW-ci-Roa"/>
<constraint firstAttribute="leading" secondItem="nG4-Pk-zlc" secondAttribute="leading" constant="-16" id="CFP-p1-0hk"/>
<constraint firstAttribute="bottom" secondItem="nG4-Pk-zlc" secondAttribute="bottom" constant="12.5" id="I3b-mk-Rqu"/>
<constraint firstAttribute="bottom" secondItem="OY1-WO-c4O" secondAttribute="bottom" id="SxR-pf-eE0"/>
<constraint firstItem="nG4-Pk-zlc" firstAttribute="top" secondItem="rQa-ge-4Pm" secondAttribute="top" constant="-15.5" id="Vg9-n3-RfJ"/>
<constraint firstItem="nG4-Pk-zlc" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="12" id="Zqo-Qc-UQK"/>
Expand All @@ -75,6 +75,7 @@
<constraint firstItem="zzU-0G-chd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="2i1-wD-H0Z" secondAttribute="trailing" constant="18" id="c7V-eN-X4R"/>
<constraint firstAttribute="trailing" secondItem="zzU-0G-chd" secondAttribute="trailing" constant="16" id="cFG-8G-R0J"/>
<constraint firstItem="rQa-ge-4Pm" firstAttribute="leading" secondItem="nG4-Pk-zlc" secondAttribute="trailing" constant="13" id="ekO-yi-3oC"/>
<constraint firstItem="OY1-WO-c4O" firstAttribute="top" secondItem="nG4-Pk-zlc" secondAttribute="bottom" constant="11" id="jg2-8K-EHd"/>
<constraint firstItem="zzU-0G-chd" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="p87-Wm-ovt"/>
<constraint firstItem="2i1-wD-H0Z" firstAttribute="top" secondItem="rQa-ge-4Pm" secondAttribute="bottom" constant="3" id="vzk-If-iw1"/>
</constraints>
Expand Down
Loading

0 comments on commit 89993b2

Please sign in to comment.