Commit da40f74562216b71a4de342a9c2f80b10d2dfe20
1 parent
7fc917f3b6
Exists in
master
and in
1 other branch
Finish group detail screen, load tweet list, friend list, join group
Showing 8 changed files with 132 additions and 35 deletions Inline Diff
LifeLog/LifeLog/GroupDetailViewController.m
1 | // | 1 | // |
2 | // GroupDetailViewController.m | 2 | // GroupDetailViewController.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by nvtu on 8/13/17. | 5 | // Created by nvtu on 8/13/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "GroupDetailViewController.h" | 9 | #import "GroupDetailViewController.h" |
10 | #import <SDWebImage/UIImageView+WebCache.h> | 10 | #import <SDWebImage/UIImageView+WebCache.h> |
11 | 11 | ||
12 | #import "Utilities.h" | 12 | #import "Utilities.h" |
13 | #import "ServerAPI.h" | 13 | #import "ServerAPI.h" |
14 | #import "SNSRecentTopicTableViewCell.h" | 14 | #import "SNSRecentTopicTableViewCell.h" |
15 | 15 | ||
16 | @interface GroupDetailViewController () | 16 | @interface GroupDetailViewController () |
17 | 17 | ||
18 | @end | 18 | @end |
19 | 19 | ||
20 | @implementation GroupDetailViewController | 20 | @implementation GroupDetailViewController |
21 | 21 | ||
22 | - (void)viewDidLoad { | 22 | - (void)viewDidLoad { |
23 | [super viewDidLoad]; | 23 | [super viewDidLoad]; |
24 | isMemberList = false; | 24 | isMemberList = false; |
25 | //register nib for table view | 25 | //register nib for table view |
26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
27 | if(_curGroup != nil) { | 27 | if(_curGroup != nil) { |
28 | [self requestGroupDetail]; | 28 | [self requestGroupDetail]; |
29 | } | 29 | } |
30 | // Do any additional setup after loading the view from its nib. | 30 | // Do any additional setup after loading the view from its nib. |
31 | } | 31 | } |
32 | 32 | ||
33 | - (void)didReceiveMemoryWarning { | 33 | - (void)didReceiveMemoryWarning { |
34 | [super didReceiveMemoryWarning]; | 34 | [super didReceiveMemoryWarning]; |
35 | // Dispose of any resources that can be recreated. | 35 | // Dispose of any resources that can be recreated. |
36 | } | 36 | } |
37 | 37 | ||
38 | - (void) setGroup : (GroupObject *) object { | 38 | - (void) setGroup : (GroupObject *) object { |
39 | _curGroup = object; | 39 | _curGroup = object; |
40 | } | 40 | } |
41 | 41 | ||
42 | - (void)setupView { | 42 | - (void)setupView { |
43 | if(_curGroup != nil) { | 43 | if(_curGroup != nil) { |
44 | if(_curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { | 44 | if(_curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { |
45 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; | 45 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; |
46 | } | 46 | } |
47 | [self.lblGrpName setText:_curGroup.name]; | 47 | [self.lblGrpName setText:_curGroup.name]; |
48 | [self.lblGrpGoal setText:_curGroup.goal]; | 48 | [self.lblGrpGoal setText:_curGroup.goal]; |
49 | [self.btJoinGrp setHidden:_curGroup.isJoin]; | 49 | [self.btJoinGrp setHidden:_curGroup.isJoin]; |
50 | NSString *mode = @""; | 50 | NSString *mode = @""; |
51 | if(_curGroup.runMode) { | 51 | if(_curGroup.runMode) { |
52 | mode = [mode stringByAppendingString:@"ランニング\n"]; | 52 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.running", nil)]; |
53 | mode = [mode stringByAppendingString:@"\n"]; | ||
53 | } | 54 | } |
54 | if(_curGroup.walkMode) { | 55 | if(_curGroup.walkMode) { |
55 | mode = [mode stringByAppendingString:@"ウォーキング\n"]; | 56 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.walking", nil)]; |
57 | mode = [mode stringByAppendingString:@"\n"]; | ||
56 | } | 58 | } |
57 | if(_curGroup.bikeMode) { | 59 | if(_curGroup.bikeMode) { |
58 | mode = [mode stringByAppendingString:@"バイク\n"]; | 60 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.bike", nil)]; |
61 | mode = [mode stringByAppendingString:@"\n"]; | ||
59 | } | 62 | } |
63 | if(_curGroup.stepMode) { | ||
64 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.step", nil)]; | ||
65 | mode = [mode stringByAppendingString:@"\n"]; | ||
66 | } | ||
67 | if(_curGroup.beginMode) { | ||
68 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.begin", nil)]; | ||
69 | mode = [mode stringByAppendingString:@"\n"]; | ||
70 | } | ||
71 | if(_curGroup.gymMode) { | ||
72 | mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.gym", nil)]; | ||
73 | mode = [mode stringByAppendingString:@"\n"]; | ||
74 | } | ||
75 | NSRange range = [mode rangeOfString:@"\n" options:NSBackwardsSearch]; | ||
76 | if(range.length > 0) { | ||
77 | mode = [mode stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:NSBackwardsSearch range:range]; | ||
78 | } | ||
60 | self.lbbGrpActiveMode.text = mode; | 79 | self.lbbGrpActiveMode.text = mode; |
61 | } | 80 | } |
62 | } | 81 | } |
63 | #pragma mark IBAction | 82 | #pragma mark IBAction |
64 | 83 | ||
65 | - (IBAction)clickBack:(id)sender { | 84 | - (IBAction)clickBack:(id)sender { |
66 | [self.navigationController popViewControllerAnimated:true]; | 85 | [self.navigationController popViewControllerAnimated:true]; |
67 | } | 86 | } |
68 | 87 | ||
69 | - (IBAction)clickSwitch:(AutoTransButton *)sender { | 88 | - (IBAction)clickSwitch:(AutoTransButton *)sender { |
70 | isMemberList = !isMemberList; | 89 | isMemberList = !isMemberList; |
90 | if(isMemberList) { | ||
91 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; | ||
92 | } | ||
93 | else { | ||
94 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; | ||
95 | } | ||
96 | [sender setUserInteractionEnabled:false]; | ||
71 | [self resetData]; | 97 | [self resetData]; |
72 | } | 98 | } |
73 | 99 | ||
74 | - (IBAction)clickJoin:(AutoTransButton *)sender { | 100 | - (IBAction)clickJoin:(AutoTransButton *)sender { |
75 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 101 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
76 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 102 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
77 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 103 | [[ServerAPI server] requestJoinGroup:token groupID:_curGroup.groupID CompletionHandler:^(NSError *error){ |
104 | GroupDetailViewController __weak *weakSelf = self; | ||
78 | dispatch_async(dispatch_get_main_queue(), ^{ | 105 | dispatch_async(dispatch_get_main_queue(), ^{ |
79 | if(hudView != nil) { | 106 | [hudView hideAnimated:true]; |
80 | [hudView hideAnimated:true]; | 107 | if(error == nil) { |
108 | _curGroup.isJoin = true; | ||
109 | [weakSelf.btJoinGrp setHidden:_curGroup.isJoin]; | ||
81 | } | 110 | } |
82 | }); | 111 | }); |
83 | }]; | 112 | }]; |
113 | |||
84 | } | 114 | } |
85 | 115 | ||
86 | 116 | ||
87 | 117 | ||
88 | #pragma mark UITableView Delegate | 118 | #pragma mark UITableView Delegate |
89 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 119 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
90 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 120 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
91 | if(isMemberList) { | 121 | if(isMemberList) { |
92 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; | 122 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
93 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 123 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
94 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 124 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
95 | } | 125 | } |
126 | else { | ||
127 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
128 | } | ||
96 | cell.lblUsername.text = @""; | 129 | cell.lblUsername.text = @""; |
97 | cell.lblDateTime.text = @""; | 130 | cell.lblDateTime.text = @""; |
98 | cell.lblDes.text = object.userName; | 131 | cell.lblDes.text = object.userName; |
99 | cell.lblMode.text = @""; | 132 | cell.lblMode.text = @""; |
100 | cell.lblDistance.text = @""; | 133 | cell.lblDistance.text = @""; |
101 | cell.lblDuration.text = @""; | 134 | cell.lblDuration.text = @""; |
102 | } | 135 | } |
103 | else { | 136 | else { |
104 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 137 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
105 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 138 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
106 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 139 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
107 | } | 140 | } |
141 | else { | ||
142 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
143 | } | ||
108 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 144 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; |
109 | cell.lblUsername.text = object.userName; | 145 | cell.lblUsername.text = object.userName; |
110 | cell.lblDes.text = object.content; | 146 | cell.lblDes.text = object.content; |
111 | cell.lblMode.text = object.mode; | 147 | cell.lblMode.text = object.mode; |
112 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 148 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
113 | cell.lblDuration.text = object.time; | 149 | cell.lblDuration.text = object.time; |
114 | } | 150 | } |
115 | 151 | ||
116 | return cell; | 152 | return cell; |
117 | } | 153 | } |
118 | 154 | ||
119 | #pragma mark Private Function | 155 | #pragma mark Private Function |
120 | 156 | ||
121 | - (void) requestGroupDetail { | 157 | - (void) requestGroupDetail { |
122 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 158 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
123 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 159 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
124 | [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { | 160 | [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { |
125 | GroupDetailViewController __weak *weakSelf = self; | 161 | GroupDetailViewController __weak *weakSelf = self; |
126 | _curGroup = object; | 162 | [_curGroup updateDate:object]; |
127 | dispatch_async(dispatch_get_main_queue(), ^{ | 163 | dispatch_async(dispatch_get_main_queue(), ^{ |
128 | [hudView hideAnimated:true]; | 164 | [hudView hideAnimated:true]; |
129 | [weakSelf setupView]; | 165 | [weakSelf setupView]; |
130 | [weakSelf callRequestToUpdateData]; | 166 | [weakSelf callRequestToUpdateData]; |
131 | }); | 167 | }); |
132 | }]; | 168 | }]; |
133 | } | 169 | } |
134 | 170 | ||
135 | -(void) callRequestToUpdateData { | 171 | -(void) callRequestToUpdateData { |
136 | [super callRequestToUpdateData]; | 172 | [super callRequestToUpdateData]; |
137 | 173 | ||
138 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 174 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
139 | MBProgressHUD *hudView = nil; | 175 | MBProgressHUD *hudView = nil; |
140 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 176 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
141 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 177 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
142 | } | 178 | } |
143 | if(isMemberList) { | 179 | if(isMemberList) { |
144 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 180 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
145 | dispatch_async(dispatch_get_main_queue(), ^{ | 181 | dispatch_async(dispatch_get_main_queue(), ^{ |
146 | if(hudView != nil) { | 182 | if(hudView != nil) { |
147 | [hudView hideAnimated:true]; | 183 | [hudView hideAnimated:true]; |
148 | } | 184 | } |
149 | }); | 185 | }); |
150 | GroupDetailViewController __weak *weakSelf = self; | 186 | GroupDetailViewController __weak *weakSelf = self; |
151 | [weakSelf updateTableData:array error:error]; | 187 | [weakSelf updateTableData:array error:error]; |
188 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | ||
152 | }]; | 189 | }]; |
153 | } | 190 | } |
154 | else { | 191 | else { |
155 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 192 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
156 | dispatch_async(dispatch_get_main_queue(), ^{ | 193 | dispatch_async(dispatch_get_main_queue(), ^{ |
157 | if(hudView != nil) { | 194 | if(hudView != nil) { |
158 | [hudView hideAnimated:true]; | 195 | [hudView hideAnimated:true]; |
159 | } | 196 | } |
160 | }); | 197 | }); |
161 | GroupDetailViewController __weak *weakSelf = self; | 198 | GroupDetailViewController __weak *weakSelf = self; |
162 | [weakSelf updateTableData:array error:error]; | 199 | [weakSelf updateTableData:array error:error]; |
200 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | ||
163 | }]; | 201 | }]; |
164 | } | 202 | } |
165 | } | 203 | } |
166 | 204 | ||
167 | @end | 205 | @end |
168 | 206 |
LifeLog/LifeLog/GroupDetailViewController.xib
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | 2 | <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> |
3 | <device id="retina4_7" orientation="portrait"> | 3 | <device id="retina4_7" orientation="portrait"> |
4 | <adaptation id="fullscreen"/> | 4 | <adaptation id="fullscreen"/> |
5 | </device> | 5 | </device> |
6 | <dependencies> | 6 | <dependencies> |
7 | <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> | 7 | <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/> |
8 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | 8 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
9 | </dependencies> | 9 | </dependencies> |
10 | <objects> | 10 | <objects> |
11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="GroupDetailViewController"> | 11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="GroupDetailViewController"> |
12 | <connections> | 12 | <connections> |
13 | <outlet property="btJoinGrp" destination="caN-x7-hJz" id="B17-YC-Rmk"/> | 13 | <outlet property="btJoinGrp" destination="caN-x7-hJz" id="B17-YC-Rmk"/> |
14 | <outlet property="btSwitch" destination="gBg-k9-tgw" id="3ZZ-Qb-d3a"/> | 14 | <outlet property="btSwitch" destination="gBg-k9-tgw" id="3ZZ-Qb-d3a"/> |
15 | <outlet property="imgAva" destination="qYg-Gw-R2b" id="f9w-A2-u4G"/> | 15 | <outlet property="imgAva" destination="qYg-Gw-R2b" id="f9w-A2-u4G"/> |
16 | <outlet property="lbbGrpActiveMode" destination="O8z-6V-YFd" id="s8J-3i-pW3"/> | 16 | <outlet property="lbbGrpActiveMode" destination="O8z-6V-YFd" id="s8J-3i-pW3"/> |
17 | <outlet property="lblGrpGoal" destination="Bdy-dI-j47" id="AKx-8y-Ifm"/> | 17 | <outlet property="lblGrpGoal" destination="Bdy-dI-j47" id="AKx-8y-Ifm"/> |
18 | <outlet property="lblGrpName" destination="YWV-pS-TCo" id="VeU-Ov-uSD"/> | 18 | <outlet property="lblGrpName" destination="YWV-pS-TCo" id="VeU-Ov-uSD"/> |
19 | <outlet property="tableBase" destination="4VU-Ye-7Au" id="m1e-cS-Sxf"/> | 19 | <outlet property="tableBase" destination="4VU-Ye-7Au" id="m1e-cS-Sxf"/> |
20 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | 20 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
21 | </connections> | 21 | </connections> |
22 | </placeholder> | 22 | </placeholder> |
23 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | 23 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
24 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | 24 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> |
25 | <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | 25 | <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> |
26 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | 26 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
27 | <subviews> | 27 | <subviews> |
28 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="25d-3H-0fr" userLabel="ViewHeader"> | 28 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="25d-3H-0fr" userLabel="ViewHeader"> |
29 | <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> | 29 | <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> |
30 | <subviews> | 30 | <subviews> |
31 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SNS" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DxD-Cy-0wi" customClass="AutoTransLabel"> | 31 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SNS" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DxD-Cy-0wi" customClass="AutoTransLabel"> |
32 | <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> | 32 | <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> |
33 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 33 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
34 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 34 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
35 | <nil key="highlightedColor"/> | 35 | <nil key="highlightedColor"/> |
36 | <userDefinedRuntimeAttributes> | 36 | <userDefinedRuntimeAttributes> |
37 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.title"/> | 37 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.title"/> |
38 | </userDefinedRuntimeAttributes> | 38 | </userDefinedRuntimeAttributes> |
39 | </label> | 39 | </label> |
40 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O3M-Ba-zHF"> | 40 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O3M-Ba-zHF"> |
41 | <rect key="frame" x="0.0" y="5" width="70" height="36"/> | 41 | <rect key="frame" x="0.0" y="5" width="70" height="36"/> |
42 | <constraints> | 42 | <constraints> |
43 | <constraint firstAttribute="width" constant="70" id="2Mk-ly-c0t"/> | 43 | <constraint firstAttribute="width" constant="70" id="2Mk-ly-c0t"/> |
44 | </constraints> | 44 | </constraints> |
45 | <state key="normal" image="today_back_button"/> | 45 | <state key="normal" image="today_back_button"/> |
46 | <connections> | 46 | <connections> |
47 | <action selector="clickBack:" destination="-1" eventType="touchUpInside" id="gS4-F3-fzi"/> | 47 | <action selector="clickBack:" destination="-1" eventType="touchUpInside" id="gS4-F3-fzi"/> |
48 | </connections> | 48 | </connections> |
49 | </button> | 49 | </button> |
50 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y09-DG-Krp"> | 50 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y09-DG-Krp"> |
51 | <rect key="frame" x="330" y="0.0" width="45" height="46"/> | 51 | <rect key="frame" x="330" y="0.0" width="45" height="46"/> |
52 | <constraints> | 52 | <constraints> |
53 | <constraint firstAttribute="width" constant="45" id="hHa-aE-1zd"/> | 53 | <constraint firstAttribute="width" constant="45" id="hHa-aE-1zd"/> |
54 | </constraints> | 54 | </constraints> |
55 | <state key="normal" image="icon_menu"/> | 55 | <state key="normal" image="icon_menu"/> |
56 | </button> | 56 | </button> |
57 | </subviews> | 57 | </subviews> |
58 | <color key="backgroundColor" red="0.098039215690000001" green="0.098039215690000001" blue="0.098039215690000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | 58 | <color key="backgroundColor" red="0.098039215690000001" green="0.098039215690000001" blue="0.098039215690000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
59 | <constraints> | 59 | <constraints> |
60 | <constraint firstItem="y09-DG-Krp" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" id="65z-ZM-a3D"/> | 60 | <constraint firstItem="y09-DG-Krp" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" id="65z-ZM-a3D"/> |
61 | <constraint firstItem="O3M-Ba-zHF" firstAttribute="leading" secondItem="25d-3H-0fr" secondAttribute="leading" id="CQk-IB-W9y"/> | 61 | <constraint firstItem="O3M-Ba-zHF" firstAttribute="leading" secondItem="25d-3H-0fr" secondAttribute="leading" id="CQk-IB-W9y"/> |
62 | <constraint firstAttribute="bottom" secondItem="y09-DG-Krp" secondAttribute="bottom" id="IWC-4b-gp6"/> | 62 | <constraint firstAttribute="bottom" secondItem="y09-DG-Krp" secondAttribute="bottom" id="IWC-4b-gp6"/> |
63 | <constraint firstItem="O3M-Ba-zHF" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" constant="5" id="JWL-bD-I2Z"/> | 63 | <constraint firstItem="O3M-Ba-zHF" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" constant="5" id="JWL-bD-I2Z"/> |
64 | <constraint firstItem="DxD-Cy-0wi" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" id="WYM-oV-6xn"/> | 64 | <constraint firstItem="DxD-Cy-0wi" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="top" id="WYM-oV-6xn"/> |
65 | <constraint firstAttribute="bottom" secondItem="O3M-Ba-zHF" secondAttribute="bottom" constant="5" id="ZA0-Bo-IQF"/> | 65 | <constraint firstAttribute="bottom" secondItem="O3M-Ba-zHF" secondAttribute="bottom" constant="5" id="ZA0-Bo-IQF"/> |
66 | <constraint firstItem="DxD-Cy-0wi" firstAttribute="leading" secondItem="25d-3H-0fr" secondAttribute="leading" id="cbx-fE-OaR"/> | 66 | <constraint firstItem="DxD-Cy-0wi" firstAttribute="leading" secondItem="25d-3H-0fr" secondAttribute="leading" id="cbx-fE-OaR"/> |
67 | <constraint firstAttribute="trailing" secondItem="DxD-Cy-0wi" secondAttribute="trailing" id="i0L-w8-Oxm"/> | 67 | <constraint firstAttribute="trailing" secondItem="DxD-Cy-0wi" secondAttribute="trailing" id="i0L-w8-Oxm"/> |
68 | <constraint firstAttribute="trailing" secondItem="y09-DG-Krp" secondAttribute="trailing" id="nNZ-jP-k6U"/> | 68 | <constraint firstAttribute="trailing" secondItem="y09-DG-Krp" secondAttribute="trailing" id="nNZ-jP-k6U"/> |
69 | <constraint firstAttribute="bottom" secondItem="DxD-Cy-0wi" secondAttribute="bottom" id="oxP-oa-3FJ"/> | 69 | <constraint firstAttribute="bottom" secondItem="DxD-Cy-0wi" secondAttribute="bottom" id="oxP-oa-3FJ"/> |
70 | <constraint firstAttribute="height" constant="46" id="u2G-4s-RB5"/> | 70 | <constraint firstAttribute="height" constant="46" id="u2G-4s-RB5"/> |
71 | </constraints> | 71 | </constraints> |
72 | </view> | 72 | </view> |
73 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YWV-pS-TCo"> | 73 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YWV-pS-TCo"> |
74 | <rect key="frame" x="15" y="54" width="345" height="21"/> | 74 | <rect key="frame" x="15" y="54" width="345" height="21"/> |
75 | <constraints> | 75 | <constraints> |
76 | <constraint firstAttribute="height" constant="21" id="fQO-ja-W9R"/> | 76 | <constraint firstAttribute="height" constant="21" id="fQO-ja-W9R"/> |
77 | </constraints> | 77 | </constraints> |
78 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 78 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
79 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 79 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
80 | <nil key="highlightedColor"/> | 80 | <nil key="highlightedColor"/> |
81 | </label> | 81 | </label> |
82 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="O8z-6V-YFd"> | 82 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="O8z-6V-YFd"> |
83 | <rect key="frame" x="15" y="85" width="243" height="60"/> | 83 | <rect key="frame" x="15" y="85" width="243" height="60"/> |
84 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 84 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
85 | <constraints> | 85 | <constraints> |
86 | <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="60" id="Bid-NM-Ree"/> | 86 | <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="60" id="Bid-NM-Ree"/> |
87 | </constraints> | 87 | </constraints> |
88 | <fontDescription key="fontDescription" type="system" pointSize="14"/> | 88 | <fontDescription key="fontDescription" type="system" pointSize="14"/> |
89 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 89 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
90 | <nil key="highlightedColor"/> | 90 | <nil key="highlightedColor"/> |
91 | </label> | 91 | </label> |
92 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bdy-dI-j47"> | 92 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bdy-dI-j47"> |
93 | <rect key="frame" x="15" y="160" width="345" height="80"/> | 93 | <rect key="frame" x="15" y="160" width="345" height="80"/> |
94 | <constraints> | 94 | <constraints> |
95 | <constraint firstAttribute="height" constant="80" id="jgH-57-Bae"/> | 95 | <constraint firstAttribute="height" constant="80" id="jgH-57-Bae"/> |
96 | </constraints> | 96 | </constraints> |
97 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 97 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
98 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 98 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
99 | <nil key="highlightedColor"/> | 99 | <nil key="highlightedColor"/> |
100 | </label> | 100 | </label> |
101 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="qYg-Gw-R2b"> | 101 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="qYg-Gw-R2b"> |
102 | <rect key="frame" x="280" y="85" width="80" height="60"/> | 102 | <rect key="frame" x="280" y="85" width="80" height="60"/> |
103 | <constraints> | 103 | <constraints> |
104 | <constraint firstAttribute="width" constant="80" id="NEk-vg-zus"/> | 104 | <constraint firstAttribute="width" constant="80" id="NEk-vg-zus"/> |
105 | <constraint firstAttribute="height" constant="60" id="qlv-ht-SUw"/> | 105 | <constraint firstAttribute="height" constant="60" id="qlv-ht-SUw"/> |
106 | </constraints> | 106 | </constraints> |
107 | </imageView> | 107 | </imageView> |
108 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gBg-k9-tgw" customClass="AutoTransButton"> | 108 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gBg-k9-tgw" customClass="AutoTransButton"> |
109 | <rect key="frame" x="15" y="270" width="162" height="30"/> | 109 | <rect key="frame" x="15" y="270" width="162" height="30"/> |
110 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | 110 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
111 | <constraints> | 111 | <constraints> |
112 | <constraint firstAttribute="height" constant="30" id="6Ir-ZZ-NOb"/> | 112 | <constraint firstAttribute="height" constant="30" id="6Ir-ZZ-NOb"/> |
113 | </constraints> | 113 | </constraints> |
114 | <state key="normal" title="メンバーを見る"> | 114 | <state key="normal" title="メンバーを見る"> |
115 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 115 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
116 | </state> | 116 | </state> |
117 | <userDefinedRuntimeAttributes> | 117 | <userDefinedRuntimeAttributes> |
118 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | 118 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
119 | <integer key="value" value="5"/> | 119 | <integer key="value" value="5"/> |
120 | </userDefinedRuntimeAttribute> | 120 | </userDefinedRuntimeAttribute> |
121 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.viewMem"/> | 121 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.viewMem"/> |
122 | </userDefinedRuntimeAttributes> | 122 | </userDefinedRuntimeAttributes> |
123 | <connections> | 123 | <connections> |
124 | <action selector="clickSwitch:" destination="-1" eventType="touchUpInside" id="z4V-ym-fqS"/> | 124 | <action selector="clickSwitch:" destination="-1" eventType="touchUpInside" id="z4V-ym-fqS"/> |
125 | </connections> | 125 | </connections> |
126 | </button> | 126 | </button> |
127 | <button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caN-x7-hJz" customClass="AutoTransButton"> | 127 | <button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caN-x7-hJz" customClass="AutoTransButton"> |
128 | <rect key="frame" x="197" y="270" width="162" height="30"/> | 128 | <rect key="frame" x="197" y="270" width="162" height="30"/> |
129 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | 129 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
130 | <constraints> | 130 | <constraints> |
131 | <constraint firstAttribute="height" constant="30" id="gIs-Km-dbx"/> | 131 | <constraint firstAttribute="height" constant="30" id="gIs-Km-dbx"/> |
132 | </constraints> | 132 | </constraints> |
133 | <state key="normal" title="グループに参加する"> | 133 | <state key="normal" title="グループに参加する"> |
134 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 134 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
135 | </state> | 135 | </state> |
136 | <userDefinedRuntimeAttributes> | 136 | <userDefinedRuntimeAttributes> |
137 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | 137 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
138 | <integer key="value" value="5"/> | 138 | <integer key="value" value="5"/> |
139 | </userDefinedRuntimeAttribute> | 139 | </userDefinedRuntimeAttribute> |
140 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.joinGr"/> | 140 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.joinGr"/> |
141 | </userDefinedRuntimeAttributes> | 141 | </userDefinedRuntimeAttributes> |
142 | <connections> | 142 | <connections> |
143 | <action selector="clickJoin:" destination="-1" eventType="touchUpInside" id="Ukt-bi-Sw2"/> | 143 | <action selector="clickJoin:" destination="-1" eventType="touchUpInside" id="Ukt-bi-Sw2"/> |
144 | </connections> | 144 | </connections> |
145 | </button> | 145 | </button> |
146 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="4VU-Ye-7Au"> | 146 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="4VU-Ye-7Au"> |
147 | <rect key="frame" x="0.0" y="310" width="375" height="307"/> | 147 | <rect key="frame" x="0.0" y="310" width="375" height="307"/> |
148 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 148 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
149 | <connections> | 149 | <connections> |
150 | <outlet property="dataSource" destination="-1" id="TLB-6X-bRI"/> | 150 | <outlet property="dataSource" destination="-1" id="TLB-6X-bRI"/> |
151 | <outlet property="delegate" destination="-1" id="QcJ-Yh-deE"/> | 151 | <outlet property="delegate" destination="-1" id="QcJ-Yh-deE"/> |
152 | </connections> | 152 | </connections> |
153 | </tableView> | 153 | </tableView> |
154 | </subviews> | 154 | </subviews> |
155 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> | 155 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> |
156 | <constraints> | 156 | <constraints> |
157 | <constraint firstItem="25d-3H-0fr" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5o2-0w-AL5"/> | 157 | <constraint firstItem="25d-3H-0fr" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5o2-0w-AL5"/> |
158 | <constraint firstAttribute="trailing" secondItem="25d-3H-0fr" secondAttribute="trailing" id="7IX-2R-C0n"/> | 158 | <constraint firstAttribute="trailing" secondItem="25d-3H-0fr" secondAttribute="trailing" id="7IX-2R-C0n"/> |
159 | <constraint firstItem="O8z-6V-YFd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="81K-BQ-6tU"/> | 159 | <constraint firstItem="O8z-6V-YFd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="81K-BQ-6tU"/> |
160 | <constraint firstAttribute="bottom" secondItem="4VU-Ye-7Au" secondAttribute="bottom" constant="50" id="GKY-NB-YYF"/> | 160 | <constraint firstAttribute="bottom" secondItem="4VU-Ye-7Au" secondAttribute="bottom" constant="50" id="GKY-NB-YYF"/> |
161 | <constraint firstItem="O8z-6V-YFd" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="HOo-rH-ysj"/> | 161 | <constraint firstItem="O8z-6V-YFd" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="HOo-rH-ysj"/> |
162 | <constraint firstItem="Bdy-dI-j47" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="I1a-bY-ME9"/> | 162 | <constraint firstItem="Bdy-dI-j47" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="I1a-bY-ME9"/> |
163 | <constraint firstItem="YWV-pS-TCo" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="IS9-SU-75m"/> | 163 | <constraint firstItem="YWV-pS-TCo" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="IS9-SU-75m"/> |
164 | <constraint firstAttribute="trailing" secondItem="Bdy-dI-j47" secondAttribute="trailing" constant="15" id="Ka2-Ki-Pu6"/> | 164 | <constraint firstAttribute="trailing" secondItem="Bdy-dI-j47" secondAttribute="trailing" constant="15" id="Ka2-Ki-Pu6"/> |
165 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="One-fp-LTK"/> | 165 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="One-fp-LTK"/> |
166 | <constraint firstAttribute="trailing" secondItem="qYg-Gw-R2b" secondAttribute="trailing" constant="15" id="PMd-CT-MVj"/> | 166 | <constraint firstAttribute="trailing" secondItem="qYg-Gw-R2b" secondAttribute="trailing" constant="15" id="PMd-CT-MVj"/> |
167 | <constraint firstItem="gBg-k9-tgw" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="bTf-qW-d1y"/> | 167 | <constraint firstItem="gBg-k9-tgw" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="bTf-qW-d1y"/> |
168 | <constraint firstItem="YWV-pS-TCo" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="bottom" constant="8" id="cKj-l3-dgv"/> | 168 | <constraint firstItem="YWV-pS-TCo" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="bottom" constant="8" id="cKj-l3-dgv"/> |
169 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="top" secondItem="caN-x7-hJz" secondAttribute="bottom" constant="10" id="eQe-Kl-cMp"/> | 169 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="top" secondItem="caN-x7-hJz" secondAttribute="bottom" constant="10" id="eQe-Kl-cMp"/> |
170 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="fru-BN-M5T"/> | 170 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="fru-BN-M5T"/> |
171 | <constraint firstItem="caN-x7-hJz" firstAttribute="top" secondItem="gBg-k9-tgw" secondAttribute="top" id="gUS-Ty-4Hk"/> | 171 | <constraint firstItem="caN-x7-hJz" firstAttribute="top" secondItem="gBg-k9-tgw" secondAttribute="top" id="gUS-Ty-4Hk"/> |
172 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="leading" secondItem="O8z-6V-YFd" secondAttribute="trailing" constant="22" id="gzU-2Q-G96"/> | 172 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="leading" secondItem="O8z-6V-YFd" secondAttribute="trailing" constant="22" id="gzU-2Q-G96"/> |
173 | <constraint firstItem="caN-x7-hJz" firstAttribute="leading" secondItem="gBg-k9-tgw" secondAttribute="trailing" constant="20" id="hWK-jf-zee"/> | 173 | <constraint firstItem="caN-x7-hJz" firstAttribute="leading" secondItem="gBg-k9-tgw" secondAttribute="trailing" constant="20" id="hWK-jf-zee"/> |
174 | <constraint firstItem="25d-3H-0fr" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="jhT-CE-fr7"/> | 174 | <constraint firstItem="25d-3H-0fr" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="jhT-CE-fr7"/> |
175 | <constraint firstItem="caN-x7-hJz" firstAttribute="width" secondItem="gBg-k9-tgw" secondAttribute="width" id="mD6-eL-KB7"/> | 175 | <constraint firstItem="caN-x7-hJz" firstAttribute="width" secondItem="gBg-k9-tgw" secondAttribute="width" id="mD6-eL-KB7"/> |
176 | <constraint firstItem="gBg-k9-tgw" firstAttribute="top" secondItem="Bdy-dI-j47" secondAttribute="bottom" constant="30" id="mgw-uX-VOK"/> | 176 | <constraint firstItem="gBg-k9-tgw" firstAttribute="top" secondItem="Bdy-dI-j47" secondAttribute="bottom" constant="30" id="mgw-uX-VOK"/> |
177 | <constraint firstAttribute="trailing" secondItem="YWV-pS-TCo" secondAttribute="trailing" constant="15" id="rEO-bb-Pqr"/> | 177 | <constraint firstAttribute="trailing" secondItem="YWV-pS-TCo" secondAttribute="trailing" constant="15" id="rEO-bb-Pqr"/> |
178 | <constraint firstAttribute="trailing" secondItem="caN-x7-hJz" secondAttribute="trailing" constant="16" id="rRn-Vw-t5g"/> | 178 | <constraint firstAttribute="trailing" secondItem="caN-x7-hJz" secondAttribute="trailing" constant="16" id="rRn-Vw-t5g"/> |
179 | <constraint firstItem="Bdy-dI-j47" firstAttribute="top" secondItem="O8z-6V-YFd" secondAttribute="bottom" constant="15" id="xEO-fP-Riz"/> | 179 | <constraint firstItem="Bdy-dI-j47" firstAttribute="top" secondItem="O8z-6V-YFd" secondAttribute="bottom" constant="15" id="xEO-fP-Riz"/> |
180 | <constraint firstAttribute="trailing" secondItem="4VU-Ye-7Au" secondAttribute="trailing" id="ylN-vm-QF2"/> | 180 | <constraint firstAttribute="trailing" secondItem="4VU-Ye-7Au" secondAttribute="trailing" id="ylN-vm-QF2"/> |
181 | </constraints> | 181 | </constraints> |
182 | <point key="canvasLocation" x="24.5" y="52.5"/> | 182 | <point key="canvasLocation" x="24.5" y="52.5"/> |
183 | </view> | 183 | </view> |
184 | </objects> | 184 | </objects> |
185 | <resources> | 185 | <resources> |
186 | <image name="icon_menu" width="30" height="30"/> | 186 | <image name="icon_menu" width="30" height="30"/> |
187 | <image name="today_back_button" width="73" height="37"/> | 187 | <image name="today_back_button" width="73" height="37"/> |
188 | </resources> | 188 | </resources> |
189 | </document> | 189 | </document> |
190 | 190 |
LifeLog/LifeLog/GroupObject.h
1 | // | 1 | // |
2 | // GroupObject.h | 2 | // GroupObject.h |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by nvtu on 8/11/17. | 5 | // Created by nvtu on 8/11/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import <Foundation/Foundation.h> | 9 | #import <Foundation/Foundation.h> |
10 | 10 | ||
11 | @interface GroupObject : NSObject | 11 | @interface GroupObject : NSObject |
12 | 12 | ||
13 | @property (nonatomic) int groupID; | 13 | @property (nonatomic) int groupID; |
14 | @property (nonatomic) int numSearch; | 14 | @property (nonatomic) int numSearch; |
15 | 15 | ||
16 | @property (nonatomic) int walkGoal; | ||
17 | @property (nonatomic) int runGoal; | ||
18 | @property (nonatomic) int bikeGoal; | ||
19 | @property (nonatomic) int stepGoal; | ||
20 | @property (nonatomic) int gymGoal; | ||
21 | @property (nonatomic) int beginGoal; | ||
22 | |||
16 | @property (nonatomic) BOOL isJoin; | 23 | @property (nonatomic) BOOL isJoin; |
17 | @property (nonatomic) BOOL walkMode; | 24 | @property (nonatomic) BOOL walkMode; |
18 | @property (nonatomic) BOOL runMode; | 25 | @property (nonatomic) BOOL runMode; |
19 | @property (nonatomic) BOOL bikeMode; | 26 | @property (nonatomic) BOOL bikeMode; |
20 | @property (nonatomic) BOOL stepMode; | 27 | @property (nonatomic) BOOL stepMode; |
21 | @property (nonatomic) BOOL gymMode; | 28 | @property (nonatomic) BOOL gymMode; |
22 | @property (nonatomic) BOOL beginMode; | 29 | @property (nonatomic) BOOL beginMode; |
23 | 30 | ||
24 | @property (nonatomic, strong) NSString * name; | 31 | @property (nonatomic, strong) NSString * name; |
25 | @property (nonatomic, strong) NSString * avatar; | 32 | @property (nonatomic, strong) NSString * avatar; |
26 | @property (nonatomic, strong) NSString * goal; | 33 | @property (nonatomic, strong) NSString * goal; |
27 | 34 | ||
28 | @property (nonatomic, strong) NSDate * createDate; | 35 | @property (nonatomic, strong) NSDate * createDate; |
29 | 36 | ||
30 | -(id) initWithData : (NSDictionary *) dict; | 37 | -(id) initWithData : (NSDictionary *) dict; |
31 | 38 | -(id) initWithData : (NSDictionary *) dict andGroupID : (int) groupID; | |
39 | -(void) updateDate : (GroupObject *) obj; | ||
32 | @end | 40 | @end |
33 | 41 |
LifeLog/LifeLog/GroupObject.m
1 | // | 1 | // |
2 | // GroupObject.m | 2 | // GroupObject.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by nvtu on 8/11/17. | 5 | // Created by nvtu on 8/11/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "GroupObject.h" | 9 | #import "GroupObject.h" |
10 | #import "Utilities.h" | 10 | #import "Utilities.h" |
11 | 11 | ||
12 | @implementation GroupObject | 12 | @implementation GroupObject |
13 | |||
14 | -(id) initWithData : (NSDictionary *) dict { | 13 | -(id) initWithData : (NSDictionary *) dict { |
15 | if([dict objectForKey:@"group_id"] != nil) { | 14 | if([dict objectForKey:@"group_id"] != nil) { |
16 | self.groupID = [dict[@"group_id"] intValue]; | 15 | self.groupID = [dict[@"group_id"] intValue]; |
17 | } | 16 | } |
18 | if([dict objectForKey:@"group_name"] != nil) { | ||
19 | self.name = dict[@"group_name"]; | ||
20 | } | ||
21 | if([dict objectForKey:@"group_avatar"] != nil) { | 17 | if([dict objectForKey:@"group_avatar"] != nil) { |
22 | self.avatar = dict[@"group_avatar"]; | 18 | self.avatar = dict[@"group_avatar"]; |
23 | } | 19 | } |
20 | if([dict objectForKey:@"created_at"] != nil) { | ||
21 | NSString *dateString = dict[@"created_at"]; | ||
22 | self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; | ||
23 | } | ||
24 | else { | ||
25 | self.createDate = [NSDate date]; | ||
26 | } | ||
27 | if([dict objectForKey:@"num_search"] != nil) { | ||
28 | self.numSearch = [dict[@"num_search"] intValue]; | ||
29 | } | ||
30 | [self parseData:dict]; | ||
31 | return self; | ||
32 | } | ||
33 | |||
34 | -(id) initWithData : (NSDictionary *) dict andGroupID : (int) groupID { | ||
35 | self.groupID = groupID; | ||
36 | if([dict objectForKey:@"join_group"] != nil && ![[dict objectForKey:@"join_group"] isKindOfClass:[NSNull class]]) { | ||
37 | self.isJoin = [dict[@"join_group"] boolValue]; | ||
38 | } | ||
39 | if([dict objectForKey:@"goal"] != nil && ![[dict objectForKey:@"goal"] isKindOfClass:[NSNull class]]) { | ||
40 | self.goal = dict[@"goal"]; | ||
41 | } | ||
42 | else { | ||
43 | self.goal = @""; | ||
44 | } | ||
45 | if([dict objectForKey:@"walk_mode_goal"] != nil && ![[dict objectForKey:@"walk_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
46 | self.walkGoal = [dict[@"walk_mode_goal"] intValue]; | ||
47 | } | ||
48 | if([dict objectForKey:@"run_mode_goal"] != nil && ![[dict objectForKey:@"run_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
49 | self.runGoal = [dict[@"run_mode_goal"] intValue]; | ||
50 | } | ||
51 | if([dict objectForKey:@"bike_mode_goal"] != nil && ![[dict objectForKey:@"bike_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
52 | self.bikeGoal = [dict[@"bike_mode_goal"] intValue]; | ||
53 | } | ||
54 | if([dict objectForKey:@"step_mode_goal"] != nil && ![[dict objectForKey:@"step_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
55 | self.stepGoal = [dict[@"step_mode_goal"] intValue]; | ||
56 | } | ||
57 | if([dict objectForKey:@"gym_mode_goal"] != nil && ![[dict objectForKey:@"gym_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
58 | self.gymGoal = [dict[@"gym_mode_goal"] intValue]; | ||
59 | } | ||
60 | if([dict objectForKey:@"beginer_mode_goal"] != nil && ![[dict objectForKey:@"beginer_mode_goal"] isKindOfClass:[NSNull class]]) { | ||
61 | self.beginGoal = [dict[@"beginer_mode_goal"] intValue]; | ||
62 | } | ||
63 | [self parseData:dict]; | ||
64 | return self; | ||
65 | } | ||
66 | |||
67 | -(void) parseData : (NSDictionary *) dict { | ||
68 | if([dict objectForKey:@"group_name"] != nil) { | ||
69 | self.name = dict[@"group_name"]; | ||
70 | } | ||
24 | if([dict objectForKey:@"walk_mode_active"] != nil && ![[dict objectForKey:@"walk_mode_active"] isKindOfClass:[NSNull class]]) { | 71 | if([dict objectForKey:@"walk_mode_active"] != nil && ![[dict objectForKey:@"walk_mode_active"] isKindOfClass:[NSNull class]]) { |
25 | self.walkMode = [dict[@"walk_mode_active"] boolValue]; | 72 | self.walkMode = [dict[@"walk_mode_active"] boolValue]; |
26 | } | 73 | } |
27 | if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { | 74 | if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { |
28 | self.runMode = [dict[@"run_mode_active"] boolValue]; | 75 | self.runMode = [dict[@"run_mode_active"] boolValue]; |
29 | } | 76 | } |
30 | if([dict objectForKey:@"bike_mode_active"] != nil && ![[dict objectForKey:@"bike_mode_active"] isKindOfClass:[NSNull class]]) { | 77 | if([dict objectForKey:@"bike_mode_active"] != nil && ![[dict objectForKey:@"bike_mode_active"] isKindOfClass:[NSNull class]]) { |
31 | self.bikeMode = [dict[@"bike_mode_active"] boolValue]; | 78 | self.bikeMode = [dict[@"bike_mode_active"] boolValue]; |
32 | } | 79 | } |
33 | if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { | 80 | if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { |
34 | self.stepMode = [dict[@"step_mode_active"] boolValue]; | 81 | self.stepMode = [dict[@"step_mode_active"] boolValue]; |
35 | } | 82 | } |
36 | if([dict objectForKey:@"gym_mode_active"] != nil && ![[dict objectForKey:@"gym_mode_active"] isKindOfClass:[NSNull class]]) { | 83 | if([dict objectForKey:@"gym_mode_active"] != nil && ![[dict objectForKey:@"gym_mode_active"] isKindOfClass:[NSNull class]]) { |
37 | self.gymMode = [dict[@"gym_mode_active"] boolValue]; | 84 | self.gymMode = [dict[@"gym_mode_active"] boolValue]; |
38 | } | 85 | } |
39 | if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { | 86 | if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { |
40 | self.beginMode = [dict[@"beginer_mode_active"] boolValue]; | 87 | self.beginMode = [dict[@"beginer_mode_active"] boolValue]; |
41 | } | 88 | } |
42 | if([dict objectForKey:@"join_group"] != nil && ![[dict objectForKey:@"join_group"] isKindOfClass:[NSNull class]]) { | 89 | } |
43 | self.isJoin = [dict[@"join_group"] boolValue]; | 90 | |
44 | } | 91 | -(void) updateDate : (GroupObject *) obj { |
45 | if([dict objectForKey:@"created_at"] != nil) { | 92 | self.name = obj.name; |
46 | NSString *dateString = dict[@"created_at"]; | 93 | self.walkMode = obj.walkMode; |
47 | self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; | 94 | self.runMode = obj.runMode; |
48 | } | 95 | self.bikeMode = obj.bikeMode; |
49 | else { | 96 | self.stepMode = obj.stepMode; |
50 | self.createDate = [NSDate date]; | 97 | self.gymMode = obj.gymMode; |
51 | } | 98 | self.beginMode = obj.beginMode; |
52 | if([dict objectForKey:@"num_search"] != nil) { | 99 | self.isJoin = obj.isJoin; |
53 | self.numSearch = [dict[@"num_search"] intValue]; | 100 | self.goal = obj.goal; |
54 | } | 101 | self.walkGoal = obj.walkGoal; |
55 | if([dict objectForKey:@"goal"] != nil && ![[dict objectForKey:@"goal"] isKindOfClass:[NSNull class]]) { | 102 | self.runGoal = obj.runGoal; |
56 | self.goal = dict[@"goal"]; | 103 | self.bikeGoal = obj.bikeGoal; |
57 | } | 104 | self.stepGoal = obj.stepGoal; |
58 | else { | 105 | self.gymGoal = obj.gymGoal; |
59 | self.goal = @""; | 106 | self.beginGoal = obj.beginGoal; |
LifeLog/LifeLog/Localizable.strings
No preview for this file type
LifeLog/LifeLog/SNSViewController.m
1 | // | 1 | // |
2 | // SNSViewController.m | 2 | // SNSViewController.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/25/17. | 5 | // Created by Nguyen Van Phong on 7/25/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "SNSViewController.h" | 9 | #import "SNSViewController.h" |
10 | 10 | ||
11 | #import <SDWebImage/UIImageView+WebCache.h> | 11 | #import <SDWebImage/UIImageView+WebCache.h> |
12 | 12 | ||
13 | #import "ServerAPI.h" | 13 | #import "ServerAPI.h" |
14 | #import "Utilities.h" | 14 | #import "Utilities.h" |
15 | 15 | ||
16 | #import "SNSRecentTopicTableViewCell.h" | 16 | #import "SNSRecentTopicTableViewCell.h" |
17 | #import "SearchGroupViewController.h" | 17 | #import "SearchGroupViewController.h" |
18 | #import "GroupDetailViewController.h" | 18 | #import "GroupDetailViewController.h" |
19 | 19 | ||
20 | @interface SNSViewController () | 20 | @interface SNSViewController () |
21 | 21 | ||
22 | @end | 22 | @end |
23 | 23 | ||
24 | @implementation SNSViewController | 24 | @implementation SNSViewController |
25 | 25 | ||
26 | - (void)viewDidLoad { | 26 | - (void)viewDidLoad { |
27 | [super viewDidLoad]; | 27 | [super viewDidLoad]; |
28 | // Do any additional setup after loading the view from its nib. | 28 | // Do any additional setup after loading the view from its nib. |
29 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); | 29 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); |
30 | 30 | ||
31 | [self callRequestToUpdateData]; | 31 | [self callRequestToUpdateData]; |
32 | 32 | ||
33 | //register nib for table view | 33 | //register nib for table view |
34 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 34 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
35 | } | 35 | } |
36 | 36 | ||
37 | - (void)didReceiveMemoryWarning { | 37 | - (void)didReceiveMemoryWarning { |
38 | [super didReceiveMemoryWarning]; | 38 | [super didReceiveMemoryWarning]; |
39 | // Dispose of any resources that can be recreated. | 39 | // Dispose of any resources that can be recreated. |
40 | } | 40 | } |
41 | 41 | ||
42 | #pragma mark IBAction | 42 | #pragma mark IBAction |
43 | - (IBAction)clickRecommendGroup:(id)sender { | 43 | - (IBAction)clickRecommendGroup:(id)sender { |
44 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; | 44 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; |
45 | [self.navigationController pushViewController:search animated:true]; | 45 | [self.navigationController pushViewController:search animated:true]; |
46 | } | 46 | } |
47 | 47 | ||
48 | - (IBAction)clickMyGroup:(id)sender { | 48 | - (IBAction)clickMyGroup:(id)sender { |
49 | // GroupDetailViewController * detail = [[GroupDetailViewController alloc] init]; | 49 | // GroupDetailViewController * detail = [[GroupDetailViewController alloc] init]; |
50 | // [self.navigationController pushViewController:detail animated:true]; | 50 | // [self.navigationController pushViewController:detail animated:true]; |
51 | } | 51 | } |
52 | 52 | ||
53 | #pragma mark UITableView Delegate | 53 | #pragma mark UITableView Delegate |
54 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 54 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
55 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 55 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
56 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 56 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
57 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 57 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
58 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 58 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
59 | } | 59 | } |
60 | else { | ||
61 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
62 | } | ||
60 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 63 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; |
61 | cell.lblUsername.text = object.userName; | 64 | cell.lblUsername.text = object.userName; |
62 | cell.lblDes.text = object.content; | 65 | cell.lblDes.text = object.content; |
63 | cell.lblMode.text = object.mode; | 66 | cell.lblMode.text = object.mode; |
64 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 67 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
65 | cell.lblDuration.text = object.time; | 68 | cell.lblDuration.text = object.time; |
66 | return cell; | 69 | return cell; |
67 | } | 70 | } |
68 | 71 | ||
69 | #pragma mark Private Function | 72 | #pragma mark Private Function |
70 | 73 | ||
71 | -(void) callRequestToUpdateData { | 74 | -(void) callRequestToUpdateData { |
72 | [super callRequestToUpdateData]; | 75 | [super callRequestToUpdateData]; |
73 | 76 | ||
74 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 77 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
75 | MBProgressHUD *hudView = nil; | 78 | MBProgressHUD *hudView = nil; |
76 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 79 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
77 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 80 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
78 | } | 81 | } |
79 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 82 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
80 | dispatch_async(dispatch_get_main_queue(), ^{ | 83 | dispatch_async(dispatch_get_main_queue(), ^{ |
81 | if(hudView != nil) { | 84 | if(hudView != nil) { |
82 | [hudView hideAnimated:true]; | 85 | [hudView hideAnimated:true]; |
83 | } | 86 | } |
84 | }); | 87 | }); |
85 | SNSViewController __weak *weakSelf = self; | 88 | SNSViewController __weak *weakSelf = self; |
86 | [weakSelf updateTableData:array error:error]; | 89 | [weakSelf updateTableData:array error:error]; |
87 | }]; | 90 | }]; |
88 | } | 91 | } |
89 | 92 | ||
90 | @end | 93 | @end |
91 | 94 |
LifeLog/LifeLog/SearchGroupViewController.m
1 | // | 1 | // |
2 | // SearchGroupViewController.m | 2 | // SearchGroupViewController.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by nvtu on 8/11/17. | 5 | // Created by nvtu on 8/11/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "SearchGroupViewController.h" | 9 | #import "SearchGroupViewController.h" |
10 | 10 | ||
11 | #import <SDWebImage/UIImageView+WebCache.h> | 11 | #import <SDWebImage/UIImageView+WebCache.h> |
12 | 12 | ||
13 | #import "ServerAPI.h" | 13 | #import "ServerAPI.h" |
14 | #import "Utilities.h" | 14 | #import "Utilities.h" |
15 | 15 | ||
16 | #import "SearchGroupTableViewCell.h" | 16 | #import "SearchGroupTableViewCell.h" |
17 | #import "GroupDetailViewController.h" | 17 | #import "GroupDetailViewController.h" |
18 | 18 | ||
19 | @interface SearchGroupViewController () | 19 | @interface SearchGroupViewController () |
20 | 20 | ||
21 | @end | 21 | @end |
22 | 22 | ||
23 | @implementation SearchGroupViewController | 23 | @implementation SearchGroupViewController |
24 | 24 | ||
25 | - (void)viewDidLoad { | 25 | - (void)viewDidLoad { |
26 | [super viewDidLoad]; | 26 | [super viewDidLoad]; |
27 | [self callRequestToUpdateData]; | 27 | [self callRequestToUpdateData]; |
28 | 28 | ||
29 | //register nib for table view | 29 | //register nib for table view |
30 | [self.tableBase registerNib:[UINib nibWithNibName:@"SearchGroupTableViewCell" bundle:nil] forCellReuseIdentifier:@"SearchGroupCell"]; | 30 | [self.tableBase registerNib:[UINib nibWithNibName:@"SearchGroupTableViewCell" bundle:nil] forCellReuseIdentifier:@"SearchGroupCell"]; |
31 | } | 31 | } |
32 | 32 | ||
33 | - (void)didReceiveMemoryWarning { | 33 | - (void)didReceiveMemoryWarning { |
34 | [super didReceiveMemoryWarning]; | 34 | [super didReceiveMemoryWarning]; |
35 | // Dispose of any resources that can be recreated. | 35 | // Dispose of any resources that can be recreated. |
36 | } | 36 | } |
37 | 37 | ||
38 | #pragma mark IBAction | 38 | #pragma mark IBAction |
39 | 39 | ||
40 | - (IBAction)clickBack:(id)sender { | 40 | - (IBAction)clickBack:(id)sender { |
41 | [self.navigationController popViewControllerAnimated:true]; | 41 | [self.navigationController popViewControllerAnimated:true]; |
42 | } | 42 | } |
43 | 43 | ||
44 | - (IBAction)clickSearch:(id)sender { | 44 | - (IBAction)clickSearch:(id)sender { |
45 | [self resetData]; | 45 | [self resetData]; |
46 | } | 46 | } |
47 | 47 | ||
48 | - (IBAction)clickCreateGroup:(id)sender { | 48 | - (IBAction)clickCreateGroup:(id)sender { |
49 | 49 | ||
50 | } | 50 | } |
51 | 51 | ||
52 | #pragma mark UITableView Delegate | 52 | #pragma mark UITableView Delegate |
53 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 53 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
54 | SearchGroupTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SearchGroupCell"]; | 54 | SearchGroupTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SearchGroupCell"]; |
55 | GroupObject *object = [_curDataList objectAtIndex:indexPath.row]; | 55 | GroupObject *object = [_curDataList objectAtIndex:indexPath.row]; |
56 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 56 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
57 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 57 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
58 | } | 58 | } |
59 | else { | ||
60 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | ||
61 | } | ||
59 | cell.lblName.text = object.name; | 62 | cell.lblName.text = object.name; |
60 | return cell; | 63 | return cell; |
61 | } | 64 | } |
62 | 65 | ||
63 | -(void) scrollViewDidScroll:(UIScrollView *)scrollView { | 66 | -(void) scrollViewDidScroll:(UIScrollView *)scrollView { |
64 | [self.view endEditing:true]; | 67 | [self.view endEditing:true]; |
65 | } | 68 | } |
66 | 69 | ||
67 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | 70 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
68 | GroupDetailViewController * detail = [[GroupDetailViewController alloc] init]; | 71 | GroupDetailViewController * detail = [[GroupDetailViewController alloc] init]; |
69 | [detail setGroup:[_curDataList objectAtIndex:indexPath.row]]; | 72 | [detail setGroup:[_curDataList objectAtIndex:indexPath.row]]; |
70 | [self.navigationController pushViewController:detail animated:true]; | 73 | [self.navigationController pushViewController:detail animated:true]; |
71 | } | 74 | } |
72 | 75 | ||
73 | #pragma mark UITextField Delegate | 76 | #pragma mark UITextField Delegate |
74 | -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | 77 | -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { |
75 | [self resetData]; | 78 | [self resetData]; |
76 | return true; | 79 | return true; |
77 | } | 80 | } |
78 | 81 | ||
79 | #pragma mark Private Function | 82 | #pragma mark Private Function |
80 | -(void) callRequestToUpdateData { | 83 | -(void) callRequestToUpdateData { |
81 | [super callRequestToUpdateData]; | 84 | [super callRequestToUpdateData]; |
82 | 85 | ||
83 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 86 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
84 | MBProgressHUD *hudView = nil; | 87 | MBProgressHUD *hudView = nil; |
85 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 88 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
86 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 89 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
87 | } | 90 | } |
88 | [[ServerAPI server] searchGroup:token withKey:self.textFieldSearch.text andPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { | 91 | [[ServerAPI server] searchGroup:token withKey:self.textFieldSearch.text andPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { |
89 | dispatch_async(dispatch_get_main_queue(), ^{ | 92 | dispatch_async(dispatch_get_main_queue(), ^{ |
90 | if(hudView != nil) { | 93 | if(hudView != nil) { |
91 | [hudView hideAnimated:true]; | 94 | [hudView hideAnimated:true]; |
92 | } | 95 | } |
93 | }); | 96 | }); |
94 | SearchGroupViewController __weak *weakSelf = self; | 97 | SearchGroupViewController __weak *weakSelf = self; |
95 | [weakSelf updateTableData:array error:error]; | 98 | [weakSelf updateTableData:array error:error]; |
96 | }]; | 99 | }]; |
97 | } | 100 | } |
98 | @end | 101 | @end |
99 | 102 |
LifeLog/LifeLog/ServerAPI.m
1 | // | 1 | // |
2 | // ServerAPI.m | 2 | // ServerAPI.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/30/17. | 5 | // Created by Nguyen Van Phong on 7/30/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "ServerAPI.h" | 9 | #import "ServerAPI.h" |
10 | 10 | ||
11 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; | 11 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; |
12 | NSString *const kUser = @"KEY_USER"; | 12 | NSString *const kUser = @"KEY_USER"; |
13 | NSString *const kToken = @"KEY_TOKEN"; | 13 | NSString *const kToken = @"KEY_TOKEN"; |
14 | NSString *const kNotificationToken = @"TOKEN_INVALID"; | 14 | NSString *const kNotificationToken = @"TOKEN_INVALID"; |
15 | 15 | ||
16 | @implementation NSString (NSString_Extended) | 16 | @implementation NSString (NSString_Extended) |
17 | - (NSString *)urlencode { | 17 | - (NSString *)urlencode { |
18 | NSMutableString *output = [NSMutableString string]; | 18 | NSMutableString *output = [NSMutableString string]; |
19 | const unsigned char *source = (const unsigned char *)[self UTF8String]; | 19 | const unsigned char *source = (const unsigned char *)[self UTF8String]; |
20 | int sourceLen = (int)strlen((const char *)source); | 20 | int sourceLen = (int)strlen((const char *)source); |
21 | for (int i = 0; i < sourceLen; ++i) { | 21 | for (int i = 0; i < sourceLen; ++i) { |
22 | const unsigned char thisChar = source[i]; | 22 | const unsigned char thisChar = source[i]; |
23 | if (thisChar == ' '){ | 23 | if (thisChar == ' '){ |
24 | [output appendString:@"+"]; | 24 | [output appendString:@"+"]; |
25 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || | 25 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || |
26 | (thisChar >= 'a' && thisChar <= 'z') || | 26 | (thisChar >= 'a' && thisChar <= 'z') || |
27 | (thisChar >= 'A' && thisChar <= 'Z') || | 27 | (thisChar >= 'A' && thisChar <= 'Z') || |
28 | (thisChar >= '0' && thisChar <= '9')) { | 28 | (thisChar >= '0' && thisChar <= '9')) { |
29 | [output appendFormat:@"%c", thisChar]; | 29 | [output appendFormat:@"%c", thisChar]; |
30 | } else { | 30 | } else { |
31 | [output appendFormat:@"%%%02X", thisChar]; | 31 | [output appendFormat:@"%%%02X", thisChar]; |
32 | } | 32 | } |
33 | } | 33 | } |
34 | return output; | 34 | return output; |
35 | } | 35 | } |
36 | @end | 36 | @end |
37 | 37 | ||
38 | @implementation ServerAPI | 38 | @implementation ServerAPI |
39 | static ServerAPI *_server = nil; | 39 | static ServerAPI *_server = nil; |
40 | 40 | ||
41 | NSURLSessionDataTask * searchTask; | 41 | NSURLSessionDataTask * searchTask; |
42 | 42 | ||
43 | @synthesize timeOutInterval = _timeOutInterval; | 43 | @synthesize timeOutInterval = _timeOutInterval; |
44 | 44 | ||
45 | + (instancetype)server | 45 | + (instancetype)server |
46 | { | 46 | { |
47 | @synchronized(self) { | 47 | @synchronized(self) { |
48 | if (_server == nil) { | 48 | if (_server == nil) { |
49 | _server = [[ServerAPI alloc] init]; | 49 | _server = [[ServerAPI alloc] init]; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | return _server; | 52 | return _server; |
53 | } | 53 | } |
54 | 54 | ||
55 | - (instancetype)init | 55 | - (instancetype)init |
56 | { | 56 | { |
57 | self = [super init]; | 57 | self = [super init]; |
58 | if (self != nil) { | 58 | if (self != nil) { |
59 | self.timeOutInterval = 150; | 59 | self.timeOutInterval = 150; |
60 | } | 60 | } |
61 | return self; | 61 | return self; |
62 | } | 62 | } |
63 | 63 | ||
64 | #pragma mark - Login and Register | 64 | #pragma mark - Login and Register |
65 | // Login | 65 | // Login |
66 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion | 66 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion |
67 | { | 67 | { |
68 | [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { | 68 | [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { |
69 | 69 | ||
70 | if (completion == NULL) { | 70 | if (completion == NULL) { |
71 | return ; | 71 | return ; |
72 | } | 72 | } |
73 | 73 | ||
74 | if (error == nil) | 74 | if (error == nil) |
75 | { | 75 | { |
76 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 76 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
77 | 77 | ||
78 | int status = [dataResult[@"status"] intValue]; | 78 | int status = [dataResult[@"status"] intValue]; |
79 | if (status == 1) { // status = 1 success | 79 | if (status == 1) { // status = 1 success |
80 | NSString *token = dataResult[@"result"][@"token"]; | 80 | NSString *token = dataResult[@"result"][@"token"]; |
81 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 81 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
82 | User *user = [[User alloc] init]; | 82 | User *user = [[User alloc] init]; |
83 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 83 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
84 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 84 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
85 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 85 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
86 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 86 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
87 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 87 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
88 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 88 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
89 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 89 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
90 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 90 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
91 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 91 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
92 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 92 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
93 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 93 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
94 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 94 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
95 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 95 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
96 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 96 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
97 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 97 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
98 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 98 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
99 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 99 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
100 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 100 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
101 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 101 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
102 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 102 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
103 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 103 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
104 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | 104 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; |
105 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 105 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
106 | completion(user, token, nil); | 106 | completion(user, token, nil); |
107 | } | 107 | } |
108 | else { // status = 0 error | 108 | else { // status = 0 error |
109 | NSString *message = dataResult[@"message"]; | 109 | NSString *message = dataResult[@"message"]; |
110 | if (message == nil) { | 110 | if (message == nil) { |
111 | message = @"Unknown error"; | 111 | message = @"Unknown error"; |
112 | } | 112 | } |
113 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 113 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
114 | completion(nil, nil, loginFaild); | 114 | completion(nil, nil, loginFaild); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | else | 117 | else |
118 | { | 118 | { |
119 | completion(nil, nil, error); | 119 | completion(nil, nil, error); |
120 | } | 120 | } |
121 | }]; | 121 | }]; |
122 | } | 122 | } |
123 | 123 | ||
124 | // Register | 124 | // Register |
125 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { | 125 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { |
126 | [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { | 126 | [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { |
127 | 127 | ||
128 | if (completion == NULL) { | 128 | if (completion == NULL) { |
129 | return ; | 129 | return ; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (error == nil) | 132 | if (error == nil) |
133 | { | 133 | { |
134 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 134 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
135 | 135 | ||
136 | int status = [dataResult[@"status"] intValue]; | 136 | int status = [dataResult[@"status"] intValue]; |
137 | if (status == 1) { // status = 1 success | 137 | if (status == 1) { // status = 1 success |
138 | NSString *token = dataResult[@"result"][@"token"]; | 138 | NSString *token = dataResult[@"result"][@"token"]; |
139 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 139 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
140 | User *user = [[User alloc] init]; | 140 | User *user = [[User alloc] init]; |
141 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 141 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
142 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 142 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
143 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 143 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
144 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 144 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
145 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 145 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
146 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 146 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
147 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 147 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
148 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 148 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
149 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 149 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
150 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 150 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
151 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 151 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
152 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 152 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
153 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 153 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
154 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 154 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
155 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 155 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
156 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 156 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
157 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 157 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
158 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 158 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
159 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 159 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
160 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 160 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
161 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 161 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
162 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | 162 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; |
163 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 163 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
164 | completion(user, token, nil); | 164 | completion(user, token, nil); |
165 | } | 165 | } |
166 | else { // status = 0 error | 166 | else { // status = 0 error |
167 | NSString *message = dataResult[@"message"]; | 167 | NSString *message = dataResult[@"message"]; |
168 | if (message == nil) { | 168 | if (message == nil) { |
169 | message = @"Unknown error"; | 169 | message = @"Unknown error"; |
170 | } | 170 | } |
171 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 171 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
172 | completion(nil, nil, loginFaild); | 172 | completion(nil, nil, loginFaild); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | else | 175 | else |
176 | { | 176 | { |
177 | completion(nil, nil, error); | 177 | completion(nil, nil, error); |
178 | } | 178 | } |
179 | }]; | 179 | }]; |
180 | } | 180 | } |
181 | 181 | ||
182 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { | 182 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { |
183 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { | 183 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { |
184 | 184 | ||
185 | if (completion == NULL) { | 185 | if (completion == NULL) { |
186 | return ; | 186 | return ; |
187 | } | 187 | } |
188 | 188 | ||
189 | if (error == nil) | 189 | if (error == nil) |
190 | { | 190 | { |
191 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 191 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
192 | 192 | ||
193 | int status = [dataResult[@"status"] intValue]; | 193 | int status = [dataResult[@"status"] intValue]; |
194 | if (status == 1) { // status = 1 success | 194 | if (status == 1) { // status = 1 success |
195 | completion(nil); | 195 | completion(nil); |
196 | } | 196 | } |
197 | else { // status = 0 error | 197 | else { // status = 0 error |
198 | NSString *message = dataResult[@"message"]; | 198 | NSString *message = dataResult[@"message"]; |
199 | if (message == nil) { | 199 | if (message == nil) { |
200 | message = @"Unknown error"; | 200 | message = @"Unknown error"; |
201 | } | 201 | } |
202 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 202 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
203 | completion(forgetPass); | 203 | completion(forgetPass); |
204 | } | 204 | } |
205 | } | 205 | } |
206 | else | 206 | else |
207 | { | 207 | { |
208 | completion(error); | 208 | completion(error); |
209 | } | 209 | } |
210 | }]; | 210 | }]; |
211 | } | 211 | } |
212 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { | 212 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { |
213 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { | 213 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { |
214 | 214 | ||
215 | if (completion == NULL) { | 215 | if (completion == NULL) { |
216 | return ; | 216 | return ; |
217 | } | 217 | } |
218 | 218 | ||
219 | if (error == nil) | 219 | if (error == nil) |
220 | { | 220 | { |
221 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 221 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
222 | 222 | ||
223 | int status = [dataResult[@"status"] intValue]; | 223 | int status = [dataResult[@"status"] intValue]; |
224 | if (status == 1) { // status = 1 success | 224 | if (status == 1) { // status = 1 success |
225 | completion(nil); | 225 | completion(nil); |
226 | } | 226 | } |
227 | else { // status = 0 error | 227 | else { // status = 0 error |
228 | NSString *message = dataResult[@"message"]; | 228 | NSString *message = dataResult[@"message"]; |
229 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 229 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
230 | completion(confirmForgetPass); | 230 | completion(confirmForgetPass); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | else | 233 | else |
234 | { | 234 | { |
235 | completion(error); | 235 | completion(error); |
236 | } | 236 | } |
237 | }]; | 237 | }]; |
238 | } | 238 | } |
239 | 239 | ||
240 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion { | 240 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion { |
241 | NSDictionary *dict = nil; | 241 | NSDictionary *dict = nil; |
242 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; | 242 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; |
243 | if (token != nil) { | 243 | if (token != nil) { |
244 | dict = @{@"token":token, @"img": base64Encoded}; | 244 | dict = @{@"token":token, @"img": base64Encoded}; |
245 | } | 245 | } |
246 | else { | 246 | else { |
247 | dict = @{@"img": base64Encoded}; | 247 | dict = @{@"img": base64Encoded}; |
248 | } | 248 | } |
249 | [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 249 | [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
250 | 250 | ||
251 | if (completion == NULL) { | 251 | if (completion == NULL) { |
252 | return ; | 252 | return ; |
253 | } | 253 | } |
254 | 254 | ||
255 | if (error == nil) | 255 | if (error == nil) |
256 | { | 256 | { |
257 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 257 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
258 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; | 258 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; |
259 | completion(image_profile, nil); | 259 | completion(image_profile, nil); |
260 | } | 260 | } |
261 | else | 261 | else |
262 | { | 262 | { |
263 | completion(nil, error); | 263 | completion(nil, error); |
264 | } | 264 | } |
265 | }]; | 265 | }]; |
266 | } | 266 | } |
267 | 267 | ||
268 | -(NSString *) convertIntToString : (int) type { | 268 | -(NSString *) convertIntToString : (int) type { |
269 | switch (type) { | 269 | switch (type) { |
270 | case 1: | 270 | case 1: |
271 | return @"week"; | 271 | return @"week"; |
272 | break; | 272 | break; |
273 | case 2: | 273 | case 2: |
274 | return @"oneMonth"; | 274 | return @"oneMonth"; |
275 | break; | 275 | break; |
276 | case 3: | 276 | case 3: |
277 | return @"threeMonth"; | 277 | return @"threeMonth"; |
278 | break; | 278 | break; |
279 | case 4: | 279 | case 4: |
280 | return @"sixMonth"; | 280 | return @"sixMonth"; |
281 | break; | 281 | break; |
282 | default: | 282 | default: |
283 | return @"today"; | 283 | return @"today"; |
284 | break; | 284 | break; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | #pragma mark - Home Screen Function | 288 | #pragma mark - Home Screen Function |
289 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion | 289 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion |
290 | { | 290 | { |
291 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 291 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
292 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; | 292 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; |
293 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 293 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
294 | 294 | ||
295 | if (completion == NULL) { | 295 | if (completion == NULL) { |
296 | return ; | 296 | return ; |
297 | } | 297 | } |
298 | 298 | ||
299 | if (error == nil) | 299 | if (error == nil) |
300 | { | 300 | { |
301 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 301 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
302 | int status = [dataResult[@"status"] intValue]; | 302 | int status = [dataResult[@"status"] intValue]; |
303 | if (status == 1) { // status = 1 success | 303 | if (status == 1) { // status = 1 success |
304 | if(dataResult[@"result"] != nil) { | 304 | if(dataResult[@"result"] != nil) { |
305 | NSDictionary * dictResult = dataResult[@"result"]; | 305 | NSDictionary * dictResult = dataResult[@"result"]; |
306 | TopObject *topObject = [[TopObject alloc] init]; | 306 | TopObject *topObject = [[TopObject alloc] init]; |
307 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; | 307 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; |
308 | topObject.targetInfor = targetInfor; | 308 | topObject.targetInfor = targetInfor; |
309 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; | 309 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; |
310 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; | 310 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; |
311 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; | 311 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; |
312 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; | 312 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; |
313 | NSArray *array = dictResult[@"dataChart"]; | 313 | NSArray *array = dictResult[@"dataChart"]; |
314 | for(NSDictionary *dict in array) { | 314 | for(NSDictionary *dict in array) { |
315 | StepObject *object = [[StepObject alloc] init]; | 315 | StepObject *object = [[StepObject alloc] init]; |
316 | if([dict objectForKey:@"numStep"] != nil) { | 316 | if([dict objectForKey:@"numStep"] != nil) { |
317 | object.step = [dict[@"numStep"] intValue]; | 317 | object.step = [dict[@"numStep"] intValue]; |
318 | } | 318 | } |
319 | if([dict objectForKey:@"hour"] != nil) { | 319 | if([dict objectForKey:@"hour"] != nil) { |
320 | object.hour = [dict[@"hour"] intValue]; | 320 | object.hour = [dict[@"hour"] intValue]; |
321 | } | 321 | } |
322 | switch (mode) { | 322 | switch (mode) { |
323 | case 1: | 323 | case 1: |
324 | object.typeStep = @"walking"; | 324 | object.typeStep = @"walking"; |
325 | break; | 325 | break; |
326 | case 2: | 326 | case 2: |
327 | object.typeStep = @"running"; | 327 | object.typeStep = @"running"; |
328 | break; | 328 | break; |
329 | case 3: | 329 | case 3: |
330 | object.typeStep = @"bike"; | 330 | object.typeStep = @"bike"; |
331 | break; | 331 | break; |
332 | default: | 332 | default: |
333 | break; | 333 | break; |
334 | } | 334 | } |
335 | [arrayStep addObject:object]; | 335 | [arrayStep addObject:object]; |
336 | } | 336 | } |
337 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; | 337 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; |
338 | completion(topObject, nil); | 338 | completion(topObject, nil); |
339 | } | 339 | } |
340 | else { | 340 | else { |
341 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 341 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
342 | completion(nil, errorObject); | 342 | completion(nil, errorObject); |
343 | } | 343 | } |
344 | } | 344 | } |
345 | else { | 345 | else { |
346 | NSString *message = dataResult[@"message"]; | 346 | NSString *message = dataResult[@"message"]; |
347 | if (message == nil) { | 347 | if (message == nil) { |
348 | message = @"Unknown error"; | 348 | message = @"Unknown error"; |
349 | } | 349 | } |
350 | 350 | ||
351 | if ([message isEqualToString:@"Token is invalid"]) { | 351 | if ([message isEqualToString:@"Token is invalid"]) { |
352 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 352 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
353 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; | 353 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; |
354 | } | 354 | } |
355 | else { | 355 | else { |
356 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 356 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
357 | completion(nil, errorObject); | 357 | completion(nil, errorObject); |
358 | } | 358 | } |
359 | } | 359 | } |
360 | } | 360 | } |
361 | else | 361 | else |
362 | { | 362 | { |
363 | completion(nil, error); | 363 | completion(nil, error); |
364 | } | 364 | } |
365 | }]; | 365 | }]; |
366 | } | 366 | } |
367 | 367 | ||
368 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion { | 368 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion { |
369 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 369 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
370 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; | 370 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; |
371 | NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate}; | 371 | NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate}; |
372 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 372 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
373 | 373 | ||
374 | if (completion == NULL) { | 374 | if (completion == NULL) { |
375 | return ; | 375 | return ; |
376 | } | 376 | } |
377 | 377 | ||
378 | if (error == nil) | 378 | if (error == nil) |
379 | { | 379 | { |
380 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 380 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
381 | int status = [dataResult[@"status"] intValue]; | 381 | int status = [dataResult[@"status"] intValue]; |
382 | if (status == 1) { // status = 1 success | 382 | if (status == 1) { // status = 1 success |
383 | completion(nil); | 383 | completion(nil); |
384 | } | 384 | } |
385 | else { | 385 | else { |
386 | NSString *message = dataResult[@"message"]; | 386 | NSString *message = dataResult[@"message"]; |
387 | if (message == nil) { | 387 | if (message == nil) { |
388 | message = @"Unknown error"; | 388 | message = @"Unknown error"; |
389 | } | 389 | } |
390 | 390 | ||
391 | if ([message isEqualToString:@"Token is invalid"]) { | 391 | if ([message isEqualToString:@"Token is invalid"]) { |
392 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 392 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
393 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; | 393 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; |
394 | } | 394 | } |
395 | else { | 395 | else { |
396 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 396 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
397 | completion(errorObject); | 397 | completion(errorObject); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | } | 400 | } |
401 | else | 401 | else |
402 | { | 402 | { |
403 | completion(error); | 403 | completion(error); |
404 | } | 404 | } |
405 | }]; | 405 | }]; |
406 | } | 406 | } |
407 | 407 | ||
408 | #pragma mark - History Screen Function | 408 | #pragma mark - History Screen Function |
409 | - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion { | 409 | - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion { |
410 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%d", [self convertIntToString:type], mode]; | 410 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%d", [self convertIntToString:type], mode]; |
411 | NSLog(@"requestHistory link %@", url); | 411 | NSLog(@"requestHistory link %@", url); |
412 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 412 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
413 | 413 | ||
414 | if (completion == NULL) { | 414 | if (completion == NULL) { |
415 | return ; | 415 | return ; |
416 | } | 416 | } |
417 | 417 | ||
418 | if (error == nil) | 418 | if (error == nil) |
419 | { | 419 | { |
420 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 420 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
421 | NSLog(@"%@", dataResult); | 421 | NSLog(@"%@", dataResult); |
422 | int status = [dataResult[@"status"] intValue]; | 422 | int status = [dataResult[@"status"] intValue]; |
423 | if (status == 1) { // status = 1 success | 423 | if (status == 1) { // status = 1 success |
424 | HistoryObject * object = [[HistoryObject alloc] initWithData:dataResult[@"result"]]; | 424 | HistoryObject * object = [[HistoryObject alloc] initWithData:dataResult[@"result"]]; |
425 | completion(object, nil); | 425 | completion(object, nil); |
426 | } | 426 | } |
427 | else { | 427 | else { |
428 | NSString *message = dataResult[@"message"]; | 428 | NSString *message = dataResult[@"message"]; |
429 | if (message == nil) { | 429 | if (message == nil) { |
430 | message = @"Unknown error"; | 430 | message = @"Unknown error"; |
431 | } | 431 | } |
432 | 432 | ||
433 | if ([message isEqualToString:@"Token is invalid"]) { | 433 | if ([message isEqualToString:@"Token is invalid"]) { |
434 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 434 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
435 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 435 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
436 | [self requestHistory:tokenNew atDate:date withType:type andMode:mode CompletionHandler:completion]; | 436 | [self requestHistory:tokenNew atDate:date withType:type andMode:mode CompletionHandler:completion]; |
437 | } | 437 | } |
438 | else { | 438 | else { |
439 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 439 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
440 | completion(nil, errorObject); | 440 | completion(nil, errorObject); |
441 | } | 441 | } |
442 | } | 442 | } |
443 | } | 443 | } |
444 | else | 444 | else |
445 | { | 445 | { |
446 | completion(nil, error); | 446 | completion(nil, error); |
447 | } | 447 | } |
448 | }]; | 448 | }]; |
449 | } | 449 | } |
450 | 450 | ||
451 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { | 451 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { |
452 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; | 452 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; |
453 | NSLog(@"requestHistoryGraph link %@", url); | 453 | NSLog(@"requestHistoryGraph link %@", url); |
454 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 454 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
455 | 455 | ||
456 | if (completion == NULL) { | 456 | if (completion == NULL) { |
457 | return ; | 457 | return ; |
458 | } | 458 | } |
459 | 459 | ||
460 | if (error == nil) | 460 | if (error == nil) |
461 | { | 461 | { |
462 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 462 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
463 | NSLog(@"%@", dataResult); | 463 | NSLog(@"%@", dataResult); |
464 | int status = [dataResult[@"status"] intValue]; | 464 | int status = [dataResult[@"status"] intValue]; |
465 | if (status == 1) { // status = 1 success | 465 | if (status == 1) { // status = 1 success |
466 | HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]]; | 466 | HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]]; |
467 | completion(object, nil); | 467 | completion(object, nil); |
468 | } | 468 | } |
469 | else { | 469 | else { |
470 | NSString *message = dataResult[@"message"]; | 470 | NSString *message = dataResult[@"message"]; |
471 | if (message == nil) { | 471 | if (message == nil) { |
472 | message = @"Unknown error"; | 472 | message = @"Unknown error"; |
473 | } | 473 | } |
474 | 474 | ||
475 | if ([message isEqualToString:@"Token is invalid"]) { | 475 | if ([message isEqualToString:@"Token is invalid"]) { |
476 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 476 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
477 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 477 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
478 | [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion]; | 478 | [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion]; |
479 | } | 479 | } |
480 | else { | 480 | else { |
481 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 481 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
482 | completion(nil, errorObject); | 482 | completion(nil, errorObject); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | } | 485 | } |
486 | else | 486 | else |
487 | { | 487 | { |
488 | completion(nil, error); | 488 | completion(nil, error); |
489 | } | 489 | } |
490 | }]; | 490 | }]; |
491 | } | 491 | } |
492 | 492 | ||
493 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 493 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
494 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page]; | 494 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page]; |
495 | NSLog(@"requestHistoryList link %@", url); | 495 | NSLog(@"requestHistoryList link %@", url); |
496 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 496 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
497 | 497 | ||
498 | if (completion == NULL) { | 498 | if (completion == NULL) { |
499 | return ; | 499 | return ; |
500 | } | 500 | } |
501 | 501 | ||
502 | if (error == nil) | 502 | if (error == nil) |
503 | { | 503 | { |
504 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 504 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
505 | NSLog(@"%@", dataResult); | 505 | NSLog(@"%@", dataResult); |
506 | int status = [dataResult[@"status"] intValue]; | 506 | int status = [dataResult[@"status"] intValue]; |
507 | if (status == 1) { // status = 1 success | 507 | if (status == 1) { // status = 1 success |
508 | if(dataResult[@"result"] != nil) { | 508 | if(dataResult[@"result"] != nil) { |
509 | NSArray * array = dataResult[@"result"][@"data"]; | 509 | NSArray * array = dataResult[@"result"][@"data"]; |
510 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; | 510 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
511 | for(NSDictionary * dict in array) { | 511 | for(NSDictionary * dict in array) { |
512 | HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; | 512 | HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; |
513 | [arrayHistory addObject:object]; | 513 | [arrayHistory addObject:object]; |
514 | } | 514 | } |
515 | completion(arrayHistory, nil); | 515 | completion(arrayHistory, nil); |
516 | } | 516 | } |
517 | else { | 517 | else { |
518 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 518 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
519 | completion(nil, errorObject); | 519 | completion(nil, errorObject); |
520 | } | 520 | } |
521 | } | 521 | } |
522 | else { | 522 | else { |
523 | NSString *message = dataResult[@"message"]; | 523 | NSString *message = dataResult[@"message"]; |
524 | if (message == nil) { | 524 | if (message == nil) { |
525 | message = @"Unknown error"; | 525 | message = @"Unknown error"; |
526 | } | 526 | } |
527 | 527 | ||
528 | if ([message isEqualToString:@"Token is invalid"]) { | 528 | if ([message isEqualToString:@"Token is invalid"]) { |
529 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 529 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
530 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 530 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
531 | [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; | 531 | [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; |
532 | } | 532 | } |
533 | else { | 533 | else { |
534 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 534 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
535 | completion(nil, errorObject); | 535 | completion(nil, errorObject); |
536 | } | 536 | } |
537 | } | 537 | } |
538 | } | 538 | } |
539 | else | 539 | else |
540 | { | 540 | { |
541 | completion(nil, error); | 541 | completion(nil, error); |
542 | } | 542 | } |
543 | }]; | 543 | }]; |
544 | } | 544 | } |
545 | 545 | ||
546 | #pragma mark - SNS Screen Function | 546 | #pragma mark - SNS Screen Function |
547 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 547 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
548 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; | 548 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; |
549 | if(groupID > -1) { | 549 | if(groupID > -1) { |
550 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; | 550 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; |
551 | } | 551 | } |
552 | NSLog(@"requestTweetsList link %@", url); | 552 | NSLog(@"requestTweetsList link %@", url); |
553 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 553 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
554 | 554 | ||
555 | if (completion == NULL) { | 555 | if (completion == NULL) { |
556 | return ; | 556 | return ; |
557 | } | 557 | } |
558 | 558 | ||
559 | if (error == nil) | 559 | if (error == nil) |
560 | { | 560 | { |
561 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 561 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
562 | NSLog(@"%@", dataResult); | 562 | NSLog(@"%@", dataResult); |
563 | int status = [dataResult[@"status"] intValue]; | 563 | int status = [dataResult[@"status"] intValue]; |
564 | if (status == 1) { // status = 1 success | 564 | if (status == 1) { // status = 1 success |
565 | if(dataResult[@"result"] != nil) { | 565 | if(dataResult[@"result"] != nil) { |
566 | NSArray * array = dataResult[@"result"]; | 566 | NSArray * array = dataResult[@"result"]; |
567 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 567 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
568 | for(NSDictionary * dict in array) { | 568 | for(NSDictionary * dict in array) { |
569 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; | 569 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; |
570 | [arrayTweets addObject:object]; | 570 | [arrayTweets addObject:object]; |
571 | } | 571 | } |
572 | completion(arrayTweets, nil); | 572 | completion(arrayTweets, nil); |
573 | } | 573 | } |
574 | else { | 574 | else { |
575 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 575 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
576 | completion(nil, errorObject); | 576 | completion(nil, errorObject); |
577 | } | 577 | } |
578 | } | 578 | } |
579 | else { | 579 | else { |
580 | NSString *message = dataResult[@"message"]; | 580 | NSString *message = dataResult[@"message"]; |
581 | if (message == nil) { | 581 | if (message == nil) { |
582 | message = @"Unknown error"; | 582 | message = @"Unknown error"; |
583 | } | 583 | } |
584 | 584 | ||
585 | if ([message isEqualToString:@"Token is invalid"]) { | 585 | if ([message isEqualToString:@"Token is invalid"]) { |
586 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 586 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
587 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 587 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
588 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 588 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
589 | } | 589 | } |
590 | else { | 590 | else { |
591 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 591 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
592 | completion(nil, errorObject); | 592 | completion(nil, errorObject); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | } | 595 | } |
596 | else | 596 | else |
597 | { | 597 | { |
598 | completion(nil, error); | 598 | completion(nil, error); |
599 | } | 599 | } |
600 | }]; | 600 | }]; |
601 | } | 601 | } |
602 | 602 | ||
603 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 603 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
604 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; | 604 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; |
605 | NSLog(@"searchGroup link %@ page %d", url, page); | 605 | NSLog(@"searchGroup link %@ page %d", url, page); |
606 | if(searchTask != nil) { | 606 | if(searchTask != nil) { |
607 | [searchTask cancel]; | 607 | [searchTask cancel]; |
608 | } | 608 | } |
609 | 609 | ||
610 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { | 610 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { |
611 | searchTask = nil; | 611 | searchTask = nil; |
612 | if (completion == NULL) { | 612 | if (completion == NULL) { |
613 | return ; | 613 | return ; |
614 | } | 614 | } |
615 | 615 | ||
616 | if (error == nil) | 616 | if (error == nil) |
617 | { | 617 | { |
618 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 618 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
619 | NSLog(@"%@", dataResult); | 619 | NSLog(@"%@", dataResult); |
620 | int status = [dataResult[@"status"] intValue]; | 620 | int status = [dataResult[@"status"] intValue]; |
621 | if (status == 1) { // status = 1 success | 621 | if (status == 1) { // status = 1 success |
622 | if(dataResult[@"result"] != nil) { | 622 | if(dataResult[@"result"] != nil) { |
623 | NSArray * array = dataResult[@"result"]; | 623 | NSArray * array = dataResult[@"result"]; |
624 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 624 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
625 | for(NSDictionary * dict in array) { | 625 | for(NSDictionary * dict in array) { |
626 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; | 626 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; |
627 | [arrayTweets addObject:object]; | 627 | [arrayTweets addObject:object]; |
628 | } | 628 | } |
629 | completion(arrayTweets, nil); | 629 | completion(arrayTweets, nil); |
630 | } | 630 | } |
631 | else { | 631 | else { |
632 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 632 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
633 | completion(nil, errorObject); | 633 | completion(nil, errorObject); |
634 | } | 634 | } |
635 | } | 635 | } |
636 | else { | 636 | else { |
637 | NSString *message = dataResult[@"message"]; | 637 | NSString *message = dataResult[@"message"]; |
638 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 638 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
639 | completion(nil, errorObject); | 639 | completion(nil, errorObject); |
640 | } | 640 | } |
641 | } | 641 | } |
642 | else | 642 | else |
643 | { | 643 | { |
644 | completion(nil, error); | 644 | completion(nil, error); |
645 | } | 645 | } |
646 | }]; | 646 | }]; |
647 | } | 647 | } |
648 | 648 | ||
649 | #pragma mark - Group Function | 649 | #pragma mark - Group Function |
650 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | 650 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { |
651 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; | 651 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; |
652 | NSLog(@"getGroupDetail link %@", url); | 652 | NSLog(@"getGroupDetail link %@", url); |
653 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 653 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
654 | 654 | ||
655 | if (completion == NULL) { | 655 | if (completion == NULL) { |
656 | return ; | 656 | return ; |
657 | } | 657 | } |
658 | 658 | ||
659 | if (error == nil) | 659 | if (error == nil) |
660 | { | 660 | { |
661 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 661 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
662 | NSLog(@"%@", dataResult); | 662 | NSLog(@"%@", dataResult); |
663 | int status = [dataResult[@"status"] intValue]; | 663 | int status = [dataResult[@"status"] intValue]; |
664 | if (status == 1) { // status = 1 success | 664 | if (status == 1) { // status = 1 success |
665 | if(dataResult[@"result"] != nil) { | 665 | if(dataResult[@"result"] != nil) { |
666 | NSArray * array = dataResult[@"result"]; | 666 | NSArray * array = dataResult[@"result"]; |
667 | GroupObject * object = [[GroupObject alloc] initWithData:array[0]]; | 667 | GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; |
668 | completion(object, nil); | 668 | completion(object, nil); |
669 | } | 669 | } |
670 | else { | 670 | else { |
671 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 671 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
672 | completion(nil, errorObject); | 672 | completion(nil, errorObject); |
673 | } | 673 | } |
674 | } | 674 | } |
675 | else { | 675 | else { |
676 | NSString *message = dataResult[@"message"]; | 676 | NSString *message = dataResult[@"message"]; |
677 | if (message == nil) { | 677 | if (message == nil) { |
678 | message = @"Unknown error"; | 678 | message = @"Unknown error"; |
679 | } | 679 | } |
680 | 680 | ||
681 | if ([message isEqualToString:@"Token is invalid"]) { | 681 | if ([message isEqualToString:@"Token is invalid"]) { |
682 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 682 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
683 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 683 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
684 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; | 684 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; |
685 | } | 685 | } |
686 | else { | 686 | else { |
687 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 687 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
688 | completion(nil, errorObject); | 688 | completion(nil, errorObject); |
689 | } | 689 | } |
690 | } | 690 | } |
691 | } | 691 | } |
692 | else | 692 | else |
693 | { | 693 | { |
694 | completion(nil, error); | 694 | completion(nil, error); |
695 | } | 695 | } |
696 | }]; | 696 | }]; |
697 | } | 697 | } |
698 | 698 | ||
699 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 699 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
700 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; | 700 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; |
701 | NSLog(@"requestMemberList link %@ page %d", url, page); | 701 | NSLog(@"requestMemberList link %@ page %d", url, page); |
702 | 702 | ||
703 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 703 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
704 | if (completion == NULL) { | 704 | if (completion == NULL) { |
705 | return ; | 705 | return ; |
706 | } | 706 | } |
707 | 707 | ||
708 | if (error == nil) | 708 | if (error == nil) |
709 | { | 709 | { |
710 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 710 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
711 | NSLog(@"%@", dataResult); | 711 | NSLog(@"%@", dataResult); |
712 | int status = [dataResult[@"status"] intValue]; | 712 | int status = [dataResult[@"status"] intValue]; |
713 | if (status == 1) { // status = 1 success | 713 | if (status == 1) { // status = 1 success |
714 | if(dataResult[@"result"] != nil) { | 714 | if(dataResult[@"result"] != nil) { |
715 | NSArray * array = dataResult[@"result"]; | 715 | NSArray * array = dataResult[@"result"]; |
716 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 716 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
717 | for(NSDictionary * dict in array) { | 717 | for(NSDictionary * dict in array) { |
718 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; | 718 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; |
719 | [arrayTweets addObject:object]; | 719 | [arrayTweets addObject:object]; |
720 | } | 720 | } |
721 | completion(arrayTweets, nil); | 721 | completion(arrayTweets, nil); |
722 | } | 722 | } |
723 | else { | 723 | else { |
724 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 724 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
725 | completion(nil, errorObject); | 725 | completion(nil, errorObject); |
726 | } | 726 | } |
727 | } | 727 | } |
728 | else { | 728 | else { |
729 | NSString *message = dataResult[@"message"]; | 729 | NSString *message = dataResult[@"message"]; |
730 | if (message == nil) { | 730 | if (message == nil) { |
731 | message = @"Unknown error"; | 731 | message = @"Unknown error"; |
732 | } | 732 | } |
733 | 733 | ||
734 | if ([message isEqualToString:@"Token is invalid"]) { | 734 | if ([message isEqualToString:@"Token is invalid"]) { |
735 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 735 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
736 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 736 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
737 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 737 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
738 | } | 738 | } |
739 | else { | 739 | else { |
740 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 740 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
741 | completion(nil, errorObject); | 741 | completion(nil, errorObject); |
742 | } | 742 | } |
743 | } | 743 | } |
744 | } | 744 | } |
745 | else | 745 | else |
746 | { | 746 | { |
747 | completion(nil, error); | 747 | completion(nil, error); |
748 | } | 748 | } |
749 | }]; | 749 | }]; |
750 | } | 750 | } |
751 | 751 | ||
752 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { | 752 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { |
753 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; | 753 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; |
754 | NSLog(@"requestJoinGroup link %@", url); | 754 | NSLog(@"requestJoinGroup link %@", url); |
755 | 755 | ||
756 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { | 756 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { |
757 | searchTask = nil; | 757 | searchTask = nil; |
758 | if (completion == NULL) { | 758 | if (completion == NULL) { |
759 | return ; | 759 | return ; |
760 | } | 760 | } |
761 | 761 | ||
762 | if (error == nil) | 762 | if (error == nil) |
763 | { | 763 | { |
764 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 764 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
765 | NSLog(@"%@", dataResult); | 765 | NSLog(@"%@", dataResult); |
766 | int status = [dataResult[@"status"] intValue]; | 766 | int status = [dataResult[@"status"] intValue]; |
767 | if (status == 1) { // status = 1 success | 767 | if (status == 1) { // status = 1 success |
768 | if(dataResult[@"result"] != nil) { | 768 | if(dataResult[@"result"] != nil) { |
769 | completion(nil); | 769 | completion(nil); |
770 | } | 770 | } |
771 | else { | 771 | else { |
772 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 772 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
773 | completion(errorObject); | 773 | completion(errorObject); |
774 | } | 774 | } |
775 | } | 775 | } |
776 | else { | 776 | else { |
777 | NSString *message = dataResult[@"message"]; | 777 | NSString *message = dataResult[@"message"]; |
778 | if ([message isEqualToString:@"Token is invalid"]) { | 778 | if ([message isEqualToString:@"Token is invalid"]) { |
779 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 779 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
780 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 780 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
781 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; | 781 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; |
782 | } | 782 | } |
783 | else { | 783 | else { |
784 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 784 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
785 | completion(errorObject); | 785 | completion(errorObject); |
786 | } | 786 | } |
787 | } | 787 | } |
788 | } | 788 | } |
789 | else | 789 | else |
790 | { | 790 | { |
791 | completion(error); | 791 | completion(error); |
792 | } | 792 | } |
793 | }]; | 793 | }]; |
794 | } | 794 | } |
795 | 795 | ||
796 | #pragma mark - Common API | 796 | #pragma mark - Common API |
797 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { | 797 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
798 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { | 798 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |
799 | 799 | ||
800 | if (completion == NULL) { | 800 | if (completion == NULL) { |
801 | return ; | 801 | return ; |
802 | } | 802 | } |
803 | 803 | ||
804 | if (error == nil) | 804 | if (error == nil) |
805 | { | 805 | { |
806 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 806 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
807 | 807 | ||
808 | int status = [dataResult[@"status"] intValue]; | 808 | int status = [dataResult[@"status"] intValue]; |
809 | if (status == 1) { // status = 1 success | 809 | if (status == 1) { // status = 1 success |
810 | NSArray *arrayResult = dataResult[@"result"]; | 810 | NSArray *arrayResult = dataResult[@"result"]; |
811 | if (arrayResult.count > 0) { | 811 | if (arrayResult.count > 0) { |
812 | NSString *token = arrayResult[0]; | 812 | NSString *token = arrayResult[0]; |
813 | completion(token, nil); | 813 | completion(token, nil); |
814 | } | 814 | } |
815 | else { | 815 | else { |
816 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 816 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
817 | completion(nil, errorObject); | 817 | completion(nil, errorObject); |
818 | } | 818 | } |
819 | 819 | ||
820 | } | 820 | } |
821 | else { // status = 0 error | 821 | else { // status = 0 error |
822 | NSString *message = dataResult[@"message"]; | 822 | NSString *message = dataResult[@"message"]; |
823 | if (message == nil) { | 823 | if (message == nil) { |
824 | message = @"Unknown error"; | 824 | message = @"Unknown error"; |
825 | } | 825 | } |
826 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 826 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
827 | completion(nil, loginFaild); | 827 | completion(nil, loginFaild); |
828 | } | 828 | } |
829 | } | 829 | } |
830 | else | 830 | else |
831 | { | 831 | { |
832 | completion(nil, error); | 832 | completion(nil, error); |
833 | } | 833 | } |
834 | }]; | 834 | }]; |
835 | } | 835 | } |
836 | 836 | ||
837 | #pragma mark - Private Function | 837 | #pragma mark - Private Function |
838 | - (void) checkToken { | 838 | - (void) checkToken { |
839 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; | 839 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; |
840 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | 840 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; |
841 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | 841 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; |
842 | if (user != nil) { | 842 | if (user != nil) { |
843 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { | 843 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { |
844 | if (error == nil) { | 844 | if (error == nil) { |
845 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | 845 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; |
846 | [[NSUserDefaults standardUserDefaults] synchronize]; | 846 | [[NSUserDefaults standardUserDefaults] synchronize]; |
847 | } | 847 | } |
848 | }]; | 848 | }]; |
849 | } | 849 | } |
850 | } | 850 | } |
851 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary | 851 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary |
852 | { | 852 | { |
853 | NSMutableArray *parts = [[NSMutableArray alloc] init]; | 853 | NSMutableArray *parts = [[NSMutableArray alloc] init]; |
854 | for (id key in dictionary) | 854 | for (id key in dictionary) |
855 | { | 855 | { |
856 | NSString *encodedValue = [[dictionary[key] description] urlencode]; | 856 | NSString *encodedValue = [[dictionary[key] description] urlencode]; |
857 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; | 857 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; |
858 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; | 858 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; |
859 | [parts addObject:part]; | 859 | [parts addObject:part]; |
860 | } | 860 | } |
861 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; | 861 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; |
862 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; | 862 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; |
863 | } | 863 | } |
864 | 864 | ||
865 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | 865 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion |
866 | { | 866 | { |
867 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; | 867 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; |
868 | request.HTTPMethod = method; | 868 | request.HTTPMethod = method; |
869 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; | 869 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; |
870 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; | 870 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; |
871 | if(token != nil && ![token isEqual: @""]) { | 871 | if(token != nil && ![token isEqual: @""]) { |
872 | [request setValue: token forHTTPHeaderField: @"token"]; | 872 | [request setValue: token forHTTPHeaderField: @"token"]; |
873 | } | 873 | } |
874 | [request setTimeoutInterval:self.timeOutInterval]; | 874 | [request setTimeoutInterval:self.timeOutInterval]; |
875 | 875 | ||
876 | if (paras != nil) | 876 | if (paras != nil) |
877 | { | 877 | { |
878 | NSData *encodedData = [self _encodeDictionary: paras]; | 878 | NSData *encodedData = [self _encodeDictionary: paras]; |
879 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; | 879 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; |
880 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; | 880 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; |
881 | [request setHTTPBody: encodedData]; | 881 | [request setHTTPBody: encodedData]; |
882 | } | 882 | } |
883 | 883 | ||
884 | NSURLSession *session = [NSURLSession sharedSession]; | 884 | NSURLSession *session = [NSURLSession sharedSession]; |
885 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request | 885 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request |
886 | completionHandler: | 886 | completionHandler: |
887 | ^(NSData *data, NSURLResponse *response, NSError *error) { | 887 | ^(NSData *data, NSURLResponse *response, NSError *error) { |
888 | if (completion == NULL) { | 888 | if (completion == NULL) { |
889 | return ; | 889 | return ; |
890 | } | 890 | } |
891 | if (error == nil) | 891 | if (error == nil) |
892 | { | 892 | { |
893 | completion(data, nil); | 893 | completion(data, nil); |
894 | } | 894 | } |
895 | else | 895 | else |
896 | { | 896 | { |
897 | completion(nil, error); | 897 | completion(nil, error); |
898 | } | 898 | } |
899 | }]; | 899 | }]; |
900 | [task resume]; | 900 | [task resume]; |
901 | return task; | 901 | return task; |
902 | } | 902 | } |
903 | 903 | ||
904 | -(void)waitUntilDone:(void(^)(void))waitBlock { | 904 | -(void)waitUntilDone:(void(^)(void))waitBlock { |
905 | //use your statement or call method here | 905 | //use your statement or call method here |
906 | if(waitBlock){ | 906 | if(waitBlock){ |
907 | waitBlock(); | 907 | waitBlock(); |
908 | } | 908 | } |
909 | } | 909 | } |
910 | 910 | ||
911 | @end | 911 | @end |
912 | 912 |