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 Inline Diff
LifeLog/LifeLog/GroupDetailViewController.h
1 | // | 1 | // |
2 | // GroupDetailViewController.h | 2 | // GroupDetailViewController.h |
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 <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
10 | #import "BaseTableViewController.h" | 10 | #import "BaseTableViewController.h" |
11 | #import "Entities.h" | 11 | #import "Entities.h" |
12 | #import "AutoTransButton.h" | ||
12 | 13 | ||
13 | @interface GroupDetailViewController : BaseTableViewController { | 14 | @interface GroupDetailViewController : BaseTableViewController { |
14 | GroupObject * _curGroup; | 15 | GroupObject * _curGroup; |
15 | } | 16 | } |
16 | @property (weak, nonatomic) IBOutlet UIImageView *imgAva; | 17 | @property (weak, nonatomic) IBOutlet UIImageView *imgAva; |
17 | 18 | ||
18 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpName; | 19 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpName; |
19 | @property (weak, nonatomic) IBOutlet UILabel *lbbGrpActiveMode; | 20 | @property (weak, nonatomic) IBOutlet UILabel *lbbGrpActiveMode; |
20 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpGoal; | 21 | @property (weak, nonatomic) IBOutlet UILabel *lblGrpGoal; |
22 | @property (weak, nonatomic) IBOutlet AutoTransButton *btJoinGrp; | ||
23 | @property (weak, nonatomic) IBOutlet AutoTransButton *btSwitch; | ||
21 | 24 | ||
22 | - (IBAction)clickBack:(id)sender; | 25 | - (IBAction)clickBack:(id)sender; |
23 | 26 | ||
24 | - (void) setGroup : (GroupObject *) object; | 27 | - (void) setGroup : (GroupObject *) object; |
28 | - (IBAction)clickSwitch:(AutoTransButton*)sender; | ||
25 | @end | 29 | @end |
26 | 30 |
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 | [self setupView]; | 24 | [self setupView]; |
25 | 25 | ||
26 | //register nib for table view | 26 | //register nib for table view |
27 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 27 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
28 | 28 | if(_curGroup != nil) { | |
29 | [self requestGroupDetail]; | ||
30 | } | ||
29 | // Do any additional setup after loading the view from its nib. | 31 | // Do any additional setup after loading the view from its nib. |
30 | } | 32 | } |
31 | 33 | ||
32 | - (void)didReceiveMemoryWarning { | 34 | - (void)didReceiveMemoryWarning { |
33 | [super didReceiveMemoryWarning]; | 35 | [super didReceiveMemoryWarning]; |
34 | // Dispose of any resources that can be recreated. | 36 | // Dispose of any resources that can be recreated. |
35 | } | 37 | } |
36 | 38 | ||
37 | - (void) setGroup : (GroupObject *) object { | 39 | - (void) setGroup : (GroupObject *) object { |
38 | _curGroup = object; | 40 | _curGroup = object; |
39 | } | 41 | } |
40 | 42 | ||
43 | - (IBAction)clickSwitch:(id)sender { | ||
44 | } | ||
45 | |||
41 | - (void)setupView { | 46 | - (void)setupView { |
42 | if(_curGroup != nil) { | 47 | if(_curGroup != nil) { |
43 | self.lblGrpName.text = _curGroup.name; | ||
44 | if(_curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { | 48 | if(_curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { |
45 | [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; | 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 | #pragma mark IBAction | 66 | #pragma mark IBAction |
52 | 67 | ||
53 | - (IBAction)clickBack:(id)sender { | 68 | - (IBAction)clickBack:(id)sender { |
54 | [self.navigationController popViewControllerAnimated:true]; | 69 | [self.navigationController popViewControllerAnimated:true]; |
55 | } | 70 | } |
56 | 71 | ||
57 | #pragma mark UITableView Delegate | 72 | #pragma mark UITableView Delegate |
58 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 73 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
59 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 74 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
60 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 75 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
61 | if(object.avatarLink && ![object.avatarLink isKindOfClass:[NSNull class]]) { | 76 | if(object.avatarLink && ![object.avatarLink isKindOfClass:[NSNull class]]) { |
62 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatarLink]]]; | 77 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatarLink]]]; |
63 | } | 78 | } |
64 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 79 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; |
65 | cell.lblUsername.text = object.userName; | 80 | cell.lblUsername.text = object.userName; |
66 | cell.lblDes.text = object.content; | 81 | cell.lblDes.text = object.content; |
67 | cell.lblMode.text = object.mode; | 82 | cell.lblMode.text = object.mode; |
68 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 83 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
69 | cell.lblDuration.text = object.time; | 84 | cell.lblDuration.text = object.time; |
70 | return cell; | 85 | return cell; |
71 | } | 86 | } |
72 | 87 | ||
73 | #pragma mark Private Function | 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 | -(void) callRequestToUpdateData { | 104 | -(void) callRequestToUpdateData { |
76 | [super callRequestToUpdateData]; | 105 | [super callRequestToUpdateData]; |
77 | 106 | ||
78 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 107 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
79 | MBProgressHUD *hudView = nil; | 108 | MBProgressHUD *hudView = nil; |
80 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 109 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
81 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 110 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
82 | } | 111 | } |
83 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 112 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
84 | dispatch_async(dispatch_get_main_queue(), ^{ | 113 | dispatch_async(dispatch_get_main_queue(), ^{ |
85 | if(hudView != nil) { | 114 | if(hudView != nil) { |
86 | [hudView hideAnimated:true]; | 115 | [hudView hideAnimated:true]; |
87 | } | 116 | } |
88 | }); | 117 | }); |
89 | GroupDetailViewController __weak *weakSelf = self; | 118 | GroupDetailViewController __weak *weakSelf = self; |
90 | [weakSelf updateTableData:array error:error]; | 119 | [weakSelf updateTableData:array error:error]; |
91 | }]; | 120 | }]; |
92 | } | 121 | } |
93 | 122 |
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="12118" systemVersion="16D32" 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="12086"/> | 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"/> | ||
14 | <outlet property="btSwitch" destination="gBg-k9-tgw" id="3ZZ-Qb-d3a"/> | ||
13 | <outlet property="imgAva" destination="qYg-Gw-R2b" id="f9w-A2-u4G"/> | 15 | <outlet property="imgAva" destination="qYg-Gw-R2b" id="f9w-A2-u4G"/> |
14 | <outlet property="lbbGrpActiveMode" destination="O8z-6V-YFd" id="s8J-3i-pW3"/> | 16 | <outlet property="lbbGrpActiveMode" destination="O8z-6V-YFd" id="s8J-3i-pW3"/> |
15 | <outlet property="lblGrpGoal" destination="Bdy-dI-j47" id="AKx-8y-Ifm"/> | 17 | <outlet property="lblGrpGoal" destination="Bdy-dI-j47" id="AKx-8y-Ifm"/> |
16 | <outlet property="lblGrpName" destination="YWV-pS-TCo" id="VeU-Ov-uSD"/> | 18 | <outlet property="lblGrpName" destination="YWV-pS-TCo" id="VeU-Ov-uSD"/> |
17 | <outlet property="tableBase" destination="4VU-Ye-7Au" id="m1e-cS-Sxf"/> | 19 | <outlet property="tableBase" destination="4VU-Ye-7Au" id="m1e-cS-Sxf"/> |
18 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | 20 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
19 | </connections> | 21 | </connections> |
20 | </placeholder> | 22 | </placeholder> |
21 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | 23 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
22 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | 24 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> |
23 | <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"/> |
24 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | 26 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
25 | <subviews> | 27 | <subviews> |
26 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="25d-3H-0fr" userLabel="ViewHeader"> | 28 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="25d-3H-0fr" userLabel="ViewHeader"> |
27 | <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"/> |
28 | <subviews> | 30 | <subviews> |
29 | <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"> |
30 | <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"/> |
31 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 33 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
32 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 34 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
33 | <nil key="highlightedColor"/> | 35 | <nil key="highlightedColor"/> |
34 | <userDefinedRuntimeAttributes> | 36 | <userDefinedRuntimeAttributes> |
35 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.title"/> | 37 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.title"/> |
36 | </userDefinedRuntimeAttributes> | 38 | </userDefinedRuntimeAttributes> |
37 | </label> | 39 | </label> |
38 | <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"> |
39 | <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"/> |
40 | <constraints> | 42 | <constraints> |
41 | <constraint firstAttribute="width" constant="70" id="2Mk-ly-c0t"/> | 43 | <constraint firstAttribute="width" constant="70" id="2Mk-ly-c0t"/> |
42 | </constraints> | 44 | </constraints> |
43 | <state key="normal" image="today_back_button"/> | 45 | <state key="normal" image="today_back_button"/> |
44 | <connections> | 46 | <connections> |
45 | <action selector="clickBack:" destination="-1" eventType="touchUpInside" id="gS4-F3-fzi"/> | 47 | <action selector="clickBack:" destination="-1" eventType="touchUpInside" id="gS4-F3-fzi"/> |
46 | </connections> | 48 | </connections> |
47 | </button> | 49 | </button> |
48 | <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"> |
49 | <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"/> |
50 | <constraints> | 52 | <constraints> |
51 | <constraint firstAttribute="width" constant="45" id="hHa-aE-1zd"/> | 53 | <constraint firstAttribute="width" constant="45" id="hHa-aE-1zd"/> |
52 | </constraints> | 54 | </constraints> |
53 | <state key="normal" image="icon_menu"/> | 55 | <state key="normal" image="icon_menu"/> |
54 | </button> | 56 | </button> |
55 | </subviews> | 57 | </subviews> |
56 | <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"/> |
57 | <constraints> | 59 | <constraints> |
58 | <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"/> |
59 | <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"/> |
60 | <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"/> |
61 | <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"/> |
62 | <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"/> |
63 | <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"/> |
64 | <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"/> |
65 | <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"/> |
66 | <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"/> |
67 | <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"/> |
68 | <constraint firstAttribute="height" constant="46" id="u2G-4s-RB5"/> | 70 | <constraint firstAttribute="height" constant="46" id="u2G-4s-RB5"/> |
69 | </constraints> | 71 | </constraints> |
70 | </view> | 72 | </view> |
71 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" 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="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YWV-pS-TCo"> |
72 | <rect key="frame" x="15" y="54" width="345" height="21"/> | 74 | <rect key="frame" x="15" y="54" width="345" height="21"/> |
73 | <constraints> | 75 | <constraints> |
74 | <constraint firstAttribute="height" constant="21" id="fQO-ja-W9R"/> | 76 | <constraint firstAttribute="height" constant="21" id="fQO-ja-W9R"/> |
75 | </constraints> | 77 | </constraints> |
76 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 78 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
77 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 79 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
78 | <nil key="highlightedColor"/> | 80 | <nil key="highlightedColor"/> |
79 | </label> | 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 | <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"/> | ||
82 | <constraints> | 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 | </constraints> | 87 | </constraints> |
85 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 88 | <fontDescription key="fontDescription" type="system" pointSize="14"/> |
86 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 89 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
87 | <nil key="highlightedColor"/> | 90 | <nil key="highlightedColor"/> |
88 | </label> | 91 | </label> |
89 | <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"> | 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 | <constraints> | 94 | <constraints> |
92 | <constraint firstAttribute="height" constant="80" id="jgH-57-Bae"/> | 95 | <constraint firstAttribute="height" constant="80" id="jgH-57-Bae"/> |
93 | </constraints> | 96 | </constraints> |
94 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 97 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
95 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 98 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
96 | <nil key="highlightedColor"/> | 99 | <nil key="highlightedColor"/> |
97 | </label> | 100 | </label> |
98 | <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"> |
99 | <rect key="frame" x="280" y="85" width="80" height="60"/> | 102 | <rect key="frame" x="280" y="85" width="80" height="60"/> |
100 | <constraints> | 103 | <constraints> |
101 | <constraint firstAttribute="width" constant="80" id="NEk-vg-zus"/> | 104 | <constraint firstAttribute="width" constant="80" id="NEk-vg-zus"/> |
102 | <constraint firstAttribute="height" constant="60" id="qlv-ht-SUw"/> | 105 | <constraint firstAttribute="height" constant="60" id="qlv-ht-SUw"/> |
103 | </constraints> | 106 | </constraints> |
104 | </imageView> | 107 | </imageView> |
105 | <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"> |
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 | <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"/> |
108 | <constraints> | 111 | <constraints> |
109 | <constraint firstAttribute="height" constant="30" id="6Ir-ZZ-NOb"/> | 112 | <constraint firstAttribute="height" constant="30" id="6Ir-ZZ-NOb"/> |
110 | </constraints> | 113 | </constraints> |
111 | <state key="normal" title="メンバーを見る"> | 114 | <state key="normal" title="メンバーを見る"> |
112 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 115 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
113 | </state> | 116 | </state> |
114 | <userDefinedRuntimeAttributes> | 117 | <userDefinedRuntimeAttributes> |
115 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | 118 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
116 | <integer key="value" value="5"/> | 119 | <integer key="value" value="5"/> |
117 | </userDefinedRuntimeAttribute> | 120 | </userDefinedRuntimeAttribute> |
118 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.viewMem"/> | 121 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.viewMem"/> |
119 | </userDefinedRuntimeAttributes> | 122 | </userDefinedRuntimeAttributes> |
123 | <connections> | ||
124 | <action selector="clickSwitch:" destination="-1" eventType="touchUpInside" id="3wX-Tc-XA3"/> | ||
125 | </connections> | ||
120 | </button> | 126 | </button> |
121 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caN-x7-hJz" customClass="AutoTransButton"> | 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 | <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"/> |
124 | <constraints> | 130 | <constraints> |
125 | <constraint firstAttribute="height" constant="30" id="gIs-Km-dbx"/> | 131 | <constraint firstAttribute="height" constant="30" id="gIs-Km-dbx"/> |
126 | </constraints> | 132 | </constraints> |
127 | <state key="normal" title="グループに参加する"> | 133 | <state key="normal" title="グループに参加する"> |
128 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 134 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
129 | </state> | 135 | </state> |
130 | <userDefinedRuntimeAttributes> | 136 | <userDefinedRuntimeAttributes> |
131 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | 137 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
132 | <integer key="value" value="5"/> | 138 | <integer key="value" value="5"/> |
133 | </userDefinedRuntimeAttribute> | 139 | </userDefinedRuntimeAttribute> |
134 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.joinGr"/> | 140 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.grDetail.bt.joinGr"/> |
135 | </userDefinedRuntimeAttributes> | 141 | </userDefinedRuntimeAttributes> |
136 | </button> | 142 | </button> |
137 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="4VU-Ye-7Au"> | 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 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 145 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
140 | <connections> | 146 | <connections> |
141 | <outlet property="dataSource" destination="-1" id="TLB-6X-bRI"/> | 147 | <outlet property="dataSource" destination="-1" id="TLB-6X-bRI"/> |
142 | <outlet property="delegate" destination="-1" id="QcJ-Yh-deE"/> | 148 | <outlet property="delegate" destination="-1" id="QcJ-Yh-deE"/> |
143 | </connections> | 149 | </connections> |
144 | </tableView> | 150 | </tableView> |
145 | </subviews> | 151 | </subviews> |
146 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> | 152 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> |
147 | <constraints> | 153 | <constraints> |
148 | <constraint firstItem="25d-3H-0fr" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5o2-0w-AL5"/> | 154 | <constraint firstItem="25d-3H-0fr" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5o2-0w-AL5"/> |
149 | <constraint firstAttribute="trailing" secondItem="25d-3H-0fr" secondAttribute="trailing" id="7IX-2R-C0n"/> | 155 | <constraint firstAttribute="trailing" secondItem="25d-3H-0fr" secondAttribute="trailing" id="7IX-2R-C0n"/> |
150 | <constraint firstItem="O8z-6V-YFd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="81K-BQ-6tU"/> | 156 | <constraint firstItem="O8z-6V-YFd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="81K-BQ-6tU"/> |
151 | <constraint firstAttribute="bottom" secondItem="4VU-Ye-7Au" secondAttribute="bottom" constant="50" id="GKY-NB-YYF"/> | 157 | <constraint firstAttribute="bottom" secondItem="4VU-Ye-7Au" secondAttribute="bottom" constant="50" id="GKY-NB-YYF"/> |
152 | <constraint firstItem="O8z-6V-YFd" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="HOo-rH-ysj"/> | 158 | <constraint firstItem="O8z-6V-YFd" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="HOo-rH-ysj"/> |
153 | <constraint firstItem="Bdy-dI-j47" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="I1a-bY-ME9"/> | 159 | <constraint firstItem="Bdy-dI-j47" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="I1a-bY-ME9"/> |
154 | <constraint firstItem="YWV-pS-TCo" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="IS9-SU-75m"/> | 160 | <constraint firstItem="YWV-pS-TCo" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="IS9-SU-75m"/> |
155 | <constraint firstAttribute="trailing" secondItem="Bdy-dI-j47" secondAttribute="trailing" constant="15" id="Ka2-Ki-Pu6"/> | 161 | <constraint firstAttribute="trailing" secondItem="Bdy-dI-j47" secondAttribute="trailing" constant="15" id="Ka2-Ki-Pu6"/> |
156 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="One-fp-LTK"/> | 162 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="top" secondItem="YWV-pS-TCo" secondAttribute="bottom" constant="10" id="One-fp-LTK"/> |
157 | <constraint firstAttribute="trailing" secondItem="qYg-Gw-R2b" secondAttribute="trailing" constant="15" id="PMd-CT-MVj"/> | 163 | <constraint firstAttribute="trailing" secondItem="qYg-Gw-R2b" secondAttribute="trailing" constant="15" id="PMd-CT-MVj"/> |
158 | <constraint firstItem="gBg-k9-tgw" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="bTf-qW-d1y"/> | 164 | <constraint firstItem="gBg-k9-tgw" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="15" id="bTf-qW-d1y"/> |
159 | <constraint firstItem="YWV-pS-TCo" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="bottom" constant="8" id="cKj-l3-dgv"/> | 165 | <constraint firstItem="YWV-pS-TCo" firstAttribute="top" secondItem="25d-3H-0fr" secondAttribute="bottom" constant="8" id="cKj-l3-dgv"/> |
160 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="top" secondItem="caN-x7-hJz" secondAttribute="bottom" constant="10" id="eQe-Kl-cMp"/> | 166 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="top" secondItem="caN-x7-hJz" secondAttribute="bottom" constant="10" id="eQe-Kl-cMp"/> |
161 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="fru-BN-M5T"/> | 167 | <constraint firstItem="4VU-Ye-7Au" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="fru-BN-M5T"/> |
162 | <constraint firstItem="caN-x7-hJz" firstAttribute="top" secondItem="gBg-k9-tgw" secondAttribute="top" id="gUS-Ty-4Hk"/> | 168 | <constraint firstItem="caN-x7-hJz" firstAttribute="top" secondItem="gBg-k9-tgw" secondAttribute="top" id="gUS-Ty-4Hk"/> |
163 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="leading" secondItem="O8z-6V-YFd" secondAttribute="trailing" constant="22" id="gzU-2Q-G96"/> | 169 | <constraint firstItem="qYg-Gw-R2b" firstAttribute="leading" secondItem="O8z-6V-YFd" secondAttribute="trailing" constant="22" id="gzU-2Q-G96"/> |
164 | <constraint firstItem="caN-x7-hJz" firstAttribute="leading" secondItem="gBg-k9-tgw" secondAttribute="trailing" constant="20" id="hWK-jf-zee"/> | 170 | <constraint firstItem="caN-x7-hJz" firstAttribute="leading" secondItem="gBg-k9-tgw" secondAttribute="trailing" constant="20" id="hWK-jf-zee"/> |
165 | <constraint firstItem="25d-3H-0fr" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="jhT-CE-fr7"/> | 171 | <constraint firstItem="25d-3H-0fr" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="jhT-CE-fr7"/> |
166 | <constraint firstItem="caN-x7-hJz" firstAttribute="width" secondItem="gBg-k9-tgw" secondAttribute="width" id="mD6-eL-KB7"/> | 172 | <constraint firstItem="caN-x7-hJz" firstAttribute="width" secondItem="gBg-k9-tgw" secondAttribute="width" id="mD6-eL-KB7"/> |
167 | <constraint firstItem="gBg-k9-tgw" firstAttribute="top" secondItem="Bdy-dI-j47" secondAttribute="bottom" constant="30" id="mgw-uX-VOK"/> | 173 | <constraint firstItem="gBg-k9-tgw" firstAttribute="top" secondItem="Bdy-dI-j47" secondAttribute="bottom" constant="30" id="mgw-uX-VOK"/> |
168 | <constraint firstAttribute="trailing" secondItem="YWV-pS-TCo" secondAttribute="trailing" constant="15" id="rEO-bb-Pqr"/> | 174 | <constraint firstAttribute="trailing" secondItem="YWV-pS-TCo" secondAttribute="trailing" constant="15" id="rEO-bb-Pqr"/> |
169 | <constraint firstAttribute="trailing" secondItem="caN-x7-hJz" secondAttribute="trailing" constant="16" id="rRn-Vw-t5g"/> | 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 | <constraint firstAttribute="trailing" secondItem="4VU-Ye-7Au" secondAttribute="trailing" id="ylN-vm-QF2"/> | 177 | <constraint firstAttribute="trailing" secondItem="4VU-Ye-7Au" secondAttribute="trailing" id="ylN-vm-QF2"/> |
172 | </constraints> | 178 | </constraints> |
173 | <point key="canvasLocation" x="24.5" y="52.5"/> | 179 | <point key="canvasLocation" x="24.5" y="52.5"/> |
174 | </view> | 180 | </view> |
175 | </objects> | 181 | </objects> |
176 | <resources> | 182 | <resources> |
177 | <image name="icon_menu" width="30" height="30"/> | 183 | <image name="icon_menu" width="30" height="30"/> |
178 | <image name="today_back_button" width="73" height="37"/> | 184 | <image name="today_back_button" width="73" height="37"/> |
179 | </resources> | 185 | </resources> |
180 | </document> | 186 | </document> |
181 | 187 |
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) BOOL isJoin; | ||
16 | @property (nonatomic) BOOL walkMode; | 17 | @property (nonatomic) BOOL walkMode; |
17 | @property (nonatomic) BOOL runMode; | 18 | @property (nonatomic) BOOL runMode; |
18 | @property (nonatomic) BOOL bikeMode; | 19 | @property (nonatomic) BOOL bikeMode; |
19 | @property (nonatomic) BOOL stepMode; | 20 | @property (nonatomic) BOOL stepMode; |
20 | @property (nonatomic) BOOL gymMode; | 21 | @property (nonatomic) BOOL gymMode; |
21 | @property (nonatomic) BOOL beginMode; | 22 | @property (nonatomic) BOOL beginMode; |
22 | 23 | ||
23 | @property (nonatomic, strong) NSString * name; | 24 | @property (nonatomic, strong) NSString * name; |
24 | @property (nonatomic, strong) NSString * avatar; | 25 | @property (nonatomic, strong) NSString * avatar; |
26 | @property (nonatomic, strong) NSString * goal; | ||
27 | |||
25 | @property (nonatomic, strong) NSDate * createDate; | 28 | @property (nonatomic, strong) NSDate * createDate; |
26 | 29 | ||
27 | -(id) initWithData : (NSDictionary *) dict; | 30 | -(id) initWithData : (NSDictionary *) dict; |
28 | 31 | ||
29 | @end | 32 | @end |
30 | 33 |
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 | 13 | ||
14 | -(id) initWithData : (NSDictionary *) dict { | 14 | -(id) initWithData : (NSDictionary *) dict { |
15 | if([dict objectForKey:@"group_id"] != nil) { | 15 | if([dict objectForKey:@"group_id"] != nil) { |
16 | self.groupID = [dict[@"group_id"] intValue]; | 16 | self.groupID = [dict[@"group_id"] intValue]; |
17 | } | 17 | } |
18 | if([dict objectForKey:@"group_name"] != nil) { | 18 | if([dict objectForKey:@"group_name"] != nil) { |
19 | self.name = dict[@"group_name"]; | 19 | self.name = dict[@"group_name"]; |
20 | } | 20 | } |
21 | if([dict objectForKey:@"group_avatar"] != nil) { | 21 | if([dict objectForKey:@"group_avatar"] != nil) { |
22 | self.avatar = dict[@"group_avatar"]; | 22 | self.avatar = dict[@"group_avatar"]; |
23 | } | 23 | } |
24 | if([dict objectForKey:@"walk_mode_active"] != nil && ![[dict objectForKey:@"walk_mode_active"] isKindOfClass:[NSNull class]]) { | 24 | if([dict objectForKey:@"walk_mode_active"] != nil && ![[dict objectForKey:@"walk_mode_active"] isKindOfClass:[NSNull class]]) { |
25 | self.walkMode = [dict[@"walk_mode_active"] boolValue]; | 25 | self.walkMode = [dict[@"walk_mode_active"] boolValue]; |
26 | } | 26 | } |
27 | if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { | 27 | if([dict objectForKey:@"run_mode_active"] != nil && ![[dict objectForKey:@"run_mode_active"] isKindOfClass:[NSNull class]]) { |
28 | self.runMode = [dict[@"run_mode_active"] boolValue]; | 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 | self.bikeMode = [dict[@"bike_mode_active"] boolValue]; | 31 | self.bikeMode = [dict[@"bike_mode_active"] boolValue]; |
32 | } | 32 | } |
33 | if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { | 33 | if([dict objectForKey:@"step_mode_active"] != nil && ![[dict objectForKey:@"step_mode_active"] isKindOfClass:[NSNull class]]) { |
34 | self.stepMode = [dict[@"step_mode_active"] boolValue]; | 34 | self.stepMode = [dict[@"step_mode_active"] boolValue]; |
35 | } | 35 | } |
36 | if([dict objectForKey:@"gym_mode_active"] != nil && ![[dict objectForKey:@"gym_mode_active"] isKindOfClass:[NSNull class]]) { | 36 | if([dict objectForKey:@"gym_mode_active"] != nil && ![[dict objectForKey:@"gym_mode_active"] isKindOfClass:[NSNull class]]) { |
37 | self.gymMode = [dict[@"gym_mode_active"] boolValue]; | 37 | self.gymMode = [dict[@"gym_mode_active"] boolValue]; |
38 | } | 38 | } |
39 | if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { | 39 | if([dict objectForKey:@"beginer_mode_active"] != nil && ![[dict objectForKey:@"beginer_mode_active"] isKindOfClass:[NSNull class]]) { |
40 | self.beginMode = [dict[@"beginer_mode_active"] boolValue]; | 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 | if([dict objectForKey:@"created_at"] != nil) { | 45 | if([dict objectForKey:@"created_at"] != nil) { |
43 | NSString *dateString = dict[@"created_at"]; | 46 | NSString *dateString = dict[@"created_at"]; |
44 | self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; | 47 | self.createDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd hh:mm:ss"]; |
45 | } | 48 | } |
46 | else { | 49 | else { |
47 | self.createDate = [NSDate date]; | 50 | self.createDate = [NSDate date]; |
48 | } | 51 | } |
49 | if([dict objectForKey:@"num_search"] != nil) { | 52 | if([dict objectForKey:@"num_search"] != nil) { |
50 | self.numSearch = [dict[@"num_search"] intValue]; | 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 | return self; | 61 | return self; |
53 | } | 62 | } |
54 | 63 | ||
55 | @end | 64 | @end |
56 | 65 |
LifeLog/LifeLog/ServerAPI.h
1 | // | 1 | // |
2 | // ServerAPI.h | 2 | // ServerAPI.h |
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 <Foundation/Foundation.h> | 9 | #import <Foundation/Foundation.h> |
10 | #import "Entities.h" | 10 | #import "Entities.h" |
11 | 11 | ||
12 | extern NSString *const kServerAddress; | 12 | extern NSString *const kServerAddress; |
13 | extern NSString *const kUser; | 13 | extern NSString *const kUser; |
14 | extern NSString *const kToken; | 14 | extern NSString *const kToken; |
15 | extern NSString *const kNotificationToken; | 15 | extern NSString *const kNotificationToken; |
16 | 16 | ||
17 | @interface ServerAPI : NSObject | 17 | @interface ServerAPI : NSObject |
18 | + (instancetype) server; | 18 | + (instancetype) server; |
19 | @property (nonatomic, assign) NSTimeInterval timeOutInterval; | 19 | @property (nonatomic, assign) NSTimeInterval timeOutInterval; |
20 | 20 | ||
21 | #pragma mark - Login and Register | 21 | #pragma mark - Login and Register |
22 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; | 22 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; |
23 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; | 23 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; |
24 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; | 24 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; |
25 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; | 25 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; |
26 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; | 26 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; |
27 | 27 | ||
28 | #pragma mark - Home Screen Function | 28 | #pragma mark - Home Screen Function |
29 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion; | 29 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion; |
30 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion; | 30 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion; |
31 | 31 | ||
32 | #pragma mark - History Screen Function | 32 | #pragma mark - History Screen Function |
33 | - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion; | 33 | - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion; |
34 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; | 34 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; |
35 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 35 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
36 | 36 | ||
37 | #pragma mark - SNS Screen Function | 37 | #pragma mark - SNS Screen Function |
38 | /* | 38 | /* |
39 | Get tweet of group and get recent tweet is same API | 39 | Get tweet of group and get recent tweet is same API |
40 | If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group | 40 | If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group |
41 | */ | 41 | */ |
42 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 42 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
43 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 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 | #pragma mark - Common API | 48 | #pragma mark - Common API |
45 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; | 49 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
46 | @end | 50 | @end |
47 | 51 |
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 | ||
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 | #pragma mark - Common API | 699 | #pragma mark - Common API |
650 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { | 700 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
651 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { | 701 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |
652 | 702 | ||
653 | if (completion == NULL) { | 703 | if (completion == NULL) { |
654 | return ; | 704 | return ; |
655 | } | 705 | } |
656 | 706 | ||
657 | if (error == nil) | 707 | if (error == nil) |
658 | { | 708 | { |
659 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 709 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
660 | 710 | ||
661 | int status = [dataResult[@"status"] intValue]; | 711 | int status = [dataResult[@"status"] intValue]; |
662 | if (status == 1) { // status = 1 success | 712 | if (status == 1) { // status = 1 success |
663 | NSArray *arrayResult = dataResult[@"result"]; | 713 | NSArray *arrayResult = dataResult[@"result"]; |
664 | if (arrayResult.count > 0) { | 714 | if (arrayResult.count > 0) { |
665 | NSString *token = arrayResult[0]; | 715 | NSString *token = arrayResult[0]; |
666 | completion(token, nil); | 716 | completion(token, nil); |
667 | } | 717 | } |
668 | else { | 718 | else { |
669 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 719 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
670 | completion(nil, errorObject); | 720 | completion(nil, errorObject); |
671 | } | 721 | } |
672 | 722 | ||
673 | } | 723 | } |
674 | else { // status = 0 error | 724 | else { // status = 0 error |
675 | NSString *message = dataResult[@"message"]; | 725 | NSString *message = dataResult[@"message"]; |
676 | if (message == nil) { | 726 | if (message == nil) { |
677 | message = @"Unknown error"; | 727 | message = @"Unknown error"; |
678 | } | 728 | } |
679 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 729 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
680 | completion(nil, loginFaild); | 730 | completion(nil, loginFaild); |
681 | } | 731 | } |
682 | } | 732 | } |
683 | else | 733 | else |
684 | { | 734 | { |
685 | completion(nil, error); | 735 | completion(nil, error); |
686 | } | 736 | } |
687 | }]; | 737 | }]; |
688 | } | 738 | } |
689 | 739 | ||
690 | #pragma mark - Private Function | 740 | #pragma mark - Private Function |
691 | - (void) checkToken { | 741 | - (void) checkToken { |
692 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; | 742 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; |
693 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | 743 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; |
694 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | 744 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; |
695 | if (user != nil) { | 745 | if (user != nil) { |
696 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { | 746 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { |
697 | if (error == nil) { | 747 | if (error == nil) { |
698 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | 748 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; |
699 | [[NSUserDefaults standardUserDefaults] synchronize]; | 749 | [[NSUserDefaults standardUserDefaults] synchronize]; |
700 | } | 750 | } |
701 | }]; | 751 | }]; |
702 | } | 752 | } |
703 | } | 753 | } |
704 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary | 754 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary |
705 | { | 755 | { |
706 | NSMutableArray *parts = [[NSMutableArray alloc] init]; | 756 | NSMutableArray *parts = [[NSMutableArray alloc] init]; |
707 | for (id key in dictionary) | 757 | for (id key in dictionary) |
708 | { | 758 | { |
709 | NSString *encodedValue = [[dictionary[key] description] urlencode]; | 759 | NSString *encodedValue = [[dictionary[key] description] urlencode]; |
710 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; | 760 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; |
711 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; | 761 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; |
712 | [parts addObject:part]; | 762 | [parts addObject:part]; |
713 | } | 763 | } |
714 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; | 764 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; |
715 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; | 765 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; |
716 | } | 766 | } |
717 | 767 | ||
718 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | 768 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion |
719 | { | 769 | { |
720 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; | 770 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; |
721 | request.HTTPMethod = method; | 771 | request.HTTPMethod = method; |
722 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; | 772 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; |
723 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; | 773 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; |
724 | if(token != nil && ![token isEqual: @""]) { | 774 | if(token != nil && ![token isEqual: @""]) { |
725 | [request setValue: token forHTTPHeaderField: @"token"]; | 775 | [request setValue: token forHTTPHeaderField: @"token"]; |
726 | } | 776 | } |
727 | [request setTimeoutInterval:self.timeOutInterval]; | 777 | [request setTimeoutInterval:self.timeOutInterval]; |
728 | 778 | ||
729 | if (paras != nil) | 779 | if (paras != nil) |
730 | { | 780 | { |
731 | NSData *encodedData = [self _encodeDictionary: paras]; | 781 | NSData *encodedData = [self _encodeDictionary: paras]; |
732 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; | 782 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; |
733 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; | 783 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; |
734 | [request setHTTPBody: encodedData]; | 784 | [request setHTTPBody: encodedData]; |
735 | } | 785 | } |
736 | 786 | ||
737 | NSURLSession *session = [NSURLSession sharedSession]; | 787 | NSURLSession *session = [NSURLSession sharedSession]; |
738 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request | 788 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request |
739 | completionHandler: | 789 | completionHandler: |
740 | ^(NSData *data, NSURLResponse *response, NSError *error) { | 790 | ^(NSData *data, NSURLResponse *response, NSError *error) { |
741 | if (completion == NULL) { | 791 | if (completion == NULL) { |
742 | return ; | 792 | return ; |
743 | } | 793 | } |
744 | if (error == nil) | 794 | if (error == nil) |
745 | { | 795 | { |
746 | completion(data, nil); | 796 | completion(data, nil); |
747 | } | 797 | } |
748 | else | 798 | else |
749 | { | 799 | { |
750 | completion(nil, error); | 800 | completion(nil, error); |
751 | } | 801 | } |
752 | }]; | 802 | }]; |
753 | [task resume]; | 803 | [task resume]; |
754 | return task; | 804 | return task; |
755 | } | 805 | } |
756 | 806 | ||
757 | -(void)waitUntilDone:(void(^)(void))waitBlock { | 807 | -(void)waitUntilDone:(void(^)(void))waitBlock { |
758 | //use your statement or call method here | 808 | //use your statement or call method here |
759 | if(waitBlock){ | 809 | if(waitBlock){ |
760 | waitBlock(); | 810 | waitBlock(); |
761 | } | 811 | } |
762 | } | 812 | } |
763 | 813 | ||
764 | @end | 814 | @end |
765 | 815 |