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
});
0 commit comments