|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | #import "Me_RootViewController.h"
|
| 10 | +#import "Coding_NetAPIManager.h" |
| 11 | +#import "UsersViewController.h" |
| 12 | +#import "AddUserViewController.h" |
| 13 | +#import "SettingViewController.h" |
| 14 | +#import "SettingMineInfoViewController.h" |
| 15 | +#import "UserInfoDetailViewController.h" |
| 16 | +#import "ProjectListViewController.h" |
| 17 | +#import "LocalFoldersViewController.h" |
| 18 | +#import "PointRecordsViewController.h" |
| 19 | +#import "AboutViewController.h" |
| 20 | +#import "HelpViewController.h" |
| 21 | + |
| 22 | +#import "RDVTabBarController.h" |
| 23 | +#import "RDVTabBarItem.h" |
| 24 | +#import "ODRefreshControl.h" |
| 25 | + |
| 26 | +#import "UserInfoIconCell.h" |
| 27 | +#import "MeRootUserCell.h" |
| 28 | +#import "MeRootServiceCell.h" |
| 29 | + |
| 30 | +#import "ServiceInfo.h" |
| 31 | + |
| 32 | +@interface Me_RootViewController ()<UITableViewDataSource, UITableViewDelegate> |
| 33 | +@property (strong, nonatomic) UITableView *myTableView; |
| 34 | +@property (nonatomic, strong) ODRefreshControl *refreshControl; |
| 35 | + |
| 36 | +@property (strong, nonatomic) User *curUser; |
| 37 | +@property (strong, nonatomic) ServiceInfo *curServiceInfo; |
| 38 | +@end |
10 | 39 |
|
11 | 40 | @implementation Me_RootViewController
|
| 41 | +- (void)viewDidLoad{ |
| 42 | + [super viewDidLoad]; |
| 43 | + // Do any additional setup after loading the view. |
| 44 | + self.title = @"我"; |
| 45 | + _curUser = [Login curLoginUser]? [Login curLoginUser]: [User userWithGlobalKey:@""]; |
| 46 | + [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addUserBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(goToAddUser)] animated:NO]; |
| 47 | + |
| 48 | + // 添加myTableView |
| 49 | + _myTableView = ({ |
| 50 | + UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; |
| 51 | + tableView.backgroundColor = kColorTableSectionBg; |
| 52 | + tableView.dataSource = self; |
| 53 | + tableView.delegate = self; |
| 54 | + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 55 | + [tableView registerClass:[UserInfoIconCell class] forCellReuseIdentifier:kCellIdentifier_UserInfoIconCell]; |
| 56 | + [tableView registerClass:[MeRootUserCell class] forCellReuseIdentifier:kCellIdentifier_MeRootUserCell]; |
| 57 | + [tableView registerClass:[MeRootServiceCell class] forCellReuseIdentifier:kCellIdentifier_MeRootServiceCell]; |
| 58 | + [self.view addSubview:tableView]; |
| 59 | + [tableView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 60 | + make.edges.equalTo(self.view); |
| 61 | + }]; |
| 62 | + UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), 0); |
| 63 | + tableView.contentInset = insets; |
| 64 | + tableView.scrollIndicatorInsets = insets; |
| 65 | + tableView; |
| 66 | + }); |
| 67 | + |
| 68 | + _refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; |
| 69 | + [_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; |
| 70 | +} |
| 71 | + |
| 72 | +- (void)viewWillAppear:(BOOL)animated{ |
| 73 | + [super viewWillAppear:animated]; |
| 74 | + [self refresh]; |
| 75 | +} |
| 76 | + |
| 77 | +- (void)refresh{ |
| 78 | + __weak typeof(self) weakSelf = self; |
| 79 | + [[Coding_NetAPIManager sharedManager] request_UserInfo_WithObj:_curUser andBlock:^(id data, NSError *error) { |
| 80 | + if (data) { |
| 81 | + weakSelf.curUser = data; |
| 82 | + [[Coding_NetAPIManager sharedManager] request_ServiceInfoBlock:^(id dataS, NSError *errorS) { |
| 83 | + if (dataS) { |
| 84 | + weakSelf.curServiceInfo = dataS; |
| 85 | + } |
| 86 | + [weakSelf.myTableView reloadData]; |
| 87 | + [weakSelf.refreshControl endRefreshing]; |
| 88 | + }]; |
| 89 | + }else{ |
| 90 | + [weakSelf.refreshControl endRefreshing]; |
| 91 | + } |
| 92 | + }]; |
| 93 | +} |
| 94 | + |
| 95 | +#pragma mark Table M |
| 96 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ |
| 97 | + return 3; |
| 98 | +} |
| 99 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 100 | + NSInteger row = (section ==0? 2: |
| 101 | + section == 1? 1: |
| 102 | + 4); |
| 103 | + return row; |
| 104 | +} |
| 105 | + |
| 106 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 107 | + |
| 108 | + if (indexPath.section == 0) { |
| 109 | + if (indexPath.row == 0) { |
| 110 | + MeRootUserCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MeRootUserCell forIndexPath:indexPath]; |
| 111 | + cell.curUser = _curUser; |
| 112 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:0]; |
| 113 | + return cell; |
| 114 | + }else{ |
| 115 | + MeRootServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MeRootServiceCell forIndexPath:indexPath]; |
| 116 | + cell.curServiceInfo = _curServiceInfo; |
| 117 | + ESWeak(self, weakSelf); |
| 118 | + cell.leftBlock = ^(){ |
| 119 | + [weakSelf goToProjects]; |
| 120 | + }; |
| 121 | + cell.rightBlock = ^(){ |
| 122 | + [weakSelf goToTeams]; |
| 123 | + }; |
| 124 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:0]; |
| 125 | + return cell; |
| 126 | + } |
| 127 | + }else{ |
| 128 | + UserInfoIconCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_UserInfoIconCell forIndexPath:indexPath]; |
| 129 | + (indexPath.section == 1? [cell setTitle:@"我的码币" icon:@"user_info_point"]: |
| 130 | + indexPath.row == 0? [cell setTitle:@"本地文件" icon:@"user_info_file"]: |
| 131 | + indexPath.row == 1? [cell setTitle:@"帮助与反馈" icon:@"user_info_help"]: |
| 132 | + indexPath.row == 2? [cell setTitle:@"设置" icon:@"user_info_setup"]: |
| 133 | + [cell setTitle:@"关于我们" icon:@"user_info_about"]); |
| 134 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; |
| 135 | + return cell; |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 140 | + CGFloat cellHeight = 0; |
| 141 | + if (indexPath.section == 0) { |
| 142 | + cellHeight = indexPath.row == 0? [MeRootUserCell cellHeight]: [MeRootServiceCell cellHeight]; |
| 143 | + }else{ |
| 144 | + cellHeight = [UserInfoIconCell cellHeight]; |
| 145 | + } |
| 146 | + return cellHeight; |
| 147 | +} |
| 148 | + |
| 149 | +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ |
| 150 | + return 1.0/[UIScreen mainScreen].scale; |
| 151 | +} |
| 152 | +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| 153 | + return 20; |
| 154 | +} |
| 155 | + |
| 156 | +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 157 | + UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 20)]; |
| 158 | + headerView.backgroundColor = kColorTableSectionBg; |
| 159 | + return headerView; |
| 160 | +} |
| 161 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 162 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 163 | + |
| 164 | + if (indexPath.section == 0) { |
| 165 | + if (indexPath.row == 0) {//个人主页 |
| 166 | + [self goToMeDisplay]; |
| 167 | + } |
| 168 | + }else if (indexPath.section == 1){//我的码币 |
| 169 | + [self goToPoint]; |
| 170 | + }else{ |
| 171 | + if (indexPath.row == 0) {//本地文件 |
| 172 | + [self goToLocalFolders]; |
| 173 | + }else if (indexPath.row == 1){//帮助与反馈 |
| 174 | + [self goToHelp]; |
| 175 | + }else if (indexPath.row == 2){//设置 |
| 176 | + [self goToSetting]; |
| 177 | + }else{//关于我们 |
| 178 | + [self goToAbout]; |
| 179 | + } |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +#pragma mark GoTo |
| 184 | +- (void)goToAddUser{ |
| 185 | + AddUserViewController *vc = [[AddUserViewController alloc] init]; |
| 186 | + vc.type = AddUserTypeFollow; |
| 187 | + [self.navigationController pushViewController:vc animated:YES]; |
| 188 | +} |
| 189 | + |
| 190 | +- (void)goToLocalFolders{ |
| 191 | + LocalFoldersViewController *vc = [LocalFoldersViewController new]; |
| 192 | + [self.navigationController pushViewController:vc animated:YES]; |
| 193 | +} |
| 194 | + |
| 195 | +- (void)goToPoint{ |
| 196 | + PointRecordsViewController *vc = [PointRecordsViewController new]; |
| 197 | + [self.navigationController pushViewController:vc animated:YES]; |
| 198 | +} |
| 199 | + |
| 200 | +- (void)goToSetting{ |
| 201 | + SettingViewController *vc = [[SettingViewController alloc] init]; |
| 202 | + vc.myUser = self.curUser; |
| 203 | + [self.navigationController pushViewController:vc animated:YES]; |
| 204 | +} |
| 205 | + |
| 206 | +- (void)goToHelp{ |
| 207 | + [self.navigationController pushViewController:[HelpViewController vcWithHelpStr] animated:YES]; |
| 208 | +} |
| 209 | + |
| 210 | +- (void)goToAbout{ |
| 211 | + [self.navigationController pushViewController:[AboutViewController new] animated:YES]; |
| 212 | +} |
| 213 | + |
| 214 | +- (void)goToProjects{ |
| 215 | + ProjectListViewController *vc = [[ProjectListViewController alloc] init]; |
| 216 | + vc.curUser = _curUser; |
| 217 | + vc.isFromMeRoot = YES; |
| 218 | + [self.navigationController pushViewController:vc animated:YES]; |
| 219 | +} |
| 220 | + |
| 221 | +- (void)goToTeams{ |
| 222 | + |
| 223 | +} |
12 | 224 |
|
| 225 | +- (void)goToMeDisplay{ |
| 226 | + |
| 227 | +} |
13 | 228 |
|
14 | 229 | @end
|
0 commit comments