Skip to content

Commit aead111

Browse files
committed
修复完善 <项目设置> - 修改图标
1 parent 383fafd commit aead111

7 files changed

Lines changed: 70 additions & 5 deletions

File tree

Coding_iOS/Controllers/NProjectViewController/NProjectViewController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ @interface NProjectViewController ()<UITableViewDataSource, UITableViewDelegate>
3434
@end
3535

3636
@implementation NProjectViewController
37+
38+
-(void)viewWillAppear:(BOOL)animated{
39+
[super viewWillAppear:animated];
40+
41+
[self.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
42+
}
43+
3744
- (void)viewDidLoad{
3845
[super viewDidLoad];
3946

Coding_iOS/Controllers/ProjectSetting/ProjectSettingViewController.m

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
#import "Projects.h"
1111
#import "UIImageView+WebCache.h"
1212
#import "Coding_NetAPIManager.h"
13+
#import "MBProgressHUD+Add.h"
14+
#import "JDStatusBarNotification.h"
1315

1416
@interface ProjectSettingViewController ()<UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
1517

1618
@property (nonatomic, strong) UIBarButtonItem *submitButtonItem;
1719
@property (nonatomic, strong) UIImage *projectIconImage;
20+
@property (nonatomic, strong) MBProgressHUD *uploadHUD;
1821

1922
@end
2023

@@ -44,6 +47,10 @@ - (void)viewDidLoad {
4447
self.submitButtonItem.enabled = NO;
4548
self.navigationItem.rightBarButtonItem = self.submitButtonItem;
4649

50+
//HUD
51+
self.uploadHUD = [[MBProgressHUD alloc] initWithView:self.view];
52+
self.uploadHUD.mode = MBProgressHUDModeDeterminate;
53+
[self.view addSubview:self.uploadHUD];
4754
}
4855

4956
-(void)submit{
@@ -75,19 +82,41 @@ -(void)selectProjectImage{
7582
}else{
7683
avatarPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
7784
}
85+
avatarPicker.allowsEditing = YES;
7886
[self presentViewController:avatarPicker animated:YES completion:nil];
7987
}] showInView:self.view];
8088
}
8189

8290
-(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];
8494

8595
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+
}];
88114
}
89115

90-
[picker dismissViewControllerAnimated:YES completion:nil];
116+
[picker dismissViewControllerAnimated:YES completion:^{
117+
[JDStatusBarNotification showWithStatus:@"正在上传项目图标" styleName:JDStatusBarStyleSuccess];
118+
[JDStatusBarNotification showActivityIndicator:YES indicatorStyle:UIActivityIndicatorViewStyleWhite];
119+
}];
91120
}
92121

93122
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

Coding_iOS/Models/Projects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ typedef NS_ENUM(NSInteger, ProjectsType)
6666
- (NSString *)toUpdatePath;
6767
- (NSDictionary *)toUpdateParams;
6868

69+
- (NSString *)toUpdateIconPath;
70+
6971
- (NSString *)toDeletePath;
7072
- (NSDictionary *)toDeleteParamsWithPassword:(NSString *)password;
7173

Coding_iOS/Models/Projects.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ -(NSDictionary *)toUpdateParams{
157157
};
158158
}
159159

160+
-(NSString *)toUpdateIconPath{
161+
return [NSString stringWithFormat:@"api/project/%@/project_icon",self.id];
162+
}
163+
160164
-(NSString *)toDeletePath{
161165
return [NSString stringWithFormat:@"api/project/%@",self.id];
162166
}

Coding_iOS/Util/Manager/CodingNetAPIClient.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ -(void)requestJsonDataWithPath:(NSString *)aPath file:(NSDictionary *)file withP
129129
UIImage *image = file[@"image"];
130130

131131
// 缩小到最大 800x800
132-
image = [image scaledToMaxSize:CGSizeMake(799, 799)];
132+
// image = [image scaledToMaxSize:CGSizeMake(500, 500)];
133133

134134
// 压缩
135135
data = UIImageJPEGRepresentation(image, 1.0);

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
- (void)request_NewProject_WithObj:(Project *)project image:(UIImage *)image andBlock:(void (^)(Project *data, NSError *error))block;
5353
- (void)request_UpdateProject_WithObj:(Project *)project andBlock:(void (^)(Project *data, NSError *error))block;
54+
- (void)request_UpdateProject_WithObj:(Project *)project icon:(UIImage *)icon andBlock:(void (^)(id data, NSError *error))block progerssBlock:(void (^)(CGFloat progressValue))progress;;
5455
- (void)request_DeleteProject_WithObj:(Project *)project password:(NSString *)password andBlock:(void (^)(Project *data, NSError *error))block;
5556

5657
//File

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,28 @@ -(void)request_UpdateProject_WithObj:(Project *)project andBlock:(void (^)(Proje
278278
}];
279279
}
280280

281+
-(void)request_UpdateProject_WithObj:(Project *)project icon:(UIImage *)icon andBlock:(void (^)(id, NSError *))block progerssBlock:(void (^)(CGFloat))progress{
282+
[MobClick event:kUmeng_Event_Request label:@"更新项目图标"];
283+
// [self showStatusBarQueryStr:@"正在上传项目图标"];
284+
285+
// 缩小到最大 500x500
286+
// icon = [icon scaledToMaxSize:CGSizeMake(500, 500)];
287+
288+
[[CodingNetAPIClient sharedJsonClient] uploadImage:icon path:[project toUpdateIconPath] name:@"file" successBlock:^(AFHTTPRequestOperation *operation, id responseObject) {
289+
id error = [self handleResponse:responseObject];
290+
if (error) {
291+
block(nil, error);
292+
}else{
293+
block(responseObject, nil);
294+
[self showStatusBarSuccessStr:@"更新项目图标成功"];
295+
}
296+
[self hideStatusBarProgress];
297+
} failureBlock:^(AFHTTPRequestOperation *operation, NSError *error) {
298+
block(nil, error);
299+
[self showStatusBarError:error];
300+
} progerssBlock:progress];
301+
}
302+
281303
-(void)request_DeleteProject_WithObj:(Project *)project password:(NSString *)password andBlock:(void (^)(Project *, NSError *))block{
282304
[MobClick event:kUmeng_Event_Request label:@"删除项目"];
283305
[self showStatusBarQueryStr:@"正在删除项目"];

0 commit comments

Comments
 (0)