|
10 | 10 | #import "Projects.h" |
11 | 11 | #import "UIImageView+WebCache.h" |
12 | 12 | #import "Coding_NetAPIManager.h" |
| 13 | +#import "MBProgressHUD+Add.h" |
| 14 | +#import "JDStatusBarNotification.h" |
13 | 15 |
|
14 | 16 | @interface ProjectSettingViewController ()<UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> |
15 | 17 |
|
16 | 18 | @property (nonatomic, strong) UIBarButtonItem *submitButtonItem; |
17 | 19 | @property (nonatomic, strong) UIImage *projectIconImage; |
| 20 | +@property (nonatomic, strong) MBProgressHUD *uploadHUD; |
18 | 21 |
|
19 | 22 | @end |
20 | 23 |
|
@@ -44,6 +47,10 @@ - (void)viewDidLoad { |
44 | 47 | self.submitButtonItem.enabled = NO; |
45 | 48 | self.navigationItem.rightBarButtonItem = self.submitButtonItem; |
46 | 49 |
|
| 50 | + //HUD |
| 51 | + self.uploadHUD = [[MBProgressHUD alloc] initWithView:self.view]; |
| 52 | + self.uploadHUD.mode = MBProgressHUDModeDeterminate; |
| 53 | + [self.view addSubview:self.uploadHUD]; |
47 | 54 | } |
48 | 55 |
|
49 | 56 | -(void)submit{ |
@@ -75,19 +82,41 @@ -(void)selectProjectImage{ |
75 | 82 | }else{ |
76 | 83 | avatarPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; |
77 | 84 | } |
| 85 | + avatarPicker.allowsEditing = YES; |
78 | 86 | [self presentViewController:avatarPicker animated:YES completion:nil]; |
79 | 87 | }] showInView:self.view]; |
80 | 88 | } |
81 | 89 |
|
82 | 90 | -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ |
83 | | - UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; |
| 91 | + UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; |
| 92 | + |
| 93 | + [self.view endEditing:YES]; |
84 | 94 |
|
85 | 95 | if (image) { |
86 | | - self.projectImageView.image = image; |
87 | | - self.projectIconImage = image; |
| 96 | + |
| 97 | + self.uploadHUD.progress = 0; |
| 98 | + [self.uploadHUD show:YES]; |
| 99 | + [[Coding_NetAPIManager sharedManager] request_UpdateProject_WithObj:self.project icon:image andBlock:^(id data, NSError *error) { |
| 100 | + if (data) { |
| 101 | + NSDictionary *dataDic = data[@"data"]; |
| 102 | + if (dataDic) { |
| 103 | + self.project.icon = dataDic[@"icon"]; |
| 104 | + [[[SDWebImageManager sharedManager] imageCache] storeImage:image forKey:self.project.icon]; |
| 105 | + } |
| 106 | + // |
| 107 | + self.projectImageView.image = image; |
| 108 | + self.projectIconImage = image; |
| 109 | + } |
| 110 | + [self.uploadHUD hide:YES]; |
| 111 | + } progerssBlock:^(CGFloat progressValue) { |
| 112 | + self.uploadHUD.progress = progressValue; |
| 113 | + }]; |
88 | 114 | } |
89 | 115 |
|
90 | | - [picker dismissViewControllerAnimated:YES completion:nil]; |
| 116 | + [picker dismissViewControllerAnimated:YES completion:^{ |
| 117 | + [JDStatusBarNotification showWithStatus:@"正在上传项目图标" styleName:JDStatusBarStyleSuccess]; |
| 118 | + [JDStatusBarNotification showActivityIndicator:YES indicatorStyle:UIActivityIndicatorViewStyleWhite]; |
| 119 | + }]; |
91 | 120 | } |
92 | 121 |
|
93 | 122 | -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ |
|
0 commit comments