Commit 0db82ed0b5691800af489bab1957ab3ef08d159e
1 parent
cedcb87d8a
Exists in
master
and in
1 other branch
add group detail API
Showing 7 changed files with 118 additions and 13 deletions Side-by-side Diff
LifeLog/LifeLog/GroupDetailViewController.h
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | #import <UIKit/UIKit.h> |
10 | 10 | #import "BaseTableViewController.h" |
11 | 11 | #import "Entities.h" |
12 | +#import "AutoTransButton.h" | |
12 | 13 | |
13 | 14 | @interface GroupDetailViewController : BaseTableViewController { |
14 | 15 | GroupObject * _curGroup; |
15 | 16 | |
... | ... | @@ -18,9 +19,12 @@ |
18 | 19 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpName; |
19 | 20 | @property (weak, nonatomic) IBOutlet UILabel *lbbGrpActiveMode; |
20 | 21 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpGoal; |
22 | +@property (weak, nonatomic) IBOutlet AutoTransButton *btJoinGrp; | |
23 | +@property (weak, nonatomic) IBOutlet AutoTransButton *btSwitch; | |
21 | 24 | |
22 | 25 | - (IBAction)clickBack:(id)sender; |
23 | 26 | |
24 | 27 | - (void) setGroup : (GroupObject *) object; |
28 | +- (IBAction)clickSwitch:(AutoTransButton*)sender; | |
25 | 29 | @end |
LifeLog/LifeLog/GroupDetailViewController.m
... | ... | @@ -25,7 +25,9 @@ |
25 | 25 | |
26 | 26 | //register nib for table view |
27 | 27 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
28 | - | |
28 | + if(_curGroup != nil) { | |
29 | + [self requestGroupDetail]; | |
30 | + } | |
29 | 31 | // Do any additional setup after loading the view from its nib. |
30 | 32 | } |
31 | 33 | |
32 | 34 | |
33 | 35 | |
34 | 36 | |
... | ... | @@ -38,16 +40,29 @@ |
38 | 40 | _curGroup = object; |
39 | 41 | } |
40 | 42 | |
43 | +- (IBAction)clickSwitch:(id)sender { | |
44 | +} | |
45 | + | |
41 | 46 | - (void)setupView { |
42 | 47 | if(_curGroup != nil) { |
43 | - self.lblGrpName.text = _curGroup.name; | |
44 | 48 | if(_curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { |
45 | 49 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; |
46 | 50 | } |
47 | - [self callRequestToUpdateData]; | |
51 | + self.lblGrpName.text = _curGroup.name; | |
52 | + self.lblGrpGoal.text = _curGroup.goal; | |
53 | + NSString *mode = @""; | |
54 | + if(_curGroup.runMode) { | |
55 | + mode = [mode stringByAppendingString:@"ランニング\n"]; | |
56 | + } | |
57 | + if(_curGroup.walkMode) { | |
58 | + mode = [mode stringByAppendingString:@"ウォーキング\n"]; | |
59 | + } | |
60 | + if(_curGroup.bikeMode) { | |
61 | + mode = [mode stringByAppendingString:@"バイク\n"]; | |
62 | + } | |
63 | + self.lbbGrpActiveMode.text = mode; | |
48 | 64 | } |
49 | 65 | } |
50 | - | |
51 | 66 | #pragma mark IBAction |
52 | 67 | |
53 | 68 | - (IBAction)clickBack:(id)sender { |
... | ... | @@ -71,6 +86,20 @@ |
71 | 86 | } |
72 | 87 | |
73 | 88 | #pragma mark Private Function |
89 | + | |
90 | +- (void) requestGroupDetail { | |
91 | + NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | |
92 | +// MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | |
93 | + [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { | |
94 | +// [hudView hideAnimated:true]; | |
95 | + GroupDetailViewController __weak *weakSelf = self; | |
96 | + _curGroup = object; | |
97 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
98 | + [weakSelf setupView]; | |
99 | + [weakSelf callRequestToUpdateData]; | |
100 | + }); | |
101 | + }]; | |
102 | +} | |
74 | 103 | |
75 | 104 | -(void) callRequestToUpdateData { |
76 | 105 | [super callRequestToUpdateData]; |
LifeLog/LifeLog/GroupDetailViewController.xib
... | ... | @@ -10,6 +10,8 @@ |
10 | 10 | <objects> |
11 | 11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="GroupDetailViewController"> |
12 | 12 | <connections> |
13 | + <outlet property="btJoinGrp" destination="caN-x7-hJz" id="B17-YC-Rmk"/> | |
14 | + <outlet property="btSwitch" destination="gBg-k9-tgw" id="3ZZ-Qb-d3a"/> | |
13 | 15 | <outlet property="imgAva" destination="qYg-Gw-R2b" id="f9w-A2-u4G"/> |
14 | 16 | <outlet property="lbbGrpActiveMode" destination="O8z-6V-YFd" id="s8J-3i-pW3"/> |
15 | 17 | <outlet property="lblGrpGoal" destination="Bdy-dI-j47" id="AKx-8y-Ifm"/> |
16 | 18 | |
17 | 19 | |
18 | 20 | |
19 | 21 | |
... | ... | @@ -77,17 +79,18 @@ |
77 | 79 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
78 | 80 | <nil key="highlightedColor"/> |
79 | 81 | </label> |
80 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" 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"> | |
81 | 83 | <rect key="frame" x="15" y="85" width="243" height="60"/> |
84 | + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | |
82 | 85 | <constraints> |
83 | - <constraint firstAttribute="height" constant="60" id="Bid-NM-Ree"/> | |
86 | + <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="60" id="Bid-NM-Ree"/> | |
84 | 87 | </constraints> |
85 | - <fontDescription key="fontDescription" type="system" pointSize="17"/> | |
88 | + <fontDescription key="fontDescription" type="system" pointSize="14"/> | |
86 | 89 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
87 | 90 | <nil key="highlightedColor"/> |
88 | 91 | </label> |
89 | 92 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bdy-dI-j47"> |
90 | - <rect key="frame" x="15" y="161" width="345" height="80"/> | |
93 | + <rect key="frame" x="15" y="160" width="345" height="80"/> | |
91 | 94 | <constraints> |
92 | 95 | <constraint firstAttribute="height" constant="80" id="jgH-57-Bae"/> |
93 | 96 | </constraints> |
... | ... | @@ -103,7 +106,7 @@ |
103 | 106 | </constraints> |
104 | 107 | </imageView> |
105 | 108 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gBg-k9-tgw" customClass="AutoTransButton"> |
106 | - <rect key="frame" x="15" y="271" width="162" height="30"/> | |
109 | + <rect key="frame" x="15" y="270" width="162" height="30"/> | |
107 | 110 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
108 | 111 | <constraints> |
109 | 112 | <constraint firstAttribute="height" constant="30" id="6Ir-ZZ-NOb"/> |
110 | 113 | |
... | ... | @@ -117,9 +120,12 @@ |
117 | 120 | </userDefinedRuntimeAttribute> |
118 | 121 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.viewMem"/> |
119 | 122 | </userDefinedRuntimeAttributes> |
123 | + <connections> | |
124 | + <action selector="clickSwitch:" destination="-1" eventType="touchUpInside" id="3wX-Tc-XA3"/> | |
125 | + </connections> | |
120 | 126 | </button> |
121 | 127 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caN-x7-hJz" customClass="AutoTransButton"> |
122 | - <rect key="frame" x="197" y="271" width="162" height="30"/> | |
128 | + <rect key="frame" x="197" y="270" width="162" height="30"/> | |
123 | 129 | <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
124 | 130 | <constraints> |
125 | 131 | <constraint firstAttribute="height" constant="30" id="gIs-Km-dbx"/> |
... | ... | @@ -135,7 +141,7 @@ |
135 | 141 | </userDefinedRuntimeAttributes> |
136 | 142 | </button> |
137 | 143 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="4VU-Ye-7Au"> |
138 | - <rect key="frame" x="0.0" y="311" width="375" height="306"/> | |
144 | + <rect key="frame" x="0.0" y="310" width="375" height="307"/> | |
139 | 145 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
140 | 146 | <connections> |
141 | 147 | <outlet property="dataSource" destination="-1" id="TLB-6X-bRI"/> |
... | ... | @@ -167,7 +173,7 @@ |
167 | 173 | <constraint firstItem="gBg-k9-tgw" firstAttribute="top" secondItem="Bdy-dI-j47" secondAttribute="bottom" constant="30" id="mgw-uX-VOK"/> |
168 | 174 | <constraint firstAttribute="trailing" secondItem="YWV-pS-TCo" secondAttribute="trailing" constant="15" id="rEO-bb-Pqr"/> |
169 | 175 | <constraint firstAttribute="trailing" secondItem="caN-x7-hJz" secondAttribute="trailing" constant="16" id="rRn-Vw-t5g"/> |
170 | - <constraint firstItem="Bdy-dI-j47" firstAttribute="top" secondItem="qYg-Gw-R2b" secondAttribute="bottom" constant="16" id="xXi-T2-c6K"/> | |
176 | + <constraint firstItem="Bdy-dI-j47" firstAttribute="top" secondItem="O8z-6V-YFd" secondAttribute="bottom" constant="15" id="xEO-fP-Riz"/> | |
171 | 177 | <constraint firstAttribute="trailing" secondItem="4VU-Ye-7Au" secondAttribute="trailing" id="ylN-vm-QF2"/> |
172 | 178 | </constraints> |
173 | 179 | <point key="canvasLocation" x="24.5" y="52.5"/> |
LifeLog/LifeLog/GroupObject.h
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | @property (nonatomic) int groupID; |
14 | 14 | @property (nonatomic) int numSearch; |
15 | 15 | |
16 | +@property (nonatomic) BOOL isJoin; | |
16 | 17 | @property (nonatomic) BOOL walkMode; |
17 | 18 | @property (nonatomic) BOOL runMode; |
18 | 19 | @property (nonatomic) BOOL bikeMode; |
... | ... | @@ -22,6 +23,8 @@ |
22 | 23 | |
23 | 24 | @property (nonatomic, strong) NSString * name; |
24 | 25 | @property (nonatomic, strong) NSString * avatar; |
26 | +@property (nonatomic, strong) NSString * goal; | |
27 | + | |
25 | 28 | @property (nonatomic, strong) NSDate * createDate; |
26 | 29 | |
27 | 30 | -(id) initWithData : (NSDictionary *) dict; |
LifeLog/LifeLog/GroupObject.m
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { |
28 | 28 | self.runMode = [dict[@"run_mode_active"] boolValue]; |
29 | 29 | } |
30 | - if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { | |
30 | + if([dict objectForKey:@"bike_mode_active"] != nil && ![[dict objectForKey:@"bike_mode_active"] isKindOfClass:[NSNull class]]) { | |
31 | 31 | self.bikeMode = [dict[@"bike_mode_active"] boolValue]; |
32 | 32 | } |
33 | 33 | if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { |
... | ... | @@ -39,6 +39,9 @@ |
39 | 39 | if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { |
40 | 40 | self.beginMode = [dict[@"beginer_mode_active"] boolValue]; |
41 | 41 | } |
42 | + if([dict objectForKey:@"join_group"] != nil && ![[dict objectForKey:@"join_group"] isKindOfClass:[NSNull class]]) { | |
43 | + self.isJoin = [dict[@"join_group"] boolValue]; | |
44 | + } | |
42 | 45 | if([dict objectForKey:@"created_at"] != nil) { |
43 | 46 | NSString *dateString = dict[@"created_at"]; |
44 | 47 | self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; |
... | ... | @@ -48,6 +51,12 @@ |
48 | 51 | } |
49 | 52 | if([dict objectForKey:@"num_search"] != nil) { |
50 | 53 | self.numSearch = [dict[@"num_search"] intValue]; |
54 | + } | |
55 | + if([dict objectForKey:@"goal"] != nil && ![[dict objectForKey:@"goal"] isKindOfClass:[NSNull class]]) { | |
56 | + self.goal = dict[@"goal"]; | |
57 | + } | |
58 | + else { | |
59 | + self.goal = @""; | |
51 | 60 | } |
52 | 61 | return self; |
53 | 62 | } |
LifeLog/LifeLog/ServerAPI.h
... | ... | @@ -41,6 +41,10 @@ |
41 | 41 | */ |
42 | 42 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
43 | 43 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
44 | + | |
45 | +#pragma mark - Group Function | |
46 | +- (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; | |
47 | + | |
44 | 48 | #pragma mark - Common API |
45 | 49 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
46 | 50 | @end |
LifeLog/LifeLog/ServerAPI.m
... | ... | @@ -646,6 +646,56 @@ |
646 | 646 | }]; |
647 | 647 | } |
648 | 648 | |
649 | +#pragma mark - Group Function | |
650 | +- (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | |
651 | + NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; | |
652 | + NSLog(@"getGroupDetail link %@", url); | |
653 | + [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | |
654 | + | |
655 | + if (completion == NULL) { | |
656 | + return ; | |
657 | + } | |
658 | + | |
659 | + if (error == nil) | |
660 | + { | |
661 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
662 | + NSLog(@"%@", dataResult); | |
663 | + int status = [dataResult[@"status"] intValue]; | |
664 | + if (status == 1) { // status = 1 success | |
665 | + if(dataResult[@"result"] != nil) { | |
666 | + NSArray * array = dataResult[@"result"]; | |
667 | + GroupObject * object = [[GroupObject alloc] initWithData:array[0]]; | |
668 | + completion(object, nil); | |
669 | + } | |
670 | + else { | |
671 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | |
672 | + completion(nil, errorObject); | |
673 | + } | |
674 | + } | |
675 | + else { | |
676 | + NSString *message = dataResult[@"message"]; | |
677 | + if (message == nil) { | |
678 | + message = @"Unknown error"; | |
679 | + } | |
680 | + | |
681 | + if ([message isEqualToString:@"Token is invalid"]) { | |
682 | + [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | |
683 | + NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | |
684 | + [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; | |
685 | + } | |
686 | + else { | |
687 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
688 | + completion(nil, errorObject); | |
689 | + } | |
690 | + } | |
691 | + } | |
692 | + else | |
693 | + { | |
694 | + completion(nil, error); | |
695 | + } | |
696 | + }]; | |
697 | +} | |
698 | + | |
649 | 699 | #pragma mark - Common API |
650 | 700 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
651 | 701 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |