Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untitled Pull Request #5

Merged
merged 3 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MasqueParty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@
isa = PBXGroup;
children = (
E9EABA211D4C7AA500B3FB1D /* LoginViewController.swift */,
E910ED0B1DA9445700673A94 /* UserViewController.swift */,
E90F718B1D7942210015E605 /* NearbyUsersViewController.swift */,
E910ED0B1DA9445700673A94 /* UserViewController.swift */,
E9E5F1261D53BB7100768848 /* ProfileViewController.swift */,
);
path = Controllers;
Expand Down
13 changes: 5 additions & 8 deletions MasqueParty/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
//
// AppDelegate.swift
// MasqueParty


//
// Created by Isaiah Jenkins on 7/29/16.
// Copyright © 2016 MasqueParty. All rights reserved.
//

import UIKit
import FBSDKCoreKit
import Firebase
import IQKeyboardManagerSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
Expand All @@ -29,7 +27,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
return true
}

func application(
_ app: UIApplication,
open url: URL,
Expand All @@ -44,12 +42,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

// MARK: UISceneSession Lifecycle

@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
return UISceneConfiguration(name: K.sceneConfigurationName, sessionRole: connectingSceneSession.role)
}

@available(iOS 13.0, *)
Expand All @@ -58,6 +56,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

}

23 changes: 7 additions & 16 deletions MasqueParty/Controllers/LoginViewController.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
//
// ViewController.swift
// LoginViewController.swift
// MasqueParty
//
// Created by Isaiah Jenkins on 7/29/16.
// Copyright © 2016 MasqueParty. All rights reserved.
//
/*
uides - user for bio clicked
uids - current user
*/


import UIKit
import Firebase
Expand Down Expand Up @@ -64,7 +59,7 @@ class LoginViewController: UIViewController {

@available(iOS 13.0, *)
func goTo(_ storyboardId: String){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let storyboard = UIStoryboard(name: K.mainStoryboard, bundle: nil)
let controller = storyboard.instantiateViewController(identifier: storyboardId)
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(controller)
}
Expand All @@ -88,19 +83,15 @@ extension LoginViewController : LoginButtonDelegate {
print(error.localizedDescription)
return
}

guard let result = result else {
return
}

if result.isCancelled {
stopLoadingSpinner()
return
}

let credential = FacebookAuthProvider
.credential(withAccessToken: AccessToken.current!.tokenString)

if #available(iOS 13.0, *) {
firebaseManager?.signIn(with: credential)
}
Expand All @@ -112,11 +103,11 @@ extension LoginViewController : LoginButtonDelegate {

extension LoginViewController : FirebaseDelegate {
func showMessagePrompt(_ message: String) {
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)
present(alert, animated: false, completion: nil)
}
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)
present(alert, animated: false, completion: nil)
}

func signInError(_ error: Error) {
stopLoadingSpinner()
Expand Down
137 changes: 55 additions & 82 deletions MasqueParty/Controllers/NearbyUsersViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NearbyCollectionViewController.swift
// NearbyUsersViewController.swift
// MasqueParty
//
// Created by Isaiah Jenkins on 9/1/16.
Expand All @@ -11,31 +11,14 @@ import Firebase
import CoreLocation

class NearbyUsersViewController: UIViewController {

@IBOutlet weak var nearbyUsersCollectionView: UICollectionView!

var firebaseManager = FirebaseManager()
var locationManager = LocationManager()
var nearbyUsers : [NearbyUser] = []
// var nearbyUsers : [NearbyUser] = [
// NearbyUser(uid: "", userProfilePicURL: "https://www.pinclipart.com/picdir/big/167-1677865_facebook-button-image-facebook-small-icon-png-clipart.png"),
// NearbyUser(uid: "", userProfilePicURL: "https://www.pinclipart.com/picdir/big/167-1677865_facebook-button-image-facebook-small-icon-png-clipart.png")
// ]

@IBOutlet var nearbyLoading: UIActivityIndicatorView!
@IBOutlet weak var nearbyUsersCollectionView: UICollectionView!
var nearbyUsers : [NearbyUser] = []

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
locationManager.requestPermission()
setTitle("Searching nearby...")
startLoadingSpinner()
//check if location services is on
if locationManager.checkIfLocationEnabled() {
//get postalCity using CoreLocation
locationManager.requestLocation()
}else{
//else set nav title to Enable location services...
setTitle("Enable location services...")
}
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -45,29 +28,48 @@ class NearbyUsersViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
firebaseManager.delegate = self
locationManager.manager.delegate = self
configureDelegates()
configureRefreshControl()
registerCustomCollectionViewCell()
locationManager.requestPermission()
locationManager.searchNearbyForUsers()
startRefreshing()
}

func registerCustomCollectionViewCell() {
nearbyUsersCollectionView.register(UINib(nibName: K.CellInfo.nearbyCellNibName, bundle: nil), forCellWithReuseIdentifier: K.CellInfo.nearbyCellIdentifier)

}

func startLoadingSpinner() {
showLoadingSpinner()
nearbyLoading.startAnimating()
func configureDelegates() {
firebaseManager.delegate = self
locationManager.manager.delegate = self
locationManager.delegate = self
}

func stopLoadingSpinner() {
nearbyLoading.stopAnimating()
showLoadingSpinner(false)
func configureRefreshControl () {
nearbyUsersCollectionView.refreshControl = UIRefreshControl()
nearbyUsersCollectionView.refreshControl?.addTarget(self, action:
#selector(resfreshNearbyUsers),
for: .valueChanged)
nearbyUsersCollectionView.refreshControl?.tintColor = .lightGray

}

func showLoadingSpinner(_ show: Bool = true){
nearbyLoading.isHidden = !show
@objc func resfreshNearbyUsers(refreshControl: UIRefreshControl) {
locationManager.searchNearbyForUsers()
}

func setTitle(_ title: String){
navigationItem.title = title
}

func startRefreshing() {
nearbyUsersCollectionView.refreshControl?.beginRefreshing()
}

func endRefreshing() {
nearbyUsersCollectionView.refreshControl?.endRefreshing()
}
}

// MARK: - UICollectionViewDataSource
Expand All @@ -78,18 +80,16 @@ extension NearbyUsersViewController : UICollectionViewDataSource {
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return nearbyUsers.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellInfo.nearbyCellIdentifier, for: indexPath as IndexPath) as! NearbyCollectionViewCell
if let userProfilePicURL = NSURL(string: nearbyUsers[indexPath.row].userProfilePicURL) as URL?,
if let userProfilePicURL = NSURL(string: nearbyUsers[indexPath.row].picURL) as URL?,
let imageData = NSData(contentsOf: userProfilePicURL) {
cell.nearbyImage.image = UIImage(data:imageData as Data)
cell.uid = nearbyUsers[indexPath.row].uid
}

return cell
}
}
Expand All @@ -98,7 +98,6 @@ extension NearbyUsersViewController : UICollectionViewDataSource {
// MARK: - UICollectionViewDelegate

extension NearbyUsersViewController : UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "goToUserProfile", sender: indexPath)
}
Expand All @@ -107,37 +106,9 @@ extension NearbyUsersViewController : UICollectionViewDelegate {
if segue.identifier == "goToUserProfile" {
let indexPath = sender as! IndexPath
let destitinationVC = segue.destination as! UserViewController
destitinationVC.uid = nearbyUsers[indexPath.row].uid
destitinationVC.nearbyUser = nearbyUsers[indexPath.row]
}
}
/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
override func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
override func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
override func collectionView(collectionView: UICollectionView, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}

override func collectionView(collectionView: UICollectionView, canPerformAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool {
return false
}

override func collectionView(collectionView: UICollectionView, performAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {

}
*/
}

// MARK: - FirebaseDelegate
Expand All @@ -147,22 +118,22 @@ extension NearbyUsersViewController : FirebaseDelegate {
nearbyUsers = []
}

func addNearbyUser(_ nearbyUserId: String, _ profilePicURL: String) {
let newUser = NearbyUser(uid: nearbyUserId, userProfilePicURL: profilePicURL)
func addNearbyUser(_ uid: String, _ picURL: String, _ name: String, _ bio: String) {
let newUser = NearbyUser(uid: uid, picURL: picURL, name: name, bio: bio)
self.nearbyUsers.append(newUser)
print("newUser", newUser)
}

func refreshCollectionView() {
func refreshCollectionView(_ currentLocation: String) {
DispatchQueue.main.async {
self.nearbyUsersCollectionView.reloadData()
if self.nearbyUsers.count > 0 {
let indexPath = IndexPath(row: self.nearbyUsers.count - 1, section: 1)
self.nearbyUsersCollectionView.scrollToItem(at: indexPath, at: .top, animated: true)
let indexPath = IndexPath(row: self.nearbyUsers.count - 1, section: 0)
self.nearbyUsersCollectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)
}
self.setControllerTitle(currentLocation)
self.endRefreshing()
}
}

}

// MARK: - CLLocationManagerDelegate
Expand All @@ -172,7 +143,7 @@ extension NearbyUsersViewController : CLLocationManagerDelegate {
if #available(iOS 14.0, *) {
if manager.authorizationStatus == .authorizedWhenInUse || manager.authorizationStatus == .authorizedAlways {
locationManager.requestLocation()
startLoadingSpinner()
setControllerTitle("Searching nearby...")
}
}
}
Expand All @@ -181,26 +152,21 @@ extension NearbyUsersViewController : CLLocationManagerDelegate {
locationManager.stopUpdatingLocation()
guard let location = locations.first else {
setTitle("No Location")
self.stopLoadingSpinner()
return
}

let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { placemarks, error in
guard error == nil else {
print(error!.localizedDescription)
self.stopLoadingSpinner()
return
}

if let firstPlacemark = placemarks?.first {
let currentlocation = firstPlacemark.subAdministrativeArea ?? "no sub area"
//update current user's postalCity in firestore
var currentlocation = firstPlacemark.subAdministrativeArea ?? "no sub area"
if let name = firstPlacemark.name {
currentlocation = name
}
self.firebaseManager.setDataForCurrentUser("postalCity", currentlocation)
//get once, query where postalCity, not current uid, limit 20
self.firebaseManager.queryForUsersInLocation(currentlocation)
self.setTitle(currentlocation)
self.stopLoadingSpinner()
}
}
}
Expand All @@ -210,4 +176,11 @@ extension NearbyUsersViewController : CLLocationManagerDelegate {
}
}

// MARK: - LocationManagerDelegate

extension NearbyUsersViewController : LocationManagerDelegate {
func setControllerTitle(_ title: String) {
setTitle(title)
}
}

Loading