Skip to content

Commit

Permalink
extended app
Browse files Browse the repository at this point in the history
  • Loading branch information
ArWeHei committed Jun 6, 2016
1 parent 62483f5 commit bd0d0f4
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 116 deletions.
28 changes: 28 additions & 0 deletions APIClient/APIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class APIViewController: UIViewController {
var target = kanyeREST.track(title: "good_morning")
var fetchedtrack: Track!

var allalbums: [Album] = []
var allalbumnames: [String]!

@IBOutlet private var lyricsLabel: UILabel!

override func viewDidLoad() {
Expand All @@ -42,5 +45,30 @@ class APIViewController: UIViewController {
}
}

for albumname in allalbumnames{
kanyeAPI.request(kanyeREST.album(title: albumname)){
result in
//print(title)
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
print(response)
let json = try JSON(data: response.data)
let tracks = try json.array("result").map(Track.init)
self.allalbums.append(Album(tracksfetched: tracks))
print(self.allalbums[0])
} catch {
print(error)
break
}
case .Failure(let error):
print("failure")
print(error)
break
}
}
}

}
}
34 changes: 12 additions & 22 deletions APIClient/Album.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,21 @@
import Foundation
import Freddy

/*
/// A Pokedex contains the Pokemon species encountered in a specific region of the Pokemon world
struct Album: JSONDecodable {

struct Album {

let name: String
let tracks: [track]
struct track: JSONDecodable {
// let track: NamedResource<Track>
init(json: JSON) throws {
self.track = try json.decode("title")
}
}
let tracks: [Track]

init(json: JSON) throws {
self.name = try json.string("album")
self.tracks = try json.arrayOf("title") //write func
init(tracksfetched: [Track]){
tracks = tracksfetched
name = tracksfetched[0].album
}
init(title: String){
self.name = title
self.tracks = try json.arrayOf("title")
}

extension Album: JSONDecodable {
public init(json: JSON) throws {
name = try json.string("album")
tracks = try json.arrayOf("title") //write func
}
}
*/
61 changes: 47 additions & 14 deletions APIClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import Moya
import Freddy

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -17,33 +18,65 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
/// The PokeAPI Provider representing the Server
let kanyeAPI = MoyaProvider<kanyeREST>()

/*let albums = [
Album(title: "the_college_dropout"),
Album(title: "late_registration"),
Album(title: "graduation"),
Album(title: "808s_&amp;_heartbreak"),
Album(title: "my_beautiful_dark_twisted_fantasy"),
Album(title: "watch_the_throne"),
Album(title: "yeezus"),
Album(title: "the_life_of_pablo")
]*/
let allalbumnames = [
"the_college_dropout",
"late_registration",
"graduation",
"808s_&amp;_heartbreak",
"my_beautiful_dark_twisted_fantasy",
"watch_the_throne",
"yeezus",
"the_life_of_pablo"
]

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

if let APIViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? APIViewController {
print("test")
// Pass the PokeAPI Provider on to the root view controller
APIViewController.kanyeAPI = kanyeAPI
APIViewController.allalbumnames = allalbumnames

}

/*if let albumViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? albumViewController {
if let albumViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? albumViewController {

print("albumviewcontroller")
//print(albumnames)
var allalbums: [Album] = []
/*for albumname in self.allalbumnames{
kanyeAPI.request(kanyeREST.album(title: albumname)){
result in
//print(title)
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
//print(response)
let json = try JSON(data: response.data)
let tracks = try json.array("result").map(Track.init)
allalbums.append(Album(tracksfetched: tracks))
//print(self.allalbums[0])
//print(allalbums)
} catch {
print(error)
break
}
case .Failure(let error):
print("failure")
print(error)
break
}
}
}*/


// Pass the PokeAPI Provider on to the root view controller
albumViewController.kanyeAPI = kanyeAPI
albumViewController.allalbums = albums
albumViewController.allalbumnames = self.allalbumnames
//albumViewController.allalbums = allalbums
print("albums loaded")

}*/
}

return true
}
Expand Down
52 changes: 29 additions & 23 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="K22-lG-r0T" kind="relationship" relationship="rootViewController" id="HYs-2H-VqK"/>
<segue destination="DR2-xt-xbP" kind="relationship" relationship="rootViewController" id="Peu-Dz-cGv"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hfS-9i-aMM" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -46,7 +46,7 @@
<constraint firstAttribute="width" secondItem="ySA-MQ-pZ6" secondAttribute="height" multiplier="2:1" id="RpE-R8-06Z"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
Expand Down Expand Up @@ -83,27 +83,19 @@
<!--album View Controller-->
<scene sceneID="esf-vQ-Cgq">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="4m3-w5-SV5" userLabel="First Responder" sceneMemberID="firstResponder"/>
<tableViewController id="DR2-xt-xbP" userLabel="album View Controller" customClass="albumViewController" customModule="kanyeAPIClient" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="Y0e-Td-7QO">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="rd5-Wf-lrj" style="IBUITableViewCellStyleDefault" id="XwV-Px-sya" customClass="albumCell" customModule="kanyeAPIClient" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="albumCell" id="XwV-Px-sya" customClass="albumCell" customModule="kanyeAPIClient" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="XwV-Px-sya" id="rNR-ak-bfI">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rd5-Wf-lrj">
<rect key="frame" x="15" y="0.0" width="570" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="LaT-8V-1np" kind="show" identifier="showTracks" id="JsA-Iw-Dlj"/>
Expand All @@ -115,13 +107,10 @@
<outlet property="delegate" destination="DR2-xt-xbP" id="c3o-N7-OUb"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="Jxa-vf-jh3">
<barButtonItem key="rightBarButtonItem" title="Stats" id="vFh-na-9vP"/>
</navigationItem>
<navigationItem key="navigationItem" id="Jxa-vf-jh3"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4m3-w5-SV5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="748" y="1193"/>
<point key="canvasLocation" x="110" y="1089"/>
</scene>
<!--track View Controller-->
<scene sceneID="Wju-gh-3ms">
Expand All @@ -132,8 +121,8 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="djr-oV-XxG" style="IBUITableViewCellStyleDefault" id="o8w-53-FCd" customClass="trackCell" customModule="kanyeAPIClient" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="trackCell" textLabel="djr-oV-XxG" style="IBUITableViewCellStyleDefault" id="o8w-53-FCd" customClass="trackCell" customModule="kanyeAPIClient" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="o8w-53-FCd" id="QA7-Ep-SwC">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
Expand All @@ -143,7 +132,7 @@
<rect key="frame" x="15" y="0.0" width="570" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand All @@ -164,7 +153,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Cfd-bq-lZv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1506" y="1193"/>
<point key="canvasLocation" x="868" y="1089"/>
</scene>
<!--track Detail-->
<scene sceneID="jUK-k3-fgA">
Expand All @@ -177,13 +166,30 @@
<view key="view" contentMode="scaleToFill" id="oSV-nQ-QER">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="epB-jB-g6D">
<rect key="frame" x="0.0" y="64" width="600" height="492"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<mutableString key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</mutableString>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="epB-jB-g6D" firstAttribute="top" secondItem="oSV-nQ-QER" secondAttribute="top" constant="64" id="2qp-j0-fz8"/>
<constraint firstItem="epB-jB-g6D" firstAttribute="rightMargin" secondItem="oSV-nQ-QER" secondAttribute="rightMargin" id="8tE-pD-lgw"/>
<constraint firstItem="epB-jB-g6D" firstAttribute="leftMargin" secondItem="oSV-nQ-QER" secondAttribute="leftMargin" id="K0t-wu-hdC"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Details" id="Mem-im-QOe"/>
<connections>
<outlet property="lyricsLabel" destination="epB-jB-g6D" id="uhy-ZX-45I"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="PnC-Ql-DbW" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2290" y="1193"/>
<point key="canvasLocation" x="1652" y="1089"/>
</scene>
</scenes>
</document>
11 changes: 6 additions & 5 deletions APIClient/albumCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import Foundation

import UIKit
import Freddy
import Moya

/*class albumCell: UITableViewCell {
func configureForEntry(album: Album) {
class albumCell: UITableViewCell {
func configurewithalbum(album: Album) {
textLabel?.text = album.name
}
}*/
func configurewithstring(title: String) {
textLabel?.text = title
}
}
Loading

0 comments on commit bd0d0f4

Please sign in to comment.