-
Notifications
You must be signed in to change notification settings - Fork 274
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
1 parent
cd2ddaf
commit 768bf9d
Showing
9 changed files
with
203 additions
and
92 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// | ||
// BSelectLocationAction.h | ||
// AFNetworking | ||
// ChatSDK | ||
// | ||
// Created by Ben on 12/11/17. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <ChatSDK/PAction.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
#import <ChatSDK/BLocationPickerController.h> | ||
|
||
@protocol CLLocationManagerDelegate; | ||
|
||
@interface BSelectLocationAction : NSObject<PAction, CLLocationManagerDelegate> { | ||
CLLocationManager * _locationManager; | ||
RXPromise * _promise; | ||
} | ||
@interface BSelectLocationAction : NSObject<PAction, BLocationPickerControllerDelegate> | ||
|
||
- (instancetype)initWithViewController:(UIViewController *)controller; | ||
|
||
@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 |
---|---|---|
@@ -1,54 +1,53 @@ | ||
// | ||
// BSelectLocationAction.m | ||
// AFNetworking | ||
// ChatSDK | ||
// | ||
// Created by Ben on 12/11/17. | ||
// | ||
|
||
#import "BSelectLocationAction.h" | ||
#import <ChatSDK/ChatCore.h> | ||
|
||
@interface BSelectLocationAction() { | ||
RXPromise * _promise; | ||
__weak UIViewController * _controller; | ||
UINavigationController * _navController; | ||
BLocationPickerController * _picker; | ||
} | ||
@end | ||
|
||
@implementation BSelectLocationAction | ||
|
||
-(RXPromise *) execute { | ||
|
||
if(_promise) { | ||
return _promise; | ||
} | ||
else { | ||
_promise = [RXPromise new]; | ||
- (instancetype)initWithViewController:(UIViewController *)controller { | ||
if ((self = [self init])) { | ||
_controller = controller; | ||
} | ||
|
||
if(!_locationManager) { | ||
_locationManager = [[CLLocationManager alloc] init]; | ||
|
||
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && | ||
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { | ||
[_locationManager requestWhenInUseAuthorization]; | ||
} | ||
|
||
_locationManager.delegate = self; | ||
_locationManager.distanceFilter = kCLDistanceFilterNone; | ||
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; | ||
} | ||
[_locationManager startUpdatingLocation]; | ||
|
||
return _promise; | ||
return self; | ||
} | ||
|
||
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { | ||
- (RXPromise *)execute { | ||
_promise = [RXPromise new]; | ||
|
||
[manager stopUpdatingLocation]; | ||
if(_locationManager) { | ||
_locationManager = nil; | ||
|
||
CLLocation * location = locations.lastObject; | ||
[_promise resolveWithResult:location]; | ||
if (!_picker) { | ||
_picker = [[BLocationPickerController alloc] init]; | ||
_picker.delegate = self; | ||
} | ||
if(_promise) { | ||
[_promise resolveWithResult: Nil]; | ||
|
||
if (!_navController) { | ||
_navController = [[UINavigationController alloc] initWithRootViewController:_picker]; | ||
} | ||
_promise = Nil; | ||
|
||
[_controller presentViewController:_navController animated:YES completion:nil]; | ||
|
||
return _promise; | ||
} | ||
|
||
- (void)locationPickerController:(id)locationPicker didSelectLocation:(CLLocation *)location { | ||
[_promise resolveWithResult:location]; | ||
} | ||
|
||
- (void)locationPickerControllerDidCancel:(id)locationPicker { | ||
[_promise rejectWithReason:nil]; | ||
} | ||
|
||
@end |
9 changes: 2 additions & 7 deletions
9
ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.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 |
---|---|---|
@@ -1,18 +1,13 @@ | ||
// | ||
// BLocationOption.h | ||
// Pods | ||
// ChatSDK | ||
// | ||
// Created by Benjamin Smiley-andrews on 17/12/2016. | ||
// | ||
// | ||
|
||
#import <ChatSDK/BChatOption.h> | ||
|
||
@class RXPromise; | ||
@class BSelectLocationAction; | ||
|
||
@interface BLocationChatOption : BChatOption { | ||
BSelectLocationAction * _action; | ||
} | ||
@interface BLocationChatOption : BChatOption | ||
|
||
@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
22 changes: 22 additions & 0 deletions
22
ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.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,22 @@ | ||
// | ||
// BLocationPickerController.h | ||
// ChatSDK | ||
// | ||
// Created by Pepe Becker on 24.04.18. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
|
||
@protocol BLocationPickerControllerDelegate <NSObject> | ||
|
||
- (void)locationPickerController:(id)locationPicker didSelectLocation:(CLLocation *)location; | ||
- (void)locationPickerControllerDidCancel:(id)locationPicker; | ||
|
||
@end | ||
|
||
@interface BLocationPickerController : UIViewController | ||
|
||
@property (nonatomic, weak) id <BLocationPickerControllerDelegate> delegate; | ||
|
||
@end |
80 changes: 80 additions & 0 deletions
80
ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.m
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,80 @@ | ||
// | ||
// BLocationPickerController.m | ||
// ChatSDK | ||
// | ||
// Created by Pepe Becker on 24.04.18. | ||
// | ||
|
||
#import "BLocationPickerController.h" | ||
@import Mapbox; | ||
|
||
@interface BLocationPickerController() <MGLMapViewDelegate, UIGestureRecognizerDelegate> | ||
|
||
@property (nonatomic) MGLMapView * mapView; | ||
@property (nonatomic) MGLPointAnnotation * annotation; | ||
|
||
@end | ||
|
||
@implementation BLocationPickerController | ||
|
||
@synthesize delegate; | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action: @selector(cancel)]; | ||
|
||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action: @selector(done)]; | ||
self.navigationItem.rightBarButtonItem.enabled = NO; | ||
|
||
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; | ||
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
[self.view addSubview:self.mapView]; | ||
self.mapView.delegate = self; | ||
|
||
self.mapView.showsUserLocation = YES; | ||
[self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:YES]; | ||
|
||
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didRecognizeTab:)]; | ||
tapRecognizer.delegate = self; | ||
[self.view addGestureRecognizer:tapRecognizer]; | ||
} | ||
|
||
- (void)didRecognizeTab:(UITapGestureRecognizer *)sender { | ||
CGPoint point = [sender locationInView:self.mapView]; | ||
CLLocationCoordinate2D coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView]; | ||
|
||
if (self.annotation) { | ||
[self.mapView removeAnnotation:self.annotation]; | ||
} | ||
|
||
self.annotation = [MGLPointAnnotation alloc]; | ||
self.annotation.coordinate = coordinate; | ||
[self.mapView addAnnotation:self.annotation]; | ||
|
||
self.navigationItem.rightBarButtonItem.enabled = YES; | ||
} | ||
|
||
- (void)cancel { | ||
[delegate locationPickerControllerDidCancel:self]; | ||
[self dismiss]; | ||
} | ||
|
||
- (void)done { | ||
CLLocationCoordinate2D coords = self.annotation.coordinate; | ||
CLLocation * location = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude]; | ||
[delegate locationPickerController:self didSelectLocation:location]; | ||
[self dismiss]; | ||
} | ||
|
||
- (void)dismiss { | ||
[self dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
#pragma mark - UIGestureRecognizerDelegate | ||
|
||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer { | ||
return YES; | ||
} | ||
|
||
@end |
Oops, something went wrong.