diff --git a/project/Streamline.xcodeproj/project.pbxproj b/project/Streamline.xcodeproj/project.pbxproj index a91d256..05ca2e0d 100644 --- a/project/Streamline.xcodeproj/project.pbxproj +++ b/project/Streamline.xcodeproj/project.pbxproj @@ -36,8 +36,14 @@ 2DDF1E251F99AA100089489C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2DDF1E241F99AA100089489C /* Images.xcassets */; }; 2DDF1E271F99AB850089489C /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DDF1E261F99AB850089489C /* Constants.swift */; }; 554A7D6E1FBC21BE00A58FA7 /* UsernameInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */; }; + 556D50431FCE24EF00398567 /* GroupSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 556D50421FCE24EF00398567 /* GroupSelectorView.swift */; }; 557A82901F95A86900A189AB /* SpotifyWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = 557A828F1F95A86900A189AB /* SpotifyWeb.swift */; }; 55B0519A1F9950A5007B282E /* SpotifyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55B051991F9950A5007B282E /* SpotifyAPI.swift */; }; + 55C10CD21FCE581A006C0AAC /* AddGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55C10CD11FCE581A006C0AAC /* AddGroupView.swift */; }; + 55ED71901FCD253B0005D9CC /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55ED718F1FCD253B0005D9CC /* MenuView.swift */; }; + 55ED71941FCD56860005D9CC /* GroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55ED71931FCD56860005D9CC /* GroupView.swift */; }; + 55ED71971FCD58810005D9CC /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55ED71961FCD58810005D9CC /* SettingView.swift */; }; + 55ED71991FCD63840005D9CC /* Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55ED71981FCD63840005D9CC /* Group.swift */; }; 9E0506D595C11CEBF4B7AF0B /* Pods_StreamlineTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB284140F1C8E9C54DFC8762 /* Pods_StreamlineTests.framework */; }; B269B4E280C9962B2F8D6148 /* Pods_StreamlineUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BBAE761855C48CADA2FEEBE /* Pods_StreamlineUITests.framework */; }; D14C0E7D1FAE6C36000818C5 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14C0E7C1FAE6C36000818C5 /* Utils.swift */; }; @@ -101,8 +107,14 @@ 2DDF1E241F99AA100089489C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 2DDF1E261F99AB850089489C /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UsernameInputView.swift; sourceTree = ""; }; + 556D50421FCE24EF00398567 /* GroupSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupSelectorView.swift; sourceTree = ""; }; 557A828F1F95A86900A189AB /* SpotifyWeb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotifyWeb.swift; sourceTree = ""; }; 55B051991F9950A5007B282E /* SpotifyAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotifyAPI.swift; sourceTree = ""; }; + 55C10CD11FCE581A006C0AAC /* AddGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddGroupView.swift; sourceTree = ""; }; + 55ED718F1FCD253B0005D9CC /* MenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = ""; }; + 55ED71931FCD56860005D9CC /* GroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupView.swift; sourceTree = ""; }; + 55ED71961FCD58810005D9CC /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = ""; }; + 55ED71981FCD63840005D9CC /* Group.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Group.swift; sourceTree = ""; }; 617D6BC49E2D68BD311C03E2 /* Pods_Streamline.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Streamline.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6FC9F10E8984FB6D86F6A1B2 /* Pods-StreamlineTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StreamlineTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-StreamlineTests/Pods-StreamlineTests.debug.xcconfig"; sourceTree = ""; }; AB284140F1C8E9C54DFC8762 /* Pods_StreamlineTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_StreamlineTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -149,6 +161,7 @@ 2D6B7DD01F92AB9F009DA338 /* Model */ = { isa = PBXGroup; children = ( + 55ED71981FCD63840005D9CC /* Group.swift */, 2D6B7DD61F92AE31009DA338 /* User.swift */, 2D6B7DD81F92AE71009DA338 /* Post.swift */, ); @@ -158,11 +171,13 @@ 2D6B7DD11F92ABAA009DA338 /* View */ = { isa = PBXGroup; children = ( + 55ED71951FCD57450005D9CC /* MenuViews */, 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */, 2D125EB21FA12FB80031A21A /* LoginView.swift */, 2D8314D61FA70862002F6C78 /* FeedView.swift */, - 2D05B9DC1FA55C8100F26A79 /* AKModalView.swift */, + 556D50421FCE24EF00398567 /* GroupSelectorView.swift */, 2D3F9A5B1F92E52300A09DCB /* PostCollectionViewCell.swift */, + 2D05B9DC1FA55C8100F26A79 /* AKModalView.swift */, 2D6780171FA501E700F30971 /* NowPlayingView.swift */, 2D763B131FA29D6600546166 /* ResultTableViewCell.swift */, 2D05B9DE1FA55D0900F26A79 /* SearchView.swift */, @@ -269,6 +284,17 @@ name = Frameworks; sourceTree = ""; }; + 55ED71951FCD57450005D9CC /* MenuViews */ = { + isa = PBXGroup; + children = ( + 55C10CD11FCE581A006C0AAC /* AddGroupView.swift */, + 55ED718F1FCD253B0005D9CC /* MenuView.swift */, + 55ED71961FCD58810005D9CC /* SettingView.swift */, + 55ED71931FCD56860005D9CC /* GroupView.swift */, + ); + path = MenuViews; + sourceTree = ""; + }; 93CEEF074DABE9DF0E996085 /* Pods */ = { isa = PBXGroup; children = ( @@ -598,14 +624,18 @@ files = ( 2D6B7DD71F92AE31009DA338 /* User.swift in Sources */, 2D552A601FA54B0500C2093C /* State.swift in Sources */, + 556D50431FCE24EF00398567 /* GroupSelectorView.swift in Sources */, 2DA03D1C1F92A8E900F88C13 /* AppDelegate.swift in Sources */, 2D125EB31FA12FB80031A21A /* LoginView.swift in Sources */, 2D29EE891F98690B0053FDF0 /* UIColorHexExtension.swift in Sources */, + 55C10CD21FCE581A006C0AAC /* AddGroupView.swift in Sources */, 557A82901F95A86900A189AB /* SpotifyWeb.swift in Sources */, 2D9017C21F92CCAA00A8C038 /* BridgeViewController.m in Sources */, + 55ED71991FCD63840005D9CC /* Group.swift in Sources */, 2D6B7DD51F92ABCE009DA338 /* DB.swift in Sources */, 2D05B9DD1FA55C8100F26A79 /* AKModalView.swift in Sources */, 55B0519A1F9950A5007B282E /* SpotifyAPI.swift in Sources */, + 55ED71901FCD253B0005D9CC /* MenuView.swift in Sources */, 2D9074A91FBB9E7600A71A5C /* UsernameInputViewController.swift in Sources */, 2D05B9DF1FA55D0900F26A79 /* SearchView.swift in Sources */, 2D8314D71FA70862002F6C78 /* FeedView.swift in Sources */, @@ -615,6 +645,8 @@ 2D3F9A571F92E2D100A09DCB /* FeedViewController.swift in Sources */, 2D6B7DD91F92AE71009DA338 /* Post.swift in Sources */, 2D6780161FA5014F00F30971 /* NowPlayingViewController.swift in Sources */, + 55ED71941FCD56860005D9CC /* GroupView.swift in Sources */, + 55ED71971FCD58810005D9CC /* SettingView.swift in Sources */, 2D6780181FA501E700F30971 /* NowPlayingView.swift in Sources */, 2DDF1E271F99AB850089489C /* Constants.swift in Sources */, 2D3F9A5C1F92E52300A09DCB /* PostCollectionViewCell.swift in Sources */, diff --git a/project/Streamline.xcworkspace/xcuserdata/vineethyeevani.xcuserdatad/UserInterfaceState.xcuserstate b/project/Streamline.xcworkspace/xcuserdata/vineethyeevani.xcuserdatad/UserInterfaceState.xcuserstate index 452c005..c98ed8e 100644 Binary files a/project/Streamline.xcworkspace/xcuserdata/vineethyeevani.xcuserdatad/UserInterfaceState.xcuserstate and b/project/Streamline.xcworkspace/xcuserdata/vineethyeevani.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/project/Streamline/Controller/FeedViewController.swift b/project/Streamline/Controller/FeedViewController.swift index c6862b7..ad9df4a 100644 --- a/project/Streamline/Controller/FeedViewController.swift +++ b/project/Streamline/Controller/FeedViewController.swift @@ -18,9 +18,14 @@ class FeedViewController: UIViewController { var blur: UIVisualEffectView! var commandCenter: MPRemoteCommandCenter! - // Search View - var searchView: SearchView! - var modalView : AKModalView! + // Search View and Menu View + var menuView : MenuView! + var searchView : SearchView! + var settingView : SettingView! + var groupSettingsView : GroupSettingsView! + var addGroupView: AddGroupView! + var groupSelectorView : GroupSelectorView! + var modalView : AKModalView! // Feed View for UI elements var subView: FeedView! @@ -71,11 +76,11 @@ class FeedViewController: UIViewController { // Setups the spotify player setupSpotify() - let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) - blur = UIVisualEffectView(effect: blurEffect) - blur.frame = view.bounds - blur.autoresizingMask = [.flexibleWidth, .flexibleHeight] - blur.alpha = 0 + let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) + blur = UIVisualEffectView(effect: blurEffect) + blur.frame = view.bounds + blur.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blur.alpha = 0 view.addSubview(blur) } @@ -100,9 +105,8 @@ class FeedViewController: UIViewController { } } - // Creates the modal search view - func createSearchView(){ - modalView = AKModalView(view: searchView) + func createModalView(uiView: UIView) { + modalView = AKModalView(view: uiView) modalView.automaticallyCenter = false view.addSubview(modalView) modalView.show() @@ -258,20 +262,27 @@ extension FeedViewController: NowPlayingProtocol, FeedViewDelegate { searchView.searchSpotify() searchView.searchBar.text = "" searchView.delegate = self - print("postbuttonpressed") /* Code to limit user to one song a day and delete user pid if it has been 24 hours */ if let timePosted = DB.currentUser.timePosted { if (Date().timeIntervalSince1970 - timePosted > 86400 || DB.currentUser.uid == "1261764229") { - self.createSearchView() + //self.createSearchView() + self.createModalView(uiView: searchView) } else { let alert = Utils.createAlert(warningMessage: "Sorry! You can only post one song a day. Try post again later") self.present(alert, animated: true, completion: nil) } } else { - self.createSearchView() + //self.createSearchView() + self.createModalView(uiView: searchView) } } + func groupsSelectorButtonPressed() { + groupSelectorView = GroupSelectorView(frame: Utils.rRect(rx: 40, ry: 120, rw: 295, rh: 289), large: true) + groupSelectorView.delegate = self + createModalView(uiView: groupSelectorView) + } + // Handles player button pressed func nowPlayingButtonPressed() { if let index = State.nowPlayingIndex { @@ -286,6 +297,15 @@ extension FeedViewController: NowPlayingProtocol, FeedViewDelegate { } //Handles logout + func menuButtonPressed() { + menuView = MenuView(frame: Utils.rRect(rx: 40, ry: 120, rw: 295, rh: 289), large: true) + menuView.delegate = self + //createMenuView() + createModalView(uiView: menuView) + } +} + +extension FeedViewController: MenuViewDelegate { func logoutButtonPressed() { let userDefaults = UserDefaults.standard userDefaults.removeObject(forKey: "SpotifySession") @@ -293,4 +313,45 @@ extension FeedViewController: NowPlayingProtocol, FeedViewDelegate { SpotifyAPI.player.logout() self.view.window!.rootViewController?.dismiss(animated: true, completion: nil) } + + func settingButtonPressed() { + settingView = SettingView(frame: Utils.rRect(rx: 40, ry: 120, rw: 295, rh: 289), large: true) + settingView.delegate = self + createModalView(uiView: settingView) + } + + func groupButtonPressed() { + groupSettingsView = GroupSettingsView(frame: Utils.rRect(rx: 40, ry: 120, rw: 295, rh: 289), large: true) + groupSettingsView.delegate = self + createModalView(uiView: groupSettingsView) + } +} + +extension FeedViewController: SettingViewDelegate { + func setNameButtonPressed() { + DB.currentUser.username = settingView.usernameTextField.text + DB.updateUsername(user: DB.currentUser) + modalView.dismiss() + } +} + +extension FeedViewController: GroupSettingsViewDelegate { + func createButtonPressed() { + addGroupView = AddGroupView(frame: Utils.rRect(rx: 40, ry: 120, rw: 295, rh: 289), large: true) + addGroupView.delegate = self + createModalView(uiView: addGroupView) + //DB.createGroup() + } +} + +extension FeedViewController: AddGroupViewDelegate { + func addGroupButtonPressed() { + if addGroupView.groupNameTextField.text != nil || addGroupView.groupNameTextField.text != "" { + DB.createGroup(groupName: self.addGroupView.groupNameTextField.text!) + } + } +} + +extension FeedViewController: GroupSelectorViewDelegate { + } diff --git a/project/Streamline/Model/Group.swift b/project/Streamline/Model/Group.swift new file mode 100644 index 0000000..dbaf5a0 --- /dev/null +++ b/project/Streamline/Model/Group.swift @@ -0,0 +1,47 @@ +// +// Group.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/28/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation +import Firebase + +class Group { + var uids: [String] = [] + var pids: [String] = [] + var posts: [Post] = [] + var name: String! + var gid: String! + + init(name: String, uids: [String], pids: [String]) { + self.name = name + self.uids = uids + self.pids = pids + } + + convenience init(gid: String) { + self.init(name: "", uids: [], pids: []) + getGroup(gid: gid) { (name, uids, pids) in + self.name = name + self.uids = uids + self.pids = pids + } + } + + func getGroup(gid: String, withBlock: @escaping (String, [String], [String]) -> ()){ + self.gid = gid + let ref = Database.database().reference().child("groups").child(gid) + ref.observeSingleEvent(of: .value, with: { (snapshot) in + let value = snapshot.value as? NSDictionary + if let value = value { + let groupName = value["name"] as! String + let uids = value["uids"] as! [String] + let pids = value["pids"] as! [String] + withBlock(groupName, uids, pids) + } + }) + } +} diff --git a/project/Streamline/Model/User.swift b/project/Streamline/Model/User.swift index 983e716..b11cf43 100644 --- a/project/Streamline/Model/User.swift +++ b/project/Streamline/Model/User.swift @@ -7,12 +7,15 @@ // import Haneke +import Firebase class User { var pid : String! var uid : String! var username : String! var imageUrl : String! + var gids : [String] = [] + var groups : [Group] = [] var timePosted : TimeInterval? init(uid: String, diff --git a/project/Streamline/Utils/DB.swift b/project/Streamline/Utils/DB.swift index b55dbf8..bd24000 100644 --- a/project/Streamline/Utils/DB.swift +++ b/project/Streamline/Utils/DB.swift @@ -97,6 +97,19 @@ struct DB { }) } + //Get the posts in a group + static func getGroupPosts(group: Group) { + //Refreshes posts on local storage + getPosts(withBlock: { + //Checks if each post is contained within the group id for the specific group + for post in DB.posts { + if group.pids.contains(post.pid) { + group.posts.append(post) + } + } + }) + } + // Creates a post in the database static func createPost(post: Post, user: User) { var ref = Database.database().reference().child("posts") @@ -121,19 +134,56 @@ struct DB { ref.child("timePosted").setValue(timePosted) } - // Gets a single post with the user id -// static func getSinglePost(pid: String, withBlock: @escaping (Post) -> ()) { -// var ref = Database.database().reference().child("posts").child(pid) -// ref.observeSingleEvent(of: .value) { (snapshot, error) in -// let post = Post(pid: pid, postDict: snapshot.value as! [String : Any]) -// withBlock(post) -// } -// } - // Sorts the posts by time stamp static func sortPosts() { DB.posts.sort(by: {(p1, p2) -> Bool in return p1.timePosted >= p2.timePosted }) } + + static func getGIDS(withBlock: @escaping () -> ()) { + let ref = Database.database().reference().child("users").child(DB.currentUser.uid).child("gids") + ref.observeSingleEvent(of: .value, with: { (snapshot) in + let value = snapshot.value as? [String] + if let value = value { + DB.currentUser.gids = value + } + }) + } + + static func getGroups(withBlock: @escaping () -> ()) { + getGIDS(withBlock: { + for gid in DB.currentUser.gids { + DB.currentUser.groups.append(Group(gid: gid)) + withBlock() + } + }) + } + + static func updateGroupsPosts(withBlock: @escaping () -> ()){ + getGroups(withBlock: { + for group in DB.currentUser.groups { + getGroupPosts(group: group) + } + withBlock() + }) + } + + static func createGroup(groupName: String){ + //Create the group and set the values to the random key + var ref = Database.database().reference().child("groups") + let key = ref.childByAutoId().key + ref = ref.child(key) + var dict: [String: Any] = ["name": groupName, "uid": [DB.currentUser.uid], "pids": [DB.currentUser.pid]] + ref.setValue(dict) + + //Take the current list of group ids and append the new group id to it + getGIDS(withBlock: { + ref = Database.database().reference().child("users").child(DB.currentUser.uid).child("gids") + DB.currentUser.gids.append(key) + ref.setValue(DB.currentUser.gids) + }) + + + } } diff --git a/project/Streamline/View/AKModalView.swift b/project/Streamline/View/AKModalView.swift index b164d55..456aa18 100644 --- a/project/Streamline/View/AKModalView.swift +++ b/project/Streamline/View/AKModalView.swift @@ -5,7 +5,6 @@ // Created by Vineeth Yeevani on 10/28/17. // Copyright © 2017 Stephen Jayakar. All rights reserved. // - // // AKModalView.swift // AKModalView @@ -13,7 +12,6 @@ // Created by Akkshay Khoslaa on 7/20/16. // Copyright © 2016 Akkshay Khoslaa. All rights reserved. // - import UIKit import Spring diff --git a/project/Streamline/View/FeedView.swift b/project/Streamline/View/FeedView.swift index 42ad569..bd856c4 100644 --- a/project/Streamline/View/FeedView.swift +++ b/project/Streamline/View/FeedView.swift @@ -12,7 +12,8 @@ class FeedView: UIView { var postCollectionView : UICollectionView! var postButton : UIButton! var postButtonArea : UIButton! - var logoutButton : UIButton! + var menuButton : UIButton! + var groupButton : UIButton! var discoverLabel : UILabel! var nowPlayingButton : UIButton! var nowPlayingLabel : UILabel! @@ -90,15 +91,22 @@ class FeedView: UIView { postButtonArea.addTarget(self, action: #selector(postButtonPressed), for: .touchUpInside) addSubview(postButtonArea) - logoutButton = UIButton(frame: Utils.rRect(rx: 15, ry: 30, rw: 74, rh: 22)) - logoutButton.setTitle("Log Out", for: .normal) - logoutButton.setTitleColor(UIColor(hex: "737171"), for: .normal) - logoutButton.addTarget(self, action: #selector(logoutButtonPressed), for: .touchUpInside) - logoutButton.titleLabel?.adjustsFontSizeToFitWidth = true - addSubview(logoutButton) + menuButton = UIButton(frame: Utils.rRect(rx: 15, ry: 30, rw: 74, rh: 22)) + menuButton.setTitle("Menu", for: .normal) + menuButton.setTitleColor(UIColor(hex: "737171"), for: .normal) + menuButton.addTarget(self, action: #selector(menuButtonPressed), for: .touchUpInside) + menuButton.titleLabel?.adjustsFontSizeToFitWidth = true + addSubview(menuButton) } func setupLabel() { + groupButton = UIButton(frame: Utils.rRect(rx: 375*0.35, ry: 20, rw: 375*0.3, rh: 44)) + groupButton.setTitle("GROUPS", for: .normal) + groupButton.setTitleColor(UIColor(hex: "737171"), for: .normal) + groupButton.addTarget(self, action: #selector(groupsSelectorButtonPressed), for: .touchUpInside) + groupButton.titleLabel?.adjustsFontSizeToFitWidth = true + addSubview(groupButton) + discoverLabel = UILabel(frame: Utils.rRect(rx: 0, ry: 20, rw: 375, rh: 44)) discoverLabel.textColor = UIColor(hex: "311b92") @@ -109,7 +117,7 @@ class FeedView: UIView { discoverLabel.font = UIFont.systemFont(ofSize: ((frame.width / 375) * 26)) - addSubview(discoverLabel) + //addSubview(discoverLabel) } required init?(coder aDecoder: NSCoder) { @@ -125,13 +133,18 @@ class FeedView: UIView { self.delegate?.nowPlayingButtonPressed() } - func logoutButtonPressed() { - self.delegate?.logoutButtonPressed() + func menuButtonPressed() { + self.delegate?.menuButtonPressed() + } + + func groupsSelectorButtonPressed() { + self.delegate?.groupsSelectorButtonPressed() } } protocol FeedViewDelegate { func postButtonPressed() func nowPlayingButtonPressed() - func logoutButtonPressed() + func menuButtonPressed() + func groupsSelectorButtonPressed() } diff --git a/project/Streamline/View/GroupSelectorView.swift b/project/Streamline/View/GroupSelectorView.swift new file mode 100644 index 0000000..9a4a136 --- /dev/null +++ b/project/Streamline/View/GroupSelectorView.swift @@ -0,0 +1,50 @@ +// +// GroupSelectorView.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/28/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation + +protocol GroupSelectorViewDelegate { + +} + +class GroupSelectorView:UIView { + var delegate: GroupSelectorViewDelegate? = nil + var view: UIView! + + var returnButton : UIButton! + var groupsPicker : UIPickerView! + + init(frame: CGRect, large: Bool) { + print(DB.currentUser.imageUrl) + + super.init(frame: frame) + + layer.cornerRadius = 5 + clipsToBounds = true + view = UIView(frame: CGRect(x:0, y:0, width: frame.width, height: frame.height)) + view.layer.cornerRadius = 4 + view.backgroundColor = .white + setupButtons() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func setupButtons() { + + } + + func setupPicker() { + + groupsPicker = UIPickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height * 0.7)) + //groupsPicker.dataSource = DB.currentUser.groups + } + + +} diff --git a/project/Streamline/View/MenuViews/AddGroupView.swift b/project/Streamline/View/MenuViews/AddGroupView.swift new file mode 100644 index 0000000..663928c --- /dev/null +++ b/project/Streamline/View/MenuViews/AddGroupView.swift @@ -0,0 +1,66 @@ +// +// AddGroupView.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/28/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation + +protocol AddGroupViewDelegate { + func addGroupButtonPressed() +} + +class AddGroupView:UIView { + var delegate: AddGroupViewDelegate? = nil + var view: UIView! + + var groupNameTextField: UITextField! + var addButton: UIButton! + + init(frame: CGRect, large: Bool) { + print(DB.currentUser.imageUrl) + + super.init(frame: frame) + + layer.cornerRadius = 5 + clipsToBounds = true + view = UIView(frame: CGRect(x:0, y:0, width: frame.width, height: frame.height)) + view.layer.cornerRadius = 4 + view.backgroundColor = .white + + addSubview(view) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //Setup methods + func setupButtons() { + addButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.8, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + addButton.layer.cornerRadius = 15 + addButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + addButton.layer.borderWidth = 2 + + addButton.backgroundColor = UIColor.white + addButton.setTitleColor(Constants.darkPurple, for: .normal) + addButton.setTitle("Add Group", for: .normal) + addButton.addTarget(self, action: #selector(addButtonPressed), for: .touchUpInside) + } + + func setupEditText() { + groupNameTextField = UITextField(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.47, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + groupNameTextField.layer.cornerRadius = 15 + groupNameTextField.backgroundColor = UIColor.white + groupNameTextField.textColor = Constants.darkPurple + groupNameTextField.placeholder = "Enter Group Name: " + DB.currentUser.username + view.addSubview(groupNameTextField) + } + + func addButtonPressed() { + delegate?.addGroupButtonPressed() + } +} + diff --git a/project/Streamline/View/MenuViews/GroupView.swift b/project/Streamline/View/MenuViews/GroupView.swift new file mode 100644 index 0000000..c2bf491 --- /dev/null +++ b/project/Streamline/View/MenuViews/GroupView.swift @@ -0,0 +1,73 @@ +// +// GroupView.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/28/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation + +import Foundation +protocol GroupSettingsViewDelegate { + func createButtonPressed() +} + +class GroupSettingsView:UIView { + var delegate: GroupSettingsViewDelegate? = nil + var view: UIView! + + var addButton : UIButton! + var createButton: UIButton! + + init(frame: CGRect, large: Bool) { + print(DB.currentUser.imageUrl) + + super.init(frame: frame) + + layer.cornerRadius = 5 + clipsToBounds = true + view = UIView(frame: CGRect(x:0, y:0, width: frame.width, height: frame.height)) + view.layer.cornerRadius = 4 + view.backgroundColor = .white + + addSubview(view) + setupGroupsButton() + } + + func setupGroupsButton() { + addButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.1, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + addButton.layer.cornerRadius = 15 + addButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + addButton.layer.borderWidth = 2 + addButton.backgroundColor = UIColor.white + addButton.setTitleColor(Constants.darkPurple, for: .normal) + addButton.setTitle("ADD GROUP", for: .normal) + addButton.addTarget(self, action: #selector(addButtonPressed), for: .touchUpInside) + view.addSubview(addButton) + + createButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.3, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + createButton.layer.cornerRadius = 15 + createButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + createButton.layer.borderWidth = 2 + createButton.backgroundColor = UIColor.white + createButton.setTitleColor(Constants.darkPurple, for: .normal) + createButton.setTitle("CREATE GROUP", for: .normal) + createButton.addTarget(self, action: #selector(createButtonPressed), for: .touchUpInside) + view.addSubview(createButton) + } + + @objc + func addButtonPressed() { + + } + + @objc + func createButtonPressed() { + delegate?.createButtonPressed() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/project/Streamline/View/MenuViews/MenuView.swift b/project/Streamline/View/MenuViews/MenuView.swift new file mode 100644 index 0000000..54d235d --- /dev/null +++ b/project/Streamline/View/MenuViews/MenuView.swift @@ -0,0 +1,119 @@ +// +// MenuView.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/27/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation +import Alamofire + +protocol MenuViewDelegate { + func logoutButtonPressed() + func settingButtonPressed() + func groupButtonPressed() +} + +class MenuView:UIView { + var delegate: MenuViewDelegate? = nil + var view: UIView! + + var profileImageView: UIImageView! + var settingButton : UIButton! + var groupButton : UIButton! + var logoutButton : UIButton! + + + init(frame: CGRect, large: Bool) { + print(DB.currentUser.imageUrl) + + super.init(frame: frame) + + layer.cornerRadius = 5 + clipsToBounds = true + view = UIView(frame: CGRect(x:0, y:0, width: frame.width, height: frame.height)) + view.layer.cornerRadius = 4 + view.backgroundColor = .white + + addSubview(view) + setupProfilePicture() + setupButtons() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //Setup functions + func setupProfilePicture() { + profileImageView = UIImageView(frame: CGRect(x: view.frame.width * 0.35, y: view.frame.width * 0.05, width: view.frame.width * 0.3, height: view.frame.width * 0.3)) + profileImageView.layer.cornerRadius = profileImageView.frame.width/2 + profileImageView.layer.borderWidth = 3.0 + profileImageView.layer.borderColor = Constants.darkPurple.cgColor + profileImageView.clipsToBounds = true + profileImageView.image = #imageLiteral(resourceName: "albumPlaceholder") + let url = URL(string: DB.currentUser.imageUrl) + DispatchQueue.global().async { + let data = try? Data(contentsOf: url!) + DispatchQueue.main.async { + self.profileImageView.image = UIImage(data: data!) + } + } + + view.addSubview(profileImageView) + } + + func setupButtons(){ + settingButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.4, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + settingButton.layer.cornerRadius = 15 + settingButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + settingButton.layer.borderWidth = 2 + + settingButton.backgroundColor = UIColor.white + settingButton.setTitleColor(Constants.darkPurple, for: .normal) + settingButton.setTitle("USER SETTINGS", for: .normal) + settingButton.addTarget(self, action: #selector(settingButtonPressed), for: .touchUpInside) + + view.addSubview(settingButton) + + groupButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.6, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + groupButton.layer.cornerRadius = 15 + groupButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + groupButton.layer.borderWidth = 2 + + groupButton.backgroundColor = UIColor.white + groupButton.setTitleColor(Constants.darkPurple, for: .normal) + groupButton.setTitle("GROUP SETTINGS", for: .normal) + groupButton.addTarget(self, action: #selector(groupButtonPressed), for: .touchUpInside) + + view.addSubview(groupButton) + + logoutButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.8, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + logoutButton.layer.cornerRadius = 15 + logoutButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + logoutButton.layer.borderWidth = 2 + + logoutButton.backgroundColor = UIColor.white + logoutButton.setTitleColor(Constants.darkPurple, for: .normal) + logoutButton.setTitle("LOGOUT", for: .normal) + logoutButton.addTarget(self, action: #selector(logoutButtonPressed), for: .touchUpInside) + + view.addSubview(logoutButton) + } + + @objc + func logoutButtonPressed() { + delegate?.logoutButtonPressed() + } + + @objc + func groupButtonPressed() { + delegate?.groupButtonPressed() + } + + @objc + func settingButtonPressed() { + delegate?.settingButtonPressed() + } +} diff --git a/project/Streamline/View/MenuViews/SettingView.swift b/project/Streamline/View/MenuViews/SettingView.swift new file mode 100644 index 0000000..6226ac9 --- /dev/null +++ b/project/Streamline/View/MenuViews/SettingView.swift @@ -0,0 +1,92 @@ +// +// SettingView.swift +// Streamline +// +// Created by Vineeth Yeevani on 11/27/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import Foundation +protocol SettingViewDelegate { + func setNameButtonPressed() +} + +class SettingView:UIView { + var delegate: SettingViewDelegate? = nil + var view: UIView! + + var profileImageView : UIImageView! + var usernameTextField : UITextField! + var setNameButton : UIButton! + + + init(frame: CGRect, large: Bool) { + print(DB.currentUser.imageUrl) + + super.init(frame: frame) + + layer.cornerRadius = 5 + clipsToBounds = true + view = UIView(frame: CGRect(x:0, y:0, width: frame.width, height: frame.height)) + view.layer.cornerRadius = 4 + view.backgroundColor = .white + + addSubview(view) + + setupTextField() + setupProfilePicture() + setupButton() + } + + //Setup Functions + func setupProfilePicture() { + profileImageView = UIImageView(frame: CGRect(x: view.frame.width * 0.35, y: view.frame.width * 0.05, width: view.frame.width * 0.3, height: view.frame.width * 0.3)) + profileImageView.layer.cornerRadius = profileImageView.frame.width/2 + profileImageView.layer.borderWidth = 3.0 + profileImageView.layer.borderColor = Constants.darkPurple.cgColor + profileImageView.clipsToBounds = true + profileImageView.image = #imageLiteral(resourceName: "albumPlaceholder") + let url = URL(string: DB.currentUser.imageUrl) + DispatchQueue.global().async { + let data = try? Data(contentsOf: url!) + DispatchQueue.main.async { + self.profileImageView.image = UIImage(data: data!) + } + } + + view.addSubview(profileImageView) + } + + func setupTextField(){ + usernameTextField = UITextField(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.47, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + usernameTextField.layer.cornerRadius = 15 + usernameTextField.backgroundColor = UIColor.white + usernameTextField.textColor = Constants.darkPurple + usernameTextField.placeholder = " Change Username: " + DB.currentUser.username + view.addSubview(usernameTextField) + } + + func setupButton() { + setNameButton = UIButton(frame: CGRect(x : view.frame.width * 0.1, y: view.frame.height * 0.70, width: view.frame.width * 0.8, height: view.frame.height * 0.1)) + setNameButton.layer.cornerRadius = 15 + setNameButton.layer.borderColor = UIColor(hex: "673AB7").cgColor + setNameButton.layer.borderWidth = 2 + + setNameButton.backgroundColor = UIColor.white + setNameButton.setTitleColor(Constants.darkPurple, for: .normal) + setNameButton.setTitle("SET USERNAME", for: .normal) + setNameButton.addTarget(self, action: #selector(setNameButtonPressed), for: .touchUpInside) + + view.addSubview(setNameButton) + } + + @objc + func setNameButtonPressed() { + delegate?.setNameButtonPressed() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +}