|
|
@@ -31,8 +31,44 @@
|
|
|
context:@"arr_queue changed"];
|
|
|
|
|
|
self.title = @"Upload List";
|
|
|
+ UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithTitle:@"Clear" style:UIBarButtonItemStylePlain target:self action:@selector(clearList)];
|
|
|
+ self.navigationItem.rightBarButtonItem = uploadListItem;
|
|
|
+
|
|
|
+
|
|
|
self.uploadTable.tableFooterView = [UIView new];
|
|
|
// appdelegate.uploadManager.delegate = self;
|
|
|
+}
|
|
|
+- (void)clearList {
|
|
|
+ AppDelegate* appdelegate = (AppDelegate* )[UIApplication sharedApplication].delegate;
|
|
|
+
|
|
|
+ if(appdelegate.uploadManager.arr_queue.count==0)
|
|
|
+ {
|
|
|
+ [RAUtils alert_view:nil title:@"Upload list is empty."];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:
|
|
|
+ @"Clear upload list" message:@"Are you sure remove all error/finish task?" preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+
|
|
|
+
|
|
|
+ UIAlertAction *OK = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ NSMutableArray* arr_tasks =[NSMutableArray new];
|
|
|
+ for(NSMutableDictionary* task in appdelegate.uploadManager.arr_queue)
|
|
|
+ {
|
|
|
+ if([task[@"status"] intValue]==TaskStatusFinish||[task[@"status"] intValue]==TaskStatusError)
|
|
|
+ [arr_tasks addObject:task];
|
|
|
+ }
|
|
|
+ [appdelegate.uploadManager removeTasks:arr_tasks];
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alert addAction:OK];
|
|
|
+
|
|
|
+ UIAlertAction *CANCEL = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ }];
|
|
|
+ [alert addAction:CANCEL];
|
|
|
+
|
|
|
+ [self presentViewController:alert animated:YES completion:nil];
|
|
|
+
|
|
|
}
|
|
|
-(void) dealloc
|
|
|
{
|
|
|
@@ -156,6 +192,103 @@
|
|
|
|
|
|
#pragma mark - TableView Delegate
|
|
|
|
|
|
+- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+ AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
|
|
|
+ NSMutableDictionary * task = Appdelegate.uploadManager.arr_queue[indexPath.row];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ UITableViewRowAction *startAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Restart"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
|
|
|
+
|
|
|
+ DebugLog(@"Start click");
|
|
|
+ task[@"retry"]=[NSNumber numberWithInt:0];
|
|
|
+ [Appdelegate.uploadManager startTask:task];
|
|
|
+
|
|
|
+ [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+ startAction.backgroundColor = UIColorFromRGB(0xff9933);
|
|
|
+
|
|
|
+
|
|
|
+ UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
|
|
|
+
|
|
|
+
|
|
|
+ [Appdelegate.uploadManager removeTask:task];
|
|
|
+
|
|
|
+ // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ removeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // UIColorFromRGB(0x336699);
|
|
|
+
|
|
|
+
|
|
|
+ // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
|
|
+
|
|
|
+ switch ([task[@"status"] intValue]) {
|
|
|
+
|
|
|
+ case TaskStatusFinish:
|
|
|
+ return @[removeAction];
|
|
|
+
|
|
|
+ case TaskStatusError:
|
|
|
+
|
|
|
+ return @[startAction,removeAction];
|
|
|
+
|
|
|
+ case TaskStatusStop:
|
|
|
+ return @[startAction];
|
|
|
+ default:
|
|
|
+ return nil;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
|
|
|
+ NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
|
|
|
+
|
|
|
+ bool ret=false;
|
|
|
+ switch ([item_json[@"status"] intValue]) {
|
|
|
+ case TaskStatusStart:
|
|
|
+ case TaskStatusWait:
|
|
|
+
|
|
|
+ ret=false;
|
|
|
+ break;
|
|
|
+ case TaskStatusFinish:
|
|
|
+ case TaskStatusStop:
|
|
|
+ case TaskStatusError:
|
|
|
+
|
|
|
+ ret = true;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ ret=false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+- (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ return UITableViewCellEditingStyleDelete;
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
// UploadCell *upCell = (UploadCell *)cell;
|
|
|
// upCell.name = @"QS-WPS00889-OPQ-WQER";
|
|
|
@@ -172,12 +305,12 @@
|
|
|
// upCell.progress = 0;
|
|
|
// upCell.state = nil;
|
|
|
//}
|
|
|
-
|
|
|
+/*
|
|
|
#pragma mark - UploadManager Delegate
|
|
|
|
|
|
- (void)uploadManager:(RAUploadManager *)manager didRemoveTasks:(NSArray *)tasks {
|
|
|
// 修复finish后滑动Table导致数组越界崩溃。
|
|
|
[self.uploadTable reloadData];
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
@end
|