@@ -44,6 +44,10 @@ - (void)viewDidLoad{
4444 });
4545 _myRefreshControl = [[ODRefreshControl alloc ] initInScrollView: self .myTableView];
4646 [_myRefreshControl addTarget: self action: @selector (refresh ) forControlEvents: UIControlEventValueChanged];
47+ }
48+
49+ - (void )viewWillAppear : (BOOL )animated {
50+ [super viewWillAppear: animated];
4751 [self refresh ];
4852}
4953
@@ -100,9 +104,9 @@ - (BOOL)findLocalFile{
100104 [pro_dict[@" list" ] addObject: fileUrl];
101105 }
102106 }
103- return YES ;
104107 }
105- return NO ;
108+ [self .myTableView reloadData ];
109+ return localFileUrlList.count > 0 ;
106110}
107111
108112- (void )refreshProjectNameWithProjects : (Projects *)projects {
@@ -130,7 +134,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
130134 NSDictionary *pro_dict = _projectList_dict[key];
131135
132136 [cell setProjectName: pro_dict[@" name" ] fileCount: [(NSArray *)pro_dict[@" list" ] count ]];
133-
137+ cell. delegate = self;
134138 [tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: kPaddingLeftWidth ];
135139 return cell;
136140}
@@ -151,4 +155,62 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
151155
152156 [self .navigationController pushViewController: vc animated: YES ];
153157}
158+
159+ #pragma mark SWTableViewCellDelegate
160+ - (BOOL )swipeableTableViewCellShouldHideUtilityButtonsOnSwipe : (SWTableViewCell *)cell {
161+ return YES ;
162+ }
163+ - (BOOL )swipeableTableViewCell : (SWTableViewCell *)cell canSwipeToState : (SWCellState)state {
164+ return YES ;
165+ }
166+
167+ - (void )swipeableTableViewCell : (SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex : (NSInteger )index {
168+ [cell hideUtilityButtonsAnimated: YES ];
169+
170+ NSIndexPath *indexPath = [self .myTableView indexPathForCell: cell];
171+ NSString *projectId = _projectId_list[indexPath.row];
172+
173+ __weak typeof (self) weakSelf = self;
174+ UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle: @" 确定要删除该文件夹内所有本地文件吗?" buttonTitles: nil destructiveTitle: @" 确认删除" cancelTitle: @" 取消" andDidDismissBlock: ^(UIActionSheet *sheet, NSInteger index) {
175+ if (index == 0 ) {
176+ [weakSelf deleteFilesWithProjectIdList: @[projectId]];
177+ }
178+ }];
179+ [actionSheet showInView: self .view];
180+ }
181+
182+ #pragma mark Delete
183+ - (void )deleteFilesWithProjectIdList : (NSArray *)projectIdList {
184+ NSMutableArray *urlList = [NSMutableArray new ];
185+ for (NSString *key in projectIdList) {
186+ NSDictionary *pro_dict = _projectList_dict[key];
187+ NSArray *curList = pro_dict[@" list" ];
188+ if (curList.count > 0 ) {
189+ [urlList addObjectsFromArray: curList];
190+ }
191+ }
192+ [self deleteFilesWithUrlList: urlList];
193+ }
194+
195+ - (void )deleteFilesWithUrlList : (NSArray *)urlList {
196+ @weakify (self);
197+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
198+ NSFileManager *fm = [NSFileManager defaultManager ];
199+ for (NSURL *fileUrl in urlList) {
200+ NSString *filePath = fileUrl.path ;
201+ if ([fm fileExistsAtPath: filePath]) {
202+ NSError *fileError;
203+ [fm removeItemAtPath: filePath error: &fileError];
204+ if (fileError) {
205+ [NSObject showError: fileError];
206+ }
207+ }
208+ }
209+ dispatch_async (dispatch_get_main_queue (), ^{
210+ @strongify (self);
211+ [self findLocalFile ];
212+ [NSObject showHudTipStr: @" 本地文件删除成功" ];
213+ });
214+ });
215+ }
154216@end
0 commit comments