|
@@ -7,7 +7,7 @@
|
|
|
//
|
|
|
|
|
|
#import "TasksViewController.h"
|
|
|
-
|
|
|
+#import "ImageHandler.h"
|
|
|
@interface TasksViewController ()
|
|
|
@property NSUserDefaults *userDefaults;
|
|
|
@property UIRefreshControl *uirefresh;
|
|
@@ -21,6 +21,7 @@
|
|
|
// Do any additional setup after loading the view.
|
|
|
_TaskTableView.delegate = self;
|
|
|
_TaskTableView.dataSource = self;
|
|
|
+// _TaskTableView sets
|
|
|
_uirefresh = [[UIRefreshControl alloc]init];
|
|
|
_uirefresh.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"PullToRefresh", nil)];
|
|
|
[_TaskTableView addSubview:_uirefresh];
|
|
@@ -38,6 +39,10 @@
|
|
|
-(void)viewDidAppear:(BOOL)animated{
|
|
|
[self pullToRefresh];
|
|
|
}
|
|
|
+-(void)updateSourceData{
|
|
|
+ [_userDefaults setObject:_TaskData forKey:@"tasks"];
|
|
|
+ [_userDefaults synchronize];
|
|
|
+}
|
|
|
|
|
|
#pragma Table Refresh
|
|
|
-(void)pullToRefresh{
|
|
@@ -63,7 +68,28 @@
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
UITableViewCell *cell = [_TaskTableView dequeueReusableCellWithIdentifier:@"TaskCellStyle"];
|
|
|
// cell.textLabel.
|
|
|
- cell.textLabel.text = _TaskData[indexPath.row];
|
|
|
+ NSMutableDictionary *tumblrData = [NSMutableDictionary dictionaryWithDictionary:_TaskData[indexPath.row]];
|
|
|
+ NSLog(@"%@",[tumblrData objectForKey:@"imgURL"]);
|
|
|
+ NSString *newPath = [ImageHandler getAndSaveThumbImageFromURLandSetToImageView:[tumblrData objectForKey:@"imgURL"] saveToName:[tumblrData objectForKey:@"videoID"] setToImage:cell.imageView];
|
|
|
+// NSLog(@"%@",newPath);
|
|
|
+// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+// NSLog(@"%@",[tumblrData objectForKey:@"imgURL"]);
|
|
|
+// UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tumblrData objectForKey:@"imgURL"]]] scale:1];
|
|
|
+// UIGraphicsBeginImageContext(CGSizeMake(80, 80));
|
|
|
+// [img drawInRect:CGRectMake(0, 0, 80, 80)];
|
|
|
+// UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
+// UIGraphicsEndImageContext();
|
|
|
+// [cell.imageView setImage:newImg];
|
|
|
+// NSString *jpgPath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/thumb/%@.jpg",[tumblrData objectForKey:@"videoID"]]];
|
|
|
+// NSLog(@"%@",jpgPath);
|
|
|
+// [UIImageJPEGRepresentation(newImg, 1.0) writeToFile:jpgPath atomically:YES];
|
|
|
+//// [cell.imageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tumblrData objectForKey:@"imgURL"]]]]];
|
|
|
+// });
|
|
|
+
|
|
|
+ cell.textLabel.text = [tumblrData objectForKey:@"videoID"];
|
|
|
+ [tumblrData setObject:newPath forKey:@"cachePath"];
|
|
|
+ _TaskData[indexPath.row] = tumblrData;
|
|
|
+ [self updateSourceData];
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
@@ -74,5 +100,75 @@
|
|
|
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
|
|
|
return 1;
|
|
|
}
|
|
|
+-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+// /UITableViewRowActionStyle *style =
|
|
|
+ UITableViewRowAction *downloadAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Download" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
|
|
|
+
|
|
|
+ }];
|
|
|
+ downloadAction.backgroundColor = [UIColor colorWithRed:166/255.0 green:226/255.0 blue:105/255.0 alpha:1];
|
|
|
+ UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
|
|
|
+
|
|
|
+ }];
|
|
|
+ return @[deleteAction,downloadAction];
|
|
|
+}
|
|
|
+-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
|
|
|
+}
|
|
|
+-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ [[_TaskTableView cellForRowAtIndexPath:indexPath] setTintColor:[UIColor redColor]];
|
|
|
+}
|
|
|
+-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ return 80;
|
|
|
+}
|
|
|
|
|
|
+#pragma Action
|
|
|
+- (IBAction)EditTaskList:(id)sender {
|
|
|
+ if([sender tag]==1){
|
|
|
+ [_TaskTableView setEditing:NO];
|
|
|
+ [sender setTitle:@"编辑"];
|
|
|
+ [_AllEditBtn setTitle:@"全部开始"];
|
|
|
+ [sender setTag:0];
|
|
|
+ [_AllEditBtn setTag:1];
|
|
|
+ }else{
|
|
|
+ [_TaskTableView setEditing:YES];
|
|
|
+ [sender setTitle:@"完成"];
|
|
|
+ [_AllEditBtn setTitle:@"删除"];
|
|
|
+ [sender setTag:1];
|
|
|
+ [_AllEditBtn setTag:2];
|
|
|
+ }
|
|
|
+}
|
|
|
+- (IBAction)EditAll:(id)sender {
|
|
|
+ if([sender tag]==2){
|
|
|
+ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"是否删除所有已选任务" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
|
|
+ [alert show];
|
|
|
+ }else{
|
|
|
+ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"所有任务加入下载队列" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
|
|
+ [alert show];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma UIAlertView Delegate
|
|
|
+-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
|
|
+ if([_AllEditBtn tag]==2){
|
|
|
+ if(buttonIndex==1){
|
|
|
+// NSArray *selectedIndexPaths =
|
|
|
+ [self deleteSelected:[_TaskTableView indexPathsForSelectedRows]];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+-(void)startAll{
|
|
|
+
|
|
|
+}
|
|
|
+-(void)deleteSelected:(NSArray *)indexPathsArray{
|
|
|
+ NSMutableIndexSet *indexSets = [[NSMutableIndexSet alloc]init];
|
|
|
+ [indexPathsArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+ NSIndexPath *index = (NSIndexPath *)obj;
|
|
|
+ [indexSets addIndex:index.row];
|
|
|
+ }];
|
|
|
+ [_TaskData removeObjectsAtIndexes:indexSets];
|
|
|
+ [self updateSourceData];
|
|
|
+ [self reloadCellData];
|
|
|
+}
|
|
|
@end
|