1212#import " Coding_NetAPIManager.h"
1313#import " LocalFolderCell.h"
1414#import " LocalFilesViewController.h"
15+ #import " EaseToolBar.h"
1516
16- @interface LocalFoldersViewController ()<UITableViewDataSource, UITableViewDelegate>
17+ @interface LocalFoldersViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate, EaseToolBarDelegate >
1718@property (assign , nonatomic ) BOOL isLoading;
1819@property (strong , nonatomic ) UITableView *myTableView;
1920@property (strong , nonatomic ) ODRefreshControl *myRefreshControl;
2021
22+ @property (nonatomic , strong ) EaseToolBar *myEditToolBar;
23+
2124@property (strong , nonatomic ) NSMutableArray *projectId_list;
2225@property (strong , nonatomic ) NSMutableDictionary *projectList_dict;
2326@end
@@ -40,6 +43,7 @@ - (void)viewDidLoad{
4043 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
4144 make.edges .equalTo (self.view );
4245 }];
46+ tableView.allowsMultipleSelectionDuringEditing = YES ;
4347 tableView;
4448 });
4549 _myRefreshControl = [[ODRefreshControl alloc ] initInScrollView: self .myTableView];
@@ -48,6 +52,7 @@ - (void)viewDidLoad{
4852
4953- (void )viewWillAppear : (BOOL )animated {
5054 [super viewWillAppear: animated];
55+ [self changeEditStateToEditing: NO ];
5156 [self refresh ];
5257}
5358
@@ -144,16 +149,20 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
144149}
145150
146151- (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+ }
157166}
158167
159168#pragma mark SWTableViewCellDelegate
@@ -179,6 +188,95 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut
179188 [actionSheet showInView: self .view];
180189}
181190
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+
182280#pragma mark Delete
183281- (void )deleteFilesWithProjectIdList : (NSArray *)projectIdList {
184282 NSMutableArray *urlList = [NSMutableArray new ];
@@ -209,6 +307,7 @@ - (void)deleteFilesWithUrlList:(NSArray *)urlList{
209307 dispatch_async (dispatch_get_main_queue (), ^{
210308 @strongify (self);
211309 [self findLocalFile ];
310+ [self changeEditStateToEditing: NO ];
212311 [NSObject showHudTipStr: @" 本地文件删除成功" ];
213312 });
214313 });
0 commit comments