Compare View
Commits (3)
Changes
Showing 15 changed files 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/HistoryViewController.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>"; }; |
| ... | ... | @@ -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,9 +14,9 @@ |
| 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/HistoryViewController.m
| ... | ... | @@ -139,14 +139,55 @@ |
| 139 | 139 | { |
| 140 | 140 | set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; |
| 141 | 141 | set1.values = yVals; |
| 142 | + | |
| 143 | + NSMutableArray *color = [[NSMutableArray alloc] init]; | |
| 144 | + for(int i = 0; i < yVals.count; i++) { | |
| 145 | + BarChartDataEntry *en = yVals[i]; | |
| 146 | + if(obj.step != 0) { | |
| 147 | + double percent = en.y / obj.step * 100; | |
| 148 | + if(percent > 80) { | |
| 149 | + [color addObject:[UIColor redColor]]; | |
| 150 | + } | |
| 151 | + else if(percent > 60) { | |
| 152 | + [color addObject:[UIColor yellowColor]]; | |
| 153 | + } | |
| 154 | + else { | |
| 155 | + [color addObject:[UIColor whiteColor]]; | |
| 156 | + } | |
| 157 | + } | |
| 158 | + else { | |
| 159 | + [color addObject:[UIColor whiteColor]]; | |
| 160 | + } | |
| 161 | + } | |
| 162 | + [set1 setColors:color]; | |
| 163 | + | |
| 142 | 164 | [self.viewBarChart.data notifyDataChanged]; |
| 143 | 165 | [self.viewBarChart notifyDataSetChanged]; |
| 144 | 166 | } |
| 145 | 167 | else |
| 146 | 168 | { |
| 147 | 169 | set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; |
| 148 | - [set1 setColor:[UIColor whiteColor]]; | |
| 149 | 170 | |
| 171 | + NSMutableArray *color = [[NSMutableArray alloc] init]; | |
| 172 | + for(int i = 0; i < yVals.count; i++) { | |
| 173 | + BarChartDataEntry *en = yVals[i]; | |
| 174 | + if(obj.step != 0) { | |
| 175 | + double percent = en.y / obj.step * 100; | |
| 176 | + if(percent > 80) { | |
| 177 | + [color addObject:[UIColor redColor]]; | |
| 178 | + } | |
| 179 | + else if(percent > 60) { | |
| 180 | + [color addObject:[UIColor yellowColor]]; | |
| 181 | + } | |
| 182 | + else { | |
| 183 | + [color addObject:[UIColor whiteColor]]; | |
| 184 | + } | |
| 185 | + } | |
| 186 | + else { | |
| 187 | + [color addObject:[UIColor whiteColor]]; | |
| 188 | + } | |
| 189 | + } | |
| 190 | + [set1 setColors:color]; | |
| 150 | 191 | NSMutableArray *dataSets = [[NSMutableArray alloc] init]; |
| 151 | 192 | [dataSets addObject:set1]; |
| 152 | 193 |
LifeLog/LifeLog/RankingObject.h
| ... | ... | @@ -0,0 +1,24 @@ |
| 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
| ... | ... | @@ -0,0 +1,38 @@ |
| 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,4 +17,7 @@ |
| 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,4 +23,17 @@ |
| 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 |
| ... | ... | @@ -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]; |
| ... | ... | @@ -66,31 +75,60 @@ |
| 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 | - | |
| 84 | -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
| 85 | - return 6; | |
| 86 | -} | |
| 87 | 78 | |
| 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 @@ extern NSString *const kNotificationToken; |
| 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
| ... | ... | @@ -425,7 +425,10 @@ NSURLSessionDataTask * searchTask; |
| 425 | 425 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
| 426 | 426 | NSDictionary * arrResult = dataResult[@"result"]; |
| 427 | 427 | if(arrResult != nil) { |
| 428 | - NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; | |
| 428 | + /* mode_1: Data for mode walking | |
| 429 | + mode_2: Data for mode running | |
| 430 | + mode_3: Data for mode bike */ | |
| 431 | + NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; | |
| 429 | 432 | for(NSString * key in arrayKey) { |
| 430 | 433 | NSDictionary *mode = [arrResult objectForKey:key]; |
| 431 | 434 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { |
| ... | ... | @@ -482,7 +485,10 @@ NSURLSessionDataTask * searchTask; |
| 482 | 485 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
| 483 | 486 | NSDictionary * arrResult = dataResult[@"result"]; |
| 484 | 487 | if(arrResult != nil) { |
| 485 | - NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; | |
| 488 | + /* mode_1: Data for mode walking | |
| 489 | + mode_2: Data for mode running | |
| 490 | + mode_3: Data for mode bike */ | |
| 491 | + NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; | |
| 486 | 492 | for(NSString * key in arrayKey) { |
| 487 | 493 | NSDictionary *mode = [arrResult objectForKey:key]; |
| 488 | 494 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { |
| ... | ... | @@ -532,7 +538,7 @@ NSURLSessionDataTask * searchTask; |
| 532 | 538 | |
| 533 | 539 | #pragma mark - SNS Screen Function |
| 534 | 540 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
| 535 | - NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; | |
| 541 | + NSString *url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?page=%d&record=10", page]; | |
| 536 | 542 | if(groupID > -1) { |
| 537 | 543 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; |
| 538 | 544 | } |
| ... | ... | @@ -892,6 +898,55 @@ NSURLSessionDataTask * searchTask; |
| 892 | 898 | } |
| 893 | 899 | }]; |
| 894 | 900 | } |
| 901 | + | |
| 902 | +#pragma mark - Ranking API | |
| 903 | +- (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | |
| 904 | + NSString *url = [kServerAddress stringByAppendingFormat:@"api/ranking/%d/%@/%@/%d", mode, [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""], page]; | |
| 905 | + NSLog(@"requestRaningList link %@", url); | |
| 906 | + [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | |
| 907 | + | |
| 908 | + if (completion == NULL) { | |
| 909 | + return ; | |
| 910 | + } | |
| 911 | + | |
| 912 | + if (error == nil) | |
| 913 | + { | |
| 914 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
| 915 | + NSLog(@"%@", dataResult); | |
| 916 | + int status = [dataResult[@"status"] intValue]; | |
| 917 | + if (status == 1) { // status = 1 success | |
| 918 | + NSArray * array = dataResult[@"result"]; | |
| 919 | + NSMutableArray * arrayRanking = [[NSMutableArray alloc] init]; | |
| 920 | + for(NSDictionary * dict in array) { | |
| 921 | + RankingObject * object = [[RankingObject alloc] initWithData:dict]; | |
| 922 | + [arrayRanking addObject:object]; | |
| 923 | + } | |
| 924 | + completion(arrayRanking, nil); | |
| 925 | + } | |
| 926 | + else { | |
| 927 | + NSString *message = dataResult[@"message"]; | |
| 928 | + if (message == nil) { | |
| 929 | + message = @"Unknown error"; | |
| 930 | + } | |
| 931 | + | |
| 932 | + if ([message isEqualToString:@"Token is invalid"]) { | |
| 933 | + [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | |
| 934 | + NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | |
| 935 | + [self requestRankingList:tokenNew startDate:startDate endDate:endDate mode:mode page:page CompletionHandler:completion]; | |
| 936 | + } | |
| 937 | + else { | |
| 938 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
| 939 | + completion(nil, errorObject); | |
| 940 | + } | |
| 941 | + } | |
| 942 | + } | |
| 943 | + else | |
| 944 | + { | |
| 945 | + completion(nil, error); | |
| 946 | + } | |
| 947 | + }]; | |
| 948 | +} | |
| 949 | + | |
| 895 | 950 | #pragma mark - Common API |
| 896 | 951 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
| 897 | 952 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |