diff --git a/LifeLog/LifeLog.xcodeproj/project.pbxproj b/LifeLog/LifeLog.xcodeproj/project.pbxproj index f54ce8c..a5224e3 100644 --- a/LifeLog/LifeLog.xcodeproj/project.pbxproj +++ b/LifeLog/LifeLog.xcodeproj/project.pbxproj @@ -44,6 +44,11 @@ 9CBDA0FA1F2ECE2C0055DED1 /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0F91F2ECE2C0055DED1 /* BaseViewController.m */; }; 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FD1F2F03810055DED1 /* RegisterViewController.m */; }; 9CBDA1001F2F03810055DED1 /* RegisterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FE1F2F03810055DED1 /* RegisterViewController.xib */; }; + E933E66B1F3E04A6002926F5 /* SearchGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E933E6691F3E04A6002926F5 /* SearchGroupViewController.m */; }; + E933E66C1F3E04A6002926F5 /* SearchGroupViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E933E66A1F3E04A6002926F5 /* SearchGroupViewController.xib */; }; + E933E6701F3E09B6002926F5 /* SearchGroupTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E933E66E1F3E09B6002926F5 /* SearchGroupTableViewCell.m */; }; + E933E6711F3E09B6002926F5 /* SearchGroupTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E933E66F1F3E09B6002926F5 /* SearchGroupTableViewCell.xib */; }; + E933E6741F3E0E4E002926F5 /* GroupObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E933E6731F3E0E4E002926F5 /* GroupObject.m */; }; E9373E471F3596940059355A /* AutoTransLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E461F3596940059355A /* AutoTransLabel.m */; }; E9373E4A1F35AA180059355A /* HistoryObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E491F35AA180059355A /* HistoryObject.m */; }; E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E4C1F361A230059355A /* HistoryGraphObject.m */; }; @@ -148,6 +153,14 @@ 9CBDA0FC1F2F03810055DED1 /* RegisterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterViewController.h; sourceTree = ""; }; 9CBDA0FD1F2F03810055DED1 /* RegisterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegisterViewController.m; sourceTree = ""; }; 9CBDA0FE1F2F03810055DED1 /* RegisterViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RegisterViewController.xib; sourceTree = ""; }; + E933E6681F3E04A6002926F5 /* SearchGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SearchGroupViewController.h; sourceTree = ""; }; + E933E6691F3E04A6002926F5 /* SearchGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SearchGroupViewController.m; sourceTree = ""; }; + E933E66A1F3E04A6002926F5 /* SearchGroupViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SearchGroupViewController.xib; sourceTree = ""; }; + E933E66D1F3E09B6002926F5 /* SearchGroupTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SearchGroupTableViewCell.h; sourceTree = ""; }; + E933E66E1F3E09B6002926F5 /* SearchGroupTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SearchGroupTableViewCell.m; sourceTree = ""; }; + E933E66F1F3E09B6002926F5 /* SearchGroupTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SearchGroupTableViewCell.xib; sourceTree = ""; }; + E933E6721F3E0E4E002926F5 /* GroupObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupObject.h; sourceTree = ""; }; + E933E6731F3E0E4E002926F5 /* GroupObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupObject.m; sourceTree = ""; }; E9373E451F3596940059355A /* AutoTransLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoTransLabel.h; sourceTree = ""; }; E9373E461F3596940059355A /* AutoTransLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AutoTransLabel.m; sourceTree = ""; }; E9373E481F35AA180059355A /* HistoryObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryObject.h; sourceTree = ""; }; @@ -246,6 +259,8 @@ E9373E4C1F361A230059355A /* HistoryGraphObject.m */, E9D9091F1F3D559D004CF99F /* TweetObject.h */, E9D909201F3D559D004CF99F /* TweetObject.m */, + E933E6721F3E0E4E002926F5 /* GroupObject.h */, + E933E6731F3E0E4E002926F5 /* GroupObject.m */, ); name = Model; sourceTree = ""; @@ -395,6 +410,7 @@ 6E84E3AC1F27A954001EB88E /* SNS */ = { isa = PBXGroup; children = ( + E933E6671F3E0479002926F5 /* SeachGroup */, 6E84E3BC1F27A9B1001EB88E /* SNSViewController.h */, 6E84E3BD1F27A9B1001EB88E /* SNSViewController.m */, 6E84E3BE1F27A9B1001EB88E /* SNSViewController.xib */, @@ -497,6 +513,19 @@ name = Pods; sourceTree = ""; }; + E933E6671F3E0479002926F5 /* SeachGroup */ = { + isa = PBXGroup; + children = ( + E933E6681F3E04A6002926F5 /* SearchGroupViewController.h */, + E933E6691F3E04A6002926F5 /* SearchGroupViewController.m */, + E933E66A1F3E04A6002926F5 /* SearchGroupViewController.xib */, + E933E66D1F3E09B6002926F5 /* SearchGroupTableViewCell.h */, + E933E66E1F3E09B6002926F5 /* SearchGroupTableViewCell.m */, + E933E66F1F3E09B6002926F5 /* SearchGroupTableViewCell.xib */, + ); + name = SeachGroup; + sourceTree = ""; + }; E9373E441F35966D0059355A /* AutoTranslateView */ = { isa = PBXGroup; children = ( @@ -647,6 +676,7 @@ 9CA8AEEB1F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib in Resources */, 6E84E3C01F27A9B1001EB88E /* SNSViewController.xib in Resources */, E9682E2F1F39675A00FE05A2 /* RankingTableViewCell.xib in Resources */, + E933E6711F3E09B6002926F5 /* SearchGroupTableViewCell.xib in Resources */, 6E8DA0F81F2BAC3500CCE941 /* TodayViewController.xib in Resources */, 6E84E3841F27A701001EB88E /* LaunchScreen.storyboard in Resources */, 6E84E3811F27A701001EB88E /* Assets.xcassets in Resources */, @@ -654,6 +684,7 @@ 6EF1630A1F29069300DA306C /* Localizable.strings in Resources */, 6E84E3B11F27A975001EB88E /* HomeViewController.xib in Resources */, 6E84E3B61F27A98B001EB88E /* HistoryViewController.xib in Resources */, + E933E66C1F3E04A6002926F5 /* SearchGroupViewController.xib in Resources */, E96855121F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.xib in Resources */, E99E13B21F33720600C78787 /* LabelCollectionViewCell.xib in Resources */, E9F73DCD1F338A0F004A3A6F /* HistoryListTableViewCell.xib in Resources */, @@ -733,6 +764,7 @@ 6E7F93431F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m in Sources */, 6E7F93421F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m in Sources */, E968550A1F3C444900317CEF /* AutoTransButton.m in Sources */, + E933E6741F3E0E4E002926F5 /* GroupObject.m in Sources */, 9CBDA0FA1F2ECE2C0055DED1 /* BaseViewController.m in Sources */, 6E8DA0F71F2BAC3400CCE941 /* TodayViewController.m in Sources */, 6E7F93451F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m in Sources */, @@ -759,8 +791,10 @@ 6E18CED31F2E39DB0029891F /* LoginViewController.m in Sources */, E9D909241F3D6E8C004CF99F /* BaseTableViewController.m in Sources */, 6E84E3761F27A701001EB88E /* main.m in Sources */, + E933E6701F3E09B6002926F5 /* SearchGroupTableViewCell.m in Sources */, 6E84E3B51F27A98B001EB88E /* HistoryViewController.m in Sources */, E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */, + E933E66B1F3E04A6002926F5 /* SearchGroupViewController.m in Sources */, 6E84E3BF1F27A9B1001EB88E /* SNSViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LifeLog/LifeLog/Entities.h b/LifeLog/LifeLog/Entities.h index 8e88afd..d639ce2 100644 --- a/LifeLog/LifeLog/Entities.h +++ b/LifeLog/LifeLog/Entities.h @@ -11,6 +11,7 @@ #import +#import "GroupObject.h" #import "TweetObject.h" #import "HistoryGraphObject.h" #import "HistoryObject.h" diff --git a/LifeLog/LifeLog/GroupObject.h b/LifeLog/LifeLog/GroupObject.h new file mode 100644 index 0000000..1200105 --- /dev/null +++ b/LifeLog/LifeLog/GroupObject.h @@ -0,0 +1,29 @@ +// +// GroupObject.h +// LifeLog +// +// Created by nvtu on 8/11/17. +// Copyright © 2017 PhongNV. All rights reserved. +// + +#import + +@interface GroupObject : NSObject + +@property (nonatomic) int groupID; +@property (nonatomic) int numSearch; + +@property (nonatomic) BOOL walkMode; +@property (nonatomic) BOOL runMode; +@property (nonatomic) BOOL bikeMode; +@property (nonatomic) BOOL stepMode; +@property (nonatomic) BOOL gymMode; +@property (nonatomic) BOOL beginMode; + +@property (nonatomic, strong) NSString * name; +@property (nonatomic, strong) NSString * avatar; +@property (nonatomic, strong) NSDate * createDate; + +-(id) initWithData : (NSDictionary *) dict; + +@end diff --git a/LifeLog/LifeLog/GroupObject.m b/LifeLog/LifeLog/GroupObject.m new file mode 100644 index 0000000..a49ca19 --- /dev/null +++ b/LifeLog/LifeLog/GroupObject.m @@ -0,0 +1,55 @@ +// +// GroupObject.m +// LifeLog +// +// Created by nvtu on 8/11/17. +// Copyright © 2017 PhongNV. All rights reserved. +// + +#import "GroupObject.h" +#import "Utilities.h" + +@implementation GroupObject + +-(id) initWithData : (NSDictionary *) dict { + if([dict objectForKey:@"group_id"] != nil) { + self.groupID = [dict[@"group_id"] intValue]; + } + if([dict objectForKey:@"group_name"] != nil) { + self.name = dict[@"group_name"]; + } + if([dict objectForKey:@"group_avatar"] != nil) { + self.avatar = dict[@"group_avatar"]; + } + if([dict objectForKey:@"walk_mode_active"] != nil && ![[dict objectForKey:@"walk_mode_active"] isKindOfClass:[NSNull class]]) { + self.walkMode = [dict[@"walk_mode_active"] boolValue]; + } + if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { + self.runMode = [dict[@"run_mode_active"] boolValue]; + } + if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { + self.bikeMode = [dict[@"bike_mode_active"] boolValue]; + } + if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { + self.stepMode = [dict[@"step_mode_active"] boolValue]; + } + if([dict objectForKey:@"gym_mode_active"] != nil && ![[dict objectForKey:@"gym_mode_active"] isKindOfClass:[NSNull class]]) { + self.gymMode = [dict[@"gym_mode_active"] boolValue]; + } + if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { + self.beginMode = [dict[@"beginer_mode_active"] boolValue]; + } + if([dict objectForKey:@"created_at"] != nil) { + NSString *dateString = dict[@"created_at"]; + self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; + } + else { + self.createDate = [NSDate date]; + } + if([dict objectForKey:@"num_search"] != nil) { + self.numSearch = [dict[@"num_search"] intValue]; + } + return self; +} + +@end diff --git a/LifeLog/LifeLog/Localizable.strings b/LifeLog/LifeLog/Localizable.strings index 9d1a528e4b2a4588da26d8d1ca3980d5e43c4f67..906a3654b4b04065e7d536d62d1b21ad1ffdaa2f 100644 GIT binary patch delta 164 zcmZow{Gha + #import "ServerAPI.h" #import "Utilities.h" -#import + +#import "SNSRecentTopicTableViewCell.h" +#import "SearchGroupViewController.h" @interface SNSViewController () @@ -34,6 +38,11 @@ // Dispose of any resources that can be recreated. } +#pragma mark IBAction +- (IBAction)clickRecommendGroup:(id)sender { + SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; + [self.navigationController pushViewController:search animated:true]; +} #pragma mark UITableView Delegate - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/LifeLog/LifeLog/SNSViewController.xib b/LifeLog/LifeLog/SNSViewController.xib index 4ce2961..a80e9f4 100644 --- a/LifeLog/LifeLog/SNSViewController.xib +++ b/LifeLog/LifeLog/SNSViewController.xib @@ -1,10 +1,10 @@ - + - + @@ -80,6 +80,9 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LifeLog/LifeLog/ServerAPI.h b/LifeLog/LifeLog/ServerAPI.h index 264b18e..3e76595 100644 --- a/LifeLog/LifeLog/ServerAPI.h +++ b/LifeLog/LifeLog/ServerAPI.h @@ -29,4 +29,5 @@ extern NSString *const kToken; #pragma mark - SNS Screen Function - (void) requestRecentlyTweetsList:(NSString *)token withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; +- (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; @end diff --git a/LifeLog/LifeLog/ServerAPI.m b/LifeLog/LifeLog/ServerAPI.m index 437c6a3..fe6ccbc 100644 --- a/LifeLog/LifeLog/ServerAPI.m +++ b/LifeLog/LifeLog/ServerAPI.m @@ -37,6 +37,8 @@ NSString *const kToken = @"KEY_TOKEN"; @implementation ServerAPI static ServerAPI *_server = nil; +NSURLSessionDataTask * searchTask; + @synthesize timeOutInterval = _timeOutInterval; + (instancetype)server @@ -438,6 +440,52 @@ static ServerAPI *_server = nil; }]; } +- (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { + NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; + NSLog(@"searchGroup link %@ page %d", url, page); + if(searchTask != nil) { + [searchTask cancel]; + } + + searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { + searchTask = nil; + if (completion == NULL) { + return ; + } + + if (error == nil) + { + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; + NSLog(@"%@", dataResult); + int status = [dataResult[@"status"] intValue]; + if (status == 1) { // status = 1 success + if(dataResult[@"result"] != nil) { + NSArray * array = dataResult[@"result"]; + NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; + for(NSDictionary * dict in array) { + GroupObject * object = [[GroupObject alloc] initWithData:dict]; + [arrayTweets addObject:object]; + } + completion(arrayTweets, nil); + } + else { + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; + completion(nil, errorObject); + } + } + else { + NSString *message = dataResult[@"message"]; + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; + completion(nil, errorObject); + } + } + else + { + completion(nil, error); + } + }]; +} + #pragma mark - Private Function - (NSData *) _encodeDictionary: (NSDictionary *) dictionary { @@ -453,7 +501,7 @@ static ServerAPI *_server = nil; return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; } -- (void) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion +- (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; request.HTTPMethod = method; @@ -488,8 +536,8 @@ static ServerAPI *_server = nil; completion(nil, error); } }]; - [task resume]; + return task; } @end diff --git a/LifeLog/LifeLog/TweetObject.m b/LifeLog/LifeLog/TweetObject.m index 00f5f0c..73539d9 100644 --- a/LifeLog/LifeLog/TweetObject.m +++ b/LifeLog/LifeLog/TweetObject.m @@ -51,9 +51,6 @@ self.avatarLink = dict[@"profile_image"]; } if([dict objectForKey:@"created_at"] != nil) { - self.createDate = dict[@"created_at"]; - } - if([dict objectForKey:@"created_at"] != nil) { NSString *dateString = dict[@"created_at"]; self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; }