Large diffs are not rendered by default.

@@ -6,4 +6,51 @@
// Copyright © 2016 Thomas Threlkeld. All rights reserved.
//
import Foundation
//
// ALRadialMenuButton.swift
// ALRadialMenu
//
// Created by Alex Littlejohn on 2015/04/26.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit

public typealias ALRadialMenuButtonAction = () -> Void
protocol PerformSegueInRootProtocol {
func createSessionButtonSelected()
func currentSessionsButtonSelected()
func sessionInvitesButtonSelected()
func sessionFeedButtonSelected()
}
protocol PerformSegueInArtistFinder{
func buttonOneTouched(name: String)
}
public class ALRadialMenuButton: UIButton {
public var index: Int?
public var home: String?
public var homeScreenSize: Double?
public var name: String?
var delegate: PerformSegueInRootProtocol!
var artistDelegate: PerformSegueInArtistFinder!
//var invitesDelegate: PerformSegueInArtistFinder!

open var action: ALRadialMenuButtonAction? {
didSet {

configureAction()
}
}

fileprivate func configureAction() {
addTarget(self, action: #selector(performAction), for: .touchUpInside)
}

internal func performAction() {
if let a = action {
a()
}

}
}
@@ -7,3 +7,85 @@
//
import Foundation
import UIKit
import QuartzCore

class AboutONBViewController: UIViewController {


@IBOutlet weak var aboutONBTextView: UITextView!
@IBOutlet weak var aboutONBBackgroundImage: UIImageView!
@IBOutlet weak var textViewBlur: UIVisualEffectView!


var tutorialText: String!
var pageIndex: Int?


override func viewDidLoad() {
super.viewDidLoad()


switch UIScreen.main.bounds.width{
case 320:
aboutONBTextView.font = UIFont.systemFont(ofSize: 20.0, weight: UIFontWeightLight)

case 375:
aboutONBTextView.font = UIFont.systemFont(ofSize: 25.0, weight: UIFontWeightLight)



case 414:
aboutONBTextView.font = UIFont.systemFont(ofSize: 30.0, weight: UIFontWeightLight)


default:
aboutONBTextView.font = UIFont.systemFont(ofSize: 30.0, weight: UIFontWeightLight)



}








self.aboutONBTextView.text = tutorialText
self.aboutONBTextView.layer.cornerRadius = 20
//self.textViewBlur.layer.cornerRadius = 20
//self.textViewBlur.clipsToBounds = true
//Blur for background
//only apply the blur if the user hasn't disabled transparency effects
if !UIAccessibilityIsReduceTransparencyEnabled() {
self.view.backgroundColor = UIColor.clear

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

self.aboutONBBackgroundImage.addSubview(blurEffectView) //if you have more UIViews, use an insertSubview API to place it where needed
} else {
self.view.backgroundColor = UIColor.black
}


//self.aboutONBTextView.addSubview(textViewBlurEffectView)





}

}




Large diffs are not rendered by default.

@@ -7,40 +7,61 @@
//
import UIKit
import Firebase

import IQKeyboardManagerSwift


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true)
FIRApp.configure()
IQKeyboardManager.sharedManager().enable = true

UIPageControl.appearance().pageIndicatorTintColor = UIColor.darkGray
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor.orange
UIPageControl.appearance().backgroundColor = UIColor.black

//UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
// Sets shadow (line below the bar) to a blank image
//UINavigationBar.appearance().shadowImage = UIImage()
// Sets the translucent background color
//UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
// Set translucent. (Default value is already true, so this can be removed if desired.)
//UINavigationBar.appearance().isTranslucent = true

// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

@@ -7,3 +7,24 @@
//
import Foundation
import UIKit

class Artist: NSObject{
var activeSessions: NSDictionary?
var name: String?
var email: String?
var instruments = [String]()
var invites = [String:Any]()
var password: String?
var artistUID: String?
var bio: String?
var profileImageUrl = [String]()
var location = [String:Any]()
var media = [String:Any]()






}
@@ -7,3 +7,105 @@
//
import Foundation
import UIKit
import Firebase
import CoreLocation


/*protocol LoadProperSessionProtocol {
func loadThisSession(indexPath: IndexPath)
}*/

protocol PerformSegueInArtistFinderController {
func performSegueToProfile(artistUID: String)
}


class ArtistCardCell: UICollectionViewCell {
//var delegate: LoadProperSessionProtocol!
var ref = FIRDatabase.database().reference()
var artistUID: String?
var buttonName: String!
var invitedSessionID: String!
var sessionDate: String!
var delegate: PerformSegueInArtistFinderController!
@IBOutlet weak var artistCardCellNameLabel: UILabel!
@IBOutlet weak var artistCardCellBioTextView: UITextView!


@IBOutlet weak var artistCardCellImageView: UIImageView!

@IBOutlet weak var distanceLabel: UILabel!
@IBOutlet weak var reputationLabel: UILabel!
@IBOutlet weak var inviteToSession: UIButton!

@IBOutlet weak var artistCardCellButton: UIButton!

@IBAction func artistCardButtonPressed(_ sender: AnyObject) {
print(artistUID)
self.delegate.performSegueToProfile(artistUID: artistUID!)
}
@IBAction func invitePressed(_ sender: AnyObject) {
ref.child("users").child(artistUID!).child("invites").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{

for snap in snapshots{
if let dictionary = snap.value as? [String: Any] {
if dictionary["sessionID"] as! String == self.invitedSessionID{
let alert = UIAlertController(title: "Whoops!", message: "Artist already has pending invite for this session.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.viewController()?.present(alert, animated: true, completion: nil)
return

}
}
}
}


let recipient = self.ref.child("users").child(self.artistUID!).child("invites")
let currentUser = FIRAuth.auth()?.currentUser?.uid

var values = [String: Any]()
//values[sessRef] = testArray //as Any?
values["sender"] = currentUser!
values["sessionID"] = self.invitedSessionID
values["instrumentNeeded"] = self.buttonName
values["sessionDate"] = self.sessionDate


recipient.childByAutoId().updateChildValues(values, withCompletionBlock: {(err, ref) in
if err != nil {
print(err)
return
}
})
})









}



var sessionId: String?
var coordinateUser1: CLLocation?
var coordinateUser2: CLLocation?
//var distance: Double?
var tempLong: CLLocationDegrees?
var tempLat: CLLocationDegrees?
override func awakeFromNib() {
}

@IBAction func cellTouched(_ sender: AnyObject) {


}
}
@@ -9,9 +9,18 @@
import UIKit

class ArtistCell: UITableViewCell {


@IBOutlet weak var artistImageView: UIImageView!

@IBOutlet weak var artistNameLabel: UILabel!
@IBOutlet weak var artistInstrumentLabel: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = UIColor.white
//self.artistImageView.layer.cornerRadius = artistImageView.frame.width/2
//self.artistImageView.clipsToBounds = true
// Initialization code
}

@@ -22,3 +31,7 @@ class ArtistCell: UITableViewCell {
}

}




@@ -1,16 +1,53 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ArtistCell" rowHeight="147" id="bgb-pk-We4" customClass="ArtistCell" customModule="OneNightBand" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="403" height="147"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="bgb-pk-We4" id="qaa-PA-Qw5">
<frame key="frameInset" width="403" height="146"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XH7-Sm-lLm">
<frame key="frameInset" minX="1.99%" minY="5.48%" width="30.52%" height="87.67%"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Artist Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FW3-Zt-ILl">
<frame key="frameInset" minX="33.00%" minY="30.14%" width="26.05%" height="40.41%"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text=":" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JtV-aX-qSC">
<frame key="frameInset" minX="61.04%" minY="36.99%" width="5.71%" height="25.34%"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Instrument" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jq5-mk-U7D">
<frame key="frameInset" minX="68.73%" minY="30.14%" width="27.05%" height="36.99%"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="artistImageView" destination="XH7-Sm-lLm" id="x57-Wf-ayY"/>
<outlet property="artistInstrumentLabel" destination="Jq5-mk-U7D" id="2hS-dt-ZVk"/>
<outlet property="artistNameLabel" destination="FW3-Zt-ILl" id="8i3-N4-8je"/>
</connections>
<point key="canvasLocation" x="82.5" y="-168.5"/>
</tableViewCell>
</objects>
</document>

Large diffs are not rendered by default.

@@ -7,3 +7,105 @@
//
import Foundation
import UIKit
import Firebase

class ArtistProfileViewController: UIViewController, UINavigationControllerDelegate, UITextViewDelegate {

@IBOutlet weak var bioTextView: UITextView!
@IBOutlet weak var vidCollectionView: UICollectionView!
@IBOutlet weak var picCollectionView: UICollectionView!
@IBOutlet weak var profilePicture: UIImageView!

var ref = FIRDatabase.database().reference()
var dictionaryOfInstruments: [NSDictionary] = [NSDictionary]()
var tags = [Tag]()
var artistUID: String!



override func viewDidLoad(){
super.viewDidLoad()

self.bioTextView.delegate = self


let userID = FIRAuth.auth()?.currentUser?.uid
ref.child("users").child(artistUID!).observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
//print(snapshot.value as? NSDictionary)
let value = snapshot.value as? NSDictionary
self.bioTextView.text = value?["bio"] as! String
self.navigationItem.title = (value?["name"] as! String)

//self.profilePicture.image?.accessibilityIdentifier = value?["profileImageUrl"] as! String
//let user = users[(indexPath as NSIndexPath).row]
//cell.textLabel?.text = user.name
//cell.detailTextLabel?.text = user.email
if let profileImageUrl = value?["profileImageUrl"] {
self.profilePicture.loadImageUsingCacheWithUrlString(profileImageUrl as! String)
}

// ...
}) { (error) in
print(error.localizedDescription)
}

ref.child("users").child(artistUID!).child("instruments").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
let tag = Tag()
tag.name = (snap.value! as! String)
tag.selected = true
self.tags.append(tag)
}
}
/* let cellNib = UINib(nibName: "TagCell", bundle: nil)
self.collectionView.register(cellNib, forCellWithReuseIdentifier: "TagCell")
self.collectionView.backgroundColor = UIColor.clear
self.sizingCell = (cellNib.instantiate(withOwner: nil, options: nil) as NSArray).firstObject as! TagCell?
//self.flowLayout.sectionInset = UIEdgeInsetsMake(8, 8, 8, 8)
self.collectionView.dataSource = self
self.collectionView.delegate = self*/

})




//print (instrumentArray)
//initializing TagCell and creating a cell for each item in array TAGS
//add logout button to Nav Bar
//navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(handleLogout))
//navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: UIControlState.normal)
//if FIRAuth.auth()?.currentUser?.uid == nil {
// perform(#selector(handleLogout), with: nil, afterDelay: 0)
// }
//set image picker delegate and then set profile pic constraints
profilePicture.layer.borderWidth = 2
profilePicture.layer.masksToBounds = false
profilePicture.layer.borderColor = UIColor.white.cgColor
profilePicture.layer.cornerRadius = profilePicture.frame.width/2
profilePicture.clipsToBounds = true


//creating and adding blur effect to subview
/*let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.backgroundImage.addSubview(blurEffectView)*/
//let gesture = UITapGestureRecognizer(target: self, action: #selector(showMenu()))
//view.addGestureRecognizer(gesture)

}


}
@@ -11,11 +11,13 @@ import Photos
import Firebase
import JSQMessagesViewController

final class ChatViewController: JSQMessagesViewController {
final class ChatViewController: JSQMessagesViewController, SessionIDDest {

// MARK: Properties
var getSessionID: GetSessionIDDelegate?

private let imageURLNotSetKey = "NOTSET"
var thisSession: Session!
var thisSessionID: String!
var sessionRef: FIRDatabaseReference?

private lazy var messageRef: FIRDatabaseReference = self.sessionRef!.child("messages")
@@ -48,10 +50,16 @@ final class ChatViewController: JSQMessagesViewController {
override func viewDidLoad() {
super.viewDidLoad()
sessionRef = FIRDatabase.database().reference().child("sessions").child(thisSession.sessionUID!)
self.navigationController?.setNavigationBarHidden(false, animated: true)
print("sessID: ", thisSessionID)
self.sessionRef = FIRDatabase.database().reference().child("sessions").child(thisSessionID)
self.senderId = FIRAuth.auth()?.currentUser?.uid
//addMessage(withId: "foo", name: "Mr.Bolt", text: "I am so fast!")
//addMessage(withId: senderId, name: "Me", text: "I bet I can run faster than you!")
//addMessage(withId: senderId, name: "Me", text: "I like to run!")
observeMessages()


// No avatars
collectionView!.collectionViewLayout.incomingAvatarViewSize = CGSize.zero
collectionView!.collectionViewLayout.outgoingAvatarViewSize = CGSize.zero
@@ -112,6 +120,7 @@ final class ChatViewController: JSQMessagesViewController {
return 15
}


override func collectionView(_ collectionView: JSQMessagesCollectionView?, attributedTextForMessageBubbleTopLabelAt indexPath: IndexPath!) -> NSAttributedString? {
let message = messages[indexPath.item]
switch message.senderId {
@@ -135,6 +144,8 @@ final class ChatViewController: JSQMessagesViewController {
// We can use the observe method to listen for new
// messages being written to the Firebase DB
newMessageRefHandle = messageQuery.observe(.childAdded, with: { (snapshot) -> Void in
print(snapshot)
if(snapshot.childrenCount > 1){
let messageData = snapshot.value as! Dictionary<String, String>

if let id = messageData["senderId"] as String!, let name = messageData["senderName"] as String!, let text = messageData["text"] as String!, text.characters.count > 0 {
@@ -151,6 +162,7 @@ final class ChatViewController: JSQMessagesViewController {
} else {
print("Error! Could not decode message data")
}
}
})

// We can also use the observer method to listen for
@@ -159,6 +171,7 @@ final class ChatViewController: JSQMessagesViewController {
// to the Firebase Storage, so we can update the message data
updatedMessageRefHandle = messageRef.observe(.childChanged, with: { (snapshot) in
let key = snapshot.key
if(snapshot.childrenCount > 1){
let messageData = snapshot.value as! Dictionary<String, String>

if let photoURL = messageData["photoURL"] as String! {
@@ -167,6 +180,7 @@ final class ChatViewController: JSQMessagesViewController {
self.fetchImageDataAtURL(photoURL, forMediaItem: mediaItem, clearsPhotoMessageMapOnSuccessForKey: key)
}
}
}
})
}

@@ -198,7 +212,7 @@ final class ChatViewController: JSQMessagesViewController {
}

private func observeTyping() {
let typingIndicatorRef = sessionRef!.child("typingIndicator")
let typingIndicatorRef = sessionRef!.child("messages").child("typingIndicator")
userIsTypingRef = typingIndicatorRef.child(senderId)
userIsTypingRef.onDisconnectRemoveValue()
usersTypingQuery = typingIndicatorRef.queryOrderedByValue().queryEqual(toValue: true)

Large diffs are not rendered by default.

@@ -7,3 +7,300 @@
//
import Foundation
import UIKit
import FirebaseStorage
import Firebase

class CreateSessionPopup: UIViewController, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, Dismissable{

weak var dismissalDelegate: DismissalDelegate?
var ref = FIRDatabase.database().reference()

lazy var sessionImageViewButton: UIButton = {
var tempButton = UIButton()
//tempButton.setBackgroundImage(UIImage(named: "icon-profile"), for: .normal)
/*tempButton.contentMode = .scaleAspectFill
tempButton.translatesAutoresizingMaskIntoConstraints = false
tempButton.isEnabled = true*/
tempButton.layer.borderWidth = 2
tempButton.layer.borderColor = UIColor.darkGray.cgColor
tempButton.backgroundColor = UIColor.clear
tempButton.setTitle("Select\n Session\n Image", for: .normal)
tempButton.titleLabel?.numberOfLines = 3
tempButton.titleLabel?.textAlignment = NSTextAlignment.center
tempButton.titleLabel?.lineBreakMode = .byWordWrapping
tempButton.setTitleColor(UIColor.gray, for: .normal)
tempButton.titleLabel?.font = UIFont.systemFont(ofSize: 28.0, weight: UIFontWeightLight)
tempButton.layer.cornerRadius = 10
tempButton.clipsToBounds = true
tempButton.contentMode = .scaleAspectFill
tempButton.translatesAutoresizingMaskIntoConstraints = false
tempButton.isEnabled = true
tempButton.alpha = 0.6
tempButton.addTarget(self, action: #selector(handleSelectSessionImageView), for: .touchUpInside)


return tempButton

}()
func setupSessionImageViewButton(){
switch UIScreen.main.bounds.width{
case 320:
sessionImageViewButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
sessionImageViewButton.bottomAnchor.constraint(equalTo: datePicker.topAnchor).isActive = true
sessionImageViewButton.widthAnchor.constraint(equalToConstant: 125).isActive = true
sessionImageViewButton.heightAnchor.constraint(equalToConstant: 125).isActive = true

case 375:
sessionImageViewButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
sessionImageViewButton.bottomAnchor.constraint(equalTo: datePicker.topAnchor).isActive = true
sessionImageViewButton.widthAnchor.constraint(equalToConstant: 150).isActive = true
sessionImageViewButton.heightAnchor.constraint(equalToConstant: 150).isActive = true

case 414:
sessionImageViewButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
sessionImageViewButton.bottomAnchor.constraint(equalTo: datePicker.topAnchor).isActive = true
sessionImageViewButton.widthAnchor.constraint(equalToConstant: 150).isActive = true
sessionImageViewButton.heightAnchor.constraint(equalToConstant: 150).isActive = true


default:
sessionImageViewButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
sessionImageViewButton.bottomAnchor.constraint(equalTo: datePicker.topAnchor).isActive = true
sessionImageViewButton.widthAnchor.constraint(equalToConstant: 150).isActive = true
sessionImageViewButton.heightAnchor.constraint(equalToConstant: 150).isActive = true


}

}

let picker = UIImagePickerController()
func handleSelectSessionImageView() {

picker.allowsEditing = true

present(picker, animated: true, completion: nil)
}


lazy var sessionImageView: UIImageView = {
let imageView = UIImageView()
imageView.isHidden = true
//imageView.image = UIImage(named: "icon-profile")
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill

//imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
imageView.isUserInteractionEnabled = true

return imageView
}()
func setupSessionImageView() {
//need x, y, width, height constraints
sessionImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
sessionImageView.topAnchor.constraint(equalTo: popupView.topAnchor).isActive = true
sessionImageView.widthAnchor.constraint(equalTo: sessionImageViewButton.widthAnchor).isActive = true
sessionImageView.heightAnchor.constraint(equalTo: sessionImageViewButton.heightAnchor).isActive = true

//sessionImageView.heightAnchor.constraint(equalToConstant: 150).isActive = true
}



@IBOutlet weak var datePicker: UIDatePicker!
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var finalizeSessionButton: UIButton!
@IBOutlet weak var sessionBioTextView: UITextView!
@IBOutlet weak var sessionNameTextField: UITextField!
@IBOutlet weak var popupView: UIView!
@IBOutlet weak var backgroundView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
popupView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
popupView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -50).isActive = true
datePicker.datePickerMode = UIDatePickerMode.date

sessionBioTextView.layer.borderColor = UIColor.darkGray.cgColor
sessionBioTextView.layer.borderWidth = 2
sessionBioTextView.layer.masksToBounds = false
view.addSubview(sessionImageView)
view.addSubview(sessionImageViewButton)
setupSessionImageView()
setupSessionImageViewButton()
backgroundView.backgroundColor = UIColor.black
//backgroundView.alpha = 0.7
sessionBioTextView.delegate = self
self.view.backgroundColor = UIColor.clear
//self.view.backgroundColor?.withAlphaComponent(0.8)
sessionBioTextView.textColor = UIColor.gray
sessionBioTextView.text = "tap to add a little info about the type of session you are trying to create."
self.showAnimate()
picker.delegate = self


}


/*public func textViewDidBeginEditing(_ textView: UITextView){
}
optional public func textViewDidEndEditing(_ textView: UITextView){
}*/

public func textViewDidBeginEditing(_ textView: UITextView) {
if sessionBioTextView.textColor == UIColor.gray {
sessionBioTextView.text = nil
sessionBioTextView.textColor = UIColor.orange
}
}
public func textViewDidEndEditing(_ textView: UITextView) {
if sessionBioTextView.text.isEmpty {
sessionBioTextView.text = "tap to add a little info about the type of session you are trying to create."
sessionBioTextView.textColor = UIColor.gray
}
}

func showAnimate()
{
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
UIView.animate(withDuration: 0.25, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
});
}

func removeAnimate()
{
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
}, completion:{(finished : Bool) in
if (finished)
{
self.view.removeFromSuperview()
}
});
}

@IBAction func cancelTouched(_ sender: AnyObject) {
dismissalDelegate?.finishedShowing(viewController: self)
removeAnimate()
}
@IBAction func finalizeTouched(_ sender: AnyObject) {
if(sessionImageView.image != nil && sessionNameTextField.text != "" && sessionBioTextView.text != "tap to add a little info about the type of session you are trying to create."){
let imageName = NSUUID().uuidString
let storageRef = FIRStorage.storage().reference().child("session_images").child("\(imageName).jpg")

if let sessionImage = self.sessionImageView.image, let uploadData = UIImageJPEGRepresentation(sessionImage, 0.1) {
storageRef.put(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil {
print(error)
return
}
//let tempURL = URL.init(fileURLWithPath: "temp")
if let sessionImageUrl = metadata?.downloadURL()?.absoluteString {
var tempArray = [String]()
var tempArray2 = [String]()
var values = Dictionary<String, Any>()
tempArray2.append((FIRAuth.auth()?.currentUser?.uid)! as String)
values["sessionName"] = self.sessionNameTextField.text
values["sessionArtists"] = [(FIRAuth.auth()?.currentUser?.uid)!:"-"]
values["sessionBio"] = self.sessionBioTextView.text
values["sessionPictureURL"] = sessionImageUrl
values["sessionMedia"] = [""]
values["messages"] = [String: Any]()
let dateformatter = DateFormatter()

dateformatter.dateStyle = DateFormatter.Style.short

//dateformatter.timeStyle = DateFormatter.Style.short
let now = dateformatter.string(from: self.datePicker.date)
values["sessionDate"] = now


let ref = FIRDatabase.database().reference()
let sessReference = ref.child("sessions").childByAutoId()

let sessReferenceAnyObject = sessReference.key
values["sessionUID"] = sessReferenceAnyObject
tempArray.append(sessReferenceAnyObject)
//print(sessReference.key)
//sessReference.childByAutoId()
sessReference.updateChildValues(values, withCompletionBlock: {(err, ref) in
if err != nil {
print(err)
return
}
})
let user = FIRAuth.auth()?.currentUser?.uid
//var sessionVals = Dictionary
//let userSessRef = ref.child("users").child(user).child("activeSessions")
self.ref.child("users").child(user!).child("activeSessions").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
tempArray.append(snap.value! as! String)
}
}
var tempDict = [String : Any]()
tempDict["activeSessions"] = tempArray
let userRef = ref.child("users").child(user!)
userRef.updateChildValues(tempDict, withCompletionBlock: {(err, ref) in
if err != nil {
print(err)
return
}
})
self.dismissalDelegate?.finishedShowing(viewController: self)
self.removeAnimate()
//this is ridiculously stupid way to reload currentSession data. find someway to fix
self.performSegue(withIdentifier: "FinalizeSessionToProfile", sender: self)
self.performSegue(withIdentifier: "CreateSessionPopupToCurrentSession", sender: self)
})
}
})
}


}else{
let alert = UIAlertController(title: "Error", message: "Missing Information", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

var selectedImageFromPicker: UIImage?
print("test")
if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
selectedImageFromPicker = editedImage

} else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {

selectedImageFromPicker = originalImage
}

if let selectedImage = selectedImageFromPicker {

sessionImageViewButton.setBackgroundImage(selectedImage, for: .normal)
//profileImageViewButton.set
sessionImageView.image = selectedImage

}

dismiss(animated: true, completion: nil)

}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
print("canceled picker")
dismiss(animated: true, completion: nil)
}


}
@@ -7,3 +7,336 @@
//
import Foundation
import UIKit
import Firebase

class CurrentSessionCollectionView: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

var currentButton: String? // make array for sessions from each button
var activeBool = false
var pastBool = false
var upcomingBool = false
var feedBool = false

var pastSessionArray = [Session]()
var upcomingSessionArray = [Session]()
var activeSessionsArray = [Session]()
var sessionFeedArray = [Session]()

var sessionIDArray = [String]()
var cellArray = [SessionCell]()
var ref = FIRDatabase.database().reference()
var sizingCell: SessionCell?
var tempSess: Session?
var tempIndex: Int?

var upcomingDidLoad = false
var sessionsOnFeedDidLoad = false
var pastSessionsDidLoad = false
var activeSessionsDidLoad = false

@IBOutlet weak var sessionCollectionView: UICollectionView!

@IBOutlet weak var sessionFeedCollectionView: UICollectionView!
@IBOutlet weak var upcomingSessionsCollectionView: UICollectionView!
@IBOutlet weak var pastSessionsCollectionView: UICollectionView!

@IBOutlet weak var sessionsOnFeed: UIButton!
@IBOutlet weak var upcomingSessions: UIButton!
@IBOutlet weak var pastSessions: UIButton!
@IBOutlet weak var activeSessions: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
self.loadCollectionViews()
}

var curFeedArrayIndex = 0
var curPastArrayIndex = 0
var curActiveArrayIndex = 0
var curUpcomingArrayIndex = 0

func loadCollectionViews(){
activeSessionsArray.removeAll()
pastSessionArray.removeAll()
upcomingSessionArray.removeAll()
sessionFeedArray.removeAll()
sessionIDArray.removeAll()
navigationItem.title = "My Sessions"
sessionCollectionView.isHidden = false
let userID = FIRAuth.auth()?.currentUser?.uid
ref.child("users").child(userID!).child("activeSessions").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
self.sessionIDArray.append((snap.value! as! String))
}
}

self.ref.child("sessions").observeSingleEvent(of: .value, with: {(snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
for id in self.sessionIDArray{
if snap.key == id{
let dictionary = snap.value as? [String: AnyObject]
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = DateFormatter.Style.none
dateFormatter.dateStyle = DateFormatter.Style.short
let now = Date()
let order = Calendar.current.compare(now, to: self.dateFormatted(dateString: dictionary?["sessionDate"] as! String), toGranularity: .day)
print(now)
print(self.dateFormatted(dateString: dictionary?["sessionDate"] as! String))
switch order {
case .orderedSame:
let tempSess = Session()
tempSess.setValuesForKeys(dictionary!)
self.activeSessionsArray.append(tempSess)
case .orderedAscending:
let tempSess = Session()
tempSess.setValuesForKeys(dictionary!)
self.upcomingSessionArray.append(tempSess)
case .orderedDescending:
let tempSess = Session()
tempSess.setValuesForKeys(dictionary!)
self.pastSessionArray.append(tempSess)
}
}
}
}
}



DispatchQueue.main.async {
for session in self.activeSessionsArray{
self.currentButton = "active"
self.curActiveArrayIndex = self.activeSessionsArray.index(of: session)!
let cellNib = UINib(nibName: "SessionCell", bundle: nil)
self.sessionCollectionView.register(cellNib, forCellWithReuseIdentifier: "SessionCell")
self.sizingCell = (cellNib.instantiate(withOwner: nil, options: nil) as NSArray).firstObject as! SessionCell?
self.sessionCollectionView.backgroundColor = UIColor.clear
self.sessionCollectionView.dataSource = self
self.sessionCollectionView.delegate = self
}
DispatchQueue.main.async {
for session in self.pastSessionArray{
self.currentButton = "past"
self.curPastArrayIndex = self.pastSessionArray.index(of: session)!

let cellNib = UINib(nibName: "SessionCell", bundle: nil)
self.pastSessionsCollectionView.register(cellNib, forCellWithReuseIdentifier: "SessionCell")
self.sizingCell = (cellNib.instantiate(withOwner: nil, options: nil) as NSArray).firstObject as! SessionCell?
self.pastSessionsCollectionView.backgroundColor = UIColor.clear
self.pastSessionsCollectionView.dataSource = self
self.pastSessionsCollectionView.delegate = self
}
DispatchQueue.main.async {
for session in self.upcomingSessionArray{
self.currentButton = "upcoming"
self.curUpcomingArrayIndex = self.upcomingSessionArray.index(of: session)!
let cellNib = UINib(nibName: "SessionCell", bundle: nil)
self.upcomingSessionsCollectionView.register(cellNib, forCellWithReuseIdentifier: "SessionCell")
self.sizingCell = (cellNib.instantiate(withOwner: nil, options: nil) as NSArray).firstObject as! SessionCell?
self.upcomingSessionsCollectionView.backgroundColor = UIColor.clear
self.upcomingSessionsCollectionView.dataSource = self
self.upcomingSessionsCollectionView.delegate = self
}
}
}
}
})
self.ref.child("sessionFeed").observeSingleEvent(of: .value, with: {(snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for id in self.sessionIDArray{
for snap in snapshots{
let dictionary = snap.value as? [String: AnyObject]
if dictionary?["sessionUID"] as! String == id{
let tempSess = Session()
tempSess.setValuesForKeys(dictionary!)
self.currentButton = "feed"
self.sessionFeedArray.append(tempSess)
}
}
}


print(self.sessionFeedArray)
for session in self.sessionFeedArray{
self.currentButton = "feed"
self.curFeedArrayIndex = self.sessionFeedArray.index(of: session)!
let cellNib = UINib(nibName: "SessionCell", bundle: nil)
self.sessionFeedCollectionView.register(cellNib, forCellWithReuseIdentifier: "SessionCell")
self.sizingCell = (cellNib.instantiate(withOwner: nil, options: nil) as NSArray).firstObject as! SessionCell?
self.sessionFeedCollectionView.backgroundColor = UIColor.clear
self.sessionFeedCollectionView.dataSource = self
self.sessionFeedCollectionView.delegate = self
}

}
})

})
}




func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(currentButton)
if(self.currentButton == "upcoming"){

return upcomingSessionArray.count


}
if(self.currentButton == "past"){
return pastSessionArray.count

}
if(self.currentButton == "feed"){
return sessionFeedArray.count
}
if(self.currentButton == "active"){
return activeSessionsArray.count
}else{
return 0
}

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SessionCell", for: indexPath as IndexPath) as! SessionCell

tempIndex = indexPath.row
self.configureCell(cell, forIndexPath: indexPath as NSIndexPath)

return cell
}



func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if(collectionView == self.upcomingSessionsCollectionView){
tempIndex = indexPath.row
self.pressedButton = "upcoming"
performSegue(withIdentifier: "SessionCollectionToSessionView", sender: self)
}
if(collectionView == self.pastSessionsCollectionView){
tempIndex = indexPath.row
self.pressedButton = "past"
performSegue(withIdentifier: "SessionCollectionToSessionView", sender: self)
}
if(collectionView == self.sessionFeedCollectionView){
tempIndex = indexPath.row
self.pressedButton = "feed"
performSegue(withIdentifier: "SessionCollectionToSessionView", sender: self)
}
if(collectionView == self.sessionCollectionView){
tempIndex = indexPath.row
self.pressedButton = "active"
performSegue(withIdentifier: "SessionCollectionToSessionView", sender: self)
}

}

func configureCell(_ cell: SessionCell, forIndexPath indexPath: NSIndexPath) {

if(self.currentButton == "upcoming"){
print("Whyyyyy")
if upcomingSessionArray.count == 0{
cell.sessionCellLabel.text = "No Upcoming Sessions"
cell.sessionCellLabel.textColor = UIColor.black
}

if(indexPath.row < upcomingSessionArray.count){
cell.sessionCellImageView.loadImageUsingCacheWithUrlString(upcomingSessionArray[indexPath.row].sessionPictureURL!)
print(self.upcomingSessionArray[indexPath.row].sessionUID)
cell.sessionCellLabel.text = upcomingSessionArray[indexPath.row].sessionName
cell.sessionCellLabel.textColor = UIColor.black
cell.sessionId = sessionIDArray[indexPath.row]
}
cellArray.append(cell)



}
if(self.currentButton == "past"){
if pastSessionArray.count == 0{
cell.sessionCellLabel.text = "No Past Sessions"
cell.sessionCellLabel.textColor = UIColor.black
}
if(indexPath.row < pastSessionArray.count){
cell.sessionCellImageView.loadImageUsingCacheWithUrlString(pastSessionArray[indexPath.row].sessionPictureURL!)
cell.sessionCellLabel.text = pastSessionArray[indexPath.row].sessionName
cell.sessionCellLabel.textColor = UIColor.black
cell.sessionId = sessionIDArray[indexPath.row]
}
cellArray.append(cell)
}
if(self.currentButton == "feed"){
if sessionFeedArray.count == 0{
cell.sessionCellLabel.text = "No Sessions on Feed"
cell.sessionCellLabel.textColor = UIColor.black
}

if(indexPath.row < sessionFeedArray.count){
print(indexPath.row)
cell.sessionCellImageView.loadImageUsingCacheWithUrlString(sessionFeedArray[indexPath.row].sessionPictureURL!)
cell.sessionCellLabel.text = sessionFeedArray[indexPath.row].sessionName
cell.sessionCellLabel.textColor = UIColor.black
cell.sessionId = sessionIDArray[indexPath.row]
}
cellArray.append(cell)
}
if(self.currentButton == "active"){
if activeSessionsArray.count == 0{
cell.sessionCellLabel.text = "No Active Sessions"
cell.sessionCellLabel.textColor = UIColor.black
}
if(indexPath.row < activeSessionsArray.count){
cell.sessionCellImageView.loadImageUsingCacheWithUrlString(activeSessionsArray[indexPath.row].sessionPictureURL!)
cell.sessionCellLabel.text = activeSessionsArray[indexPath.row].sessionName
cell.sessionCellLabel.textColor = UIColor.black
cell.sessionId = sessionIDArray[indexPath.row]
}
cellArray.append(cell)
}
}
var pressedButton = ""
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SessionCollectionToSessionView" {
if let viewController = segue.destination as? SessionMakerViewController {
viewController.sessionID = self.sessionIDArray[tempIndex!]
if(self.pressedButton == "upcoming"){
viewController.sessionID = self.upcomingSessionArray[tempIndex!].sessionUID
}
if(self.pressedButton == "past"){
viewController.sessionID = self.pastSessionArray[tempIndex!].sessionUID
}
if(self.pressedButton == "feed"){
viewController.sessionID = self.sessionFeedArray[tempIndex!].sessionUID
}
if(self.pressedButton == "active"){
viewController.sessionID = self.activeSessionsArray[tempIndex!].sessionUID
}
}
}
}

func dateFormatted(dateString: String)->Date{

let dateFormatter = DateFormatter()

dateFormatter.dateFormat = "MM-dd-yy"

let dateObj = dateFormatter.date(from: dateString)


return(dateObj)!

}




}

@@ -10,8 +10,8 @@ import UIKit

class FlowLayout: UICollectionViewFlowLayout {

override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributesForElementsInRect = super.layoutAttributesForElementsInRect(rect)
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributesForElementsInRect = super.layoutAttributesForElements(in: rect)
var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]()

var leftMargin: CGFloat = 0.0;
@@ -30,4 +30,4 @@ class FlowLayout: UICollectionViewFlowLayout {

return newAttributesForElementsInRect
}
}
}
@@ -37,4 +37,4 @@
<key>DATABASE_URL</key>
<string>https://gaido-31ec2.firebaseio.com</string>
</dict>
</plist>
</plist>
@@ -12,7 +12,7 @@ import UIKit
let imageCache = NSCache<AnyObject, AnyObject>()

extension UIImageView{
func loadImageUsingCacheWithUrlString(urlString: String) {
func loadImageUsingCacheWithUrlString(_ urlString: String) {

self.image = nil

@@ -23,7 +23,7 @@ extension UIImageView{
}

//otherwise fire off a new download
let url = NSURL(string: urlString)
let url = URL(string: urlString)
URLSession.shared.dataTask(with: url! as URL, completionHandler: { (data, response, error) in

//download hit an error so lets return out
@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
@@ -20,6 +24,8 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>Used to select user photo.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
@@ -7,3 +7,12 @@
//
import Foundation

class Invite: NSObject {
var sender: String?
var sessionID: String?
var instrumentNeeded: String?
var sessionDate: String?


}
@@ -7,3 +7,253 @@
//
import Foundation
import UIKit
import Firebase

class InviteViewData: UIViewController {

var inviteSenderText: String!
var sessionNameText: String!
var instrumentNeededText: String!
var dateText: String!
var inviteID: String!
var ref = FIRDatabase.database().reference()
var sessionArtistsArray = [String]()
var sessionArray = [String]()

@IBOutlet weak var AcceptButton: UIButton!
@IBAction func AcceptPressed(_ sender: AnyObject) {
self.view.setNeedsDisplay()
let currentUser = FIRAuth.auth()?.currentUser?.uid

FIRDatabase.database().reference().child("users").child(currentUser!).child("invites").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
if let dictionary = snap.value as? [String: Any] {
if dictionary["sessionID"] as! String == self.sessionNameText{
FIRDatabase.database().reference().child("users").child(currentUser!).child("activeSessions").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
self.sessionArray.append(snap.value! as! String)
}
self.sessionArray.append(self.sessionNameText)
var tempDict = [String : Any]()
tempDict["activeSessions"] = self.sessionArray




FIRDatabase.database().reference().child("users").child(currentUser!).updateChildValues(tempDict, withCompletionBlock: {(err, ref) in
if err != nil {
print(err)
return
}
})
}



/*FIRDatabase.database().reference().child("sessions").child(self.sessionNameText).child("sessionArtists").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
self.sessionArtistsArray.append(snap.value! as! String)
}
FIRDatabase.database().reference().child("users").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
if(snap.key == FIRAuth.auth()?.currentUser?.uid){
if let dictionary = snap.value as? [String: Any] {
self.currentArtist = dictionary["artistUID"] as! String
}
}
}
self.sessionArtistsArray.append(self.currentArtist)
}
var values2 = [String: Any]()
values2["sessionArtists"] = self.sessionArtistsArray
FIRDatabase.database().reference().child("sessions").child(self.sessionNameText).updateChildValues(values2)
})
}
})*/
})



snap.ref.removeValue()
}
}
}
}
})
let newSessionArtist = [currentUser!: self.instrumentNeededText!]
FIRDatabase.database().reference().child("sessions").child(self.sessionNameText).child("sessionArtists").updateChildValues(newSessionArtist)



print("accepted")


}
@IBOutlet weak var declineButton: UIButton!


@IBAction func declinedPressed(_ sender: AnyObject) {
let currentUser = FIRAuth.auth()?.currentUser?.uid
FIRDatabase.database().reference().child("users").child(currentUser!).child("invites").observeSingleEvent(of: .value, with: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
if let dictionary = snap.value as? [String: Any] {
if dictionary["sessionID"] as! String == self.sessionNameText{
snap.ref.removeValue()

}
}
}
}
})

print("declined")

}

@IBOutlet weak var senderPicToProf: UIButton!
@IBAction func senderPicToProfTouched(_ sender: AnyObject) {
}
//@IBOutlet weak var inviteSender: UILabel?
lazy var inviteSender: UILabel = {
var tempLabel = UILabel()
tempLabel.textColor = UIColor.black
tempLabel.translatesAutoresizingMaskIntoConstraints = false
return tempLabel
}()
func setupInviteSender(){
inviteSender.topAnchor.constraint(equalTo: senderPicToProf.bottomAnchor).isActive = true
//inviteSender.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
inviteSender.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
}
lazy var sessionName: UILabel = {
var tempLabel = UILabel()
tempLabel.textColor = UIColor.white
tempLabel.font = UIFont.systemFont(ofSize: 24, weight: UIFontWeightLight)
tempLabel.translatesAutoresizingMaskIntoConstraints = false
return tempLabel
}()
func setupSessionName(){
sessionName.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
sessionName.topAnchor.constraint(equalTo: inviteSender.bottomAnchor, constant: 5).isActive = true
// inviteSender.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
}
lazy var instrumentNeeded: UILabel = {
var tempLabel = UILabel()
tempLabel.textColor = UIColor.white
tempLabel.font = UIFont.systemFont(ofSize: 24, weight: UIFontWeightLight)
tempLabel.translatesAutoresizingMaskIntoConstraints = false
return tempLabel
}()
func setupInstrumentNeeded(){
instrumentNeeded.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
instrumentNeeded.topAnchor.constraint(equalTo: sessionName.bottomAnchor, constant: 5).isActive = true
// inviteSender.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
}
lazy var date: UILabel = {
var tempLabel = UILabel()
tempLabel.textColor = UIColor.white
tempLabel.font = UIFont.systemFont(ofSize: 24, weight: UIFontWeightLight)
tempLabel.translatesAutoresizingMaskIntoConstraints = false
return tempLabel
}()
func setupDate(){
date.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
date.topAnchor.constraint(equalTo: instrumentNeeded.bottomAnchor, constant: 5).isActive = true
// inviteSender.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
}



var sessionInvitedTo = Session()


var pageIndex: Int?
var currentArtist = String()

override func viewDidLoad() {
super.viewDidLoad()

AcceptButton.layer.borderWidth = 2
AcceptButton.layer.borderColor = UIColor.green.withAlphaComponent(0.64).cgColor

declineButton.layer.borderColor = UIColor.red.withAlphaComponent(0.68).cgColor
declineButton.layer.borderWidth = 2

view.addSubview(inviteSender)
view.addSubview(sessionName)
view.addSubview(instrumentNeeded)
view.addSubview(date)

setupInviteSender()
setupSessionName()
setupInstrumentNeeded()
setupDate()


FIRDatabase.database().reference().child("sessions").observeSingleEvent(of: .value, with: { (snapshot) in

if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
if snap.key == self.sessionNameText{

let dictionary = snap.value as? [String: Any]
self.sessionInvitedTo.setValuesForKeys(dictionary!)

self.sessionName.text = self.sessionInvitedTo.sessionName
self.instrumentNeeded.text = self.instrumentNeededText
self.date.text = self.sessionInvitedTo.sessionDate
let tempImage = UIImageView()

tempImage.loadImageUsingCacheWithUrlString(self.sessionInvitedTo.sessionPictureURL! as String)
self.senderPicToProf.setImage(tempImage.image, for: .normal)


}
}
}


FIRDatabase.database().reference().child("users").observeSingleEvent(of: .value, with: { (snapshot) in

if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
for snap in snapshots{
if(snap.key == FIRAuth.auth()?.currentUser?.uid){
if let dictionary = snap.value as? [String: Any] {
self.currentArtist = dictionary["name"] as! String
}

}
if snap.key == self.sessionInvitedTo.sessionArtists.first?.key{
if let dictionary = snap.value as? [String: Any]{
self.inviteSender.text = dictionary["name"] as? String
}
}

}
}
})
})






}
}
@@ -6,4 +6,147 @@
// Copyright © 2016 Thomas Threlkeld. All rights reserved.
//
import Foundation
//
// KaedeTextField.swift
// Swish
//
// Created by RaĂşl Riera on 20/01/2015.
// Copyright (c) 2015 com.raulriera.swishapp. All rights reserved.
//
import UIKit

/**
A KaedeTextField is a subclass of the TextFieldEffects object, is a control that displays an UITextField with a customizable visual effect around the foreground of the control.
*/
@IBDesignable open class KaedeTextField: TextFieldEffects {

/**
The color of the placeholder text.
This property applies a color to the complete placeholder string. The default value for this property is a black color.
*/
@IBInspectable dynamic open var placeholderColor: UIColor = UIColor.lightGray {
didSet {

updatePlaceholder()
}
}

/**
The scale of the placeholder font.
This property determines the size of the placeholder label relative to the font size of the text field.
*/
@IBInspectable dynamic open var placeholderFontScale: CGFloat = 0.8 {
didSet {
updatePlaceholder()
}
}

/**
The view’s foreground color.
The default value for this property is a clear color.
*/
@IBInspectable dynamic open var foregroundColor: UIColor? {
didSet {
updateForegroundColor()
}
}

override open var placeholder: String? {
didSet {
updatePlaceholder()
}
}

override open var bounds: CGRect {
didSet {
drawViewsForRect(bounds)
}
}

fileprivate let foregroundView = UIView()
fileprivate let placeholderInsets = CGPoint(x: 10, y: 5)
fileprivate let textFieldInsets = CGPoint(x: 10, y: 0)

// MARK: - TextFieldsEffects
override open func drawViewsForRect(_ rect: CGRect) {
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))

foregroundView.frame = frame
foregroundView.isUserInteractionEnabled = false
foregroundView.layer.cornerRadius = 10
placeholderLabel.frame = frame.insetBy(dx: placeholderInsets.x, dy: placeholderInsets.y)
placeholderLabel.font = placeholderFontFromFont(font!)

updateForegroundColor()
updatePlaceholder()

if text!.isNotEmpty || isFirstResponder {
animateViewsForTextEntry()
}

addSubview(foregroundView)
addSubview(placeholderLabel)
}

override open func animateViewsForTextEntry() {
UIView.animate(withDuration: 0.35, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: .beginFromCurrentState, animations: ({
self.placeholderLabel.frame.origin = CGPoint(x: self.frame.size.width * 0.65, y: self.placeholderInsets.y)
}), completion: nil)

UIView.animate(withDuration: 0.45, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.5, options: .beginFromCurrentState, animations: ({
self.foregroundView.frame.origin = CGPoint(x: self.frame.size.width * 0.6, y: 0)
}), completion: { _ in
self.animationCompletionHandler?(.textEntry)
})
}

override open func animateViewsForTextDisplay() {
if text!.isEmpty {
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: .beginFromCurrentState, animations: ({
self.placeholderLabel.frame.origin = self.placeholderInsets
}), completion: nil)

UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 2.0, options: .beginFromCurrentState, animations: ({
self.foregroundView.frame.origin = CGPoint.zero
}), completion: { _ in
self.animationCompletionHandler?(.textDisplay)
})
}
}

// MARK: - Private
fileprivate func updateForegroundColor() {
foregroundView.backgroundColor = foregroundColor
}

fileprivate func updatePlaceholder() {
placeholderLabel.text = placeholder
placeholderLabel.textColor = placeholderColor
}

fileprivate func placeholderFontFromFont(_ font: UIFont) -> UIFont! {
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
return smallerFont
}

// MARK: - Overrides
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
let frame = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width * 0.6, height: bounds.size.height))

return frame.insetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
}

override open func textRect(forBounds bounds: CGRect) -> CGRect {
let frame = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width * 0.6, height: bounds.size.height))

return frame.insetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
}

}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -8,14 +8,159 @@
import UIKit

class ONBGuitarButton: UIImageView {

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
class ONBGuitarButton: UIImageView, UIGestureRecognizerDelegate {
var lane = 0
var sessionName: String?
var session: Session?
var sessionViews: Int?
var isDisplayed: Bool?
var tap: NSObject?
var _yPosition: CGFloat = 0.0
var _slope = CGFloat()
var _baseX: CGFloat = 0.0

let kStartY = 200
let kMaxY = 12.5

func initWithLane(lane: Int){
self.lane = lane
//print(lane)
self.setIsDiplayedButton(isDisplayedButton: false)
self.tintColor = UIColor.red
self.image = UIImage(named: "GuitarPin_Red.png")
switch (self.lane) {
case 0:
if UIScreen.main.bounds.width == 320{
_baseX = 109
}

if UIScreen.main.bounds.width == 375{
_baseX = 157
}
if UIScreen.main.bounds.width == 414{
_baseX = 180
}
_slope = -0.85
break;
case 1:
if UIScreen.main.bounds.width == 320{
_baseX = 124
}

if UIScreen.main.bounds.width == 375{
_baseX = 167
}
if UIScreen.main.bounds.width == 414{
_baseX = 193
}
_slope = -0.53
break;
case 2:
if UIScreen.main.bounds.width == 320{
_baseX = 147
}

if UIScreen.main.bounds.width == 375{
_baseX = 180
}
if UIScreen.main.bounds.width == 414{
_baseX = 200
}

_slope = -0.2
break;
case 3:
if UIScreen.main.bounds.width == 320{
_baseX = 167
}

if UIScreen.main.bounds.width == 375{
_baseX = 194
}
if UIScreen.main.bounds.width == 414{
_baseX = 210
}
_slope = 0.14
break;
case 4:
if UIScreen.main.bounds.width == 320{
_baseX = 192
}

if UIScreen.main.bounds.width == 375{
_baseX = 210
}
if UIScreen.main.bounds.width == 414{
_baseX = 220
}
_slope = 0.47
break;
case 5:
if UIScreen.main.bounds.width == 320{
_baseX = 207
}

if UIScreen.main.bounds.width == 375{
_baseX = 220
}
if UIScreen.main.bounds.width == 414{
_baseX = 230
}
_slope = 0.83
break
default:
break
}


}
func setYPosition(yPosition: CGFloat){
var tempPosition = yPosition
_yPosition = yPosition
if (tempPosition < 1) {
tempPosition = 1
self.alpha = 0
//_yPosition = yPosition //might be line thats fucking shit up
//return;
}
let size = powf(Float(tempPosition), 1.5) + 10
//print(size)
self.frame = CGRect(x: 0, y: 0, width: CGFloat(size), height: CGFloat(size))
//self.center = CGPointMake(yPosition * 5.0 * _slope + _baseX, yPosition * 5.0 + kStartY);
self.center = CGPoint(x: CGFloat(powf(Float(tempPosition), 2)) * _slope + _baseX,y: CGFloat(powf(Float(tempPosition), 2)) + CGFloat(kStartY))

//Intro fade
if (tempPosition < 8){
self.alpha = min(1, (tempPosition - 1) * 0.2)
}
if (tempPosition > 10){ //Trailing Fade
self.alpha = min(1, max(0, 1 - (tempPosition - CGFloat(kMaxY)) * 0.5))
}

}

func setIsDiplayedButton(isDisplayedButton: Bool)
{
if (isDisplayedButton == self.isDisplayed){
return
}
if (isDisplayedButton){
self.image = UIImage(named:"GuitarPin_Green.png")
}
else{
self.image = UIImage(named:"GuitarPin_Red.png")
}
self.isDisplayed = isDisplayedButton

}
*/


func offsetYPosition(offset: CGFloat){
setYPosition(yPosition: _yPosition + offset)
}




}
@@ -0,0 +1,29 @@
//
// PictureCollectionViewCell.swift
// OneNightBand
//
// Created by Thomas Threlkeld on 12/6/16.
// Copyright © 2016 Thomas Threlkeld. All rights reserved.
//
import UIKit
import YouTubePlayer

class PictureCollectionViewCell: UICollectionViewCell, UIImagePickerControllerDelegate {

@IBOutlet weak var picImageView: UIImageView!


override func awakeFromNib() {
super.awakeFromNib()
//imagePicker.delegate = self
}







}

Large diffs are not rendered by default.

@@ -7,3 +7,18 @@
//
import Foundation

class Session: NSObject{
var sessionArtists = [String: Any]()
var sessionBio: String?
var sessionName: String?
var sessionPictureURL: String?
var sessionUID: String?
var sessionDate: String?
var messages = [String: Any]()
var sessionMedia = [String]()




}
@@ -8,18 +8,27 @@
import UIKit

class SessionViewerCollectionCellCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var sessionCellButton: UIButton?

/*protocol LoadProperSessionProtocol {
func loadThisSession(indexPath: IndexPath)
}*/

class SessionCell: UICollectionViewCell {
//var delegate: LoadProperSessionProtocol!

@IBOutlet weak var sessionCellLabel: UILabel?
@IBOutlet weak var sessionCellLabel: UILabel!
@IBOutlet weak var sessionCellImageView: UIImageView!
var sessionId: String?

override func awakeFromNib() {
self.backgroundColor = UIColor.clear
self.sessionCellLabel?.textColor = UIColor.white
//self.backgroundColor = UIColor.clear
//self.sessionCellLabel?.textColor = UIColor.white
//self.layer.cornerRadius = 4
}
@IBAction func sessionCellButtonTouched(_ sender: AnyObject) {

}

@IBAction func cellTouched(_ sender: AnyObject) {


}
}
@@ -7,14 +7,321 @@
//
import UIKit
import Firebase

class SessionFeedViewController: UIViewController {




protocol FeedDismissalDelegate : class
{
func finishedShowing(viewController: UIViewController);

}

protocol FeedDismissable : class
{
weak var feedDismissalDelegate : FeedDismissalDelegate? { get set }
}

extension FeedDismissalDelegate where Self: UIViewController
{
func finishedShowing(viewController: UIViewController) {
if viewController.isBeingPresented && viewController.presentingViewController == self
{
self.dismiss(animated: true, completion: nil)
return
}

//self.navigationController?.popViewController(animated: true)
}
}




class SessionFeedViewController: UIViewController, UIGestureRecognizerDelegate,UINavigationControllerDelegate, FeedDismissalDelegate {

@IBOutlet weak var sessionImageView: UIImageView!
@IBOutlet weak var sessionViewCountLabel: UILabel!
@IBOutlet weak var sessionNameLabel: UILabel!
@IBOutlet weak var sessionInfoView: UIView!
@IBOutlet weak var backgroundGuitarImage: UIImageView!


var sessionArray = [Session]()
var ref = FIRDatabase.database().reference()
var firstTouch = CGPoint()
var viewPins: NSMutableArray!
var scrollOffset = CGFloat()
var currentButton: ONBGuitarButton?
var player:Player?


@IBOutlet weak var playerContainerView: PlayerView!


//var ref = FIRDatabase.database().reference()
var currentVideoURL: URL?
let kFretY = 383

override func viewDidAppear(_ animated: Bool) {
//self.player = storyboard.view
self.player = Player()

//self.currentButton = currentButtonFunc()

self.player?.view.frame = self.sessionImageView.frame
//self.playerContainerView.viewController()?.addChildViewController(player!)
//self.playerContainerView.viewController().
//self.player?.delegate = self
switch UIScreen.main.bounds.width{
case 320:
self.player?.view.frame = CGRect(x: 35,y:50,width:250,height:130)

case 375:
self.player?.view.frame = CGRect(x: 40,y:85,width:300,height:200)


case 414:
self.player?.view.frame = CGRect(x: 33,y:100,width:350,height:250)

default:
self.player?.view.frame = CGRect(x: 60,y:140,width:350,height:250)



}




self.sessionInfoView.autoresizesSubviews = true

self.addChildViewController(self.player!)
sessionInfoView.addSubview((self.player?.view)!)
// self.sessionInfoView.addSubview((controller?.view)!)
}
func addNewSession(){
performSegue(withIdentifier: "FeedToUpload", sender: self)
}
func backToNav(){
performSegue(withIdentifier: "BackToMainNav", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()

let backButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(SessionFeedViewController.backToNav))
navigationItem.leftBarButtonItem = backButton
let uploadButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(SessionFeedViewController.addNewSession))
navigationItem.rightBarButtonItem = uploadButton



self.ref.child("sessionFeed").observeSingleEvent(of: .value, with: {(snapshot) in
if snapshot.childrenCount != 0{
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{

for snap in snapshots{
let tempSess = Session()
let dictionary = snap.value as? [String: AnyObject]
tempSess.setValuesForKeys(dictionary!)
self.sessionArray.append(tempSess)

}
}
self.view.clipsToBounds = true
self.scrollOffset = 0

self.viewPins = NSMutableArray()
//for i in -27..<7{
for i in 0..<self.sessionArray.count{
let button = ONBGuitarButton()
button.initWithLane(lane: Int(arc4random_uniform(6)))
button.setYPosition(yPosition: (3 - CGFloat(i)) * 2.3)
//button.image = UIImage(named:"GuitarPin_Red.png")


self.view.addSubview(button)
self.viewPins.add(button)

let tap = UITapGestureRecognizer(target: self, action: #selector(self.scrollToPin))

tap.numberOfTapsRequired = 1
button.addGestureRecognizer(tap)
button.isUserInteractionEnabled = true


button.session = self.sessionArray[i]
}

for button in self.viewPins{
print((button as! ONBGuitarButton)._baseX)
print((button as! ONBGuitarButton).lane)
}
//self.currentButton = self.currentButtonFunc()
//self.displaySessionInfo()
}

})




// Do any additional setup after loading the view.
}



func prepareForSegue(segue: UIStoryboardSegue, sender _: AnyObject?) {
if let vc = segue.destination as? FeedDismissable
{
vc.feedDismissalDelegate = self
}
}


func scrollToPin(sender: UITapGestureRecognizer){
let button = sender.view //as! ONBGuitarButton
let scrollDistance = 13 - sqrt((button?.center.y)! - 200)

UIView.animate(withDuration: 0.5, animations:{self.viewPins.forEach { button in
(button as! ONBGuitarButton).offsetYPosition(offset: scrollDistance)
self.scrollOffset += scrollDistance
}

}, completion: {
(value: Bool) in
self.displaySessionInfo()
})
}
//func goToSession()
func displaySessionInfo(){

let cButton = currentButton


var tempLabel = (cButton?.session?.sessionName)!
sessionNameLabel.text = "Session Name: \(tempLabel)"

sessionViewCountLabel.text = "Views: 346"//String(describing: currentButtonSess.sessionViews) need to add views to Session in database
//sessionImageView.loadImageUsingCacheWithUrlString((cButton.session?.sessionPictureURL)!)
self.ref.child("sessions").child((cButton?.session?.sessionUID)!).child("sessionMedia").observeSingleEvent(of: .value, with: {(snapshot) in

//self.currentVideoURL = (snapshot.value as! URL)


//let storageRef = FIRStorage.storage().reference().child("session_videos").child(self.currentVideoURL!)
let url = NSURL(string: (snapshot.value as! [String]).first!)

//let videoUrl = self.currentVideoURL
self.player?.setUrl(url as! URL)
self.player?.fillMode = "AVLayerVideoGravityResizeAspectFill"
//self.player?.playerView = self.playerContainerView
if (cButton?.center.y)! >= self.sessionInfoView.bounds.maxY{
self.player?.playFromBeginning()
}else{
self.player?.stop()
//cButton.setIsDiplayedButton(isDisplayedButton: false)
}

})


}

func currentButtonFunc()->ONBGuitarButton{
var closest = self.viewPins[0]
for i in viewPins{
if(fabs((i as! ONBGuitarButton).center.y - CGFloat(kFretY)) < (fabs((closest as! ONBGuitarButton).center.y - CGFloat(kFretY)))){
closest = i

}
}
if (currentButton != nil) && currentButton != closest as? ONBGuitarButton{
currentButton?.setIsDiplayedButton(isDisplayedButton: false)
}

if(closest as! ONBGuitarButton).center.y >= self.sessionInfoView.bounds.maxY{
(closest as! ONBGuitarButton).setIsDiplayedButton(isDisplayedButton: true)
}else{
(closest as! ONBGuitarButton).setIsDiplayedButton(isDisplayedButton: false)
}
/*if (closest as! ONBGuitarButton).center.y >= self.sessionInfoView.bounds.maxY{
(closest as! ONBGuitarButton).setIsDiplayedButton(isDisplayedButton: true)
}else{
(closest as! ONBGuitarButton).setIsDiplayedButton(isDisplayedButton: false)
}*/

//self.currentButton?.setIsDiplayedButton(isDisplayedButton: false) tempButton.setIsDiplayedButton(isDisplayedButton: true)
//tempButton.setIsDiplayedButton(isDisplayedButton: false)
/*if (tempButton.center.y >= self.sessionInfoView.bounds.maxY){
tempButton.setIsDiplayedButton(isDisplayedButton: true)
}else{
tempButton.setIsDiplayedButton(isDisplayedButton: false)
}*/

self.currentButton = (closest as! ONBGuitarButton)
return (closest as! ONBGuitarButton)
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

let t = touches.first
//print(t)
firstTouch = (t?.location(in: self.view))!
//print(firstTouch)
firstTouch.y /= 15
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

let t = touches.first
var nextTouch = t?.location(in: self.view)
nextTouch?.y /= 15
if sessionArray.count != 0{
for i in viewPins{
(i as! ONBGuitarButton).offsetYPosition(offset: (nextTouch?.y)! - firstTouch.y)
scrollOffset += (nextTouch?.y)! - firstTouch.y



}






firstTouch = nextTouch!
if currentButtonFunc().isDisplayed == true{
displaySessionInfo()
}
/*if ((currentButton?.center.y)! >= self.sessionInfoView.bounds.maxY){
currentButton?.setIsDiplayedButton(isDisplayedButton: true)
}else{
currentButton?.setIsDiplayedButton(isDisplayedButton: false)
}*/
// if(currentButtonFunc().center.y >= self.sessionInfoView.bounds.maxY){
//currentButtonFunc().setIsDiplayedButton(isDisplayedButton: true)
//displaySessionInfo()
// }
//displaySessionInfo()
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
@@ -7,3 +7,138 @@
//
import Foundation
import Firebase
import UIKit

class SessionInvitesViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
var invitePageViewController: UIPageViewController!
var inviteArray = [Invite]()
var snapKey = [String: Any]()


let emptyLabel: UILabel = {
var tempLabel = UILabel()
tempLabel.text = "You have 0 pending invites"
tempLabel.textColor = UIColor.black
tempLabel.font = UIFont.systemFont(ofSize: 24.0, weight: UIFontWeightLight)
tempLabel.translatesAutoresizingMaskIntoConstraints = false
return tempLabel

}()
func setupEmptyLabel(){
emptyLabel.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
emptyLabel.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
}




var ref = FIRDatabase.database().reference()

override func viewDidLoad() {
super.viewDidLoad()



self.view.addSubview(emptyLabel)
setupEmptyLabel()
emptyLabel.isHidden = true


let currentUser = FIRAuth.auth()?.currentUser?.uid

FIRDatabase.database().reference().child("users").child(currentUser!).child("invites").observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.childrenCount != 0{
self.emptyLabel.isHidden = true
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
//var index = 0
for snap in snapshots{

if let dictionary = snap.value as? [String: Any] {

//self.snapKey = dictionary
let invite = Invite()
invite.setValuesForKeys(dictionary)
self.inviteArray.append(invite)
//print(dictionary)
}
}
}
self.invitePageViewController = self.storyboard?.instantiateViewController(withIdentifier: "UITutorialPageViewController") as! UIPageViewController
self.invitePageViewController.dataSource = self
self.invitePageViewController.delegate = self


let initialContentViewController = self.pageTutorialAtIndex(0) as InviteViewData
var viewControllers = [InviteViewData]()
viewControllers = [initialContentViewController]


self.invitePageViewController.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
//making pageView only take up top half of screen
self.invitePageViewController.view.frame.size.height = self.view.frame.size.height
//adding subview
self.addChildViewController(self.invitePageViewController)
self.view.addSubview(self.invitePageViewController.view)
self.invitePageViewController.didMove(toParentViewController: self)
self.invitePageViewController.gestureRecognizers.first?.cancelsTouchesInView = false
}else{
self.emptyLabel.isHidden = false
}

})

}

//PageController Functions
func pageTutorialAtIndex(_ index: Int) ->InviteViewData{
let pageContentViewController = self.storyboard?.instantiateViewController(withIdentifier: "InviteViewData") as! InviteViewData
if(presentationCount(for: self.invitePageViewController) != 0){
pageContentViewController.pageIndex = index
pageContentViewController.inviteSenderText = self.inviteArray[index].sender
pageContentViewController.sessionNameText = self.inviteArray[index].sessionID
pageContentViewController.instrumentNeededText = self.inviteArray[index].instrumentNeeded
pageContentViewController.dateText = self.inviteArray[index].sessionDate
}

return pageContentViewController
}

open func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?{
let viewController = viewController as! InviteViewData
var index = viewController.pageIndex! as Int
if(index == 0 || index == NSNotFound){
return nil
}
index -= 1
return self.pageTutorialAtIndex(index)
}

open func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?{
let viewController = viewController as! InviteViewData
var index = viewController.pageIndex! as Int

if(index == (inviteArray.endIndex) - 1 || index == NSNotFound){
return nil
}
index += 1
if(index == inviteArray.count){
return nil
}
return self.pageTutorialAtIndex(index)
}

open func presentationCount(for pageViewController: UIPageViewController) -> Int{

return inviteArray.count //inviteArray.count
}

open func presentationIndex(for pageViewController: UIPageViewController) -> Int{
return 0
}


}