forked from avielg/Anyway-iOS
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
187 changed files
with
17,994 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Anyway.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// AccidentsViewController.swift | ||
// Anyway | ||
// | ||
// Created by Aviel Gross on 7/6/15. | ||
// Copyright (c) 2015 Hasadna. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class AccidentsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { | ||
|
||
static let segueId = "show accidents" | ||
|
||
var dataSource = [Marker]() | ||
|
||
@IBOutlet weak var tableView: UITableView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
navigationItem.titleView = UIImageView(image: UIImage(named: "logo_rectangle")!) | ||
} | ||
|
||
override func viewWillAppear(animated: Bool) { | ||
super.viewWillAppear(animated) | ||
tableView.deselectRowIfNeeded() | ||
} | ||
|
||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | ||
guard let | ||
dest = segue.destinationViewController as? DetailViewController, | ||
cell = sender as? UITableViewCell, | ||
path = tableView.indexPathForCell(cell), | ||
marker = dataSource.safeRetrieveElement(path.row) | ||
else {return} | ||
|
||
dest.detailData = marker | ||
} | ||
|
||
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return dataSource.count | ||
} | ||
|
||
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCellWithIdentifier("detail cell", forIndexPath: indexPath) | ||
|
||
let data = dataSource[indexPath.row] | ||
|
||
if let name = data.iconName { | ||
cell.imageView?.image = UIImage(named: name) | ||
} | ||
|
||
cell.textLabel?.text = data.title ?? "" | ||
cell.detailTextLabel?.text = "\(data.subtitle ?? "") \(data.created.shortDate)" | ||
|
||
|
||
return cell | ||
} | ||
|
||
@IBAction func ActionClose(sender: UIBarButtonItem) { | ||
(self.presentingViewController ?? self.navigationController?.presentingViewController)?.dismissViewControllerAnimated(true) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// AlamofireSwiftyJSON.swift | ||
// AlamofireSwiftyJSON | ||
// | ||
// Created by Pinglin Tang on 14-9-22. | ||
// Copyright (c) 2014 SwiftyJSON. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Alamofire | ||
import SwiftyJSON | ||
|
||
// MARK: - Request for Swift JSON | ||
|
||
extension Request { | ||
|
||
/** | ||
Adds a handler to be called once the request has finished. | ||
|
||
:param: completionHandler A closure to be executed once the request has finished. The closure takes 4 arguments: the URL request, the URL response, if one was received, the SwiftyJSON enum, if one could be created from the URL response and data, and any error produced while creating the SwiftyJSON enum. | ||
|
||
:returns: The request. | ||
*/ | ||
public func responseSwiftyJSON(completionHandler: (NSURLRequest, NSHTTPURLResponse?, SwiftyJSON.JSON, NSError?) -> Void) -> Self { | ||
return responseSwiftyJSON(nil, options:NSJSONReadingOptions.AllowFragments, completionHandler:completionHandler) | ||
} | ||
|
||
/** | ||
Adds a handler to be called once the request has finished. | ||
|
||
:param: queue The queue on which the completion handler is dispatched. | ||
:param: options The JSON serialization reading options. `.AllowFragments` by default. | ||
:param: completionHandler A closure to be executed once the request has finished. The closure takes 4 arguments: the URL request, the URL response, if one was received, the SwiftyJSON enum, if one could be created from the URL response and data, and any error produced while creating the SwiftyJSON enum. | ||
|
||
:returns: The request. | ||
*/ | ||
public func responseSwiftyJSON(queue: dispatch_queue_t? = nil, options: NSJSONReadingOptions = .AllowFragments, completionHandler: (NSURLRequest, NSHTTPURLResponse?, JSON, NSError?) -> Void) -> Self { | ||
|
||
return response(queue: queue, responseSerializer: Request.JSONResponseSerializer(options: options), completionHandler: { ( response ) -> Void in | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { | ||
var responseJSON: JSON | ||
if response.result.isFailure | ||
{ | ||
responseJSON = JSON.null | ||
} else { | ||
responseJSON = SwiftyJSON.JSON(response.result.value!) | ||
} | ||
dispatch_async(queue ?? dispatch_get_main_queue(), { | ||
completionHandler(self.request!, self.response, responseJSON, response.result.error as NSError?) | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// AnnotationCoordinateUtility.h | ||
// Anyway | ||
// | ||
// Created by Aviel Gross on 2/23/15. | ||
// Copyright (c) 2015 Hasadna. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@import MapKit; | ||
|
||
@interface AnnotationCoordinateUtility : NSObject | ||
/* | ||
Take [Annotation] and mutate everything that needed | ||
*/ | ||
+ (void)mutateCoordinatesOfClashingAnnotations:(NSArray *)annotations; | ||
|
||
|
||
/* | ||
@return [NSValue:Annotation] of all points in given coordinate grouped by coordinates | ||
*/ | ||
+ (NSDictionary *)groupAnnotationsByLocationValue:(NSArray *)annotations; | ||
|
||
/* | ||
@return [Annotation] of all points in given coordinate | ||
*/ | ||
+ (NSArray *)groupForCoodinate:(CLLocationCoordinate2D)coord fromAnnotations:(NSArray *)annotations; | ||
|
||
/* | ||
@param annotations [Annotation] at the same coordinate | ||
*/ | ||
+ (void)repositionAnnotations:(NSArray *)annotations toAvoidClashAtCoordination:(CLLocationCoordinate2D)coordinate circleDistanceDelta:(double)delta; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// AnnotationCoordinateUtility.m | ||
// Anyway | ||
// | ||
// Created by Aviel Gross on 2/23/15. | ||
// Copyright (c) 2015 Hasadna. All rights reserved. | ||
// | ||
|
||
#import "AnnotationCoordinateUtility.h" | ||
|
||
@implementation AnnotationCoordinateUtility | ||
|
||
+ (NSArray *)groupForCoodinate:(CLLocationCoordinate2D)coord fromAnnotations:(NSArray *)annotations { | ||
NSDictionary *coordinateValuesToAnnotations = [self groupAnnotationsByLocationValue:annotations]; | ||
NSValue *value = [self valueFromCoordinate:coord]; | ||
return coordinateValuesToAnnotations[value]; | ||
} | ||
|
||
+ (void)mutateCoordinatesOfClashingAnnotations:(NSArray *)annotations { | ||
|
||
NSDictionary *coordinateValuesToAnnotations = [self groupAnnotationsByLocationValue:annotations]; | ||
|
||
for (NSValue *coordinateValue in coordinateValuesToAnnotations.allKeys) { | ||
NSMutableArray *outletsAtLocation = coordinateValuesToAnnotations[coordinateValue]; | ||
if (outletsAtLocation.count > 1) { | ||
CLLocationCoordinate2D coordinate; | ||
[coordinateValue getValue:&coordinate]; | ||
[self repositionAnnotations:outletsAtLocation toAvoidClashAtCoordination:coordinate circleDistanceDelta:13]; | ||
} | ||
} | ||
} | ||
|
||
+ (NSValue *)valueFromCoordinate:(CLLocationCoordinate2D)coord { | ||
return [NSValue valueWithBytes:&coord objCType:@encode(CLLocationCoordinate2D)]; | ||
} | ||
|
||
+ (NSDictionary *)groupAnnotationsByLocationValue:(NSArray *)annotations { | ||
|
||
NSMutableDictionary *result = [NSMutableDictionary dictionary]; | ||
|
||
for (id<MKAnnotation> pin in annotations) { | ||
|
||
//Change coord to NSObject key | ||
CLLocationCoordinate2D coordinate = pin.coordinate; | ||
NSValue *coordinateValue = [self valueFromCoordinate:coordinate]; | ||
|
||
//Get all the values of this coord object key | ||
NSMutableArray *annotationsAtLocation = result[coordinateValue]; | ||
|
||
//If none - create an array with this annotations inside | ||
if (!annotationsAtLocation) { | ||
annotationsAtLocation = [NSMutableArray array]; | ||
result[coordinateValue] = annotationsAtLocation; | ||
} | ||
|
||
//If any - add this annotation to the array | ||
[annotationsAtLocation addObject:pin]; | ||
} | ||
return result; | ||
} | ||
|
||
+ (void)repositionAnnotations:(NSArray *)annotations toAvoidClashAtCoordination:(CLLocationCoordinate2D)coordinate circleDistanceDelta:(double)delta { | ||
|
||
double distance = delta * annotations.count / 2.0; | ||
double radiansBetweenAnnotations = (M_PI * 2) / annotations.count; | ||
|
||
for (int i = 0; i < annotations.count; i++) { | ||
|
||
double heading = radiansBetweenAnnotations * i; | ||
CLLocationCoordinate2D newCoordinate = [self calculateCoordinateFrom:coordinate onBearing:heading atDistance:distance]; | ||
|
||
id <MKAnnotation> annotation = annotations[i]; | ||
|
||
[annotation setCoordinate:newCoordinate]; | ||
//annotation.coordinate = newCoordinate; | ||
} | ||
} | ||
|
||
+ (CLLocationCoordinate2D)calculateCoordinateFrom:(CLLocationCoordinate2D)coordinate onBearing:(double)bearingInRadians atDistance:(double)distanceInMetres { | ||
|
||
double coordinateLatitudeInRadians = coordinate.latitude * M_PI / 180; | ||
double coordinateLongitudeInRadians = coordinate.longitude * M_PI / 180; | ||
|
||
double distanceComparedToEarth = distanceInMetres / 6378100; | ||
|
||
double resultLatitudeInRadians = asin(sin(coordinateLatitudeInRadians) * cos(distanceComparedToEarth) + cos(coordinateLatitudeInRadians) * sin(distanceComparedToEarth) * cos(bearingInRadians)); | ||
double resultLongitudeInRadians = coordinateLongitudeInRadians + atan2(sin(bearingInRadians) * sin(distanceComparedToEarth) * cos(coordinateLatitudeInRadians), cos(distanceComparedToEarth) - sin(coordinateLatitudeInRadians) * sin(resultLatitudeInRadians)); | ||
|
||
CLLocationCoordinate2D result; | ||
result.latitude = resultLatitudeInRadians * 180 / M_PI; | ||
result.longitude = resultLongitudeInRadians * 180 / M_PI; | ||
return result; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#import "AnnotationCoordinateUtility.h" | ||
#import "OCMapView.h" | ||
#import "JGProgressHUD.h" | ||
#import "JGProgressHUDAnimation.h" | ||
#import "JGProgressHUDFadeZoomAnimation.h" | ||
#import "RMDateSelectionViewController.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// AppDelegate.swift | ||
// Anyway | ||
// | ||
// Created by Aviel Gross on 2/16/15. | ||
// Copyright (c) 2015 Hasadna. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
|
||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | ||
// Override point for customization after application launch. | ||
return true | ||
} | ||
|
||
func applicationWillResignActive(application: UIApplication) { | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
} | ||
|
||
func applicationDidEnterBackground(application: UIApplication) { | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
func applicationWillEnterForeground(application: UIApplication) { | ||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
func applicationDidBecomeActive(application: UIApplication) { | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
|
||
func applicationWillTerminate(application: UIApplication) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/> | ||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view contentMode="scaleToFill" id="iN0-l3-epB"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Hasadna. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye"> | ||
<rect key="frame" x="20" y="439" width="441" height="21"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Anyway" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX"> | ||
<rect key="frame" x="20" y="140" width="441" height="43"/> | ||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/> | ||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/> | ||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/> | ||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/> | ||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/> | ||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/> | ||
</constraints> | ||
<nil key="simulatedStatusBarMetrics"/> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<point key="canvasLocation" x="548" y="455"/> | ||
</view> | ||
</objects> | ||
</document> |
Oops, something went wrong.