From b263ce3a22d58d0bec2181b2e5c0c3fc4bcb9d69 Mon Sep 17 00:00:00 2001 From: Okechi Date: Fri, 12 Feb 2016 09:55:36 -0500 Subject: [PATCH] working in image downloading for all views --- GetHip.xcodeproj/project.pbxproj | 12 ++ GetHip/CurrentlyPlayingViewController.swift | 20 ++- GetHip/FriendData.swift | 2 +- GetHip/FriendDataSource.swift | 40 +++-- GetHip/FriendRequestViewController.swift | 16 +- GetHip/FriendsListViewController.swift | 13 +- GetHip/InPartyViewController.swift | 49 +++++++ GetHip/Main.storyboard | 155 ++++++++++---------- GetHip/PendingRequestViewController.swift | 2 +- GetHip/SettingsDetailViewWrapper.swift | 9 +- GetHip/SettingsTableViewController.swift | 2 +- GetHip/UserParseDataSource.swift | 16 +- 12 files changed, 224 insertions(+), 112 deletions(-) create mode 100644 GetHip/InPartyViewController.swift diff --git a/GetHip.xcodeproj/project.pbxproj b/GetHip.xcodeproj/project.pbxproj index fe8573d..0377100 100644 --- a/GetHip.xcodeproj/project.pbxproj +++ b/GetHip.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 3E1BDA6B1C37111D00EE3B84 /* GetHipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1BDA6A1C37111D00EE3B84 /* GetHipTests.swift */; }; 3E1DE9A81C3837E800CA6CD4 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E1DE9A71C3837E800CA6CD4 /* AudioToolbox.framework */; }; 3E1DE9AE1C38395F00CA6CD4 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E1DE9AD1C38395F00CA6CD4 /* SystemConfiguration.framework */; }; + 3E1EE6391C6D02EB00F5C5D7 /* InPartyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1EE6381C6D02EB00F5C5D7 /* InPartyViewController.swift */; }; 3E24F9FF1C5B51690091B9D9 /* Send@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E24F9FE1C5B51690091B9D9 /* Send@2x.png */; }; 3E326BCC1C51C20000F785CF /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E326BCB1C51C20000F785CF /* SettingsTableViewController.swift */; }; 3E326BCE1C51C77600F785CF /* SettingsCellWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E326BCD1C51C77600F785CF /* SettingsCellWrapper.swift */; }; @@ -152,6 +153,7 @@ 3E1DE9A71C3837E800CA6CD4 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 3E1DE9AB1C3838A800CA6CD4 /* libsystem_network.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsystem_network.dylib; path = usr/lib/system/libsystem_network.dylib; sourceTree = SDKROOT; }; 3E1DE9AD1C38395F00CA6CD4 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + 3E1EE6381C6D02EB00F5C5D7 /* InPartyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPartyViewController.swift; sourceTree = ""; }; 3E24F9FE1C5B51690091B9D9 /* Send@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Send@2x.png"; path = "../../../Dropbox/Gethip/Screens/Friends + Invite Screens/i5/Friend Found/Send@2x.png"; sourceTree = ""; }; 3E326BCB1C51C20000F785CF /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = ""; }; 3E326BCD1C51C77600F785CF /* SettingsCellWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsCellWrapper.swift; sourceTree = ""; }; @@ -333,6 +335,7 @@ 3E101F041C52E50400C895CA /* PartySessionSource */ = { isa = PBXGroup; children = ( + 3E1EE6371C6D029800F5C5D7 /* InParty */, 3E34125A1C54C73A006226E0 /* PartySession.swift */, 3E627FC21C55978E005C0372 /* PartySessionManager.swift */, 3E101F071C52E65300C895CA /* PartyServiceManager.swift */, @@ -436,6 +439,14 @@ name = Frameworks; sourceTree = ""; }; + 3E1EE6371C6D029800F5C5D7 /* InParty */ = { + isa = PBXGroup; + children = ( + 3E1EE6381C6D02EB00F5C5D7 /* InPartyViewController.swift */, + ); + name = InParty; + sourceTree = ""; + }; 3E3412551C54C2BC006226E0 /* SelectSong */ = { isa = PBXGroup; children = ( @@ -812,6 +823,7 @@ 3E101F081C52E65300C895CA /* PartyServiceManager.swift in Sources */, 3E330B1A1C38502F00276FE4 /* LoginViewController.swift in Sources */, 3E627FEA1C55AE35005C0372 /* TDAudioFileStream.m in Sources */, + 3E1EE6391C6D02EB00F5C5D7 /* InPartyViewController.swift in Sources */, 3E627FC31C55978E005C0372 /* PartySessionManager.swift in Sources */, 3E627FE61C55AE35005C0372 /* NSInputStream+URLInitialization.m in Sources */, 3E5485B51C69CE2F00E7D5AB /* InvitedCollectionViewCell.swift in Sources */, diff --git a/GetHip/CurrentlyPlayingViewController.swift b/GetHip/CurrentlyPlayingViewController.swift index 02f57c0..8a257c4 100644 --- a/GetHip/CurrentlyPlayingViewController.swift +++ b/GetHip/CurrentlyPlayingViewController.swift @@ -19,15 +19,17 @@ class CurrentlyPlayingViewController: UIViewController { //Host buttons @IBOutlet var volCtrl: UISlider! - @IBOutlet var ppButton: UIButton! - @IBAction func endParty(sender: AnyObject){ + @IBOutlet var ppfButton: UIButton! + @IBAction func playPauseFav(sender: UIButton){ } - //Guest buttons - @IBOutlet var favButton: UIButton! - @IBAction func favoriteSong(sender: AnyObject){ + //Guest buttons + + //Regular buttons + @IBAction func partyView(sender: UIButton){ + self.performSegueWithIdentifier("InPartySegue", sender: nil) } @@ -55,14 +57,18 @@ class CurrentlyPlayingViewController: UIViewController { } - /* + // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. + + if(segue.identifier == "InPartySegue"){ + + } } - */ + } diff --git a/GetHip/FriendData.swift b/GetHip/FriendData.swift index 973361c..2fa8166 100644 --- a/GetHip/FriendData.swift +++ b/GetHip/FriendData.swift @@ -10,7 +10,7 @@ import Foundation class FriendData { var displayName: String! - var profileImg: UIImage! + var profileImg: UIImageView! var status: String! init(display: String, status: String){ diff --git a/GetHip/FriendDataSource.swift b/GetHip/FriendDataSource.swift index ab3b968..01a2628 100644 --- a/GetHip/FriendDataSource.swift +++ b/GetHip/FriendDataSource.swift @@ -33,19 +33,21 @@ class FriendDataSource{ let userName = object.objectForKey("OtherUser")!.objectForKey("username") as! String let requestStatus = object.objectForKey("RequestStatus")! as! String - /* let pimage:PFFile = object["profilePicture"] as! PFFile - - pimage.getDataInBackgroundWithBlock({ - (imageData, error) -> Void in - if !(error != nil) { - image = UIImage(data: imageData!)! - } - })*/ - - var newFriend: FriendData = FriendData(display: userName, status: requestStatus) - //print(userName) - self.dataSource.append(newFriend) + var newFriend: FriendData = FriendData(display: userName, status: requestStatus) + + var img = object.objectForKey("OtherUser")!.objectForKey("profilePicture")! as? PFFile + + dispatch_async(dispatch_get_main_queue(), { + img!.getDataInBackgroundWithBlock({ + (imgData, error) -> Void in + + var downloadedImg = UIImage(data: imgData!) + newFriend.profileImg.image = downloadedImg + }) + }) + //print(userName) + self.dataSource.append(newFriend) } @@ -64,8 +66,20 @@ class FriendDataSource{ let userName = object.objectForKey("OtherUser")!.objectForKey("username") as! String let requestStatus = object.objectForKey("RequestStatus")! as! String - var newFriend: FriendData = FriendData(display: userName, status: requestStatus) + + var img = object.objectForKey("OtherUser")!.objectForKey("profilePicture")! as? PFFile + + dispatch_async(dispatch_get_main_queue(), { + img!.getDataInBackgroundWithBlock({ + (imgData, error) -> Void in + + var downloadedImg = UIImage(data: imgData!) + newFriend.profileImg.image = downloadedImg + }) + }) + + //print(userName) self.dataSource.append(newFriend) diff --git a/GetHip/FriendRequestViewController.swift b/GetHip/FriendRequestViewController.swift index a0e9dc8..05a7753 100644 --- a/GetHip/FriendRequestViewController.swift +++ b/GetHip/FriendRequestViewController.swift @@ -59,8 +59,9 @@ class FriendRequestViewController: UIViewController{ println(friendRequest.objectId!) var params = NSMutableDictionary() - params.setObject(friendRequest.objectId! as String!, forKey: "friendRequest") + params.setObject((object!.objectForKey("username") as! String!), forKey: "otherUser") + PFCloud.callFunctionInBackground("alertPotentialFriend", withParameters: params as [NSObject : AnyObject]) //var params = NSMutableDictionary() //params.s //var param = ["friendRequest" : friendRequest.objectId!] @@ -148,6 +149,19 @@ extension FriendRequestViewController: UITextFieldDelegate{ (object: PFObject?, error: NSError?) -> Void in if(error == nil){ self.foundName.text = object?.objectForKey("username") as? String + + //download profile imge + var img = object!.objectForKey("profilePicture")! as? PFFile + + dispatch_async(dispatch_get_main_queue(), { + img!.getDataInBackgroundWithBlock({ + (imgData, error) -> Void in + + var downloadedImg = UIImage(data: imgData!) + self.displayImage.image = downloadedImg + }) + }) + self.sendRequest.enabled = true }else{ self.foundName.text = "No Friend Found :(" diff --git a/GetHip/FriendsListViewController.swift b/GetHip/FriendsListViewController.swift index bbf9dca..cfbcfd4 100644 --- a/GetHip/FriendsListViewController.swift +++ b/GetHip/FriendsListViewController.swift @@ -84,7 +84,7 @@ class FriendsListViewController: UIViewController, UITableViewDelegate, UITableV cell!.proImage.backgroundColor = UIColor.grayColor() } else{ - + cell!.proImage.image = friend?.profileImg!.image! } //rounds uiimage and configures UIImageView @@ -143,12 +143,15 @@ class FriendsListViewController: UIViewController, UITableViewDelegate, UITableV if segue.identifier == "FriendRequestSegue" { var frndNames: [String] = [] println(self.friends.count) - for i in 0...self.friends.count-1{ - var frends: FriendData! = self.friends[i] as! FriendData - println(frends.displayName!) - frndNames.append(frends.displayName!) + if (self.friends.count != 0){ + for i in 0...self.friends.count-1{ + var frends: FriendData! = self.friends[i] as! FriendData + println(frends.displayName!) + frndNames.append(frends.displayName!) + } } + /*for name in self.friends{ //bad instruction here, fix later println(name.displayName as String!) diff --git a/GetHip/InPartyViewController.swift b/GetHip/InPartyViewController.swift new file mode 100644 index 0000000..23f8e37 --- /dev/null +++ b/GetHip/InPartyViewController.swift @@ -0,0 +1,49 @@ +// +// InPartyViewController.swift +// GetHip +// +// Created by Okechi on 2/11/16. +// Copyright (c) 2016 Kroleo. All rights reserved. +// + +import UIKit + +class InPartyViewController: UIViewController { + var party: PartyServiceManager! + @IBOutlet var friendsInParty: UICollectionView! + @IBOutlet var AddMore: UIButton! + @IBOutlet var leaveOrEnd: UIButton! + + //Only visible for host + @IBAction func inviteMore(sender: UIButton!){ + + } + + //Alternates to either end a party or leave a party depending on host or guest role + @IBAction func endOrLeaveParty(sender: UIButton){ + + } + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/GetHip/Main.storyboard b/GetHip/Main.storyboard index 0a60662..3ff5cd2 100644 --- a/GetHip/Main.storyboard +++ b/GetHip/Main.storyboard @@ -54,7 +54,7 @@ @@ -656,39 +656,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -808,22 +828,16 @@ - - + + + + + + @@ -849,6 +863,9 @@ + + + - - - - - - - + @@ -1249,7 +1249,6 @@ - diff --git a/GetHip/PendingRequestViewController.swift b/GetHip/PendingRequestViewController.swift index e585406..4ae9889 100644 --- a/GetHip/PendingRequestViewController.swift +++ b/GetHip/PendingRequestViewController.swift @@ -133,7 +133,7 @@ class PendingRequestViewController: UITableViewController { cell!.proImg.backgroundColor = UIColor.grayColor() } else{ - + cell!.proImg.image = pending?.profileImg.image! } //rounds uiimage and configures UIImageView diff --git a/GetHip/SettingsDetailViewWrapper.swift b/GetHip/SettingsDetailViewWrapper.swift index 1a2bb8e..e225942 100644 --- a/GetHip/SettingsDetailViewWrapper.swift +++ b/GetHip/SettingsDetailViewWrapper.swift @@ -198,19 +198,20 @@ class ProfileDetailViewController: UIViewController, UINavigationControllerDeleg } - func setData(){ - self.profileImg = nil + func setData(proImage:UIImageView){ + self.profileImg = proImage } override func viewDidLoad() { super.viewDidLoad() - self.img!.layer.cornerRadius = self.img!.frame.size.width/2 + if self.profileImg == nil{ self.img!.backgroundColor = UIColor.grayColor() } else{ - self.img = self.profileImg + self.img.image = self.profileImg.image! } + self.img.layer.cornerRadius = self.img!.frame.size.width/2 self.ChngPhtoBtn!.layer.borderWidth = 1 self.ChngPhtoBtn!.layer.cornerRadius = 5 diff --git a/GetHip/SettingsTableViewController.swift b/GetHip/SettingsTableViewController.swift index 60af396..f6dd284 100644 --- a/GetHip/SettingsTableViewController.swift +++ b/GetHip/SettingsTableViewController.swift @@ -210,7 +210,7 @@ class SettingsTableViewController: UIViewController, UITableViewDataSource, UITa if self.user.count > 0 { let vc: ProfileDetailViewController = (segue.destinationViewController as? ProfileDetailViewController)! - vc.setData() + vc.setData((self.user[0] as? UserParseData)!.profileImg) println("img") } diff --git a/GetHip/UserParseDataSource.swift b/GetHip/UserParseDataSource.swift index 9ff468c..96111c1 100644 --- a/GetHip/UserParseDataSource.swift +++ b/GetHip/UserParseDataSource.swift @@ -32,7 +32,9 @@ class UserParseDataSource{ usrName = object.objectForKey("username")! as! String displayName = object.objectForKey("displayName") as! String - + + + if displayName.isEmpty { displayName = usrName } @@ -41,6 +43,18 @@ class UserParseDataSource{ usr = UserParseData(usrName: usrName, dispName: displayName, email: email) + + var img = object.objectForKey("profilePicture")! as? PFFile + + dispatch_async(dispatch_get_main_queue(), { + img!.getDataInBackgroundWithBlock({ + (imgData, error) -> Void in + + var downloadedImg = UIImage(data: imgData!) + usr.profileImg = UIImageView(image: downloadedImg) + }) + }) + self.user.append(usr) //print(userName)