Skip to content

Commit

Permalink
Merge branch 'mapview-abstraction'
Browse files Browse the repository at this point in the history
Conflicts:
	Classes/LocationService/SGLocationService.m
	Classes/LocationService/SGLocationTypes.m
	Classes/Model/SGRecord.h
	Classes/Model/SGRecord.m
	Classes/SGClient.h
	Classes/Utilities/SGGeoJSON.h
	Classes/Utilities/SGGeoJSON.m
	Classes/Utilities/SGPointHelper.h
	SGClient.xcodeproj/project.pbxproj
	Tests/SGBackgroundLocationTests.m
	Tests/SGRecordTests.m
  • Loading branch information
dsmith committed Jun 24, 2010
2 parents 9d13d94 + 58f55e7 commit 0c1501c
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 321 deletions.
1 change: 1 addition & 0 deletions Classes/LocationService/Queries/SGHistoryQuery.h
Expand Up @@ -34,6 +34,7 @@

#import <Foundation/Foundation.h>
#import "SGQuery.h"
#import "SGRecordAnnotation.h"

/*!
* @class SGHistoryQuery
Expand Down
45 changes: 20 additions & 25 deletions Classes/LocationService/SGLocationService.m
Expand Up @@ -423,7 +423,8 @@ - (void) stopTrackingRecords
locationManager.delegate = nil;
[locationManager release];
locationManager = nil;
}
}

}

#pragma mark -
Expand Down Expand Up @@ -453,30 +454,28 @@ - (void) locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLoca
}

#if __IPHONE_4_0 >= __IPHONE_OS_VERSION_MAX_ALLOWED

NSMutableArray* totalCachedRecords = [NSMutableArray array];
if(backgroundTask) {
NSArray* records = nil;
for(id<SGLocationServiceDelegate> delegate in delegates) {
if([delegate respondsToSelector:@selector(locationService:recordsForBackgroundLocationUpdate:)]) {
records = [delegate locationService:self recordsForBackgroundLocationUpdate:newLocation];
if(records)
[totalUpdatedRecords addObjectsFromArray:records];
}

NSMutableArray* totalCachedRecords = [NSMutableArray array];
NSArray* records = nil;
for(id<SGLocationServiceDelegate> delegate in delegates) {
if([delegate respondsToSelector:@selector(locationService:recordsForBackgroundLocationUpdate:)]) {
records = [delegate locationService:self recordsForBackgroundLocationUpdate:newLocation];
if(records)
[totalUpdatedRecords addObjectsFromArray:records];
}
for(id<SGLocationServiceDelegate> delegate in delegates) {
if([delegate respondsToSelector:@selector(locationService:shouldCacheRecord:)]) {
for(id<SGRecordAnnotation> record in totalUpdatedRecords)
if([delegate locationService:self shouldCacheRecord:record])
[totalCachedRecords addObject:record];
}
}

for(id<SGLocationServiceDelegate> delegate in delegates) {
if([delegate respondsToSelector:@selector(locationService:shouldCacheRecord:)]) {
for(id<SGRecordAnnotation> record in totalUpdatedRecords)
if([delegate locationService:self shouldCacheRecord:record])
[totalCachedRecords addObject:record];
}

[totalUpdatedRecords removeObjectsInArray:totalCachedRecords];
[self cacheBackgroundRecords:totalCachedRecords];
}

[totalUpdatedRecords removeObjectsInArray:totalCachedRecords];
[self cacheBackgroundRecords:totalCachedRecords];

#endif

[self updateBackgroundRecords:totalUpdatedRecords];
Expand All @@ -491,8 +490,6 @@ - (void) locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)
#pragma mark -
#pragma mark SGLocationService delegate methods

#if __IPHONE_4_0 >= __IPHONE_OS_VERSION_MAX_ALLOWED

- (void) locationService:(SGLocationService*)service succeededForResponseId:(NSString*)requestId responseObject:(NSObject*)responseObject
{
if([cachedResponseIds containsObject:requestId]) {
Expand All @@ -510,8 +507,6 @@ - (void) locationService:(SGLocationService*)service failedForResponseId:(NSStri
}
}

#endif

#pragma mark -
#pragma mark Record Information

Expand Down
58 changes: 9 additions & 49 deletions Classes/Model/SGRecord.h
Expand Up @@ -32,7 +32,6 @@
// Created by Derek Smith.
//

#import <MapKit/MapKit.h>
#import "SGRecordAnnotation.h"

@class SGHistoryQuery;
Expand All @@ -48,7 +47,7 @@
* It is recommended that this class be subclassed because most records stored in SimpleGeo will have user-defined properties. See
* @link //simplegeo/ooc/cl/SGGeoJSONEncoder SGGeoJSONEncoder @/link.
*/
@interface SGRecord : NSObject <SGRecordAnnotation>
@interface SGRecord : NSObject <SGRecordAnnotation, SGHistoricRecordAnnoation>
{
NSString* recordId;

Expand All @@ -65,18 +64,7 @@
NSString* selfLink;

NSMutableDictionary* properties;

NSDictionary* history;
SGHistoryQuery* historyQuery;

@private
BOOL historyChanged;

#if __IPHONE_4_0 >= __IPHONE_OS_VERSION_MAX_ALLOWED

MKPolyline* polyline;

#endif
}

/*!
Expand Down Expand Up @@ -147,65 +135,37 @@
@property (nonatomic, retain) NSMutableDictionary* properties;

/*!
* @method
* @abstract
* @discussion 
* @property
* @abstract The history of this record.
>>>>>>> mapview-abstraction
*/
@property (nonatomic, retain) NSDictionary* history;

/*!
* @method
* @abstract 
* @discussion 
*/
@property (nonatomic, readonly) SGHistoryQuery* historyQuery;

/*!
* @method updateRecordWithGeoJSONObject:
* @abstract Updates the record using the GeoJSONOBject.
* See @link //simplegeo/ooc/instm/SGRecordAnnotation/updateRecordWithGeoJSONObject: updateRecordWithGeoJSONObject: @/link.
*/
- (void) updateRecordWithGeoJSONObject:(NSDictionary*)dictionary;

/*!
* @method getHistory:cursor:
* @abstract 
* @discussion 
* @param limit 
* @param cursor 
* @result 
*/
- (NSString*) getHistory:(int)limit cursor:(NSString*)cursor;

/*!
* @method updateHistory:
* @abstract 
* @discussion 
* @abstract Appends the new history with the current history.
>>>>>>> mapview-abstraction
* @param newHistory 
*/
- (void) updateHistory:(NSDictionary*)newHistory;

/*!
* @method updateCoordinate:
* @abstract 
* @discussion 
* @abstract Updates the history and @link coordinate coordinate @/link while sending
* a request an update to SimpleGeo.
>>>>>>> mapview-abstraction
* @param coord 
* @result 
*/
- (NSString*) updateCoordinate:(CLLocationCoordinate2D)coord;

#if __IPHONE_4_0 >= __IPHONE_OS_VERSION_MAX_ALLOWED

/*!
* @method historyPolyline
* @abstract 
* @discussion 
* @result 
*/
- (MKPolyline*) historyPolyline;

#endif

@end


Expand Down
40 changes: 3 additions & 37 deletions Classes/Model/SGRecord.m
Expand Up @@ -34,7 +34,6 @@

#import "SGRecord.h"

#import "SGPointHelper.h"
#import "SGLocationService.h"
#import "SGLocationTypes.h"
#import "SGGeoJSONEncoder.h"
Expand All @@ -49,7 +48,7 @@ - (BOOL) _isValid:(NSObject *)object;
@end

@implementation SGRecord
@synthesize longitude, latitude, created, expires, layer, recordId, properties, layerLink, selfLink, history, historyQuery;
@synthesize longitude, latitude, created, expires, layer, recordId, properties, layerLink, selfLink, history;
@dynamic type;

- (id) init
Expand All @@ -61,18 +60,15 @@ - (id) init
recordId = nil;
created = [[NSDate date] timeIntervalSince1970];
expires = 0;
type = nil;
type = @"object";
layerLink = nil;
selfLink = nil;
properties = [[NSMutableDictionary alloc] init];
layer = nil;
history = nil;
historyQuery = nil;

if(!layer)
layer = @"";

historyChanged = NO;
}

return self;
Expand Down Expand Up @@ -101,7 +97,6 @@ - (NSString*) type

- (void) updateHistory:(NSDictionary*)newHistory
{
historyChanged = YES;
if(history)
newHistory = SGGeometryCollectionAppend(history, newHistory);

Expand Down Expand Up @@ -163,20 +158,12 @@ - (NSString*) description
self.layer, self.latitude, self.longitude, (int)self.expires, (int)self.created];
}

- (NSString*) getHistory:(int)limit cursor:(NSString*)cursor
{
historyQuery = [[SGHistoryQuery alloc] initWithRecord:self];
historyQuery.cursor = cursor;
historyQuery.limit = limit;
return [[SGLocationService sharedLocationService] history:historyQuery];
}

- (NSString*) updateCoordinate:(CLLocationCoordinate2D)coord
{
NSString* updateResponseId = nil;
double newLatitude = coord.latitude;
double newLongitude = coord.longitude;
if(longitude && latitude && (newLatitude != latitude && newLongitude != longitude)) {
if(newLatitude != latitude && newLongitude != longitude) {
SGLog(@"SGRecord - Updating record coordinates to %f,%f from %f,%f", newLatitude, newLongitude, latitude, longitude);
if(!history) {
NSMutableDictionary* geometryCollection = SGGeometryCollectionCreate();
Expand All @@ -194,27 +181,6 @@ - (NSString*) updateCoordinate:(CLLocationCoordinate2D)coord
return updateResponseId;
}

#if __IPHONE_4_0 >= __IPHONE_OS_VERSION_MAX_ALLOWED

- (MKPolyline*) historyPolyline
{
if(history && historyChanged) {
NSMutableArray* coords = [NSMutableArray array];
for(NSDictionary* geometry in [history geometries])
[coords addObject:[geometry coordinates]];

if(polyline)
[polyline release];

polyline = [[MKPolyline polylineWithCoordinates:SGLonLatArrayToCLLocationCoordArray(coords)
count:[coords count]] retain];
}

return polyline;
}

#endif

#pragma mark -
#pragma mark Helper methods

Expand Down
25 changes: 25 additions & 0 deletions Classes/Model/SGRecordAnnotation.h
Expand Up @@ -109,4 +109,29 @@
*/
- (void) updateRecordWithGeoJSONObject:(NSDictionary*)dictionary;

@end

/*!
* @protocol SGHistoricalRecordAnnoation
* @abstract 
* @discussion
*/
@protocol SGHistoricRecordAnnoation <SGRecordAnnotation>

/*!
* @method updateHistory:
* @abstract 
* @discussion 
* @param history 
*/
- (void) updateHistory:(NSDictionary*)history;

/*!
* @method history
* @abstract 
* @discussion 
* @result 
*/
- (NSDictionary*) history;

@end
1 change: 0 additions & 1 deletion Classes/SGClient.h
Expand Up @@ -18,7 +18,6 @@

#import "SGCacheHandler.h"
#import "SGCommitLog.h"
#import "SGPointHelper.h"

#import "SGAuthorization.h"
#import "SGGeoJSONEncoder.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -32,6 +32,9 @@
// Created by Derek Smith.
//

#import "GeoJSON+NSArray.h"
#import "GeoJSON+NSDictionary.h"

/*!
* @function SGGeometryCollectionCreate()
* @abstract Creates a new GeoJSON geometry collection object.
Expand Down
File renamed without changes.

0 comments on commit 0c1501c

Please sign in to comment.