Commit 3c805063b5b987fbb80f35b76673c9d33c2ab091
1 parent
26548f2f08
Exists in
master
update api notice
Showing 5 changed files with 97 additions and 19 deletions Side-by-side Diff
LifeLog/LifeLog/HomeViewConb troller.m
... | ... | @@ -117,8 +117,45 @@ |
117 | 117 | progressHud.detailsLabel.text = NSLocalizedString(@"lifelog.home.progressHud.title", nil); |
118 | 118 | // [self saveDataStep7LastDay]; |
119 | 119 | targetStep = numberTotal; |
120 | + [self requestNotice]; | |
120 | 121 | } |
121 | 122 | |
123 | +- (void)requestNotice | |
124 | +{ | |
125 | + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
126 | + [dateFormatter setDateFormat:@"yyyy-MM-dd"]; | |
127 | + NSString *dateString = [dateFormatter stringFromDate:_dateCurrent]; | |
128 | + HomeViewController __weak *weakSelf = self; | |
129 | + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
130 | + //Do background work | |
131 | + [[ServerAPI server] getNoticeByDate:dateString CompletionHandler:^(NSArray *arrResults, NSError *error) { | |
132 | + if(weakSelf == nil) { | |
133 | + return ; | |
134 | + } | |
135 | + if (error == nil) { | |
136 | + // NSLog(@"List Notices: %@", arrResults); | |
137 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
138 | + NSString *stringNotice = @""; | |
139 | + for (NSString *noticeInfor in arrResults) { | |
140 | + NSString *noticeString = [NSString stringWithFormat:@"%@\n", noticeInfor]; | |
141 | + stringNotice = [stringNotice stringByAppendingString:noticeString]; | |
142 | + } | |
143 | + weakSelf.tvNotice.text = stringNotice; | |
144 | + }); | |
145 | + } | |
146 | + else { | |
147 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
148 | + weakSelf.tvNotice.text = @""; | |
149 | + /* | |
150 | + NSString *message = [error.userInfo objectForKey:@"message"]; | |
151 | + [Utilities showErrorMessage:message withViewController:weakSelf]; | |
152 | + */ | |
153 | + }); | |
154 | + } | |
155 | + }]; | |
156 | + }); | |
157 | +} | |
158 | + | |
122 | 159 | - (void)viewWillAppear:(BOOL)animated { |
123 | 160 | [super viewWillAppear:animated]; |
124 | 161 | NSDate *dateNow = [NSDate date]; |
... | ... | @@ -169,6 +206,7 @@ |
169 | 206 | [progressHud setHidden:YES]; |
170 | 207 | }); |
171 | 208 | }]; |
209 | + /* | |
172 | 210 | [[ServerAPI server] requestHomeWithMode:mode andDate:dateString CompletionHandler:^(HomeObject *homeObject, NSError *error) { |
173 | 211 | if(weakSelf == nil) { |
174 | 212 | return ; |
... | ... | @@ -192,6 +230,7 @@ |
192 | 230 | [progressHud setHidden:YES]; |
193 | 231 | }); |
194 | 232 | }]; |
233 | + */ | |
195 | 234 | } |
196 | 235 | |
197 | 236 | - (void)viewWillDisappear:(BOOL)animated { |
... | ... | @@ -222,6 +261,7 @@ |
222 | 261 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
223 | 262 | [self resetStepUI]; |
224 | 263 | [self saveStepForDay:self.dateCurrent]; |
264 | + [self requestNotice]; | |
225 | 265 | } |
226 | 266 | |
227 | 267 | - (IBAction)rightButtonTouchUpInside:(id)sender |
... | ... | @@ -231,6 +271,7 @@ |
231 | 271 | [self resetStepUI]; |
232 | 272 | //[self saveStepForDay:self.dateCurrent]; |
233 | 273 | [self requestTopByDate:self.dateCurrent]; |
274 | + [self requestNotice]; | |
234 | 275 | } |
235 | 276 | |
236 | 277 | - (IBAction)segmentValueChange:(id)sender { |
... | ... | @@ -346,7 +387,7 @@ |
346 | 387 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; |
347 | 388 | NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; |
348 | 389 | NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; |
349 | - NSLog(@"dateBegin: %@ | dateEnd: %@ | numberStep: %li", dateBegin, dateEnd, numberStep); | |
390 | + // NSLog(@"dateBegin: %@ | dateEnd: %@ | numberStep: %li", dateBegin, dateEnd, numberStep); | |
350 | 391 | [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { |
351 | 392 | if (error) { |
352 | 393 | NSLog(@"Error: %@", error); |
LifeLog/LifeLog/HomeViewController.xib
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
3 | 3 | <device id="retina4_7" orientation="portrait"> |
4 | 4 | <adaptation id="fullscreen"/> |
5 | 5 | </device> |
6 | 6 | <dependencies> |
7 | 7 | <deployment identifier="iOS"/> |
8 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/> | |
8 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/> | |
9 | 9 | <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> |
10 | 10 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
11 | 11 | </dependencies> |
12 | 12 | |
13 | 13 | |
... | ... | @@ -153,22 +153,15 @@ |
153 | 153 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
154 | 154 | <nil key="highlightedColor"/> |
155 | 155 | </label> |
156 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ใ็ฅใใ" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lnt-4H-Ao8"> | |
156 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ใ็ฅใใ" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lnt-4H-Ao8"> | |
157 | 157 | <rect key="frame" x="8" y="275" width="359" height="30"/> |
158 | 158 | <constraints> |
159 | 159 | <constraint firstAttribute="height" constant="30" id="isj-iQ-BcF"/> |
160 | 160 | </constraints> |
161 | - <fontDescription key="fontDescription" type="system" pointSize="20"/> | |
161 | + <fontDescription key="fontDescription" type="system" pointSize="25"/> | |
162 | 162 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
163 | 163 | <nil key="highlightedColor"/> |
164 | 164 | </label> |
165 | - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_other" translatesAutoresizingMaskIntoConstraints="NO" id="BoP-c1-c0q"> | |
166 | - <rect key="frame" x="20" y="313" width="75" height="67"/> | |
167 | - <constraints> | |
168 | - <constraint firstAttribute="width" constant="75" id="lKw-2n-DMo"/> | |
169 | - <constraint firstAttribute="height" constant="67" id="m58-CT-3kB"/> | |
170 | - </constraints> | |
171 | - </imageView> | |
172 | 165 | <segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="ibb-Yl-iqu"> |
173 | 166 | <rect key="frame" x="75" y="575" width="224" height="29"/> |
174 | 167 | <segments> |
175 | 168 | |
... | ... | @@ -182,10 +175,10 @@ |
182 | 175 | </connections> |
183 | 176 | </segmentedControl> |
184 | 177 | <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kdD-rj-BtX" userLabel="tvNotice"> |
185 | - <rect key="frame" x="103" y="313" width="264" height="204"/> | |
178 | + <rect key="frame" x="8" y="313" width="359" height="204"/> | |
186 | 179 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
187 | 180 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
188 | - <fontDescription key="fontDescription" type="system" pointSize="14"/> | |
181 | + <fontDescription key="fontDescription" type="system" pointSize="17"/> | |
189 | 182 | <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> |
190 | 183 | </textView> |
191 | 184 | </subviews> |
... | ... | @@ -201,7 +194,6 @@ |
201 | 194 | <constraint firstAttribute="trailing" secondItem="LPY-Zl-cOp" secondAttribute="trailing" constant="10" id="CX3-BL-hNh"/> |
202 | 195 | <constraint firstItem="vRa-cr-YTe" firstAttribute="leading" secondItem="J2A-tf-wH0" secondAttribute="trailing" constant="10" id="Cax-pu-Kp7"/> |
203 | 196 | <constraint firstItem="3Xj-IB-96h" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="E8R-qO-PtJ"/> |
204 | - <constraint firstItem="kdD-rj-BtX" firstAttribute="leading" secondItem="BoP-c1-c0q" secondAttribute="trailing" constant="8" id="EE0-bp-sbO"/> | |
205 | 197 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerX" secondItem="vRa-cr-YTe" secondAttribute="centerX" id="EEt-Ct-vxb"/> |
206 | 198 | <constraint firstItem="u3S-9u-GMZ" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" placeholder="YES" id="GbN-me-UEd"/> |
207 | 199 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerY" secondItem="vRa-cr-YTe" secondAttribute="centerY" id="HXS-oH-EPB"/> |
208 | 200 | |
... | ... | @@ -209,11 +201,9 @@ |
209 | 201 | <constraint firstAttribute="trailing" secondItem="lnt-4H-Ao8" secondAttribute="trailing" constant="8" id="IEA-1V-AZx"/> |
210 | 202 | <constraint firstItem="ibb-Yl-iqu" firstAttribute="top" secondItem="VAz-hq-dvR" secondAttribute="bottom" constant="20" id="Ib2-KY-3A7"/> |
211 | 203 | <constraint firstAttribute="bottom" secondItem="ibb-Yl-iqu" secondAttribute="bottom" constant="64" id="Iv8-Al-1Ff"/> |
212 | - <constraint firstItem="BoP-c1-c0q" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="OVd-PH-Yxx"/> | |
213 | 204 | <constraint firstItem="DuE-Dh-nEe" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="Rum-yc-3Ym"/> |
214 | 205 | <constraint firstItem="Low-8n-pqa" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="W7b-Hb-9ME"/> |
215 | 206 | <constraint firstItem="IaR-IO-4RA" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="b4I-Me-4xZ"/> |
216 | - <constraint firstItem="BoP-c1-c0q" firstAttribute="top" secondItem="lnt-4H-Ao8" secondAttribute="bottom" constant="8" id="bAt-3o-b1H"/> | |
217 | 207 | <constraint firstItem="wfu-aB-xXm" firstAttribute="top" secondItem="IaR-IO-4RA" secondAttribute="bottom" constant="40" id="bH1-l5-YRA"/> |
218 | 208 | <constraint firstItem="lnt-4H-Ao8" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="ea3-Dx-s4s"/> |
219 | 209 | <constraint firstItem="at8-co-gC4" firstAttribute="centerX" secondItem="Low-8n-pqa" secondAttribute="centerX" id="h5o-Cj-Z7s"/> |
... | ... | @@ -226,6 +216,7 @@ |
226 | 216 | <constraint firstItem="J2A-tf-wH0" firstAttribute="top" secondItem="u3S-9u-GMZ" secondAttribute="bottom" constant="10" id="nu9-Lj-5xz"/> |
227 | 217 | <constraint firstAttribute="trailing" secondItem="3Xj-IB-96h" secondAttribute="trailing" constant="8" id="pF6-db-UUi"/> |
228 | 218 | <constraint firstItem="3Xj-IB-96h" firstAttribute="top" secondItem="wfu-aB-xXm" secondAttribute="bottom" constant="8" id="psY-0r-fPJ"/> |
219 | + <constraint firstItem="kdD-rj-BtX" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="q4Z-No-KmH"/> | |
229 | 220 | <constraint firstItem="TUf-Tp-93t" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="sC4-Kr-3bN"/> |
230 | 221 | <constraint firstItem="at8-co-gC4" firstAttribute="centerY" secondItem="Low-8n-pqa" secondAttribute="centerY" id="tav-ge-tCT"/> |
231 | 222 | <constraint firstItem="VAz-hq-dvR" firstAttribute="top" secondItem="kdD-rj-BtX" secondAttribute="bottom" constant="8" id="ujL-1z-cUf"/> |
... | ... | @@ -241,7 +232,6 @@ |
241 | 232 | <image name="avatar_default" width="80" height="80"/> |
242 | 233 | <image name="icon_left" width="30" height="30"/> |
243 | 234 | <image name="icon_menu" width="30" height="30"/> |
244 | - <image name="icon_other" width="150" height="134"/> | |
245 | 235 | <image name="icon_right" width="30" height="30"/> |
246 | 236 | </resources> |
247 | 237 | </document> |
LifeLog/LifeLog/Info.plist
LifeLog/LifeLog/ServerAPI.h
... | ... | @@ -54,5 +54,7 @@ |
54 | 54 | |
55 | 55 | #pragma mark - Common API |
56 | 56 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
57 | +#pragma mark - Get Notice | |
58 | +- (void)getNoticeByDate: (NSString *)date CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | |
57 | 59 | @end |
LifeLog/LifeLog/ServerAPI.m
... | ... | @@ -1045,6 +1045,51 @@ |
1045 | 1045 | }]; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | +- (void)getNoticeByDate: (NSString *)date CompletionHandler:(void (^)(NSArray *, NSError *)) completion | |
1049 | +{ | |
1050 | + [self _request:[kServerAddress stringByAppendingFormat: @"api/getnoticesbydate/%@", date] method:@"GET" token:@"" paras:nil completion:^(NSData *data, NSError *error) { | |
1051 | + | |
1052 | + if (completion == NULL) { | |
1053 | + return ; | |
1054 | + } | |
1055 | + | |
1056 | + if (error == nil) | |
1057 | + { | |
1058 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
1059 | + | |
1060 | + int status = [dataResult[@"status"] intValue]; | |
1061 | + if (status == 1) { // status = 1 success | |
1062 | + NSArray *arrayResult = dataResult[@"result"][@"listNotice"]; | |
1063 | + if (arrayResult.count > 0) { | |
1064 | + NSMutableArray *notices = [[NSMutableArray alloc] init]; | |
1065 | + for(NSDictionary *dict in arrayResult) { | |
1066 | + NSString *object = [dict objectForKey:@"notice_content"]; | |
1067 | + [notices addObject:object]; | |
1068 | + } | |
1069 | + completion(notices, nil); | |
1070 | + } | |
1071 | + else { | |
1072 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Today is not notice"}]; | |
1073 | + completion(nil, errorObject); | |
1074 | + } | |
1075 | + | |
1076 | + } | |
1077 | + else { // status = 0 error | |
1078 | + NSString *message = dataResult[@"message"]; | |
1079 | + if (message == nil) { | |
1080 | + message = @"Unknown error"; | |
1081 | + } | |
1082 | + NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
1083 | + completion(nil, loginFaild); | |
1084 | + } | |
1085 | + } | |
1086 | + else | |
1087 | + { | |
1088 | + completion(nil, error); | |
1089 | + } | |
1090 | + }]; | |
1091 | +} | |
1092 | + | |
1048 | 1093 | #pragma mark - Private Function |
1049 | 1094 | - (void) checkToken { |
1050 | 1095 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; |