diff --git a/GetHip/CurrentlyPlayingViewController.swift b/GetHip/CurrentlyPlayingViewController.swift index 1f77e4d..61a47f7 100644 --- a/GetHip/CurrentlyPlayingViewController.swift +++ b/GetHip/CurrentlyPlayingViewController.swift @@ -11,7 +11,7 @@ import MediaPlayer import AVFoundation import MultipeerConnectivity -class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDelegate{ +class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDelegate, UICollectionViewDataSource, UICollectionViewDelegate{ //persistant data var party: PartyServiceManager! var usr: [UserParseData] = [] @@ -21,19 +21,97 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg var playing = true var timer = NSTimer() var nextHost: String! + @IBOutlet var segmentControl: UISegmentedControl! - //controller data + @IBAction func switchViews(segCtrl: UISegmentedControl){ + + if(segCtrl.selectedSegmentIndex == 0){ + //hide all in party view elements + self.friendsInParty.hidden = true + self.leaveOrEnd.hidden = true + self.leaveOrEnd.enabled = false + self.addMore.hidden = true + self.addMore.enabled == true + + + //show all relevent current playing ui components + self.songImg.hidden = false + self.titleLabel.hidden = false + self.artistAndAlbumLabel.hidden = false + self.minLabel.hidden = false + self.maxLabel.hidden = false + self.progressBar.hidden = false + + if(self.party.role == PeerType.Host_Creator || self.party.role == PeerType.Guest_Creator){ + + self.volCtrl.hidden == false + self.volCtrl.enabled = true + + } + + } + + if(segCtrl.selectedSegmentIndex == 1){ + //show all in party view elements + self.friendsInParty.hidden = false + self.leaveOrEnd.hidden = false + self.leaveOrEnd.enabled = true + + + if(self.party.role == PeerType.Host_Creator || self.party.role == PeerType.Guest_Creator){ + + self.addMore.hidden = false + self.addMore.enabled == true + } + + + //hide all relevent current playing ui components + self.songImg.hidden = true + self.titleLabel.hidden = true + self.artistAndAlbumLabel.hidden = true + self.minLabel.hidden = true + self.maxLabel.hidden = true + self.progressBar.hidden = true + + self.volCtrl.hidden == true + self.volCtrl.enabled = false + } + + } + + //controller data for currently playing segment @IBOutlet var songImg: UIImageView! @IBOutlet var titleLabel: UILabel! @IBOutlet var artistAndAlbumLabel: UILabel! @IBOutlet var minLabel: UILabel! @IBOutlet var maxLabel: UILabel! @IBOutlet var progressBar: UIProgressView! - - //Host buttons + /*Host Buttons*/ @IBOutlet var volCtrl: UISlider! @IBOutlet var ppfButton: UIButton! + //controller data for in party view + @IBOutlet var friendsInParty: UICollectionView! + @IBOutlet var leaveOrEnd: UIButton! + /*Host Buttons*/ + @IBOutlet var addMore: UIButton! + + + + //Action Methods for In Party View + + //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){ + + } + + + //Action Methods for Currently Playing View @IBAction func volChng(sender: UISlider){ self.audioPlayer.volume = sender.value } @@ -63,10 +141,6 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg } - - //Guest buttons - - override func viewDidLoad() { @@ -74,9 +148,24 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg // Do any additional setup after loading the view. + + //set up for in party view + self.friendsInParty.dataSource = self + self.friendsInParty.delegate = self + self.friendsInParty.hidden = true + self.leaveOrEnd.hidden = true + self.leaveOrEnd.enabled = false + + + //Set up for CurrentlyPlayingView self.progressBar.setProgress(0, animated: true) + self.volCtrl.hidden = true + self.volCtrl.enabled = false if(self.party.role == PeerType.Host_Creator || self.party.role == PeerType.Guest_Creator){ + self.volCtrl.hidden = false + self.volCtrl.enabled = true + self.audioPlayer = AVPlayer(URL: self.party.currentSong.valueForProperty(MPMediaItemPropertyAssetURL) as! NSURL) self.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size) @@ -100,6 +189,8 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg //NSNotificationCenter.defaultCenter().addObserver(self, selector: "songDidEnd:", name: "AVPlayerItemDidPlayToEndTimeNotification", object: nil) }else if (self.party.role == PeerType.Guest_Invited || self.party.role == PeerType.Host_Invited){ + self.volCtrl.hidden = true + self.volCtrl.enabled = false self.songImg.image = self.party.currentSongIMG self.titleLabel.text = (self.party.currentSongTitle) @@ -113,6 +204,11 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg + } + + override func viewDidAppear(animated: Bool) { + //make this part check which view to display later + } func songDidEnd(notification: NSNotification){ @@ -229,6 +325,43 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg } +//collection view methods +extension CurrentlyPlayingViewController { + + func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + + var cell: InvitedCollectionViewCell! + + + let friend = self.party.invitedFriends[indexPath.row] + cell = self.friendsInParty.dequeueReusableCellWithReuseIdentifier("InvitedCollectionCell", forIndexPath: indexPath) as! InvitedCollectionViewCell + + if friend.profileImg == nil { + cell.friendImage.backgroundColor = UIColor.grayColor() + } + else{ + cell.friendImage.image = friend.profileImg.image! + } + + //rounds uiimage and configures UIImageView + cell.friendImage.layer.cornerRadius = cell.friendImage.frame.size.width/2 + cell.friendImage.clipsToBounds = true + + + + return cell + + } + + func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + + return self.party.invitedFriends.count + + + } + +} + extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { func foundPeer() { @@ -266,23 +399,35 @@ extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { }else if(instruction == "want_to_be_host"){ - let alert = UIAlertController(title: "Hosting Request", message: "Would you like to be the next host for the party and pick a song?", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "Accept", style: .Default, handler:{ - (action: UIAlertAction!) -> Void in + if objc_getClass("UIAlertController") != nil { - self.party.currentHost = self.party.myPeerID.displayName - alert.dismissViewControllerAnimated(true, completion: nil) + let alert = UIAlertController(title: "Hosting Request", message: "Would you like to be the next host for the party and pick a song?", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "Accept", style: .Default, handler:{ + (action: UIAlertAction!) -> Void in + + self.party.currentHost = self.party.myPeerID.displayName + alert.dismissViewControllerAnimated(true, completion: nil) + + })) - })) - - alert.addAction(UIAlertAction(title: "Decline", style: .Default, handler:{ - (action: UIAlertAction!) -> Void in - var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "does_not_accept"] - self.party.sendInstruction(dictionary, toPeer: fromPeer) - alert.dismissViewControllerAnimated(true, completion: nil) - })) - - self.presentViewController(alert, animated: true, completion: nil) + + alert.addAction(UIAlertAction(title: "Decline", style: .Default, handler:{ + (action: UIAlertAction!) -> Void in + var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "does_not_accept"] + self.party.sendInstruction(dictionary, toPeer: fromPeer) + alert.dismissViewControllerAnimated(true, completion: nil) + })) + + self.presentViewController(alert, animated: true, completion: nil) + + }else{ + let alert = UIAlertView() + alert.title = "Password Changed" + alert.message = "Your password has been updated." + alert.addButtonWithTitle("Yes") + alert.addButtonWithTitle("No") + alert.show() + } }else if(instruction == "start_picking_a_song"){ if(self.party.role == PeerType.Host_Invited){ diff --git a/GetHip/FriendRequestViewController.swift b/GetHip/FriendRequestViewController.swift index de37461..cb767b6 100644 --- a/GetHip/FriendRequestViewController.swift +++ b/GetHip/FriendRequestViewController.swift @@ -53,10 +53,23 @@ class FriendRequestViewController: UIViewController{ (succeeded, error) -> Void in if(succeeded){ - var alert = UIAlertController(title: "Request Sent!", message: "Your friend request was sent successfully!", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) - self.presentViewController(alert, animated: true, completion: nil) + //for ios 7 and lower compatibility + + if objc_getClass("UIAlertController") != nil { + + var alert = UIAlertController(title: "Request Sent!", message: "Your friend request was sent successfully!", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + + }else{ + let alert = UIAlertView() + alert.title = "Request Sent!" + alert.message = "Your friend request was sent successfully!" + alert.addButtonWithTitle("OK") + alert.show() + } println(friendRequest.objectId!) var params = NSMutableDictionary() @@ -151,9 +164,25 @@ extension FriendRequestViewController: UITextFieldDelegate{ if(self.searchedEmail == (self.tabBarController as! HomeTabController).userData[0].email){ - let alert = UIAlertController(title: "That's You!", message: "Sorry, you can't send a request to yourself.", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) - self.presentViewController(alert, animated: true, completion: nil) + + + //for ios 7 and lower compatibility + if objc_getClass("UIAlertController") != nil { + + + let alert = UIAlertController(title: "That's You!", message: "Sorry, you can't send a request to yourself.", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + self.presentViewController(alert, animated: true, completion: nil) + + }else{ + let alert = UIAlertView() + alert.title = "That's You!" + alert.message = "Sorry, you can't send a request to yourself." + alert.addButtonWithTitle("OK") + alert.show() + } + + } else if(inFriendsList == false){ @@ -199,19 +228,47 @@ extension FriendRequestViewController: UITextFieldDelegate{ }) }else{ - let alert = UIAlertController(title: "Request Already Made", message: "You have already sent a friend request to this user.", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) - self.presentViewController(alert, animated: true, completion: nil) - } + + //for ios 7 and lower compatibility + + if objc_getClass("UIAlertController") != nil { + let alert = UIAlertController(title: "Request Already Made!", message: "You have already sent a friend request to this user.", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + self.presentViewController(alert, animated: true, completion: nil) + + + }else{ + let alert = UIAlertView() + alert.title = "Request Already Made!" + alert.message = "You have already sent a friend request to this user." + alert.addButtonWithTitle("OK") + alert.show() + } + + } }) }) }else{ - let alert = UIAlertController(title: "Already Friends", message: "You are already friends with this user!", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + //for ios 7 and lower compatibility + + if objc_getClass("UIAlertController") != nil { + let alert = UIAlertController(title: "Already Friends!", message: "You are already friends with this user!", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) self.presentViewController(alert, animated: true, completion: nil) + + + }else{ + let alert = UIAlertView() + alert.title = "Already Friends!" + alert.message = "You are already friends with this user!" + alert.addButtonWithTitle("OK") + alert.show() + } + + } diff --git a/GetHip/HomeScreenViewController.swift b/GetHip/HomeScreenViewController.swift index 7079e8e..aa290aa 100644 --- a/GetHip/HomeScreenViewController.swift +++ b/GetHip/HomeScreenViewController.swift @@ -139,6 +139,11 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { //initialize host role self.partyData.setRole(PeerType(rawValue: 0)!) + //remove fake peers that would appear in list if a peer that is found disconnects before entering invite screen + + + + vc.setData(self.userData, frndData: self.friendData, party: self.partyData, request: self.requestData) diff --git a/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo.png b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo.png new file mode 100644 index 0000000..135f9b6 Binary files /dev/null and b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo.png differ diff --git a/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo@2x.png b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo@2x.png new file mode 100644 index 0000000..7f04335 Binary files /dev/null and b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Background photo@2x.png differ diff --git a/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Contents.json b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Contents.json new file mode 100644 index 0000000..1e863f0 --- /dev/null +++ b/GetHip/Images-3.xcassets/Background/BackgroundPhoto.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "Background photo.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "Background photo@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GetHip/Info.plist b/GetHip/Info.plist index 70b8d19..794755d 100644 --- a/GetHip/Info.plist +++ b/GetHip/Info.plist @@ -35,7 +35,7 @@ CFBundleVersion - 3 + 4 FacebookAppID 1166375230058840 FacebookDisplayName diff --git a/GetHip/InvitedToPartyViewController.swift b/GetHip/InvitedToPartyViewController.swift index 81bdac7..9954075 100644 --- a/GetHip/InvitedToPartyViewController.swift +++ b/GetHip/InvitedToPartyViewController.swift @@ -23,13 +23,21 @@ class InvitedToPartyViewController: UIViewController , PartyServiceManagerDelega @IBAction func declineInvite(sender: UIButton){ self.inviteHandle(false, self.partyData.session) + self.shouldEndInvite = true self.dismissViewControllerAnimated(true, completion: nil) } @IBAction func acceptInvite(sender: UIButton){ self.partyData.currentHost = self.fromPeer.displayName self.inviteHandle(true, self.partyData.session) + self.shouldEndInvite = true self.performSegueWithIdentifier("JoiningPartySegue", sender: self) + /*self.dismissViewControllerAnimated(true, completion: { + () -> Void in + + + })*/ + } override func viewDidLoad() { diff --git a/GetHip/JoiningPartyViewController.swift b/GetHip/JoiningPartyViewController.swift index 89cc751..7eaaa3b 100644 --- a/GetHip/JoiningPartyViewController.swift +++ b/GetHip/JoiningPartyViewController.swift @@ -105,11 +105,19 @@ extension JoiningPartyViewController: PartyServiceManagerDelegate { if (instruction == "start_party"){ - println("mark 4") + println("mark 4: start party") + //var microDelay = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("doIt"), userInfo: nil, repeats: false) self.performSegueWithIdentifier("EnteringPartySegue", sender: self) + println("micro-triggered") + } } + func doIt(){ + self.performSegueWithIdentifier("EnteringPartySegue", sender: self) + println("triggered") + } + } diff --git a/GetHip/LoadingPartyViewController.swift b/GetHip/LoadingPartyViewController.swift index 1ea471a..e67c250 100644 --- a/GetHip/LoadingPartyViewController.swift +++ b/GetHip/LoadingPartyViewController.swift @@ -91,6 +91,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_party"] for peer in self.party.session.connectedPeers as! [MCPeerID] { + println("start_party_from_host") self.party.sendInstruction(dictionary, toPeer: peer ) } @@ -100,7 +101,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, func attemptToStart(){ - + /* for peer in self.party.session.connectedPeers as! [MCPeerID] { if self.arePeersReady[peer.displayName] == false{ @@ -108,7 +109,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, self.party.sendInstruction(dictionary, toPeer: peer) } } - + */ var delTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("startParty"), userInfo: nil, repeats: false) diff --git a/GetHip/LoginController.swift b/GetHip/LoginController.swift index f09257e..78e49b8 100644 --- a/GetHip/LoginController.swift +++ b/GetHip/LoginController.swift @@ -41,25 +41,71 @@ class LoginController: UIViewController, PFLogInViewControllerDelegate, UITextFi self.presentViewController(tabBarController, animated: true, completion: nil) }else{ - var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + //for ios 7 and lower compatibility - self.presentViewController(alert, animated: true, completion: nil) + if objc_getClass("UIAlertController") != nil { + var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + + + + }else{ + let alert = UIAlertView() + alert.title = "Invalid Login" + alert.message = "Invalid email or password" + alert.addButtonWithTitle("OK") + alert.show() + } } }) }else{ - var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) - self.presentViewController(alert, animated: true, completion: nil) + //for ios 7 and lower compatibility + + if objc_getClass("UIAlertController") != nil { + var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + + + + }else{ + let alert = UIAlertView() + alert.title = "Invalid Login" + alert.message = "Invalid email or password" + alert.addButtonWithTitle("OK") + alert.show() + } + + } }) }) }else{ - var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) - self.presentViewController(alert, animated: true, completion: nil) - /* + + //for ios 7 and lower compatibility + + if objc_getClass("UIAlertController") != nil { + var alert = UIAlertController(title: "Invalid Login", message: "Invalid email or password", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + self.presentViewController(alert, animated: true, completion: nil) + + + + }else{ + let alert = UIAlertView() + alert.title = "Invalid Login" + alert.message = "Invalid email or password" + alert.addButtonWithTitle("OK") + alert.show() + } + + + + /* PFUser.logInWithUsernameInBackground(userEmailField.text!, password: password.text!, block: { (user, error) -> Void in diff --git a/GetHip/Main.storyboard b/GetHip/Main.storyboard index 789fbb8..bc91854 100644 --- a/GetHip/Main.storyboard +++ b/GetHip/Main.storyboard @@ -522,17 +522,17 @@ - + - + - - @@ -1098,10 +1100,10 @@ - + - - + @@ -1660,12 +1662,12 @@ - + - + @@ -1781,14 +1783,14 @@ - + - - - - + + + + + + + + + + + + @@ -1880,12 +1892,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1893,6 +1965,7 @@ + @@ -1900,9 +1973,10 @@ - + + @@ -1910,16 +1984,20 @@ - + + + + + @@ -1943,7 +2021,7 @@ - + @@ -2086,10 +2164,10 @@ - + -