| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,9 +9,11 @@ | |||
| 9 | 9 | #import "LocalFilesViewController.h" | |
| 10 | 10 | #import "LocalFileCell.h" | |
| 11 | 11 | #import "LocalFileViewController.h" | |
| 12 | + #import "EaseToolBar.h" | ||
| 12 | 13 | ||
| 13 | - @interface LocalFilesViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate> | ||
| 14 | + @interface LocalFilesViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate, EaseToolBarDelegate> | ||
| 14 | 15 | @property (strong, nonatomic) UITableView *myTableView; | |
| 16 | + @property (nonatomic, strong) EaseToolBar *myEditToolBar; | ||
| 15 | 17 | ||
| 16 | 18 | @end | |
| 17 | 19 | ||
@@ -33,8 +35,10 @@ - (void)viewDidLoad{ | |||
| 33 | 35 | [tableView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 34 | 36 | make.edges.equalTo(self.view); | |
| 35 | 37 | }]; | |
| 38 | + tableView.allowsMultipleSelectionDuringEditing = YES; | ||
| 36 | 39 | tableView; | |
| 37 | 40 | }); | |
| 41 | + [self changeEditStateToEditing:NO]; | ||
| 38 | 42 | } | |
| 39 | 43 | ||
| 40 | 44 | #pragma mark T | |
@@ -55,13 +59,17 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa | |||
| 55 | 59 | } | |
| 56 | 60 | ||
| 57 | 61 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
| 58 | - [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 59 | - | ||
| 60 | - LocalFileViewController *vc = [LocalFileViewController new]; | ||
| 61 | - vc.projectName = self.projectName; | ||
| 62 | - vc.fileUrl = self.fileList[indexPath.row]; | ||
| 63 | - | ||
| 64 | - [self.navigationController pushViewController:vc animated:YES]; | ||
| 62 | + if (tableView.isEditing) { | ||
| 63 | + | ||
| 64 | + }else{ | ||
| 65 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 66 | + | ||
| 67 | + LocalFileViewController *vc = [LocalFileViewController new]; | ||
| 68 | + vc.projectName = self.projectName; | ||
| 69 | + vc.fileUrl = self.fileList[indexPath.row]; | ||
| 70 | + | ||
| 71 | + [self.navigationController pushViewController:vc animated:YES]; | ||
| 72 | + } | ||
| 65 | 73 | } | |
| 66 | 74 | ||
| 67 | 75 | #pragma mark SWTableViewCellDelegate | |
@@ -86,6 +94,92 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut | |||
| 86 | 94 | [actionSheet showInView:self.view]; | |
| 87 | 95 | } | |
| 88 | 96 | ||
| 97 | + #pragma mark Edit | ||
| 98 | + - (void)changeEditStateToEditing:(BOOL)isEditing{ | ||
| 99 | + [_myTableView setEditing:isEditing animated:YES]; | ||
| 100 | + NSArray *rightBarButtonItems; | ||
| 101 | + if (isEditing) { | ||
| 102 | + UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(changeEditState)]; | ||
| 103 | + UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; | ||
| 104 | + spaceItem.width = 20; | ||
| 105 | + UIBarButtonItem *item2 = [UIBarButtonItem itemWithBtnTitle:@"反选" target:self action:@selector(reverseSelect)]; | ||
| 106 | + rightBarButtonItems = @[item1, spaceItem, item2]; | ||
| 107 | + }else{ | ||
| 108 | + UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(changeEditState)]; | ||
| 109 | + rightBarButtonItems = @[item1]; | ||
| 110 | + } | ||
| 111 | + [self.navigationItem setRightBarButtonItems:rightBarButtonItems animated:YES]; | ||
| 112 | + [self configToolBar]; | ||
| 113 | + [self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.3]; | ||
| 114 | + } | ||
| 115 | + - (void)changeEditState{ | ||
| 116 | + [self changeEditStateToEditing:!_myTableView.isEditing]; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + - (void)reverseSelect{ | ||
| 120 | + if (_myTableView.isEditing) { | ||
| 121 | + NSArray *selectedIndexList = [_myTableView indexPathsForSelectedRows]; | ||
| 122 | + NSMutableArray *reverseIndexList = [NSMutableArray new]; | ||
| 123 | + for (NSInteger index = 0; index < _fileList.count; index++) { | ||
| 124 | + NSIndexPath *curIndex = [NSIndexPath indexPathForRow:index inSection:0]; | ||
| 125 | + if (![selectedIndexList containsObject:curIndex]) { | ||
| 126 | + [reverseIndexList addObject:curIndex]; | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + for (NSIndexPath *indexPath in selectedIndexList) { | ||
| 130 | + [_myTableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 131 | + } | ||
| 132 | + for (NSIndexPath *indexPath in reverseIndexList) { | ||
| 133 | + [_myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + - (void)configToolBar{ | ||
| 139 | + //添加底部ToolBar | ||
| 140 | + if (!_myEditToolBar) { | ||
| 141 | + EaseToolBarItem *item = [EaseToolBarItem easeToolBarItemWithTitle:@" 删除" image:@"button_file_denete_enable" disableImage:nil]; | ||
| 142 | + _myEditToolBar = [EaseToolBar easeToolBarWithItems:@[item]]; | ||
| 143 | + _myEditToolBar.delegate = self; | ||
| 144 | + [self.view addSubview:_myEditToolBar]; | ||
| 145 | + [_myEditToolBar mas_makeConstraints:^(MASConstraintMaker *make) { | ||
| 146 | + make.bottom.equalTo(self.view.mas_bottom); | ||
| 147 | + make.size.mas_equalTo(_myEditToolBar.frame.size); | ||
| 148 | + }]; | ||
| 149 | + } | ||
| 150 | + _myEditToolBar.hidden = !_myTableView.isEditing; | ||
| 151 | + UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0,_myTableView.isEditing? CGRectGetHeight(_myEditToolBar.frame): 0.0, 0.0); | ||
| 152 | + self.myTableView.contentInset = contentInsets; | ||
| 153 | + self.myTableView.scrollIndicatorInsets = contentInsets; | ||
| 154 | + } | ||
| 155 | + #pragma mark EaseToolBarDelegate | ||
| 156 | + - (void)easeToolBar:(EaseToolBar *)toolBar didClickedIndex:(NSInteger)index{ | ||
| 157 | + NSArray *selectedIndexPath = [_myTableView indexPathsForSelectedRows]; | ||
| 158 | + if (selectedIndexPath.count <= 0) { | ||
| 159 | + return; | ||
| 160 | + } | ||
| 161 | + if (toolBar == _myEditToolBar) { | ||
| 162 | + if (index == 0) { | ||
| 163 | + __weak typeof(self) weakSelf = self; | ||
| 164 | + UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定要删除选中的本地文件吗?" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { | ||
| 165 | + if (index == 0) { | ||
| 166 | + [weakSelf deleteSelectedFiles]; | ||
| 167 | + } | ||
| 168 | + }]; | ||
| 169 | + [actionSheet showInView:self.view]; | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + - (void)deleteSelectedFiles{ | ||
| 175 | + NSArray *selectedIndexPath = [_myTableView indexPathsForSelectedRows]; | ||
| 176 | + NSMutableArray *selectedFiles = [[NSMutableArray alloc] initWithCapacity:selectedIndexPath.count]; | ||
| 177 | + for (NSIndexPath *indexPath in selectedIndexPath) { | ||
| 178 | + [selectedFiles addObject:_fileList[indexPath.row]]; | ||
| 179 | + } | ||
| 180 | + [self deleteFilesWithUrlList:selectedFiles]; | ||
| 181 | + } | ||
| 182 | + | ||
| 89 | 183 | #pragma mark Delete | |
| 90 | 184 | - (void)deleteFilesWithUrlList:(NSArray *)urlList{ | |
| 91 | 185 | @weakify(self); | |
@@ -104,7 +198,7 @@ - (void)deleteFilesWithUrlList:(NSArray *)urlList{ | |||
| 104 | 198 | dispatch_async(dispatch_get_main_queue(), ^{ | |
| 105 | 199 | @strongify(self); | |
| 106 | 200 | [self.fileList removeObjectsInArray:urlList]; | |
| 107 | - [self.myTableView reloadData]; | ||
| 201 | + [self changeEditStateToEditing:NO]; | ||
| 108 | 202 | [NSObject showHudTipStr:@"本地文件删除成功"]; | |
| 109 | 203 | }); | |
| 110 | 204 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,12 +12,15 @@ | |||
| 12 | 12 | #import "Coding_NetAPIManager.h" | |
| 13 | 13 | #import "LocalFolderCell.h" | |
| 14 | 14 | #import "LocalFilesViewController.h" | |
| 15 | + #import "EaseToolBar.h" | ||
| 15 | 16 | ||
| 16 | - @interface LocalFoldersViewController ()<UITableViewDataSource, UITableViewDelegate> | ||
| 17 | + @interface LocalFoldersViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate, EaseToolBarDelegate> | ||
| 17 | 18 | @property (assign, nonatomic) BOOL isLoading; | |
| 18 | 19 | @property (strong, nonatomic) UITableView *myTableView; | |
| 19 | 20 | @property (strong, nonatomic) ODRefreshControl *myRefreshControl; | |
| 20 | 21 | ||
| 22 | + @property (nonatomic, strong) EaseToolBar *myEditToolBar; | ||
| 23 | + | ||
| 21 | 24 | @property (strong, nonatomic) NSMutableArray *projectId_list; | |
| 22 | 25 | @property (strong, nonatomic) NSMutableDictionary *projectList_dict; | |
| 23 | 26 | @end | |
@@ -40,6 +43,7 @@ - (void)viewDidLoad{ | |||
| 40 | 43 | [tableView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 41 | 44 | make.edges.equalTo(self.view); | |
| 42 | 45 | }]; | |
| 46 | + tableView.allowsMultipleSelectionDuringEditing = YES; | ||
| 43 | 47 | tableView; | |
| 44 | 48 | }); | |
| 45 | 49 | _myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; | |
@@ -48,6 +52,7 @@ - (void)viewDidLoad{ | |||
| 48 | 52 | ||
| 49 | 53 | - (void)viewWillAppear:(BOOL)animated{ | |
| 50 | 54 | [super viewWillAppear:animated]; | |
| 55 | + [self changeEditStateToEditing:NO]; | ||
| 51 | 56 | [self refresh]; | |
| 52 | 57 | } | |
| 53 | 58 | ||
@@ -144,16 +149,20 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa | |||
| 144 | 149 | } | |
| 145 | 150 | ||
| 146 | 151 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
| 147 | - [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 148 | - | ||
| 149 | - NSString *key = _projectId_list[indexPath.row]; | ||
| 150 | - NSDictionary *pro_dict = _projectList_dict[key]; | ||
| 151 | - | ||
| 152 | - LocalFilesViewController *vc = [LocalFilesViewController new]; | ||
| 153 | - vc.projectName = pro_dict[@"name"]; | ||
| 154 | - vc.fileList = pro_dict[@"list"]; | ||
| 155 | - | ||
| 156 | - [self.navigationController pushViewController:vc animated:YES]; | ||
| 152 | + if (tableView.isEditing) { | ||
| 153 | + | ||
| 154 | + }else{ | ||
| 155 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 156 | + | ||
| 157 | + NSString *key = _projectId_list[indexPath.row]; | ||
| 158 | + NSDictionary *pro_dict = _projectList_dict[key]; | ||
| 159 | + | ||
| 160 | + LocalFilesViewController *vc = [LocalFilesViewController new]; | ||
| 161 | + vc.projectName = pro_dict[@"name"]; | ||
| 162 | + vc.fileList = pro_dict[@"list"]; | ||
| 163 | + | ||
| 164 | + [self.navigationController pushViewController:vc animated:YES]; | ||
| 165 | + } | ||
| 157 | 166 | } | |
| 158 | 167 | ||
| 159 | 168 | #pragma mark SWTableViewCellDelegate | |
@@ -179,6 +188,95 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut | |||
| 179 | 188 | [actionSheet showInView:self.view]; | |
| 180 | 189 | } | |
| 181 | 190 | ||
| 191 | + #pragma mark Edit | ||
| 192 | + - (void)changeEditStateToEditing:(BOOL)isEditing{ | ||
| 193 | + [_myTableView setEditing:isEditing animated:YES]; | ||
| 194 | + NSArray *rightBarButtonItems; | ||
| 195 | + if (isEditing) { | ||
| 196 | + UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(changeEditState)]; | ||
| 197 | + UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; | ||
| 198 | + spaceItem.width = 20; | ||
| 199 | + UIBarButtonItem *item2 = [UIBarButtonItem itemWithBtnTitle:@"反选" target:self action:@selector(reverseSelect)]; | ||
| 200 | + rightBarButtonItems = @[item1, spaceItem, item2]; | ||
| 201 | + }else{ | ||
| 202 | + UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(changeEditState)]; | ||
| 203 | + rightBarButtonItems = @[item1]; | ||
| 204 | + } | ||
| 205 | + [self.navigationItem setRightBarButtonItems:rightBarButtonItems animated:YES]; | ||
| 206 | + [self configToolBar]; | ||
| 207 | + [self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.3]; | ||
| 208 | + } | ||
| 209 | + - (void)changeEditState{ | ||
| 210 | + [self changeEditStateToEditing:!_myTableView.isEditing]; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + - (void)reverseSelect{ | ||
| 214 | + if (_myTableView.isEditing) { | ||
| 215 | + NSArray *selectedIndexList = [_myTableView indexPathsForSelectedRows]; | ||
| 216 | + NSMutableArray *reverseIndexList = [NSMutableArray new]; | ||
| 217 | + for (NSInteger index = 0; index < _projectId_list.count; index++) { | ||
| 218 | + NSIndexPath *curIndex = [NSIndexPath indexPathForRow:index inSection:0]; | ||
| 219 | + if (![selectedIndexList containsObject:curIndex]) { | ||
| 220 | + [reverseIndexList addObject:curIndex]; | ||
| 221 | + } | ||
| 222 | + } | ||
| 223 | + for (NSIndexPath *indexPath in selectedIndexList) { | ||
| 224 | + [_myTableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 225 | + } | ||
| 226 | + for (NSIndexPath *indexPath in reverseIndexList) { | ||
| 227 | + [_myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; | ||
| 228 | + } | ||
| 229 | + } | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + - (void)configToolBar{ | ||
| 233 | + //添加底部ToolBar | ||
| 234 | + if (!_myEditToolBar) { | ||
| 235 | + EaseToolBarItem *item = [EaseToolBarItem easeToolBarItemWithTitle:@" 删除" image:@"button_file_denete_enable" disableImage:nil]; | ||
| 236 | + _myEditToolBar = [EaseToolBar easeToolBarWithItems:@[item]]; | ||
| 237 | + _myEditToolBar.delegate = self; | ||
| 238 | + [self.view addSubview:_myEditToolBar]; | ||
| 239 | + [_myEditToolBar mas_makeConstraints:^(MASConstraintMaker *make) { | ||
| 240 | + make.bottom.equalTo(self.view.mas_bottom); | ||
| 241 | + make.size.mas_equalTo(_myEditToolBar.frame.size); | ||
| 242 | + }]; | ||
| 243 | + } | ||
| 244 | + _myEditToolBar.hidden = !_myTableView.isEditing; | ||
| 245 | + UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0,_myTableView.isEditing? CGRectGetHeight(_myEditToolBar.frame): 0.0, 0.0); | ||
| 246 | + self.myTableView.contentInset = contentInsets; | ||
| 247 | + self.myTableView.scrollIndicatorInsets = contentInsets; | ||
| 248 | + } | ||
| 249 | + #pragma mark EaseToolBarDelegate | ||
| 250 | + - (void)easeToolBar:(EaseToolBar *)toolBar didClickedIndex:(NSInteger)index{ | ||
| 251 | + NSArray *selectedIndexPath = [_myTableView indexPathsForSelectedRows]; | ||
| 252 | + if (selectedIndexPath.count <= 0) { | ||
| 253 | + return; | ||
| 254 | + } | ||
| 255 | + if (toolBar == _myEditToolBar) { | ||
| 256 | + if (index == 0) { | ||
| 257 | + __weak typeof(self) weakSelf = self; | ||
| 258 | + UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定要删除选中文件夹内所有本地文件吗?" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { | ||
| 259 | + if (index == 0) { | ||
| 260 | + [weakSelf deleteSelectedFolders]; | ||
| 261 | + } | ||
| 262 | + }]; | ||
| 263 | + [actionSheet showInView:self.view]; | ||
| 264 | + } | ||
| 265 | + } | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + - (void)deleteSelectedFolders{ | ||
| 269 | + NSArray *selectedIndexPath = [_myTableView indexPathsForSelectedRows]; | ||
| 270 | + NSMutableArray *selectedFolders = [[NSMutableArray alloc] initWithCapacity:selectedIndexPath.count]; | ||
| 271 | + for (NSIndexPath *indexPath in selectedIndexPath) { | ||
| 272 | + NSString *projectId = _projectId_list[indexPath.row]; | ||
| 273 | + if (projectId.length > 0) { | ||
| 274 | + [selectedFolders addObject:projectId]; | ||
| 275 | + } | ||
| 276 | + } | ||
| 277 | + [self deleteFilesWithProjectIdList:selectedFolders]; | ||
| 278 | + } | ||
| 279 | + | ||
| 182 | 280 | #pragma mark Delete | |
| 183 | 281 | - (void)deleteFilesWithProjectIdList:(NSArray *)projectIdList{ | |
| 184 | 282 | NSMutableArray *urlList = [NSMutableArray new]; | |
@@ -209,6 +307,7 @@ - (void)deleteFilesWithUrlList:(NSArray *)urlList{ | |||
| 209 | 307 | dispatch_async(dispatch_get_main_queue(), ^{ | |
| 210 | 308 | @strongify(self); | |
| 211 | 309 | [self findLocalFile]; | |
| 310 | + [self changeEditStateToEditing:NO]; | ||
| 212 | 311 | [NSObject showHudTipStr:@"本地文件删除成功"]; | |
| 213 | 312 | }); | |
| 214 | 313 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus | |||
| 25 | 25 | CGFloat icon_width = 45.0; | |
| 26 | 26 | if (!_iconView) { | |
| 27 | 27 | _iconView = [UIImageView new]; | |
| 28 | + _iconView.contentMode = UIViewContentModeScaleAspectFill; | ||
| 28 | 29 | _iconView.layer.masksToBounds = YES; | |
| 29 | 30 | _iconView.layer.cornerRadius = 2.0; | |
| 30 | 31 | _iconView.layer.borderWidth = 0.5; | |
@@ -72,7 +73,7 @@ - (void)setFileUrl:(NSURL *)fileUrl{ | |||
| 72 | 73 | } | |
| 73 | 74 | if (image) { | |
| 74 | 75 | CGFloat icon_width = 2 * 45.0; | |
| 75 | - image = [image scaleToSize:CGSizeMake(icon_width, icon_width) usingMode:NYXResizeModeScaleToFill]; | ||
| 76 | + image = [image scaleToSize:CGSizeMake(icon_width, icon_width) usingMode:NYXResizeModeAspectFill]; | ||
| 76 | 77 | }else{ | |
| 77 | 78 | image = [UIImage imageWithFileType:fileType]; | |
| 78 | 79 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments