diff --git a/APIClient/APIViewController.swift b/APIClient/APIViewController.swift index 08d3df0..fffcf04 100644 --- a/APIClient/APIViewController.swift +++ b/APIClient/APIViewController.swift @@ -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() { @@ -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 + } + } + } + } } \ No newline at end of file diff --git a/APIClient/Album.swift b/APIClient/Album.swift index a38d2e6..6f75f1d 100644 --- a/APIClient/Album.swift +++ b/APIClient/Album.swift @@ -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 - - 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 } - } -*/ \ No newline at end of file diff --git a/APIClient/AppDelegate.swift b/APIClient/AppDelegate.swift index c5f4f28..f108e5c 100644 --- a/APIClient/AppDelegate.swift +++ b/APIClient/AppDelegate.swift @@ -8,6 +8,7 @@ import UIKit import Moya +import Freddy @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -17,16 +18,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { /// The PokeAPI Provider representing the Server let kanyeAPI = MoyaProvider() - /*let albums = [ - Album(title: "the_college_dropout"), - Album(title: "late_registration"), - Album(title: "graduation"), - Album(title: "808s_&_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_&_heartbreak", + "my_beautiful_dark_twisted_fantasy", + "watch_the_throne", + "yeezus", + "the_life_of_pablo" + ] func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { @@ -34,16 +35,48 @@ class AppDelegate: UIResponder, UIApplicationDelegate { 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 } diff --git a/APIClient/Base.lproj/Main.storyboard b/APIClient/Base.lproj/Main.storyboard index d8383e3..00625d4 100644 --- a/APIClient/Base.lproj/Main.storyboard +++ b/APIClient/Base.lproj/Main.storyboard @@ -18,7 +18,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -83,27 +83,19 @@ + - - + + - - - @@ -115,13 +107,10 @@ - - - + - - + @@ -132,8 +121,8 @@ - - + + @@ -143,7 +132,7 @@ - + @@ -164,7 +153,7 @@ - + @@ -177,13 +166,30 @@ + + + + + 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. + + + + + + + + + + + + - + diff --git a/APIClient/albumCell.swift b/APIClient/albumCell.swift index ce011de..ddc5501 100644 --- a/APIClient/albumCell.swift +++ b/APIClient/albumCell.swift @@ -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 } -}*/ \ No newline at end of file + func configurewithstring(title: String) { + textLabel?.text = title + } +} \ No newline at end of file diff --git a/APIClient/albumViewController.swift b/APIClient/albumViewController.swift index f8610c1..f7b7494 100644 --- a/APIClient/albumViewController.swift +++ b/APIClient/albumViewController.swift @@ -6,26 +6,61 @@ // Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. // +import Foundation import UIKit import Freddy import Moya -/* + class albumViewController: UITableViewController { /// The Poke API provider that handles requests for server resources var kanyeAPI: MoyaProvider! - - var allalbums: [Album]! + var allalbums: [Album] = [] + var allalbumnames: [String]? //var albums: [APIResource]! + override func viewDidLoad() { + //super.viewDidLoad() + print("VC loaded") + self.title = "Kanye = God" + 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) + print(tracks) + self.allalbums.append(Album(tracksfetched: tracks)) + //print(self.allalbums[0]) + print(self.allalbums) + } catch { + print(error) + break + } + case .Failure(let error): + print("failure") + print(error) + break + } + } + } + + + print("didload") + } // MARK: User Interaction - override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { + /*override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { switch identifier { case "showTracks": - if let indexPath = tableView.indexPathForSelectedRow, case .loaded = albums[indexPath.row] { + if let indexPath = tableView.indexPathForSelectedRow, case .loaded = allalbums[indexPath.row] { return true } else { return false @@ -33,11 +68,12 @@ class albumViewController: UITableViewController { default: return true } - } + }*/ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { switch segue.identifier! { case "showTracks": + print("selected") guard let trackViewController = segue.destinationViewController as? trackViewController else { return } @@ -47,6 +83,7 @@ class albumViewController: UITableViewController { let selectedAlbum = allalbums[indexPath.row] trackViewController.kanyeAPI = kanyeAPI trackViewController.trackAlbum = selectedAlbum + trackViewController.alltracks = selectedAlbum.tracks default: break } @@ -59,36 +96,20 @@ class albumViewController: UITableViewController { extension albumViewController { - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { - return 1 - } + override func numberOfSectionsInTableView(tableView: UITableView) -> Int {return 1} override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return allalbums.count + print(self.allalbumnames!.count) + return self.allalbumnames!.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - // Load the resource for this row if necessary - if case .notLoaded(let target) = albums[indexPath.row] { - albums[indexPath.row] = kanyeAPI.request(target) { result in - self.albums[indexPath.row] = result - tableView.reloadRowsAtIndexPaths([ indexPath ], withRowAnimation: .Fade) - } - } - // Obtain a cell and configure it let cell = tableView.dequeueReusableCellWithIdentifier("albumCell", forIndexPath: indexPath) as! albumCell - cell.configureForEntry(allalbums[indexPath.row]) - if case .loaded = albums[indexPath.row] { - cell.selectionStyle = .Default - cell.accessoryType = .DisclosureIndicator - } else { - cell.selectionStyle = .None - cell.accessoryType = .None - } + let albumname = self.allalbumnames![indexPath.row] + cell.configurewithstring(albumname) return cell } } -*/ \ No newline at end of file diff --git a/APIClient/track.swift b/APIClient/track.swift index d831aa2..5b2127d 100644 --- a/APIClient/track.swift +++ b/APIClient/track.swift @@ -17,7 +17,7 @@ struct Track: JSONDecodable { let lyrics: String let album: String - init(json: JSON) throws { + public init(json: JSON) throws { self.title = try json.decode("title") self.lyrics = try json.decode("lyrics") self.album = try json.decode("album") diff --git a/APIClient/trackDetailViewController.swift b/APIClient/trackDetailViewController.swift index 4ab4cbb..2b950f0 100644 --- a/APIClient/trackDetailViewController.swift +++ b/APIClient/trackDetailViewController.swift @@ -16,4 +16,12 @@ class trackDetailViewController: UIViewController { var kanyeAPI: MoyaProvider! var track: Track! + @IBOutlet var lyricsLabel: UITextView! + + override func viewDidLoad() { + self.lyricsLabel.text = self.track!.lyrics + self.lyricsLabel.editable = false + self.title = self.track!.title + " / " + self.track!.album + } + } \ No newline at end of file diff --git a/APIClient/trackViewController.swift b/APIClient/trackViewController.swift index 1cb2911..019f193 100644 --- a/APIClient/trackViewController.swift +++ b/APIClient/trackViewController.swift @@ -9,18 +9,18 @@ import UIKit import Freddy import Moya -/* + class trackViewController: UITableViewController { var kanyeAPI: MoyaProvider! - var trackAlbum: Album! - var alltracks: [Track]! + var trackAlbum: Album? + var alltracks: [Track]? //var tracks: [APIResource]! // MARK: User Interaction - override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { + /*override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { switch identifier { case "showDetail": if let indexPath = tableView.indexPathForSelectedRow, case .loaded = tracks[indexPath.row] { @@ -31,7 +31,7 @@ class trackViewController: UITableViewController { default: return true } - } + }*/ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { switch segue.identifier! { @@ -42,7 +42,7 @@ class trackViewController: UITableViewController { guard let indexPath = tableView.indexPathForSelectedRow else { return } - let selectedTrack = tracks[indexPath.row] + let selectedTrack = alltracks![indexPath.row] trackDetailViewController.kanyeAPI = kanyeAPI trackDetailViewController.track = selectedTrack default: @@ -62,31 +62,17 @@ extension trackViewController { } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return alltracks.count + return alltracks!.count } + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - // Load the resource for this row if necessary - if case .notLoaded(let target) = tracks[indexPath.row] { - tracks[indexPath.row] = kanyeAPI.request(target) { result in - self.tracks[indexPath.row] = result - tableView.reloadRowsAtIndexPaths([ indexPath ], withRowAnimation: .Fade) - } - } - // Obtain a cell and configure it let cell = tableView.dequeueReusableCellWithIdentifier("trackCell", forIndexPath: indexPath) as! trackCell - cell.configureForEntry(alltracks[indexPath.row]) - if case .loaded = tracks[indexPath.row] { - cell.selectionStyle = .Default - cell.accessoryType = .DisclosureIndicator - } else { - cell.selectionStyle = .None - cell.accessoryType = .None - } + let track = alltracks![indexPath.row] + cell.configureForEntry(track) return cell } } -*/ \ No newline at end of file diff --git a/kanyeAPIClient.xcodeproj/project.pbxproj b/kanyeAPIClient.xcodeproj/project.pbxproj index edce70f..489001e 100644 --- a/kanyeAPIClient.xcodeproj/project.pbxproj +++ b/kanyeAPIClient.xcodeproj/project.pbxproj @@ -296,6 +296,7 @@ TargetAttributes = { 874D06541CEF295E009A494D = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 5NV62CF7F7; }; 87EC714E1CFA380F00FBDDDE = { CreatedOnToolsVersion = 7.3.1; @@ -650,10 +651,13 @@ baseConfigurationReference = 93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = APIClient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient"; PRODUCT_NAME = kanyeAPIClient; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -662,10 +666,13 @@ baseConfigurationReference = FFE13D543A95D28F27CFBDA4 /* Pods-APIClient.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = APIClient/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient"; PRODUCT_NAME = kanyeAPIClient; + PROVISIONING_PROFILE = ""; }; name = Release; };