Skip to content

Commit 077c7d7

Browse files
committed
Save user's most recent location tfor better kluster loading on launch
1 parent ffecb95 commit 077c7d7

File tree

7 files changed

+65
-12
lines changed

7 files changed

+65
-12
lines changed

Cluster.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
9D7CC5AB1C7E7958002D21D0 /* MessageTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AA1C7E7958002D21D0 /* MessageTextView.swift */; };
6262
9D7CC5AD1C7E8EFB002D21D0 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */; };
6363
9D807F7F1C90834600FA5768 /* BLMultiColorLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D807F7E1C90834600FA5768 /* BLMultiColorLoader.m */; };
64+
9D807F811C90B08D00FA5768 /* LocationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D807F801C90B08D00FA5768 /* LocationStore.swift */; };
6465
9DAF9F871C87A3A2000B8586 /* ProfileNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DAF9F861C87A3A2000B8586 /* ProfileNameView.swift */; };
6566
9DAF9F8C1C89E022000B8586 /* CAPSPageMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DAF9F8B1C89E022000B8586 /* CAPSPageMenu.swift */; };
6667
9DAF9F8E1C89E7A4000B8586 /* Profile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DAF9F8D1C89E7A4000B8586 /* Profile.storyboard */; };
@@ -172,6 +173,7 @@
172173
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
173174
9D807F7D1C90834600FA5768 /* BLMultiColorLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BLMultiColorLoader.h; sourceTree = "<group>"; };
174175
9D807F7E1C90834600FA5768 /* BLMultiColorLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BLMultiColorLoader.m; sourceTree = "<group>"; };
176+
9D807F801C90B08D00FA5768 /* LocationStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationStore.swift; sourceTree = "<group>"; };
175177
9DAF9F861C87A3A2000B8586 /* ProfileNameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileNameView.swift; sourceTree = "<group>"; };
176178
9DAF9F8B1C89E022000B8586 /* CAPSPageMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CAPSPageMenu.swift; sourceTree = "<group>"; };
177179
9DAF9F8D1C89E7A4000B8586 /* Profile.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = "<group>"; };
@@ -380,6 +382,7 @@
380382
children = (
381383
9D7CC5AC1C7E8EFB002D21D0 /* Message.swift */,
382384
9DFB7D611C86211C00EF3E62 /* KlusterStore.swift */,
385+
9D807F801C90B08D00FA5768 /* LocationStore.swift */,
383386
);
384387
name = Models;
385388
sourceTree = "<group>";
@@ -713,6 +716,7 @@
713716
28EE236F1BDF1FF9009161AE /* ImagePickerCollectionView.swift in Sources */,
714717
286563F21C0E8B6E00C21668 /* MyKlusterTableViewCell.swift in Sources */,
715718
28EE236D1BDF1FF9009161AE /* ImageAction.swift in Sources */,
719+
9D807F811C90B08D00FA5768 /* LocationStore.swift in Sources */,
716720
28EE23461BDF1F83009161AE /* BlurView.swift in Sources */,
717721
28EE23541BDF1F83009161AE /* SoundPlayer.swift in Sources */,
718722
9D2EFA411BF6534400D91812 /* KlusterSearchController.swift in Sources */,

Cluster/Base.lproj/Main.storyboard

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@
13251325
<outlet property="biographyLabel" destination="Zyu-Yz-Gte" id="QxE-We-OPB"/>
13261326
<outlet property="coverImage" destination="4th-al-Vy1" id="J3B-OA-Dwi"/>
13271327
<outlet property="editButton" destination="YPD-vd-zbQ" id="mLd-pS-D6B"/>
1328+
<outlet property="locationLabel" destination="Cwa-67-syF" id="Co5-hH-L2V"/>
13281329
<outlet property="menuButton" destination="RxG-pW-nCC" id="RBu-x0-Iy0"/>
13291330
<outlet property="nameLabel" destination="vXs-zw-kMo" id="4kV-IU-uj9"/>
13301331
<outlet property="profileImageView" destination="oAd-jH-lfd" id="rnr-mN-J5N"/>

Cluster/EditProfileTableViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class EditProfileTableViewController: UITableViewController, UIImagePickerContro
3131
if (self.validAttributes()) {
3232
let firstName = self.firstNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
3333
let lastName = self.lastNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
34-
let age = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
34+
let ageString = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
3535
let location = self.locationTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
3636
let biography = self.aboutMeTextView.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
37+
38+
3739
self.user.setObject(firstName!, forKey: "firstName")
3840
self.user.setObject(lastName!, forKey: "lastName")
39-
self.user.setObject(age!, forKey: "age")
41+
self.user.setObject(Int(ageString!)!, forKey: "age")
4042
self.user.setObject(location!, forKey: "location")
4143
self.user.setObject(biography!, forKey: "biography")
4244
self.user.saveEventually()

Cluster/HomeViewController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class HomeViewController: UIViewController {
3535
override func viewDidLoad() {
3636
super.viewDidLoad()
3737

38+
let latitude = LocationStore.sharedStore.currentLatitude()
39+
let longitude = LocationStore.sharedStore.currentLongitude()
40+
self.currentGeoPoint = PFGeoPoint.init(latitude: latitude, longitude: longitude)
41+
3842
// Hide search bar and cancel button
3943
self.searchBar.hidden = true
4044
self.cancelButton.hidden = true
@@ -92,6 +96,9 @@ class HomeViewController: UIViewController {
9296
PFGeoPoint.geoPointForCurrentLocationInBackground({ (geoPoint, error) -> Void in
9397
if (error == nil) {
9498
self.currentGeoPoint = geoPoint
99+
if let geoPoint = geoPoint {
100+
LocationStore.sharedStore.updateLocation(geoPoint.latitude, longitude: geoPoint.longitude)
101+
}
95102
}
96103
})
97104
}

Cluster/LocationStore.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// LocationStore.swift
3+
// Cluster
4+
//
5+
// Created by Michael Fellows on 3/9/16.
6+
// Copyright © 2016 ImagineME. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class LocationStore : NSObject {
12+
let latitudeKey = "keyCurrentLatitiude"
13+
let longitudeKey = "keyCurrentLongitude"
14+
static let sharedStore = LocationStore()
15+
16+
func updateLocation(latitude: Double!, longitude: Double!) {
17+
NSUserDefaults.standardUserDefaults().setDouble(latitude, forKey: self.latitudeKey)
18+
NSUserDefaults.standardUserDefaults().setDouble(longitude, forKey: self.longitudeKey)
19+
}
20+
21+
func currentLatitude() -> Double {
22+
return NSUserDefaults.standardUserDefaults().doubleForKey(self.latitudeKey)
23+
}
24+
25+
func currentLongitude() -> Double {
26+
return NSUserDefaults.standardUserDefaults().doubleForKey(self.longitudeKey)
27+
}
28+
}

Cluster/MessagesTableViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class MessagesTableViewController: UITableViewController {
1212

1313
var parentNavigationController : UINavigationController?
1414

15+
var shouldContinueFetchingMessages: Bool = true
16+
var queryLimit = 20
1517
var kluster: Kluster!
1618
var textView: MessageTextView!
1719
let textViewHeight = 60.0 as CGFloat
@@ -108,7 +110,11 @@ class MessagesTableViewController: UITableViewController {
108110
if (error != nil) {
109111
print("Error fetching messages.")
110112
} else {
113+
self.shouldContinueFetchingMessages = objects?.count >= 20
111114
self.messages = objects as! [PFObject]
115+
// let newMessages = objects as! [PFObject]
116+
// self.messages = newMessages.reverse() + self.messages
117+
112118
self.messages = self.messages.reverse()
113119

114120
self.tableView.reloadData()

Cluster/ProfileViewController.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Photos
1111

1212
class ProfileViewController: UIViewController {
1313

14-
var user = PFUser.currentUser()
14+
var user: PFUser! = PFUser.currentUser()
1515

1616
@IBOutlet weak var coverImage: UIImageView!
1717
@IBOutlet weak var editButton: DesignableButton!
@@ -22,7 +22,7 @@ class ProfileViewController: UIViewController {
2222
@IBOutlet weak var profileImageView: PFImageView!
2323
@IBOutlet weak var ageLabel: UILabel!
2424
@IBOutlet weak var biographyLabel: UILabel!
25-
25+
@IBOutlet weak var locationLabel: UILabel!
2626
@IBAction func menuButtonPressed(sender: AnyObject) {
2727
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
2828
let editProfileController = storyboard.instantiateViewControllerWithIdentifier("EditProfileTableViewController")
@@ -113,26 +113,31 @@ class ProfileViewController: UIViewController {
113113
self.profileImageView.file = self.user!.objectForKey("avatar") as? PFFile
114114
self.profileImageView.loadInBackground()
115115

116-
let firstName = user?.objectForKey("firstName") as! String
117-
let lastName = user?.objectForKey("lastName") as! String
116+
let firstName = self.user.objectForKey("firstName") as! String
117+
let lastName = self.user.objectForKey("lastName") as! String
118118
self.nameLabel.text = firstName + " " + lastName
119119

120-
if (self.user?.objectForKey("age") != nil) {
121-
let age = self.user?.objectForKey("age") as? Int
120+
if let location = self.user.objectForKey("location") as? String {
121+
self.locationLabel.text = location
122+
} else {
123+
self.locationLabel.text = "🌎"
124+
}
125+
126+
if let age = self.user.objectForKey("age") as? Int {
122127
self.ageLabel.text = "\(age) yrs"
123128
} else {
124129
self.ageLabel.text = "🤔"
125130
}
126-
127-
if (self.user?.objectForKey("biography") != nil) {
128-
131+
132+
if let bio = self.user.objectForKey("biography") as? String {
133+
self.biographyLabel.text = bio
129134
} else {
130135
self.biographyLabel.text = self.randomBiographyString()
131136
}
132137
}
133138

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

0 commit comments

Comments
 (0)