Commit e796f8345cf407df174166eb3d8c949a6b12f59f
1 parent
29486f50ff
Exists in
master
and in
1 other branch
Add ranking API in Ranking Screen, display result in screen
Showing 14 changed files with 212 additions and 88 deletions Side-by-side Diff
- LifeLog/LifeLog.xcodeproj/project.pbxproj
- LifeLog/LifeLog/BaseTableViewController.m
- LifeLog/LifeLog/Entities.h
- LifeLog/LifeLog/HistoryGraphObject.h
- LifeLog/LifeLog/HistoryGraphObject.m
- LifeLog/LifeLog/RankingObject.h
- LifeLog/LifeLog/RankingObject.m
- LifeLog/LifeLog/RankingTableViewCell.h
- LifeLog/LifeLog/RankingTableViewCell.m
- LifeLog/LifeLog/RankingViewController.h
- LifeLog/LifeLog/RankingViewController.m
- LifeLog/LifeLog/RankingViewController.xib
- LifeLog/LifeLog/ServerAPI.h
- LifeLog/LifeLog/ServerAPI.m
LifeLog/LifeLog.xcodeproj/project.pbxproj
... | ... | @@ -56,7 +56,6 @@ |
56 | 56 | E933E67A1F40513C002926F5 /* GroupDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E933E6781F40513C002926F5 /* GroupDetailViewController.xib */; }; |
57 | 57 | E9373E471F3596940059355A /* AutoTransLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E461F3596940059355A /* AutoTransLabel.m */; }; |
58 | 58 | E9373E4A1F35AA180059355A /* HistoryObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E491F35AA180059355A /* HistoryObject.m */; }; |
59 | - E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E4C1F361A230059355A /* HistoryGraphObject.m */; }; | |
60 | 59 | E9497FD51F46EC1100E6AF8D /* MemberObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9497FD41F46EC1100E6AF8D /* MemberObject.m */; }; |
61 | 60 | E95F4CED1F475C6A00D27E80 /* CreateGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E95F4CEB1F475C6A00D27E80 /* CreateGroupViewController.m */; }; |
62 | 61 | E95F4CEE1F475C6A00D27E80 /* CreateGroupViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E95F4CEC1F475C6A00D27E80 /* CreateGroupViewController.xib */; }; |
... | ... | @@ -67,6 +66,7 @@ |
67 | 66 | E968550A1F3C444900317CEF /* AutoTransButton.m in Sources */ = {isa = PBXBuildFile; fileRef = E96855091F3C444900317CEF /* AutoTransButton.m */; }; |
68 | 67 | E96855111F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E968550F1F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.m */; }; |
69 | 68 | E96855121F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E96855101F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.xib */; }; |
69 | + E97588FC1F513BAD00782484 /* RankingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E97588FB1F513BAD00782484 /* RankingObject.m */; }; | |
70 | 70 | E997E0261F3AB66500709FB1 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E997E0251F3AB66500709FB1 /* Social.framework */; }; |
71 | 71 | E99E13AB1F336F3600C78787 /* CollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AA1F336F3600C78787 /* CollectionView.m */; }; |
72 | 72 | E99E13AD1F336F4500C78787 /* CollectionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E99E13AC1F336F4500C78787 /* CollectionView.xib */; }; |
... | ... | @@ -184,8 +184,6 @@ |
184 | 184 | E9373E461F3596940059355A /* AutoTransLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AutoTransLabel.m; sourceTree = "<group>"; }; |
185 | 185 | E9373E481F35AA180059355A /* HistoryObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryObject.h; sourceTree = "<group>"; }; |
186 | 186 | E9373E491F35AA180059355A /* HistoryObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryObject.m; sourceTree = "<group>"; }; |
187 | - E9373E4B1F361A230059355A /* HistoryGraphObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryGraphObject.h; sourceTree = "<group>"; }; | |
188 | - E9373E4C1F361A230059355A /* HistoryGraphObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryGraphObject.m; sourceTree = "<group>"; }; | |
189 | 187 | E9497FD31F46EC1100E6AF8D /* MemberObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemberObject.h; sourceTree = "<group>"; }; |
190 | 188 | E9497FD41F46EC1100E6AF8D /* MemberObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MemberObject.m; sourceTree = "<group>"; }; |
191 | 189 | E95F4CEA1F475C6A00D27E80 /* CreateGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateGroupViewController.h; sourceTree = "<group>"; }; |
... | ... | @@ -202,6 +200,8 @@ |
202 | 200 | E968550E1F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNSRecentTopicTableViewCell.h; sourceTree = "<group>"; }; |
203 | 201 | E968550F1F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNSRecentTopicTableViewCell.m; sourceTree = "<group>"; }; |
204 | 202 | E96855101F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SNSRecentTopicTableViewCell.xib; sourceTree = "<group>"; }; |
203 | + E97588FA1F513BAD00782484 /* RankingObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RankingObject.h; sourceTree = "<group>"; }; | |
204 | + E97588FB1F513BAD00782484 /* RankingObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RankingObject.m; sourceTree = "<group>"; }; | |
205 | 205 | E997E0251F3AB66500709FB1 /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; }; |
206 | 206 | E99E13A91F336F3600C78787 /* CollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionView.h; sourceTree = "<group>"; }; |
207 | 207 | E99E13AA1F336F3600C78787 /* CollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectionView.m; sourceTree = "<group>"; }; |
208 | 208 | |
... | ... | @@ -288,14 +288,14 @@ |
288 | 288 | 6E18CEDB1F2E40F50029891F /* User.m */, |
289 | 289 | E9373E481F35AA180059355A /* HistoryObject.h */, |
290 | 290 | E9373E491F35AA180059355A /* HistoryObject.m */, |
291 | - E9373E4B1F361A230059355A /* HistoryGraphObject.h */, | |
292 | - E9373E4C1F361A230059355A /* HistoryGraphObject.m */, | |
293 | 291 | E9D9091F1F3D559D004CF99F /* TweetObject.h */, |
294 | 292 | E9D909201F3D559D004CF99F /* TweetObject.m */, |
295 | 293 | E933E6721F3E0E4E002926F5 /* GroupObject.h */, |
296 | 294 | E933E6731F3E0E4E002926F5 /* GroupObject.m */, |
297 | 295 | E9497FD31F46EC1100E6AF8D /* MemberObject.h */, |
298 | 296 | E9497FD41F46EC1100E6AF8D /* MemberObject.m */, |
297 | + E97588FA1F513BAD00782484 /* RankingObject.h */, | |
298 | + E97588FB1F513BAD00782484 /* RankingObject.m */, | |
299 | 299 | ); |
300 | 300 | name = Model; |
301 | 301 | sourceTree = "<group>"; |
... | ... | @@ -867,6 +867,7 @@ |
867 | 867 | 9CA8AEEA1F31BB4600C5FC74 /* ConfirmForgetPassViewController.m in Sources */, |
868 | 868 | E99E13B11F33720600C78787 /* LabelCollectionViewCell.m in Sources */, |
869 | 869 | 6EDC8BEE1F2C2FB800765ACC /* Utilities.m in Sources */, |
870 | + E97588FC1F513BAD00782484 /* RankingObject.m in Sources */, | |
870 | 871 | E96855111F3C5D9A00317CEF /* SNSRecentTopicTableViewCell.m in Sources */, |
871 | 872 | 6E84E3C51F27ACAE001EB88E /* MapViewController.m in Sources */, |
872 | 873 | 6E18CEDC1F2E40F50029891F /* User.m in Sources */, |
... | ... | @@ -879,7 +880,6 @@ |
879 | 880 | E933E6701F3E09B6002926F5 /* SearchGroupTableViewCell.m in Sources */, |
880 | 881 | 6E84E3B51F27A98B001EB88E /* HistoryViewController.m in Sources */, |
881 | 882 | E95F4CF31F48B39200D27E80 /* MyGroupViewController.m in Sources */, |
882 | - E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */, | |
883 | 883 | E933E66B1F3E04A6002926F5 /* SearchGroupViewController.m in Sources */, |
884 | 884 | 6E84E3BF1F27A9B1001EB88E /* SNSViewController.m in Sources */, |
885 | 885 | ); |
LifeLog/LifeLog/BaseTableViewController.m
... | ... | @@ -61,10 +61,10 @@ |
61 | 61 | }); |
62 | 62 | } |
63 | 63 | if(error == nil) { |
64 | + if(_curPage == 1) { | |
65 | + [_curDataList removeAllObjects]; | |
66 | + } | |
64 | 67 | if(array.count != 0) { |
65 | - if(_curPage == 1) { | |
66 | - [_curDataList removeAllObjects]; | |
67 | - } | |
68 | 68 | [_curDataList addObjectsFromArray:array]; |
69 | 69 | dispatch_async(dispatch_get_main_queue(), ^{ |
70 | 70 | [weakSelf.tableBase reloadData]; |
LifeLog/LifeLog/Entities.h
... | ... | @@ -14,10 +14,10 @@ |
14 | 14 | #import "MemberObject.h" |
15 | 15 | #import "GroupObject.h" |
16 | 16 | #import "TweetObject.h" |
17 | -#import "HistoryGraphObject.h" | |
18 | 17 | #import "HistoryObject.h" |
19 | 18 | #import "User.h" |
20 | 19 | #import "TopObject.h" |
20 | +#import "RankingObject.h" | |
21 | 21 | |
22 | 22 | #endif /* Entities_h */ |
LifeLog/LifeLog/HistoryGraphObject.h
1 | -// | |
2 | -// HistoryGraphObject.h | |
3 | -// LifeLog | |
4 | -// | |
5 | -// Created by nvtu on 8/5/17. | |
6 | -// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import <Foundation/Foundation.h> | |
10 | - | |
11 | -@interface HistoryGraphObject : NSObject | |
12 | - | |
13 | -@property (nonatomic, strong) NSMutableArray * arrayTime; | |
14 | -@property (nonatomic, strong) NSMutableArray * arrayStep; | |
15 | - | |
16 | --(id) initWithData : (NSDictionary *) dict; | |
17 | - | |
18 | -@end |
LifeLog/LifeLog/HistoryGraphObject.m
1 | -// | |
2 | -// HistoryGraphObject.m | |
3 | -// LifeLog | |
4 | -// | |
5 | -// Created by nvtu on 8/5/17. | |
6 | -// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
7 | -// | |
8 | - | |
9 | -#import "HistoryGraphObject.h" | |
10 | - | |
11 | -@implementation HistoryGraphObject | |
12 | - | |
13 | --(id) initWithData : (NSDictionary *) dict { | |
14 | - | |
15 | - if([dict objectForKey:@"data"] != nil) { | |
16 | - self.arrayStep = [[NSMutableArray alloc] init]; | |
17 | - self.arrayTime = [[NSMutableArray alloc] init]; | |
18 | - NSArray *arrayGraph = dict[@"data"]; | |
19 | - for(NSDictionary *sub in arrayGraph) { | |
20 | - if([sub objectForKey:@"hour"] != nil && [sub objectForKey:@"step"] != nil) { | |
21 | - [self.arrayTime addObject:[sub objectForKey:@"hour"]]; | |
22 | - [self.arrayStep addObject:[sub objectForKey:@"step"]]; | |
23 | - } | |
24 | - } | |
25 | - } | |
26 | - else { | |
27 | - return nil; | |
28 | - } | |
29 | - return self; | |
30 | -} | |
31 | - | |
32 | - | |
33 | -@end |
LifeLog/LifeLog/RankingObject.h
1 | +// | |
2 | +// RankingObject.h | |
3 | +// LifeLog | |
4 | +// | |
5 | +// Created by nvtu on 8/26/17. | |
6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <Foundation/Foundation.h> | |
10 | + | |
11 | +@interface RankingObject : NSObject | |
12 | + | |
13 | +@property (nonatomic) int userID; | |
14 | +@property (nonatomic) int rank; | |
15 | +@property (nonatomic) int steps; | |
16 | +@property (nonatomic) int time; | |
17 | +@property (nonatomic) float distance; | |
18 | + | |
19 | +@property (nonatomic, strong) NSString * userName; | |
20 | +@property (nonatomic, strong) NSString * avatar; | |
21 | + | |
22 | +-(id) initWithData : (NSDictionary *) dict; | |
23 | + | |
24 | +@end |
LifeLog/LifeLog/RankingObject.m
1 | +// | |
2 | +// RankingObject.m | |
3 | +// LifeLog | |
4 | +// | |
5 | +// Created by nvtu on 8/26/17. | |
6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "RankingObject.h" | |
10 | + | |
11 | +@implementation RankingObject | |
12 | + | |
13 | +-(id) initWithData : (NSDictionary *) dict { | |
14 | + if([dict objectForKey:@"user_id"] != nil) { | |
15 | + self.userID = [dict[@"user_id"] intValue]; | |
16 | + } | |
17 | + if([dict objectForKey:@"rank"] != nil) { | |
18 | + self.rank = [dict[@"rank"] intValue]; | |
19 | + } | |
20 | + if([dict objectForKey:@"steps"] != nil) { | |
21 | + self.steps = [dict[@"steps"] intValue]; | |
22 | + } | |
23 | + if([dict objectForKey:@"distance"] != nil) { | |
24 | + self.distance = [dict[@"distance"] floatValue]; | |
25 | + } | |
26 | + if([dict objectForKey:@"time"] != nil) { | |
27 | + self.time = [dict[@"time"] intValue]; | |
28 | + } | |
29 | + if([dict objectForKey:@"username"] != nil) { | |
30 | + self.userName = dict[@"username"]; | |
31 | + } | |
32 | + if([dict objectForKey:@"profile_image"] != nil) { | |
33 | + self.avatar = dict[@"profile_image"]; | |
34 | + } | |
35 | + return self; | |
36 | +} | |
37 | + | |
38 | +@end |
LifeLog/LifeLog/RankingTableViewCell.h
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import <UIKit/UIKit.h> |
10 | +#import "RankingObject.h" | |
10 | 11 | |
11 | 12 | @interface RankingTableViewCell : UITableViewCell |
12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *lblIndex; |
... | ... | @@ -16,5 +17,8 @@ |
16 | 17 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; |
17 | 18 | |
18 | 19 | @property (weak, nonatomic) IBOutlet UIImageView *imgAvatar; |
20 | + | |
21 | +-(void) setRankingData : (RankingObject *) object; | |
22 | + | |
19 | 23 | @end |
LifeLog/LifeLog/RankingTableViewCell.m
... | ... | @@ -7,7 +7,9 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "RankingTableViewCell.h" |
10 | +#import <SDWebImage/UIImageView+WebCache.h> | |
10 | 11 | |
12 | +#import "Utilities.h" | |
11 | 13 | @implementation RankingTableViewCell |
12 | 14 | |
13 | 15 | - (void)awakeFromNib { |
... | ... | @@ -21,5 +23,18 @@ |
21 | 23 | // Configure the view for the selected state |
22 | 24 | } |
23 | 25 | |
26 | +-(void) setRankingData : (RankingObject *) object { | |
27 | + if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
28 | + [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
29 | + } | |
30 | + else { | |
31 | + [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
32 | + } | |
33 | + self.lblIndex.text = [NSString stringWithFormat:@"%d", object.rank]; | |
34 | + self.lblName.text = object.userName; | |
35 | + self.lblDistance.text = [NSString stringWithFormat:@"%0.1f km", object.distance]; | |
36 | + self.lblStep.text = [NSString stringWithFormat:@"%d ๆญฉ", object.steps]; | |
37 | + self.lblTime.text = [Utilities convertSecondToShortTime:object.time]; | |
38 | +} | |
24 | 39 | @end |
LifeLog/LifeLog/RankingViewController.h
... | ... | @@ -8,15 +8,18 @@ |
8 | 8 | |
9 | 9 | #import <UIKit/UIKit.h> |
10 | 10 | |
11 | +#import "BaseTableViewController.h" | |
11 | 12 | #import "CollectionView.h" |
12 | 13 | |
13 | -@interface RankingViewController : UIViewController | |
14 | +@interface RankingViewController : BaseTableViewController { | |
15 | + NSDate * _startDate; | |
16 | + NSDate * _endDate; | |
17 | +} | |
14 | 18 | |
15 | 19 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionTime; |
16 | 20 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode; |
17 | 21 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; |
18 | - | |
19 | -@property (weak, nonatomic) IBOutlet UITableView *tableRank; | |
22 | +@property (weak, nonatomic) IBOutlet UILabel *lblDateTime; | |
20 | 23 | |
21 | 24 | - (IBAction)clickButton:(UIButton *)sender; |
22 | 25 | @end |
LifeLog/LifeLog/RankingViewController.m
... | ... | @@ -9,6 +9,9 @@ |
9 | 9 | #import "RankingViewController.h" |
10 | 10 | #import "RankingTableViewCell.h" |
11 | 11 | |
12 | +#import "ServerAPI.h" | |
13 | +#import "Utilities.h" | |
14 | + | |
12 | 15 | @interface RankingViewController () |
13 | 16 | |
14 | 17 | @end |
15 | 18 | |
... | ... | @@ -22,8 +25,14 @@ |
22 | 25 | |
23 | 26 | [self setupView]; |
24 | 27 | |
28 | + _startDate = [NSDate date]; | |
29 | + _endDate = _startDate; | |
30 | + self.lblDateTime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ EEEE" locale:@"ja_JP"]; | |
31 | + | |
25 | 32 | //register nib for table view |
26 | - [self.tableRank registerNib:[UINib nibWithNibName:@"RankingTableViewCell" bundle:nil] forCellReuseIdentifier:@"RankCell"]; | |
33 | + [self.tableBase registerNib:[UINib nibWithNibName:@"RankingTableViewCell" bundle:nil] forCellReuseIdentifier:@"RankCell"]; | |
34 | + | |
35 | + [self callRequestToUpdateData]; | |
27 | 36 | } |
28 | 37 | |
29 | 38 | - (void)didReceiveMemoryWarning { |
... | ... | @@ -39,7 +48,7 @@ |
39 | 48 | [self.viewCollectionTime setSpacing:1]; |
40 | 49 | [self.viewCollectionTime setArrayTitle:timeTitle]; |
41 | 50 | self.viewCollectionTime.changeCurrentIndex = ^(int index){ |
42 | - [self callRequestToUpdateData]; | |
51 | + [self changeDate]; | |
43 | 52 | }; |
44 | 53 | |
45 | 54 | NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.rank.mode.1", nil), NSLocalizedString(@"lifelog.rank.mode.2", nil), NSLocalizedString(@"lifelog.rank.mode.3", nil), NSLocalizedString(@"lifelog.rank.mode.4", nil), nil]; |
46 | 55 | |
47 | 56 | |
48 | 57 | |
... | ... | @@ -66,32 +75,61 @@ |
66 | 75 | } |
67 | 76 | |
68 | 77 | #pragma mark UITableView Delegate |
69 | -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { | |
70 | -// if(_curHisList == nil || _curHisList.count == 0) { | |
71 | -// UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)]; | |
72 | -// noDataLabel.text = @"No data available"; | |
73 | -// noDataLabel.backgroundColor = [UIColor clearColor]; | |
74 | -// noDataLabel.textColor = [UIColor whiteColor]; | |
75 | -// noDataLabel.textAlignment = NSTextAlignmentCenter; | |
76 | -// tableView.backgroundView = noDataLabel; | |
77 | -// tableView.backgroundView.layer.zPosition -= 1; | |
78 | -// return 0; | |
79 | -// } | |
80 | -// tableView.backgroundView = nil; | |
81 | - return 1; | |
82 | -} | |
83 | 78 | |
84 | -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
85 | - return 6; | |
86 | -} | |
87 | - | |
88 | 79 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
89 | 80 | RankingTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RankCell"]; |
81 | + [cell setRankingData:[_curDataList objectAtIndex:indexPath.row]]; | |
90 | 82 | return cell; |
91 | 83 | } |
92 | 84 | |
93 | 85 | #pragma mark Private function |
94 | 86 | - (void)callRequestToUpdateData { |
87 | + [super callRequestToUpdateData]; | |
88 | + | |
89 | + NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | |
90 | + MBProgressHUD *hudView = nil; | |
91 | + int mode = self.viewCollectionMode.getCurrentIndex + 1; | |
92 | + //dont have all | |
93 | + mode = fmin(mode, 3); | |
94 | + | |
95 | + if(_curPage == 1 && !self.refreshControl.isRefreshing) { | |
96 | + hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | |
97 | + } | |
98 | + [[ServerAPI server] requestRankingList:token startDate:_startDate endDate:_endDate mode:mode page:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | |
99 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
100 | + if(hudView != nil) { | |
101 | + [hudView hideAnimated:true]; | |
102 | + } | |
103 | + }); | |
104 | + RankingViewController __weak *weakSelf = self; | |
105 | + [weakSelf updateTableData:array error:error]; | |
106 | + }]; | |
107 | +} | |
108 | + | |
109 | +- (void) changeDate { | |
110 | + switch (self.viewCollectionTime.getCurrentIndex) { | |
111 | + case 1: | |
112 | + _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7]; | |
113 | + break; | |
114 | + case 2: | |
115 | + _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30]; | |
116 | + break; | |
117 | + case 3: | |
118 | + _startDate = [_endDate dateByAddingTimeInterval:-86400 * 365]; | |
119 | + break; | |
120 | + default: | |
121 | + _startDate = _endDate; | |
122 | + break; | |
123 | + } | |
124 | + if(_startDate == _endDate) { | |
125 | + self.lblDateTime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ EEEE" locale:@"ja_JP"]; | |
126 | + } | |
127 | + else { | |
128 | + NSString * startDateString = [Utilities stringFromDate:_startDate withFormat:@"YYYYๅนดMMๆddๆฅ" locale:@"ja_JP"]; | |
129 | + NSString * endDateString = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ" locale:@"ja_JP"]; | |
130 | + self.lblDateTime.text = [NSString stringWithFormat:@"%@-%@", startDateString, endDateString]; | |
131 | + } | |
132 | + [self callRequestToUpdateData]; | |
95 | 133 | } |
96 | 134 | @end |
LifeLog/LifeLog/RankingViewController.xib
1 | 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 | 3 | <device id="retina4_7" orientation="portrait"> |
4 | 4 | <adaptation id="fullscreen"/> |
5 | 5 | </device> |
6 | 6 | <dependencies> |
7 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> | |
7 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/> | |
8 | 8 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
9 | 9 | </dependencies> |
10 | 10 | <objects> |
11 | 11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RankingViewController"> |
12 | 12 | <connections> |
13 | - <outlet property="tableRank" destination="R3A-K9-MFe" id="uEX-sL-6D2"/> | |
13 | + <outlet property="lblDateTime" destination="5Ro-k6-fvT" id="5uO-ff-Pmc"/> | |
14 | + <outlet property="tableBase" destination="R3A-K9-MFe" id="Tf9-Rg-PEW"/> | |
14 | 15 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
15 | 16 | <outlet property="viewCollectionMode" destination="B33-xX-Jro" id="HP4-Xb-LJm"/> |
16 | 17 | <outlet property="viewCollectionTime" destination="syA-uK-pbr" id="WdA-Cq-Flj"/> |
LifeLog/LifeLog/ServerAPI.h
... | ... | @@ -48,6 +48,9 @@ |
48 | 48 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; |
49 | 49 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
50 | 50 | |
51 | +#pragma mark - Ranking API | |
52 | +- (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | |
53 | + | |
51 | 54 | #pragma mark - Common API |
52 | 55 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
53 | 56 | @end |
LifeLog/LifeLog/ServerAPI.m
... | ... | @@ -532,7 +532,7 @@ |
532 | 532 | |
533 | 533 | #pragma mark - SNS Screen Function |
534 | 534 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
535 | - NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; | |
535 | + NSString *url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?page=%d&record=10", page]; | |
536 | 536 | if(groupID > -1) { |
537 | 537 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; |
538 | 538 | } |
... | ... | @@ -892,6 +892,55 @@ |
892 | 892 | } |
893 | 893 | }]; |
894 | 894 | } |
895 | + | |
896 | +#pragma mark - Ranking API | |
897 | +- (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | |
898 | + NSString *url = [kServerAddress stringByAppendingFormat:@"api/ranking/%d/%@/%@/%d", mode, [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""], page]; | |
899 | + NSLog(@"requestRaningList link %@", url); | |
900 | + [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | |
901 | + | |
902 | + if (completion == NULL) { | |
903 | + return ; | |
904 | + } | |
905 | + | |
906 | + if (error == nil) | |
907 | + { | |
908 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
909 | + NSLog(@"%@", dataResult); | |
910 | + int status = [dataResult[@"status"] intValue]; | |
911 | + if (status == 1) { // status = 1 success | |
912 | + NSArray * array = dataResult[@"result"]; | |
913 | + NSMutableArray * arrayRanking = [[NSMutableArray alloc] init]; | |
914 | + for(NSDictionary * dict in array) { | |
915 | + RankingObject * object = [[RankingObject alloc] initWithData:dict]; | |
916 | + [arrayRanking addObject:object]; | |
917 | + } | |
918 | + completion(arrayRanking, nil); | |
919 | + } | |
920 | + else { | |
921 | + NSString *message = dataResult[@"message"]; | |
922 | + if (message == nil) { | |
923 | + message = @"Unknown error"; | |
924 | + } | |
925 | + | |
926 | + if ([message isEqualToString:@"Token is invalid"]) { | |
927 | + [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | |
928 | + NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | |
929 | + [self requestRankingList:tokenNew startDate:startDate endDate:endDate mode:mode page:page CompletionHandler:completion]; | |
930 | + } | |
931 | + else { | |
932 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
933 | + completion(nil, errorObject); | |
934 | + } | |
935 | + } | |
936 | + } | |
937 | + else | |
938 | + { | |
939 | + completion(nil, error); | |
940 | + } | |
941 | + }]; | |
942 | +} | |
943 | + | |
895 | 944 | #pragma mark - Common API |
896 | 945 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
897 | 946 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |