From 5ec8a09ef3f2a4354347f5df1f7e0df202e30a0c Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 29 Mar 2015 17:39:19 +0200 Subject: [PATCH 1/8] dynamic twitterquery by locality --- CriticalMass/PLChatModel.h | 3 +- CriticalMass/PLChatModel.m | 12 +++--- CriticalMass/PLChatViewController.m | 6 --- CriticalMass/PLConstants.h | 1 - CriticalMass/PLConstants.m | 3 +- CriticalMass/PLDataModel.h | 10 +---- CriticalMass/PLDataModel.m | 51 +++++++++++++++++++------- CriticalMass/PLTwitterViewController.h | 7 +--- CriticalMass/PLTwitterViewController.m | 30 ++++++++++++--- CriticalMass/PLUtils.h | 1 + CriticalMass/PLUtils.m | 8 +++- 11 files changed, 80 insertions(+), 52 deletions(-) diff --git a/CriticalMass/PLChatModel.h b/CriticalMass/PLChatModel.h index 481c191c4..0bd7256c4 100644 --- a/CriticalMass/PLChatModel.h +++ b/CriticalMass/PLChatModel.h @@ -14,8 +14,7 @@ @interface PLChatModel : NSObject -@property(nonatomic, strong) PLDataModel *data; -@property(nonatomic, strong) NSMutableArray *messages; +@property(nonatomic, readonly) NSMutableArray *messages; + (id)sharedManager; - (void)collectMessage:(NSString*)message; diff --git a/CriticalMass/PLChatModel.m b/CriticalMass/PLChatModel.m index 3014a21d7..9f6f7ea8e 100644 --- a/CriticalMass/PLChatModel.m +++ b/CriticalMass/PLChatModel.m @@ -12,6 +12,12 @@ #import "PLChatObject.h" #import +@interface PLChatModel() + +@property(nonatomic, strong) PLDataModel *data; + +@end + @implementation PLChatModel + (id)sharedManager { @@ -44,12 +50,6 @@ - (void)collectMessage:(NSString*) text { co.isActive = NO; [_messages addObject:co]; - - // TODO: sort not working here WTF -// [_messages sortUsingDescriptors: -// [NSArray arrayWithObjects: -// [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES], nil]]; - [_data request]; // notify view diff --git a/CriticalMass/PLChatViewController.m b/CriticalMass/PLChatViewController.m index b242138c3..e2b1d50f7 100644 --- a/CriticalMass/PLChatViewController.m +++ b/CriticalMass/PLChatViewController.m @@ -57,24 +57,18 @@ - (void)viewDidLoad { } -(void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessagesReceived) name:kNotificationChatMessagesReceived object:_chatModel]; - } -(void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:kNotificationChatMessagesReceived object:nil]; } -(void)viewDidAppear:(BOOL)animated{ - [super viewDidAppear:animated]; [self.view endEditing:YES]; // Hide keyboard diff --git a/CriticalMass/PLConstants.h b/CriticalMass/PLConstants.h index 65c2b6cf6..0a4238c8c 100644 --- a/CriticalMass/PLConstants.h +++ b/CriticalMass/PLConstants.h @@ -33,6 +33,5 @@ FOUNDATION_EXPORT NSTimeInterval const kRequestRepeatTime; FOUNDATION_EXPORT NSUInteger const kMaxRequestsInBackground; FOUNDATION_EXPORT double const kTestLocationLatitude; FOUNDATION_EXPORT double const kTestLocationLongitude; -FOUNDATION_EXPORT NSString *const kTwitterQuery; @end diff --git a/CriticalMass/PLConstants.m b/CriticalMass/PLConstants.m index 34544b8a4..979ba64e4 100644 --- a/CriticalMass/PLConstants.m +++ b/CriticalMass/PLConstants.m @@ -34,5 +34,4 @@ @implementation PLConstants NSTimeInterval const kRequestRepeatTime = 30.0; NSUInteger const kMaxRequestsInBackground = 480; double const kTestLocationLatitude = +52.50266880; -double const kTestLocationLongitude = +13.41227278; -NSString *const kTwitterQuery = @"#criticalmaps"; \ No newline at end of file +double const kTestLocationLongitude = +13.41227278; \ No newline at end of file diff --git a/CriticalMass/PLDataModel.h b/CriticalMass/PLDataModel.h index d65eb81bd..376e0342f 100644 --- a/CriticalMass/PLDataModel.h +++ b/CriticalMass/PLDataModel.h @@ -13,16 +13,10 @@ @class PLChatModel; -@interface PLDataModel : NSObject{ - - CLLocationManager *_locationManager; - AFHTTPRequestOperationManager *_operationManager; - NSTimer *_timer; - NSUInteger _updateCount; - NSUInteger _requestCount; -} +@interface PLDataModel : NSObject @property (nonatomic, readonly) NSString *uid; +@property (nonatomic, readonly) NSString *locality; @property (nonatomic, readonly) CLLocation *currentLocation; @property (nonatomic, readonly) NSDictionary *otherLocations; @property (nonatomic, readonly) BOOL gpsEnabled; diff --git a/CriticalMass/PLDataModel.m b/CriticalMass/PLDataModel.m index 58ee28416..d9d71873f 100644 --- a/CriticalMass/PLDataModel.m +++ b/CriticalMass/PLDataModel.m @@ -11,6 +11,16 @@ #import "PLUtils.h" #import +@interface PLDataModel() + +@property(nonatomic, strong) CLLocationManager *locationManager; +@property(nonatomic, strong) AFHTTPRequestOperationManager *operationManager; +@property(nonatomic, strong) NSTimer *timer; +@property(nonatomic, assign) NSUInteger updateCount; +@property(nonatomic, assign) NSUInteger requestCount; + +@end + @implementation PLDataModel + (id)sharedManager { @@ -142,7 +152,21 @@ - (void)disableGps{ [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationGpsStateChanged object:self]; } -#pragma mark - Handler +-(void)setIsBackroundMode:(BOOL)isBackroundMode +{ + _isBackroundMode = isBackroundMode; + + if (_isBackroundMode) { + _requestCount = 0; + }else{ + if(!_gpsEnabled && _gpsEnabledUser){ + [self enableGps]; + } + } + + DLog(@"backgroundMode: %@", _isBackroundMode ? @"YES" : @"NO"); +} + - (void)onTimer { [self request]; @@ -173,23 +197,22 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca [self performSelector:@selector(startRequestInterval) withObject:nil afterDelay:1.0]; } } + _updateCount++; -} - --(void)setIsBackroundMode:(BOOL)isBackroundMode -{ - _isBackroundMode = isBackroundMode; - if (_isBackroundMode) { - _requestCount = 0; - }else{ - if(!_gpsEnabled && _gpsEnabledUser){ - [self enableGps]; - } + if(_locality){ + return; } - DLog(@"backgroundMode: %@", _isBackroundMode ? @"YES" : @"NO"); + CLGeocoder *geoCoder = [[CLGeocoder alloc] init]; + [geoCoder reverseGeocodeLocation:_currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { + if (error){ + NSLog(@"Geocode failed with error: %@", error); + return; + } + CLPlacemark *placemark = [placemarks objectAtIndex:0]; + _locality = [placemark locality]; + }]; } - @end diff --git a/CriticalMass/PLTwitterViewController.h b/CriticalMass/PLTwitterViewController.h index 253cd2f0e..deeee1881 100644 --- a/CriticalMass/PLTwitterViewController.h +++ b/CriticalMass/PLTwitterViewController.h @@ -11,11 +11,6 @@ #import "SAMLoadingView.h" #import -@interface PLTwitterViewController : UIViewController{ - STTwitterAPI *_twitter; - UITableView *_tableView; - NSArray *_statuses; - SAMLoadingView *_loadingView; -} +@interface PLTwitterViewController : UIViewController @end \ No newline at end of file diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index 3eaa8ce7f..eabe6128b 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -11,10 +11,19 @@ #import "PLConstants.h" #import "PLTwitterTableViewCell.h" #import "HOButton.h" +#import "PLUtils.h" +#import "PLDataModel.h" @interface PLTwitterViewController () +@property(nonatomic,strong) STTwitterAPI *twitter; +@property(nonatomic,strong) UITableView *tableView; +@property(nonatomic,strong) NSArray *statuses; +@property(nonatomic,strong) SAMLoadingView *loadingView; +@property(nonatomic,strong) PLDataModel *data; +@property(nonatomic,strong) NSString *twitterQuery; + @end @implementation PLTwitterViewController @@ -22,8 +31,17 @@ @implementation PLTwitterViewController - (void)viewDidLoad { [super viewDidLoad]; + _data = [PLDataModel sharedManager]; + + if(_data.locality){ + _twitterQuery = [PLUtils getTwitterQueryByLocality:_data.locality]; + }else{ + _twitterQuery = @"#criticalmaps"; + } + PLLabel *label = [[PLLabel alloc] initWithFrame:CGRectMake(0, 19, self.view.frame.size.width, 50)]; - label.text = @"Latest Tweets of #criticalmaps"; + label.text = [NSString stringWithFormat:@"Latest Tweets of %@", _twitterQuery]; + [label setFont: [UIFont fontWithName:@"HelveticaNeue-Light" size:16.0f]]; [self.view addSubview:label]; @@ -52,12 +70,8 @@ - (void)viewDidLoad { [self.view.layer addSublayer:shapeLayer]; - //[_tableVC.tableView registerClass:[HOTwoRowViewCell class] forCellReuseIdentifier:@"CustomCell"]; - //_tableVC.tableView.tableHeaderView = [self headerView]; - [self.view addSubview:_tableView]; - _twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"e0vyKNT3iC89SkUaIzEvX1oii" consumerSecret:@"151lpogCiUp4RhjRNZukl2tJSeGyskq37U8wmldFm9FDPfzBW8"]; _loadingView = [[SAMLoadingView alloc] initWithFrame: frame]; @@ -75,7 +89,7 @@ - (void)loadTweets { [_twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) { - [_twitter getSearchTweetsWithQuery: kTwitterQuery + [_twitter getSearchTweetsWithQuery: _twitterQuery successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) { _statuses = statuses; [_tableView reloadData]; @@ -110,6 +124,10 @@ - (IBAction)onClickReload:(id)sender { [self loadTweets]; } +- (void)updateTwitterQuery { + +} + #pragma mark - Data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section diff --git a/CriticalMass/PLUtils.h b/CriticalMass/PLUtils.h index 63bdd37cf..5cadf7cbc 100644 --- a/CriticalMass/PLUtils.h +++ b/CriticalMass/PLUtils.h @@ -14,5 +14,6 @@ +(NSString*)locationdegrees2String:(double)degrees; +(double)string2Locationdegrees:(NSString*)string; +(NSString*)getTimestamp; ++(NSString*)getTwitterQueryByLocality:(NSString*)locality; @end diff --git a/CriticalMass/PLUtils.m b/CriticalMass/PLUtils.m index 68c7a3de9..25da4d8a6 100644 --- a/CriticalMass/PLUtils.m +++ b/CriticalMass/PLUtils.m @@ -16,7 +16,8 @@ +(NSString*)locationdegrees2String:(double)degrees return [[NSString stringWithFormat:@"%.06f", degrees] stringByReplacingOccurrencesOfString:@"." withString:@""]; } -+(double)string2Locationdegrees:(NSString*)string{ ++(double)string2Locationdegrees:(NSString*)string +{ return (double)([string floatValue]/1000000); } @@ -25,4 +26,9 @@ +(NSString*)getTimestamp return [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970] * 1000]; } ++(NSString*)getTwitterQueryByLocality:(NSString*)locality +{ + return [NSString stringWithFormat:@"#cm%@",[locality lowercaseString]]; +} + @end From 4b75f5a56df53f44d0d05b4424ba611a10f234e5 Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 29 Mar 2015 19:12:14 +0200 Subject: [PATCH 2/8] add additional --- .gitignore | 3 ++ CriticalMaps.xcodeproj/project.pbxproj | 6 ++++ CriticalMass/PLAppDelegate.m | 2 ++ CriticalMass/PLUtils.m | 4 ++- Podfile | 1 + Podfile.lock | 49 ++++++++++++++------------ 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 84b016ca3..bc3546311 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ xcuserdata Pods/ Podfile.lock CriticalMaps.xcodeproj + +PLAdditional.h +PLAdditional.m diff --git a/CriticalMaps.xcodeproj/project.pbxproj b/CriticalMaps.xcodeproj/project.pbxproj index 0398fbe47..db84c0a2d 100644 --- a/CriticalMaps.xcodeproj/project.pbxproj +++ b/CriticalMaps.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 90F46A24D8DB4FCAABF4CF34 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FD3CAC801A84BBA8D151E5D /* libPods.a */; }; + 940A9AEE1AC861C800F90DC3 /* PLAdditional.m in Sources */ = {isa = PBXBuildFile; fileRef = 940A9AED1AC861C800F90DC3 /* PLAdditional.m */; }; 941511091A10004D0010205B /* PLTwitterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 941511081A10004D0010205B /* PLTwitterViewController.m */; }; 942B71B61A5770CA00D02CA1 /* PLTwitterTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 942B71B51A5770CA00D02CA1 /* PLTwitterTableViewCell.m */; }; 942E2D8219C316BD00BF92D7 /* PLUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 942E2D8119C316BD00BF92D7 /* PLUtils.m */; }; @@ -50,6 +51,8 @@ /* Begin PBXFileReference section */ 1FD3CAC801A84BBA8D151E5D /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 42F8D420591A3C7DB831663C /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 940A9AEC1AC861C800F90DC3 /* PLAdditional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLAdditional.h; sourceTree = ""; }; + 940A9AED1AC861C800F90DC3 /* PLAdditional.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLAdditional.m; sourceTree = ""; }; 941511071A10004D0010205B /* PLTwitterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLTwitterViewController.h; sourceTree = ""; }; 941511081A10004D0010205B /* PLTwitterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLTwitterViewController.m; sourceTree = ""; }; 942B71B41A5770CA00D02CA1 /* PLTwitterTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLTwitterTableViewCell.h; sourceTree = ""; }; @@ -180,6 +183,8 @@ 94F0304819C1E4EC00F86611 /* PLConstants.m */, 942E2D8019C316BD00BF92D7 /* PLUtils.h */, 942E2D8119C316BD00BF92D7 /* PLUtils.m */, + 940A9AEC1AC861C800F90DC3 /* PLAdditional.h */, + 940A9AED1AC861C800F90DC3 /* PLAdditional.m */, ); name = Root; sourceTree = ""; @@ -414,6 +419,7 @@ 94AD50461A963D0600547B40 /* PLChatModel.m in Sources */, 94A9C1AF19BF43AB0027C5DC /* PLDataModel.m in Sources */, 945441AE1A111A6A00C8024F /* PLLabel.m in Sources */, + 940A9AEE1AC861C800F90DC3 /* PLAdditional.m in Sources */, 94F0304919C1E4EC00F86611 /* PLConstants.m in Sources */, 94CF089919BDF227009FFF43 /* PLTabBarController.m in Sources */, 9484E8031A62E63F0007F9F3 /* HOButton.m in Sources */, diff --git a/CriticalMass/PLAppDelegate.m b/CriticalMass/PLAppDelegate.m index 9e77064e1..358a32576 100644 --- a/CriticalMass/PLAppDelegate.m +++ b/CriticalMass/PLAppDelegate.m @@ -12,6 +12,7 @@ #import "PLRulesViewController.h" #import "PLConstants.h" #import "PLDataModel.h" +#import "PLAdditional.h" #import "Appirater.h" @implementation PLAppDelegate @@ -31,6 +32,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [Appirater setDebug:YES]; } + [PLAdditional setup]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; diff --git a/CriticalMass/PLUtils.m b/CriticalMass/PLUtils.m index 25da4d8a6..3bc0e3249 100644 --- a/CriticalMass/PLUtils.m +++ b/CriticalMass/PLUtils.m @@ -28,7 +28,9 @@ +(NSString*)getTimestamp +(NSString*)getTwitterQueryByLocality:(NSString*)locality { - return [NSString stringWithFormat:@"#cm%@",[locality lowercaseString]]; + NSString *ret = [NSString stringWithFormat:@"#cm%@",[locality lowercaseString]]; + ret = [ret stringByReplacingOccurrencesOfString:@" " withString:@""]; + return ret; } @end diff --git a/Podfile b/Podfile index 228d9f816..9c56b7e6c 100644 --- a/Podfile +++ b/Podfile @@ -9,6 +9,7 @@ pod 'NSString-Hashes' pod 'AccordionView' pod 'TTTAttributedLabel' pod 'STTwitter' +pod 'GoogleAnalytics-iOS-SDK', '3.0.3c' pod 'SAMLoadingView' pod 'SDWebImage' pod 'Appirater' \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index a5e861c4b..159cffcd0 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,39 +1,41 @@ PODS: - AccordionView (0.0.5) - - AFNetworking (2.5.1): - - AFNetworking/NSURLConnection (= 2.5.1) - - AFNetworking/NSURLSession (= 2.5.1) - - AFNetworking/Reachability (= 2.5.1) - - AFNetworking/Security (= 2.5.1) - - AFNetworking/Serialization (= 2.5.1) - - AFNetworking/UIKit (= 2.5.1) - - AFNetworking/NSURLConnection (2.5.1): + - AFNetworking (2.5.2): + - AFNetworking/NSURLConnection (= 2.5.2) + - AFNetworking/NSURLSession (= 2.5.2) + - AFNetworking/Reachability (= 2.5.2) + - AFNetworking/Security (= 2.5.2) + - AFNetworking/Serialization (= 2.5.2) + - AFNetworking/UIKit (= 2.5.2) + - AFNetworking/NSURLConnection (2.5.2): - AFNetworking/Reachability - AFNetworking/Security - AFNetworking/Serialization - - AFNetworking/NSURLSession (2.5.1): + - AFNetworking/NSURLSession (2.5.2): - AFNetworking/Reachability - AFNetworking/Security - AFNetworking/Serialization - - AFNetworking/Reachability (2.5.1) - - AFNetworking/Security (2.5.1) - - AFNetworking/Serialization (2.5.1) - - AFNetworking/UIKit (2.5.1): + - AFNetworking/Reachability (2.5.2) + - AFNetworking/Security (2.5.2) + - AFNetworking/Serialization (2.5.2) + - AFNetworking/UIKit (2.5.2): - AFNetworking/NSURLConnection - AFNetworking/NSURLSession - Appirater (2.0.4) + - GoogleAnalytics-iOS-SDK (3.0.3c) - NSString-Hashes (1.2.2) - SAMLoadingView (0.1.0) - - SDWebImage (3.7.1): - - SDWebImage/Core (= 3.7.1) - - SDWebImage/Core (3.7.1) - - STTwitter (0.1.9) - - TTTAttributedLabel (1.13.2) + - SDWebImage (3.7.2): + - SDWebImage/Core (= 3.7.2) + - SDWebImage/Core (3.7.2) + - STTwitter (0.2.0) + - TTTAttributedLabel (1.13.3) DEPENDENCIES: - AccordionView - AFNetworking - Appirater + - GoogleAnalytics-iOS-SDK (= 3.0.3c) - NSString-Hashes - SAMLoadingView - SDWebImage @@ -42,12 +44,13 @@ DEPENDENCIES: SPEC CHECKSUMS: AccordionView: bc022d5ae3b05a96b0b1ccd41cf37cc6796161a7 - AFNetworking: 8bee59492a6ff15d69130efa4d0dc67e0094a52a + AFNetworking: fefbce9660acb17f48ae0011292d4da0f457bf36 Appirater: cbdb7f305562cfde585300bfff86da01ae559deb + GoogleAnalytics-iOS-SDK: 4377a29aa3e039030df30fd5c6075baeed3c916c NSString-Hashes: ddf6e856e93d3c83c5d4ef8fcdea2a96ed77c6bc SAMLoadingView: 11b746311268140f6a2380723215fe96a6d15dee - SDWebImage: 116e88633b5b416ea0ca4b334a4ac59cf72dd38d - STTwitter: c9ddaac928660d64e346546d554069a7cdaaf5aa - TTTAttributedLabel: 7c4592f9a806badb8b48dc634cb9800447c51594 + SDWebImage: 71b7cdc1d1721d6a82ed62889030225f2c249e29 + STTwitter: 743ead8a65466ec0fe9b64cd2811de5590a0ed76 + TTTAttributedLabel: 6f3174aef8e738f44dff97c2eb7d8184f6ab6277 -COCOAPODS: 0.35.0 +COCOAPODS: 0.36.1 From 014b5c27c67b39c5e0e5d6376dd1a770b9c2c358 Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 5 Apr 2015 21:01:12 +0200 Subject: [PATCH 3/8] refactoring; color-theme --- CriticalMaps.xcodeproj/project.pbxproj | 8 +- CriticalMass/PLChatViewController.m | 3 +- CriticalMass/PLConstants.m | 3 +- CriticalMass/PLMapViewController.h | 7 +- CriticalMass/PLMapViewController.m | 17 ++-- CriticalMass/PLSettingsTableViewController.h | 1 - CriticalMass/PLSettingsTableViewController.m | 14 ++-- CriticalMass/PLTabBarController.m | 14 +--- CriticalMass/PLTwitterViewController.m | 88 ++++++++------------ CriticalMass/PLUtils.m | 1 + CriticalMass/UIColor+Helper.h | 15 ++++ CriticalMass/UIColor+Helper.m | 20 +++++ 12 files changed, 99 insertions(+), 92 deletions(-) create mode 100644 CriticalMass/UIColor+Helper.h create mode 100644 CriticalMass/UIColor+Helper.m diff --git a/CriticalMaps.xcodeproj/project.pbxproj b/CriticalMaps.xcodeproj/project.pbxproj index db84c0a2d..c9e4848af 100644 --- a/CriticalMaps.xcodeproj/project.pbxproj +++ b/CriticalMaps.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 94CF089619BDECAE009FFF43 /* PLRulesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CF089519BDECAE009FFF43 /* PLRulesViewController.m */; }; 94CF089919BDF227009FFF43 /* PLTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CF089819BDF227009FFF43 /* PLTabBarController.m */; }; 94DC348E1A9E5C39000E9D85 /* PLChatObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DC348D1A9E5C39000E9D85 /* PLChatObject.m */; }; + 94ECBDA61AD1B7CC00A8D75A /* UIColor+Helper.m in Sources */ = {isa = PBXBuildFile; fileRef = 94ECBDA51AD1B7CC00A8D75A /* UIColor+Helper.m */; }; 94F0304919C1E4EC00F86611 /* PLConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 94F0304819C1E4EC00F86611 /* PLConstants.m */; }; /* End PBXBuildFile section */ @@ -97,6 +98,8 @@ 94CF089819BDF227009FFF43 /* PLTabBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLTabBarController.m; sourceTree = ""; }; 94DC348C1A9E5C39000E9D85 /* PLChatObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLChatObject.h; sourceTree = ""; }; 94DC348D1A9E5C39000E9D85 /* PLChatObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLChatObject.m; sourceTree = ""; }; + 94ECBDA41AD1B7CC00A8D75A /* UIColor+Helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Helper.h"; sourceTree = ""; }; + 94ECBDA51AD1B7CC00A8D75A /* UIColor+Helper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Helper.m"; sourceTree = ""; }; 94F0304719C1E4EC00F86611 /* PLConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLConstants.h; sourceTree = ""; }; 94F0304819C1E4EC00F86611 /* PLConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLConstants.m; sourceTree = ""; }; EB65E4E1C81486F82961461F /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; @@ -143,13 +146,13 @@ 94AD50481A963DC800547B40 /* Controller */ = { isa = PBXGroup; children = ( - 9474656219CA3078005485BD /* PLSettingsTableViewController.h */, 94CF089119BDEC9C009FFF43 /* PLMapViewController.h */, 94CF089219BDEC9C009FFF43 /* PLMapViewController.m */, 94CF089419BDECAE009FFF43 /* PLRulesViewController.h */, 94CF089519BDECAE009FFF43 /* PLRulesViewController.m */, 941511071A10004D0010205B /* PLTwitterViewController.h */, 941511081A10004D0010205B /* PLTwitterViewController.m */, + 9474656219CA3078005485BD /* PLSettingsTableViewController.h */, 9474656319CA3078005485BD /* PLSettingsTableViewController.m */, 94591A691A6C67640080BCEC /* PLChatViewController.h */, 94591A6A1A6C67640080BCEC /* PLChatViewController.m */, @@ -185,6 +188,8 @@ 942E2D8119C316BD00BF92D7 /* PLUtils.m */, 940A9AEC1AC861C800F90DC3 /* PLAdditional.h */, 940A9AED1AC861C800F90DC3 /* PLAdditional.m */, + 94ECBDA41AD1B7CC00A8D75A /* UIColor+Helper.h */, + 94ECBDA51AD1B7CC00A8D75A /* UIColor+Helper.m */, ); name = Root; sourceTree = ""; @@ -418,6 +423,7 @@ 942E2D8219C316BD00BF92D7 /* PLUtils.m in Sources */, 94AD50461A963D0600547B40 /* PLChatModel.m in Sources */, 94A9C1AF19BF43AB0027C5DC /* PLDataModel.m in Sources */, + 94ECBDA61AD1B7CC00A8D75A /* UIColor+Helper.m in Sources */, 945441AE1A111A6A00C8024F /* PLLabel.m in Sources */, 940A9AEE1AC861C800F90DC3 /* PLAdditional.m in Sources */, 94F0304919C1E4EC00F86611 /* PLConstants.m in Sources */, diff --git a/CriticalMass/PLChatViewController.m b/CriticalMass/PLChatViewController.m index e2b1d50f7..030fdd9ee 100644 --- a/CriticalMass/PLChatViewController.m +++ b/CriticalMass/PLChatViewController.m @@ -9,6 +9,7 @@ #import "PLChatViewController.h" #import "PLChatObject.h" #import "PLConstants.h" +#import "UIColor+Helper.h" @interface PLChatViewController () @@ -30,7 +31,7 @@ - (void)viewDidLoad { self.tableView.delegate = self; [self.view addSubview: self.tableView]; - // add + // add gesture recognizer UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)]; [self.tableView addGestureRecognizer:gesture]; diff --git a/CriticalMass/PLConstants.m b/CriticalMass/PLConstants.m index 979ba64e4..1ce87eedf 100644 --- a/CriticalMass/PLConstants.m +++ b/CriticalMass/PLConstants.m @@ -20,7 +20,6 @@ @implementation PLConstants BOOL const kDebugInitialTabIndex = 0; BOOL const kDebugShowAppirater = NO; - // Urls NSString *const kUrlService = @"http://api.criticalmaps.net/postv2"; @@ -34,4 +33,4 @@ @implementation PLConstants NSTimeInterval const kRequestRepeatTime = 30.0; NSUInteger const kMaxRequestsInBackground = 480; double const kTestLocationLatitude = +52.50266880; -double const kTestLocationLongitude = +13.41227278; \ No newline at end of file +double const kTestLocationLongitude = +13.41227278; diff --git a/CriticalMass/PLMapViewController.h b/CriticalMass/PLMapViewController.h index 242000bb5..7c3e31014 100644 --- a/CriticalMass/PLMapViewController.h +++ b/CriticalMass/PLMapViewController.h @@ -11,11 +11,6 @@ #import "PLDataModel.h" #import "PLInfoOverlayView.h" -@interface PLMapViewController : UIViewController{ - PLDataModel *_data; - MKMapView *_map; - UIView *_infoOverlay; -} - +@interface PLMapViewController : UIViewController @end \ No newline at end of file diff --git a/CriticalMass/PLMapViewController.m b/CriticalMass/PLMapViewController.m index e71f8377d..608a4a177 100644 --- a/CriticalMass/PLMapViewController.m +++ b/CriticalMass/PLMapViewController.m @@ -13,6 +13,10 @@ @interface PLMapViewController () +@property(nonatomic,strong) PLDataModel *data; +@property(nonatomic,strong) MKMapView *map; +@property(nonatomic,strong) UIView *infoOverlay; + @end @implementation PLMapViewController @@ -29,7 +33,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - + _data = [PLDataModel sharedManager]; [self initMap]; @@ -63,16 +67,6 @@ - (void)initMap _map.mapType = MKMapTypeStandard; _map.showsPointsOfInterest = NO; - /* - No OSM yet. - - // OpenStreetMap overlay - NSString *template = kUrlTile; - MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template]; - overlay.canReplaceMapContent = YES; - [_map addOverlay:overlay level:MKOverlayLevelAboveLabels]; - */ - if(kDebug && kDebugEnableTestLocation){ _map.centerCoordinate = CLLocationCoordinate2DMake(kTestLocationLatitude, kTestLocationLongitude); } @@ -168,7 +162,6 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; - MKAnnotationView *annotationView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"BikeAnnotationView"]; if (!annotationView) diff --git a/CriticalMass/PLSettingsTableViewController.h b/CriticalMass/PLSettingsTableViewController.h index 6fec24ffc..d2720e5b6 100644 --- a/CriticalMass/PLSettingsTableViewController.h +++ b/CriticalMass/PLSettingsTableViewController.h @@ -10,5 +10,4 @@ @interface PLSettingsTableViewController : UITableViewController - @end diff --git a/CriticalMass/PLSettingsTableViewController.m b/CriticalMass/PLSettingsTableViewController.m index 90cfb3da0..ea2d62b03 100644 --- a/CriticalMass/PLSettingsTableViewController.m +++ b/CriticalMass/PLSettingsTableViewController.m @@ -9,15 +9,16 @@ #import "PLSettingsTableViewController.h" #import "PLDataModel.h" #import "PLConstants.h" +#import "UIColor+Helper.h" -@interface PLSettingsTableViewController () +@interface PLSettingsTableViewController() + +@property(nonatomic,strong) PLDataModel *data; +@property(nonatomic,strong) UISwitch *gpsSwitch; @end -@implementation PLSettingsTableViewController{ - PLDataModel *_data; - UISwitch *_gpsSwitch; -} +@implementation PLSettingsTableViewController - (id)initWithStyle:(UITableViewStyle)style { @@ -32,7 +33,6 @@ - (id)initWithStyle:(UITableViewStyle)style - (void)viewDidLoad { [super viewDidLoad]; - self.clearsSelectionOnViewWillAppear = YES; } @@ -73,6 +73,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.textLabel.text = @"Enable GPS"; _gpsSwitch = [[UISwitch alloc]init]; + _gpsSwitch.onTintColor = [UIColor magicColor]; [_gpsSwitch addTarget:self action:@selector(onSwitchGPS:) forControlEvents:UIControlEventTouchUpInside]; [_gpsSwitch setOn:_data.gpsEnabled]; cell.accessoryView = _gpsSwitch; @@ -105,7 +106,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.detailTextLabel.text = @"Help finacing our tracking server"; } } - return cell; } diff --git a/CriticalMass/PLTabBarController.m b/CriticalMass/PLTabBarController.m index c1b846f81..f47160eab 100644 --- a/CriticalMass/PLTabBarController.m +++ b/CriticalMass/PLTabBarController.m @@ -4,6 +4,7 @@ #import "PLChatViewController.h" #import "PLTwitterViewController.h" #import "PLSettingsTableViewController.h" +#import "UIColor+Helper.h" @interface PLTabBarController () @@ -12,22 +13,13 @@ @interface PLTabBarController () @implementation PLTabBarController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - - - - - } - return self; -} - (void)viewDidLoad { [super viewDidLoad]; + self.view.tintColor = [UIColor magicColor]; + UIViewController *viewController1 = [[PLMapViewController alloc] init]; UIViewController *viewController2 = [[PLRulesViewController alloc] init]; UIViewController *viewController3 = [[PLChatViewController alloc] init]; diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index eabe6128b..fb47cc402 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -13,14 +13,14 @@ #import "HOButton.h" #import "PLUtils.h" #import "PLDataModel.h" +#import "UIColor+Helper.h" @interface PLTwitterViewController () @property(nonatomic,strong) STTwitterAPI *twitter; -@property(nonatomic,strong) UITableView *tableView; +@property(nonatomic,strong) UITableViewController *tableVC; @property(nonatomic,strong) NSArray *statuses; -@property(nonatomic,strong) SAMLoadingView *loadingView; @property(nonatomic,strong) PLDataModel *data; @property(nonatomic,strong) NSString *twitterQuery; @@ -39,50 +39,42 @@ - (void)viewDidLoad { _twitterQuery = @"#criticalmaps"; } - PLLabel *label = [[PLLabel alloc] initWithFrame:CGRectMake(0, 19, self.view.frame.size.width, 50)]; - label.text = [NSString stringWithFormat:@"Latest Tweets of %@", _twitterQuery]; - - [label setFont: [UIFont fontWithName:@"HelveticaNeue-Light" size:16.0f]]; - [self.view addSubview:label]; - - HOButton *reloadBtn = [[HOButton alloc] init]; - [reloadBtn setImage:[UIImage imageNamed:@"Reload"] forState:UIControlStateNormal]; - reloadBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 9, 10, 9); - [reloadBtn addTarget:self action:@selector(onClickReload:) forControlEvents:UIControlEventTouchUpInside]; - reloadBtn.center = CGPointMake(self.view.frame.size.width-40, 40); - [self.view addSubview:reloadBtn]; - + // table CGRect frame = CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height - 120); - - _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain]; - [_tableView setDelegate:self]; - [_tableView setDataSource:self]; - - UIBezierPath *path = [UIBezierPath bezierPath]; - [path moveToPoint:CGPointMake(0, 70.0)]; - [path addLineToPoint:CGPointMake(self.view.frame.size.width, 70.0)]; - - CAShapeLayer *shapeLayer = [CAShapeLayer layer]; - shapeLayer.path = [path CGPath]; - shapeLayer.strokeColor = [[UIColor blackColor] CGColor]; - shapeLayer.lineWidth = 1.0; - shapeLayer.fillColor = [[UIColor clearColor] CGColor]; - - [self.view.layer addSublayer:shapeLayer]; - - [self.view addSubview:_tableView]; + _tableVC = [[UITableViewController alloc] init]; + [_tableVC.tableView setDelegate:self]; + [_tableVC.tableView setDataSource:self]; + _tableVC.tableView.frame = frame; + [self.view addSubview:_tableVC.tableView]; _twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"e0vyKNT3iC89SkUaIzEvX1oii" consumerSecret:@"151lpogCiUp4RhjRNZukl2tJSeGyskq37U8wmldFm9FDPfzBW8"]; - - _loadingView = [[SAMLoadingView alloc] initWithFrame: frame]; - _loadingView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [self.view addSubview:_loadingView]; + + // navbar + UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; + navBar.backgroundColor = [UIColor whiteColor]; + UINavigationItem *navItem = [[UINavigationItem alloc] init]; + navItem.title = [[NSString stringWithFormat:@"%@", _twitterQuery] uppercaseString]; + navBar.items = @[ navItem ]; + [self.view addSubview:navBar]; + + // refresh control + _tableVC.refreshControl = [[UIRefreshControl alloc] init]; + _tableVC.refreshControl.backgroundColor = [UIColor magicColor]; + _tableVC.refreshControl.tintColor = [UIColor whiteColor]; + [_tableVC.refreshControl addTarget:self + action:@selector(onRefreshPull) + forControlEvents:UIControlEventValueChanged]; [self loadTweets]; } +-(void)viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; + [_tableVC.tableView reloadData]; +} + + - (void)loadTweets { - [_loadingView setHidden:NO]; [_twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) { DLog(@"Access granted with %@", bearerToken); @@ -92,9 +84,9 @@ - (void)loadTweets { [_twitter getSearchTweetsWithQuery: _twitterQuery successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) { _statuses = statuses; - [_tableView reloadData]; - [_loadingView setHidden:YES]; - + [_tableVC.tableView reloadData]; + [_tableVC.refreshControl endRefreshing]; + } errorBlock:^(NSError *error) { // ... }]; @@ -109,12 +101,6 @@ - (void)loadTweets { } -- (void)viewWillAppear:(BOOL)animated{ - [super viewDidAppear:animated]; - - [_tableView reloadData]; -} - - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -124,8 +110,8 @@ - (IBAction)onClickReload:(id)sender { [self loadTweets]; } -- (void)updateTwitterQuery { - +- (void)onRefreshPull { + [self loadTweets]; } #pragma mark - Data source @@ -149,7 +135,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } NSDictionary *status = [_statuses objectAtIndex:indexPath.row]; - + DLog(@"%@", status); NSString *profileImageURL = status[@"user"][@"profile_image_url"]; @@ -159,7 +145,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N [cell.imageView sd_setImageWithURL:[NSURL URLWithString: profileImageURL] placeholderImage:[UIImage imageNamed:@"Twitter"]]; - + cell.textLabel.text = [NSString stringWithFormat:@"@%@: %@", screenName, text]; //cell.detailTextLabel.text = [NSString stringWithFormat:@"@%@ | %@", screenName, dateString]; diff --git a/CriticalMass/PLUtils.m b/CriticalMass/PLUtils.m index 3bc0e3249..e7b9b17e6 100644 --- a/CriticalMass/PLUtils.m +++ b/CriticalMass/PLUtils.m @@ -8,6 +8,7 @@ #import "PLUtils.h" +// TODO: move to category! @implementation PLUtils diff --git a/CriticalMass/UIColor+Helper.h b/CriticalMass/UIColor+Helper.h new file mode 100644 index 000000000..3b0cd1d87 --- /dev/null +++ b/CriticalMass/UIColor+Helper.h @@ -0,0 +1,15 @@ +// +// UIColor+Helper.h +// CriticalMaps +// +// Created by Norman Sander on 05.04.15. +// Copyright (c) 2015 Pokus Labs. All rights reserved. +// + +#import + +@interface UIColor (Helper) + ++ (UIColor *)magicColor; + +@end diff --git a/CriticalMass/UIColor+Helper.m b/CriticalMass/UIColor+Helper.m new file mode 100644 index 000000000..f71e421c0 --- /dev/null +++ b/CriticalMass/UIColor+Helper.m @@ -0,0 +1,20 @@ +// +// UIColor+Helper.m +// CriticalMaps +// +// Created by Norman Sander on 05.04.15. +// Copyright (c) 2015 Pokus Labs. All rights reserved. +// + +#import "UIColor+Helper.h" + +#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] + +@implementation UIColor (Helper) + ++ (UIColor *)magicColor { + return UIColorFromRGB(0x028a68); +} + + +@end From 5a55059c1cf019c4afb46f28b2d7098568d879dc Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 5 Apr 2015 21:12:05 +0200 Subject: [PATCH 4/8] update pods; change link color --- CriticalMass/PLRulesViewController.m | 9 ++++++++- Podfile.lock | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CriticalMass/PLRulesViewController.m b/CriticalMass/PLRulesViewController.m index 7af4671ae..dbeb12126 100644 --- a/CriticalMass/PLRulesViewController.m +++ b/CriticalMass/PLRulesViewController.m @@ -8,6 +8,7 @@ #import "PLRulesViewController.h" #import "AccordionView.h" +#import "UIColor+Helper.h" @interface PLRulesViewController () @@ -74,11 +75,17 @@ - (void)viewDidLoad [accordion setAllowsMultipleSelection:NO]; [accordion setAllowsEmptySelection:YES]; - // add link to cm hamburg TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, self.view.frame.size.height-80, self.view.frame.size.width-20, 30)]; label.font = [UIFont systemFontOfSize:12.0f]; NSString *labelText = @"Bilder von criticalmass-hh.de (CC BY-NC-ND 3.0 DE)"; + + NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName + , nil]; + NSArray *objects = [[NSArray alloc] initWithObjects:[UIColor magicColor],[NSNumber numberWithInt:kCTUnderlineStyleNone], nil]; + NSDictionary *linkAttributes = [[NSDictionary alloc] initWithObjects:objects forKeys:keys]; + label.linkAttributes = linkAttributes; + label.text = labelText; NSRange range = [labelText rangeOfString:@"criticalmass-hh.de"]; [label addLinkToURL:[NSURL URLWithString:@"open-cmhamburg"] withRange:range]; diff --git a/Podfile.lock b/Podfile.lock index 159cffcd0..dbd379488 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -43,14 +43,14 @@ DEPENDENCIES: - TTTAttributedLabel SPEC CHECKSUMS: - AccordionView: bc022d5ae3b05a96b0b1ccd41cf37cc6796161a7 + AccordionView: 4f82751476a96ec60985041a48bf4c94ac1ea5ab AFNetworking: fefbce9660acb17f48ae0011292d4da0f457bf36 - Appirater: cbdb7f305562cfde585300bfff86da01ae559deb - GoogleAnalytics-iOS-SDK: 4377a29aa3e039030df30fd5c6075baeed3c916c - NSString-Hashes: ddf6e856e93d3c83c5d4ef8fcdea2a96ed77c6bc - SAMLoadingView: 11b746311268140f6a2380723215fe96a6d15dee + Appirater: 8783318c36414e8de3ea023443028df94c1b784b + GoogleAnalytics-iOS-SDK: 44a1874cccd8294a0376fd8ee136f7c898c151a5 + NSString-Hashes: c3848d809e92650e4fb17db5d8cc4bd2aa1eaddd + SAMLoadingView: 7ffc4f0efe85f9717d6e367b6b93e32befe4407c SDWebImage: 71b7cdc1d1721d6a82ed62889030225f2c249e29 - STTwitter: 743ead8a65466ec0fe9b64cd2811de5590a0ed76 + STTwitter: 4fda61d0a96c707f94df85677b1a4aedbcec6fcd TTTAttributedLabel: 6f3174aef8e738f44dff97c2eb7d8184f6ab6277 -COCOAPODS: 0.36.1 +COCOAPODS: 0.36.3 From 8123614af6beda0bd4f0af7ebb27a26e5fecd766 Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 5 Apr 2015 21:15:23 +0200 Subject: [PATCH 5/8] minor fixes --- CriticalMass/PLTwitterViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index fb47cc402..41b9b0f3f 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -55,6 +55,7 @@ - (void)viewDidLoad { UINavigationItem *navItem = [[UINavigationItem alloc] init]; navItem.title = [[NSString stringWithFormat:@"%@", _twitterQuery] uppercaseString]; navBar.items = @[ navItem ]; + navBar.translucent = NO; [self.view addSubview:navBar]; // refresh control From 50a2e9fc0c424e789549b4dc3b5433e4a57da7bb Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Sun, 5 Apr 2015 22:46:41 +0200 Subject: [PATCH 6/8] refactoring; no data message --- CriticalMass/PLChatViewController.h | 7 --- CriticalMass/PLChatViewController.m | 57 +++++++++++++++----- CriticalMass/PLRulesViewController.m | 32 +++++++---- CriticalMass/PLSettingsTableViewController.m | 1 + CriticalMass/PLTwitterViewController.m | 32 ++++++++--- CriticalMass/PLUtils.m | 2 - README.md | 5 +- 7 files changed, 96 insertions(+), 40 deletions(-) diff --git a/CriticalMass/PLChatViewController.h b/CriticalMass/PLChatViewController.h index 8c8157e4c..eb9999c03 100644 --- a/CriticalMass/PLChatViewController.h +++ b/CriticalMass/PLChatViewController.h @@ -13,11 +13,4 @@ @interface PLChatViewController : UIViewController -@property (nonatomic, strong) PLChatModel *chatModel; -@property (nonatomic, strong) PLDataModel *dataModel; -@property (nonatomic, strong) UITableView *tableView; -@property (nonatomic, strong) UIView *controlView; -@property (nonatomic, strong) UITextField *textField; -@property (nonatomic, strong) HOButton *btnSend; - @end diff --git a/CriticalMass/PLChatViewController.m b/CriticalMass/PLChatViewController.m index 030fdd9ee..12dac9d3e 100644 --- a/CriticalMass/PLChatViewController.m +++ b/CriticalMass/PLChatViewController.m @@ -13,6 +13,13 @@ @interface PLChatViewController () +@property (nonatomic, strong) PLChatModel *chatModel; +@property (nonatomic, strong) PLDataModel *dataModel; +@property (nonatomic, strong) UITableView *tableView; +@property (nonatomic, strong) UIView *controlView; +@property (nonatomic, strong) UITextField *textField; +@property (nonatomic, strong) HOButton *btnSend; + @end @implementation PLChatViewController @@ -26,7 +33,7 @@ - (void)viewDidLoad { _chatModel = [PLChatModel sharedManager]; // add table - self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-140)]; + self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height-190)]; self.tableView.dataSource = self; self.tableView.delegate = self; [self.view addSubview: self.tableView]; @@ -39,7 +46,6 @@ - (void)viewDidLoad { self.controlView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-110, self.view.frame.size.width, 50)]; [self.view addSubview:self.controlView]; - // add textfield self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 240, 50)]; self.textField.layer.borderWidth = 1.0; @@ -58,6 +64,15 @@ - (void)viewDidLoad { } -(void)viewWillAppear:(BOOL)animated { + // navbar + UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; + navBar.backgroundColor = [UIColor whiteColor]; + UINavigationItem *navItem = [[UINavigationItem alloc] init]; + navItem.title = [@"Chat" uppercaseString]; + navBar.items = @[ navItem ]; + navBar.translucent = NO; + [self.view addSubview:navBar]; + [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessagesReceived) name:kNotificationChatMessagesReceived object:_chatModel]; } @@ -116,6 +131,32 @@ - (void)moveContent:(BOOL)moveUp{ #pragma mark - UITableViewDataSource Methods +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + + if (_chatModel.messages.count) { + self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; + self.tableView.backgroundView = nil; + return 1; + } else { + + // Display a message when the table is empty + UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; + + messageLabel.text = @"No chat activity at the moment..."; + messageLabel.textColor = [UIColor blackColor]; + messageLabel.numberOfLines = 0; + messageLabel.textAlignment = NSTextAlignmentCenter; + messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; + [messageLabel sizeToFit]; + + self.tableView.backgroundView = messageLabel; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; + } + + return 0; +} + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _chatModel.messages.count; @@ -123,21 +164,14 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; - if(!_chatModel.messages){ - return cell; - } - - if(!(_chatModel.messages.count > indexPath.row)){ - return cell; - } - PLChatObject *message = [_chatModel.messages objectAtIndex:indexPath.row]; cell.textLabel.text = message.text; cell.imageView.image = [UIImage imageNamed:@"Punk"]; + cell.imageView.image = [cell.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + cell.imageView.tintColor = [UIColor magicColor]; cell.imageView.frame = CGRectMake(0,0,12,12); if(message.isActive){ @@ -186,5 +220,4 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event [self.textField resignFirstResponder]; } - @end diff --git a/CriticalMass/PLRulesViewController.m b/CriticalMass/PLRulesViewController.m index dbeb12126..b9d4124df 100644 --- a/CriticalMass/PLRulesViewController.m +++ b/CriticalMass/PLRulesViewController.m @@ -24,35 +24,35 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { - _titles = [NSArray arrayWithObjects: + _titles = @[ @"Corken!?", @"Gegenverkehr", @"Sachte, Keule!", @"Keine Vollbremsungen", @"Vorne nur bei Grün", @"Locker bleiben", - @"Hab Spaß!", - nil]; + @"Hab Spaß!" + ]; - _texts = [NSArray arrayWithObjects: + _texts = @[ @"Schütze Autofahrer vor sich selbst durch corken!", @"Verzichte darauf auf der Gegenfahrbahn zu fahren.", @"Vorne: nicht rasen!\nHinten, Lücken zufahren!", @"Wenn's mal nicht anders geht, versuche die anderen per Handzeichen zu warnen.", @"Wenn du an der Spitze der Mass fährst, musst du warten bis die Ampel auf Grün schaltet.", @"Lass dich nicht provozieren. Sei freundlich zur Polizei und zu Autofahrern, auch wenn die's nicht sind.", - @"Genieße autofreie Straßen. Fahr ein bisschen mit den Sound-Rädern mit. Check die Bikes deiner Mitfahrer aus. Quatsch Autofahrer, Passanten, Mitfahrer an. Hab Spaß!", - nil]; + @"Genieße autofreie Straßen. Fahr ein bisschen mit den Sound-Rädern mit. Check die Bikes deiner Mitfahrer aus. Quatsch Autofahrer, Passanten, Mitfahrer an. Hab Spaß!" + ]; - _images = [NSArray arrayWithObjects: + _images = @[ @"Corken", @"WrongLane", @"Slowly", @"Brake", @"Green", @"Friendly", - @"Pose", - nil]; + @"Pose" + ]; } return self; } @@ -63,8 +63,16 @@ - (void)viewDidLoad [self.view setBackgroundColor:[UIColor whiteColor]]; - AccordionView *accordion = [[AccordionView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, self.view.frame.size.height-120)]; + // navbar + UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; + navBar.backgroundColor = [UIColor whiteColor]; + UINavigationItem *navItem = [[UINavigationItem alloc] init]; + navItem.title = [@"KNIGGE" uppercaseString]; + navBar.items = @[ navItem ]; + navBar.translucent = NO; + [self.view addSubview:navBar]; + AccordionView *accordion = [[AccordionView alloc] initWithFrame:CGRectMake(0, 71, self.view.frame.size.width, self.view.frame.size.height-149)]; [self.view addSubview:accordion]; for (int i=0; i < [_images count]; i++) { @@ -74,6 +82,7 @@ - (void)viewDidLoad [accordion setNeedsLayout]; [accordion setAllowsMultipleSelection:NO]; [accordion setAllowsEmptySelection:YES]; + accordion.startsClosed = YES; // add link to cm hamburg TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, self.view.frame.size.height-80, self.view.frame.size.width-20, 30)]; @@ -104,10 +113,11 @@ - (UIButton*)getHeader:(NSInteger)index { UIButton *header = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 38)]; [header setTitle:_titles[index] forState:UIControlStateNormal]; - header.titleLabel.font = [UIFont systemFontOfSize:20]; [header setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; + header.titleLabel.font = [UIFont systemFontOfSize:20]; header.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; header.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10); + header.backgroundColor = [UIColor whiteColor]; return header; } diff --git a/CriticalMass/PLSettingsTableViewController.m b/CriticalMass/PLSettingsTableViewController.m index ea2d62b03..2829ed0a8 100644 --- a/CriticalMass/PLSettingsTableViewController.m +++ b/CriticalMass/PLSettingsTableViewController.m @@ -33,6 +33,7 @@ - (id)initWithStyle:(UITableViewStyle)style - (void)viewDidLoad { [super viewDidLoad]; + self.clearsSelectionOnViewWillAppear = YES; } diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index 41b9b0f3f..bfc8d65ee 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -117,6 +117,32 @@ - (void)onRefreshPull { #pragma mark - Data source +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + + if (_statuses.count) { + tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; + tableView.backgroundView = nil; + return 1; + } else { + + // Display a message when the table is empty + UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; + + messageLabel.text = @"No data is currently available. Please pull down to refresh."; + messageLabel.textColor = [UIColor blackColor]; + messageLabel.numberOfLines = 0; + messageLabel.textAlignment = NSTextAlignmentCenter; + messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; + [messageLabel sizeToFit]; + + tableView.backgroundView = messageLabel; + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; + } + + return 0; +} + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_statuses count]; @@ -153,10 +179,4 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return 1; -} - @end diff --git a/CriticalMass/PLUtils.m b/CriticalMass/PLUtils.m index e7b9b17e6..a49f05ffa 100644 --- a/CriticalMass/PLUtils.m +++ b/CriticalMass/PLUtils.m @@ -8,8 +8,6 @@ #import "PLUtils.h" -// TODO: move to category! - @implementation PLUtils +(NSString*)locationdegrees2String:(double)degrees diff --git a/README.md b/README.md index da74faa96..82cb83cd8 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ check: http://criticalmaps.net - [ ] better design - [ ] individual fonts - [x] twitterfeed -- [ ] feedback functionality -- [ ] share functionality +- [ ] feedback mail composer +- [ ] sharing - [ ] zoom buttons +- [x] chat From 3e611055d12d63744e5e50c9e7a3950da4521ea5 Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Mon, 6 Apr 2015 12:33:39 +0200 Subject: [PATCH 7/8] minor fixes --- CriticalMass/PLChatViewController.m | 22 +++++++++++----------- CriticalMass/PLTwitterViewController.m | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CriticalMass/PLChatViewController.m b/CriticalMass/PLChatViewController.m index 12dac9d3e..39e279ad2 100644 --- a/CriticalMass/PLChatViewController.m +++ b/CriticalMass/PLChatViewController.m @@ -32,8 +32,17 @@ - (void)viewDidLoad { _dataModel = [PLDataModel sharedManager]; _chatModel = [PLChatModel sharedManager]; + // navbar + UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; + navBar.backgroundColor = [UIColor whiteColor]; + UINavigationItem *navItem = [[UINavigationItem alloc] init]; + navItem.title = [@"Chat" uppercaseString]; + navBar.items = @[ navItem ]; + navBar.translucent = NO; + [self.view addSubview:navBar]; + // add table - self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height-190)]; + self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 71, self.view.frame.size.width, self.view.frame.size.height-189)]; self.tableView.dataSource = self; self.tableView.delegate = self; [self.view addSubview: self.tableView]; @@ -64,15 +73,6 @@ - (void)viewDidLoad { } -(void)viewWillAppear:(BOOL)animated { - // navbar - UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; - navBar.backgroundColor = [UIColor whiteColor]; - UINavigationItem *navItem = [[UINavigationItem alloc] init]; - navItem.title = [@"Chat" uppercaseString]; - navBar.items = @[ navItem ]; - navBar.translucent = NO; - [self.view addSubview:navBar]; - [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessagesReceived) name:kNotificationChatMessagesReceived object:_chatModel]; } @@ -147,7 +147,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView messageLabel.textColor = [UIColor blackColor]; messageLabel.numberOfLines = 0; messageLabel.textAlignment = NSTextAlignmentCenter; - messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; +// messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; [messageLabel sizeToFit]; self.tableView.backgroundView = messageLabel; diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index bfc8d65ee..5a2ae260c 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -129,11 +129,11 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView // Display a message when the table is empty UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; - messageLabel.text = @"No data is currently available. Please pull down to refresh."; + messageLabel.text = @"No data is currently available.\nPlease pull down to refresh."; messageLabel.textColor = [UIColor blackColor]; messageLabel.numberOfLines = 0; messageLabel.textAlignment = NSTextAlignmentCenter; - messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; +// messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; [messageLabel sizeToFit]; tableView.backgroundView = messageLabel; From 65016242472ed6001d81caaabaf01ec78af5f005 Mon Sep 17 00:00:00 2001 From: Norman Sander Date: Wed, 8 Apr 2015 00:18:44 +0200 Subject: [PATCH 8/8] release --- CriticalMass/CriticalMaps-Info.plist | 4 ++-- CriticalMass/PLDataModel.m | 5 +---- CriticalMass/PLTwitterViewController.m | 21 +++++++++++++++++---- CriticalMass/UIColor+Helper.m | 1 - 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CriticalMass/CriticalMaps-Info.plist b/CriticalMass/CriticalMaps-Info.plist index abc223cb4..39c345470 100644 --- a/CriticalMass/CriticalMaps-Info.plist +++ b/CriticalMass/CriticalMaps-Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.4 + 0.6.0 CFBundleSignature ???? CFBundleVersion - 0.5.4.2 + 0.6.0.2 LSApplicationCategoryType LSRequiresIPhoneOS diff --git a/CriticalMass/PLDataModel.m b/CriticalMass/PLDataModel.m index d9d71873f..a2137f675 100644 --- a/CriticalMass/PLDataModel.m +++ b/CriticalMass/PLDataModel.m @@ -73,7 +73,6 @@ - (void)initHTTPRequestManager _operationManager = [AFHTTPRequestOperationManager manager]; _operationManager.requestSerializer = [AFJSONRequestSerializer serializer]; _operationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; - } - (void)startRequestInterval @@ -95,9 +94,7 @@ - (void)stopRequestInterval - (void)request { - _chatModel = [PLChatModel sharedManager]; - _requestCount++; NSString *longitudeString = _gpsEnabled ? [PLUtils locationdegrees2String:_currentLocation.coordinate.longitude] : @""; @@ -210,7 +207,7 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca NSLog(@"Geocode failed with error: %@", error); return; } - CLPlacemark *placemark = [placemarks objectAtIndex:0]; + CLPlacemark *placemark = placemarks.firstObject; _locality = [placemark locality]; }]; } diff --git a/CriticalMass/PLTwitterViewController.m b/CriticalMass/PLTwitterViewController.m index 5a2ae260c..b9762575e 100644 --- a/CriticalMass/PLTwitterViewController.m +++ b/CriticalMass/PLTwitterViewController.m @@ -23,6 +23,7 @@ @interface PLTwitterViewController () @property(nonatomic,strong) NSArray *statuses; @property(nonatomic,strong) PLDataModel *data; @property(nonatomic,strong) NSString *twitterQuery; +@property(nonatomic,assign) NSArray *supportedLocalities; @end @@ -31,9 +32,21 @@ @implementation PLTwitterViewController - (void)viewDidLoad { [super viewDidLoad]; + _supportedLocalities = @[ + @"berlin", + @"wien", + @"cambridge", + @"hamburg", + @"dresden", + @"köln", + @"potsdam" + ]; + _data = [PLDataModel sharedManager]; - if(_data.locality){ + if(_data.locality + && [_supportedLocalities containsObject:[_data.locality lowercaseString]]){ + _twitterQuery = [PLUtils getTwitterQueryByLocality:_data.locality]; }else{ _twitterQuery = @"#criticalmaps"; @@ -48,7 +61,7 @@ - (void)viewDidLoad { [self.view addSubview:_tableVC.tableView]; _twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"e0vyKNT3iC89SkUaIzEvX1oii" consumerSecret:@"151lpogCiUp4RhjRNZukl2tJSeGyskq37U8wmldFm9FDPfzBW8"]; - + // navbar UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; navBar.backgroundColor = [UIColor whiteColor]; @@ -71,7 +84,7 @@ - (void)viewDidLoad { -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; - [_tableVC.tableView reloadData]; + [_tableVC.tableView reloadData]; } @@ -133,7 +146,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView messageLabel.textColor = [UIColor blackColor]; messageLabel.numberOfLines = 0; messageLabel.textAlignment = NSTextAlignmentCenter; -// messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; + // messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20]; [messageLabel sizeToFit]; tableView.backgroundView = messageLabel; diff --git a/CriticalMass/UIColor+Helper.m b/CriticalMass/UIColor+Helper.m index f71e421c0..913281cb9 100644 --- a/CriticalMass/UIColor+Helper.m +++ b/CriticalMass/UIColor+Helper.m @@ -16,5 +16,4 @@ + (UIColor *)magicColor { return UIColorFromRGB(0x028a68); } - @end