Skip to content
Prev Previous commit
Next Next commit
Save user's most recent location tfor better kluster loading on launch
  • Loading branch information
mafellows committed Mar 9, 2016
commit 077c7d7ecf98ca62b948bd34aa42d32f21afbd3e
4 changes: 4 additions & 0 deletions Cluster.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
9D7CC5AB1C7E7958002D21D0 /* MessageTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AA1C7E7958002D21D0 /* MessageTextView.swift */; };
9D7CC5AD1C7E8EFB002D21D0 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */; };
9D807F7F1C90834600FA5768 /* BLMultiColorLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D807F7E1C90834600FA5768 /* BLMultiColorLoader.m */; };
9D807F811C90B08D00FA5768 /* LocationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D807F801C90B08D00FA5768 /* LocationStore.swift */; };
9DAF9F871C87A3A2000B8586 /* ProfileNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DAF9F861C87A3A2000B8586 /* ProfileNameView.swift */; };
9DAF9F8C1C89E022000B8586 /* CAPSPageMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DAF9F8B1C89E022000B8586 /* CAPSPageMenu.swift */; };
9DAF9F8E1C89E7A4000B8586 /* Profile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DAF9F8D1C89E7A4000B8586 /* Profile.storyboard */; };
Expand Down Expand Up @@ -172,6 +173,7 @@
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
9D807F7D1C90834600FA5768 /* BLMultiColorLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLMultiColorLoader.h; sourceTree = "<group>"; };
9D807F7E1C90834600FA5768 /* BLMultiColorLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLMultiColorLoader.m; sourceTree = "<group>"; };
9D807F801C90B08D00FA5768 /* LocationStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationStore.swift; sourceTree = "<group>"; };
9DAF9F861C87A3A2000B8586 /* ProfileNameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileNameView.swift; sourceTree = "<group>"; };
9DAF9F8B1C89E022000B8586 /* CAPSPageMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CAPSPageMenu.swift; sourceTree = "<group>"; };
9DAF9F8D1C89E7A4000B8586 /* Profile.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -380,6 +382,7 @@
children = (
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */,
9DFB7D611C86211C00EF3E62 /* KlusterStore.swift */,
9D807F801C90B08D00FA5768 /* LocationStore.swift */,
);
name = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -713,6 +716,7 @@
28EE236F1BDF1FF9009161AE /* ImagePickerCollectionView.swift in Sources */,
286563F21C0E8B6E00C21668 /* MyKlusterTableViewCell.swift in Sources */,
28EE236D1BDF1FF9009161AE /* ImageAction.swift in Sources */,
9D807F811C90B08D00FA5768 /* LocationStore.swift in Sources */,
28EE23461BDF1F83009161AE /* BlurView.swift in Sources */,
28EE23541BDF1F83009161AE /* SoundPlayer.swift in Sources */,
9D2EFA411BF6534400D91812 /* KlusterSearchController.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Cluster/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@
<outlet property="biographyLabel" destination="Zyu-Yz-Gte" id="QxE-We-OPB"/>
<outlet property="coverImage" destination="4th-al-Vy1" id="J3B-OA-Dwi"/>
<outlet property="editButton" destination="YPD-vd-zbQ" id="mLd-pS-D6B"/>
<outlet property="locationLabel" destination="Cwa-67-syF" id="Co5-hH-L2V"/>
<outlet property="menuButton" destination="RxG-pW-nCC" id="RBu-x0-Iy0"/>
<outlet property="nameLabel" destination="vXs-zw-kMo" id="4kV-IU-uj9"/>
<outlet property="profileImageView" destination="oAd-jH-lfd" id="rnr-mN-J5N"/>
Expand Down
6 changes: 4 additions & 2 deletions Cluster/EditProfileTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class EditProfileTableViewController: UITableViewController, UIImagePickerContro
if (self.validAttributes()) {
let firstName = self.firstNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let lastName = self.lastNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let age = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let ageString = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let location = self.locationTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let biography = self.aboutMeTextView.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())


self.user.setObject(firstName!, forKey: "firstName")
self.user.setObject(lastName!, forKey: "lastName")
self.user.setObject(age!, forKey: "age")
self.user.setObject(Int(ageString!)!, forKey: "age")
self.user.setObject(location!, forKey: "location")
self.user.setObject(biography!, forKey: "biography")
self.user.saveEventually()
Expand Down
7 changes: 7 additions & 0 deletions Cluster/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class HomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let latitude = LocationStore.sharedStore.currentLatitude()
let longitude = LocationStore.sharedStore.currentLongitude()
self.currentGeoPoint = PFGeoPoint.init(latitude: latitude, longitude: longitude)

// Hide search bar and cancel button
self.searchBar.hidden = true
self.cancelButton.hidden = true
Expand Down Expand Up @@ -92,6 +96,9 @@ class HomeViewController: UIViewController {
PFGeoPoint.geoPointForCurrentLocationInBackground({ (geoPoint, error) -> Void in
if (error == nil) {
self.currentGeoPoint = geoPoint
if let geoPoint = geoPoint {
LocationStore.sharedStore.updateLocation(geoPoint.latitude, longitude: geoPoint.longitude)
}
}
})
}
Expand Down
28 changes: 28 additions & 0 deletions Cluster/LocationStore.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// LocationStore.swift
// Cluster
//
// Created by Michael Fellows on 3/9/16.
// Copyright © 2016 ImagineME. All rights reserved.
//

import Foundation

class LocationStore : NSObject {
let latitudeKey = "keyCurrentLatitiude"
let longitudeKey = "keyCurrentLongitude"
static let sharedStore = LocationStore()

func updateLocation(latitude: Double!, longitude: Double!) {
NSUserDefaults.standardUserDefaults().setDouble(latitude, forKey: self.latitudeKey)
NSUserDefaults.standardUserDefaults().setDouble(longitude, forKey: self.longitudeKey)
}

func currentLatitude() -> Double {
return NSUserDefaults.standardUserDefaults().doubleForKey(self.latitudeKey)
}

func currentLongitude() -> Double {
return NSUserDefaults.standardUserDefaults().doubleForKey(self.longitudeKey)
}
}
6 changes: 6 additions & 0 deletions Cluster/MessagesTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class MessagesTableViewController: UITableViewController {

var parentNavigationController : UINavigationController?

var shouldContinueFetchingMessages: Bool = true
var queryLimit = 20
var kluster: Kluster!
var textView: MessageTextView!
let textViewHeight = 60.0 as CGFloat
Expand Down Expand Up @@ -108,7 +110,11 @@ class MessagesTableViewController: UITableViewController {
if (error != nil) {
print("Error fetching messages.")
} else {
self.shouldContinueFetchingMessages = objects?.count >= 20
self.messages = objects as! [PFObject]
// let newMessages = objects as! [PFObject]
// self.messages = newMessages.reverse() + self.messages

self.messages = self.messages.reverse()

self.tableView.reloadData()
Expand Down
25 changes: 15 additions & 10 deletions Cluster/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Photos

class ProfileViewController: UIViewController {

var user = PFUser.currentUser()
var user: PFUser! = PFUser.currentUser()

@IBOutlet weak var coverImage: UIImageView!
@IBOutlet weak var editButton: DesignableButton!
Expand All @@ -22,7 +22,7 @@ class ProfileViewController: UIViewController {
@IBOutlet weak var profileImageView: PFImageView!
@IBOutlet weak var ageLabel: UILabel!
@IBOutlet weak var biographyLabel: UILabel!

@IBOutlet weak var locationLabel: UILabel!
@IBAction func menuButtonPressed(sender: AnyObject) {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let editProfileController = storyboard.instantiateViewControllerWithIdentifier("EditProfileTableViewController")
Expand Down Expand Up @@ -113,26 +113,31 @@ class ProfileViewController: UIViewController {
self.profileImageView.file = self.user!.objectForKey("avatar") as? PFFile
self.profileImageView.loadInBackground()

let firstName = user?.objectForKey("firstName") as! String
let lastName = user?.objectForKey("lastName") as! String
let firstName = self.user.objectForKey("firstName") as! String
let lastName = self.user.objectForKey("lastName") as! String
self.nameLabel.text = firstName + " " + lastName

if (self.user?.objectForKey("age") != nil) {
let age = self.user?.objectForKey("age") as? Int
if let location = self.user.objectForKey("location") as? String {
self.locationLabel.text = location
} else {
self.locationLabel.text = "🌎"
}

if let age = self.user.objectForKey("age") as? Int {
self.ageLabel.text = "\(age) yrs"
} else {
self.ageLabel.text = "🤔"
}
if (self.user?.objectForKey("biography") != nil) {


if let bio = self.user.objectForKey("biography") as? String {
self.biographyLabel.text = bio
} else {
self.biographyLabel.text = self.randomBiographyString()
}
}

private func randomBiographyString() -> String {
let firstName = self.user?.objectForKey("firstName") as? String
let firstName = self.user.objectForKey("firstName") as! String
return "Surely \(firstName) is clever, but they haven't shared anything with us."
}
}