Skip to content

Commit 2ef32de

Browse files
committed
代码优化
1 parent 3e93468 commit 2ef32de

24 files changed

Lines changed: 180 additions & 229 deletions

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
4EACB4431A2C45300097ABB3 /* button_file_download_enable.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EACB4421A2C45300097ABB3 /* button_file_download_enable.png */; };
133133
4EACB4461A2C60110097ABB3 /* ProjectActivities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EACB4451A2C60110097ABB3 /* ProjectActivities.m */; };
134134
4EBD0C661A1F2011004B4284 /* nav_project_file@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EBD0C651A1F2011004B4284 /* nav_project_file@2x.png */; };
135+
4EBDA87C1A6640340035ED96 /* UIActionSheet+Common.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBDA87B1A6640340035ED96 /* UIActionSheet+Common.m */; };
135136
4EC5AD921A258DF8006FA97C /* icon_file_cell_delete@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD8F1A258DF8006FA97C /* icon_file_cell_delete@2x.png */; };
136137
4EC5AD931A258DF8006FA97C /* icon_file_cell_move@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD901A258DF8006FA97C /* icon_file_cell_move@2x.png */; };
137138
4EC5AD941A258DF8006FA97C /* icon_file_cell_rename@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EC5AD911A258DF8006FA97C /* icon_file_cell_rename@2x.png */; };
@@ -711,6 +712,8 @@
711712
4EACB4441A2C60110097ABB3 /* ProjectActivities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectActivities.h; sourceTree = "<group>"; };
712713
4EACB4451A2C60110097ABB3 /* ProjectActivities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectActivities.m; sourceTree = "<group>"; };
713714
4EBD0C651A1F2011004B4284 /* nav_project_file@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "nav_project_file@2x.png"; sourceTree = "<group>"; };
715+
4EBDA87A1A6640340035ED96 /* UIActionSheet+Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIActionSheet+Common.h"; sourceTree = "<group>"; };
716+
4EBDA87B1A6640340035ED96 /* UIActionSheet+Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIActionSheet+Common.m"; sourceTree = "<group>"; };
714717
4EC5AD8F1A258DF8006FA97C /* icon_file_cell_delete@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_file_cell_delete@2x.png"; sourceTree = "<group>"; };
715718
4EC5AD901A258DF8006FA97C /* icon_file_cell_move@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_file_cell_move@2x.png"; sourceTree = "<group>"; };
716719
4EC5AD911A258DF8006FA97C /* icon_file_cell_rename@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_file_cell_rename@2x.png"; sourceTree = "<group>"; };
@@ -1635,6 +1638,8 @@
16351638
4ECE8AD41A3943E80021E29C /* UIView+Common.m */,
16361639
4ECE8AD51A3943E80021E29C /* UIViewController+Swizzle.h */,
16371640
4ECE8AD61A3943E80021E29C /* UIViewController+Swizzle.m */,
1641+
4EBDA87A1A6640340035ED96 /* UIActionSheet+Common.h */,
1642+
4EBDA87B1A6640340035ED96 /* UIActionSheet+Common.m */,
16381643
);
16391644
path = OC_Category;
16401645
sourceTree = "<group>";
@@ -2984,6 +2989,7 @@
29842989
8E59F0EE1A00F34E009A905F /* ProjectCodeListView.m in Sources */,
29852990
4ECE8B041A3946C10021E29C /* UnReadManager.m in Sources */,
29862991
4EA679131A1466A6001A0324 /* ProjectFiles.m in Sources */,
2992+
4EBDA87C1A6640340035ED96 /* UIActionSheet+Common.m in Sources */,
29872993
4E96E7BB1A1B25D40037C098 /* DirectoryWatcher.m in Sources */,
29882994
4E6BA2E41A1EE6AF005FD721 /* UIButton+AFNetworking.m in Sources */,
29892995
8EF643C919FF7E2900F7EEB0 /* TopicCommentCell.m in Sources */,

Coding_iOS/Coding_iOS-Prefix.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "UILabel+Common.h"
3030
#import "NSDate+Common.h"
3131
#import "UIBarButtonItem+Common.h"
32+
#import "UIActionSheet+Common.h"
3233
#import "UITTTAttributedLabel.h"
3334
#import "NSObject+ObjectMap.h"
3435
#import "ImageSizeManager.h"

Coding_iOS/Controllers/ConversationViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#import "QBImagePickerController.h"
1212
#import "UIMessageInputView.h"
1313

14-
@interface ConversationViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UITextViewDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, QBImagePickerControllerDelegate, UIMessageInputViewDelegate>
14+
@interface ConversationViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, QBImagePickerControllerDelegate, UIMessageInputViewDelegate>
1515
@property (strong, nonatomic) PrivateMessages *myPriMsgs;
1616
@end

Coding_iOS/Controllers/ConversationViewController.m

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2014年 Coding. All rights reserved.
77
//
88

9-
#define kTagActionResendMessage 1005
10-
#define kTagActionDeleteMessage 1006
119
#define kCellIdentifier_Message @"MessageCell"
1210
#define kCellIdentifier_MessageMedia @"MessageMediaCell"
1311

@@ -198,8 +196,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
198196
ESStrongSelf;
199197
_self.messageToResendOrDelete = curMessage;
200198
[_self.myMsgInputView isAndResignFirstResponder];
201-
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"重新发送" delegate:_self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"发送", nil];
202-
actionSheet.tag = kTagActionResendMessage;
199+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"重新发送" buttonTitles:@[@"发送"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
200+
if (index == 0 && _self.messageToResendOrDelete) {
201+
[_self sendPrivateMessageWithMsg:_messageToResendOrDelete];
202+
203+
}
204+
}];
203205
[actionSheet showInView:kKeyWindow];
204206
};
205207
cell.refreshMessageMediaCCellBlock = ^(CGFloat diff){
@@ -245,8 +247,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
245247
- (void)showAlertToDeleteMessage:(PrivateMessage *)toDeleteMsg{
246248
self.messageToResendOrDelete = toDeleteMsg;
247249
[self.myMsgInputView isAndResignFirstResponder];
248-
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"删除后将不会出现在你的私信记录中" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认删除" otherButtonTitles:nil];
249-
actionSheet.tag = kTagActionDeleteMessage;
250+
ESWeakSelf
251+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"删除后将不会出现在你的私信记录中" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
252+
ESStrongSelf
253+
if (index == 0 && _self.messageToResendOrDelete) {
254+
[_self deletePrivateMessageWithMsg:_messageToResendOrDelete];
255+
}
256+
}];
250257
[actionSheet showInView:kKeyWindow];
251258
}
252259

@@ -375,22 +382,6 @@ - (void)inputViewAddIndex:(NSInteger)index{
375382
break;
376383
}
377384
}
378-
#pragma mark UIActionSheetDelegate M
379-
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
380-
if (actionSheet.tag == kTagActionResendMessage){
381-
if (buttonIndex == 0) {
382-
if (_messageToResendOrDelete) {
383-
[self sendPrivateMessageWithMsg:_messageToResendOrDelete];
384-
}
385-
}
386-
}else if (actionSheet.tag == kTagActionDeleteMessage){
387-
if (buttonIndex == 0) {
388-
if (_messageToResendOrDelete) {
389-
[self deletePrivateMessageWithMsg:_messageToResendOrDelete];
390-
}
391-
}
392-
}
393-
}
394385

395386
#pragma mark UIImagePickerControllerDelegate
396387
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

Coding_iOS/Controllers/EditTaskViewController.m

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
326326
}else{
327327
cell.deleteBtnClickedBlock = ^(Task *toDelete){
328328
[weakSelf.view endEditing:YES];
329-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"删除此任务"];
330-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
331-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
332-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
333-
switch (index) {
334-
case 0:
335-
[weakSelf deleteTask:toDelete];
336-
break;
337-
default:
338-
break;
329+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"删除此任务" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
330+
if (index == 0) {
331+
[weakSelf deleteTask:toDelete];
339332
}
340333
}];
341334
[actionSheet showInView:kKeyWindow];
@@ -515,16 +508,9 @@ - (void)doCommentToComment:(TaskComment *)toComment sender:(id)sender{
515508
_myMsgInputView.placeHolder = [NSString stringWithFormat:@"回复 %@:", _toComment.owner.name];
516509
if (_toComment.owner_id.intValue == [Login curLoginUser].id.intValue) {
517510
__weak typeof(self) weakSelf = self;
518-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"删除此评论"];
519-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
520-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
521-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
522-
switch (index) {
523-
case 0:
524-
[weakSelf deleteComment:weakSelf.toComment];
525-
break;
526-
default:
527-
break;
511+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"删除此评论" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
512+
if (index == 0) {
513+
[weakSelf deleteComment:weakSelf.toComment];
528514
}
529515
}];
530516
[actionSheet showInView:kKeyWindow];

Coding_iOS/Controllers/FileListViewController.m

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,9 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut
415415
}else{
416416
__weak typeof(self) weakSelf = self;
417417

418-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:[NSString stringWithFormat:@"确定要删除文件夹:%@",folder.name]];
419-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
420-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
421-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
422-
switch (index) {
423-
case 0:
424-
[weakSelf deleteFolder:folder];
425-
break;
426-
default:
427-
break;
418+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:[NSString stringWithFormat:@"确定要删除文件夹:%@",folder.name] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
419+
if (index == 0) {
420+
[weakSelf deleteFolder:folder];
428421
}
429422
}];
430423
[actionSheet showInView:kKeyWindow];
@@ -477,13 +470,10 @@ - (void)deleteFile:(ProjectFile *)file{
477470

478471
NSURL *fileUrl = [file hasBeenDownload];
479472
Coding_DownloadTask *cDownloadTask = [file cDownloadTask];
480-
473+
UIActionSheet *actionSheet;
474+
481475
if (fileUrl) {
482-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"只是删除本地文件还是连同服务器文件一起删除?"];
483-
[actionSheet bk_addButtonWithTitle:@"仅删除本地文件" handler:nil];
484-
[actionSheet bk_setDestructiveButtonWithTitle:@"一起删除" handler:nil];
485-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
486-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
476+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"只是删除本地文件还是连同服务器文件一起删除?" buttonTitles:@[@"仅删除本地文件"] destructiveTitle:@"一起删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
487477
switch (index) {
488478
case 0:
489479
[weakSelf deleteFile:weakFile fromDisk:YES];
@@ -495,13 +485,8 @@ - (void)deleteFile:(ProjectFile *)file{
495485
break;
496486
}
497487
}];
498-
[actionSheet showInView:kKeyWindow];
499488
}else if (cDownloadTask){
500-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"确定将服务器上的该文件删除?"];
501-
[actionSheet bk_addButtonWithTitle:@"只是取消下载" handler:nil];
502-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
503-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
504-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
489+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该文件删除?" buttonTitles:@[@"只是取消下载"] destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
505490
switch (index) {
506491
case 0:
507492
[weakSelf deleteFile:weakFile fromDisk:YES];
@@ -513,22 +498,14 @@ - (void)deleteFile:(ProjectFile *)file{
513498
break;
514499
}
515500
}];
516-
[actionSheet showInView:kKeyWindow];
517501
}else{
518-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"确定将服务器上的该文件删除?"];
519-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
520-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
521-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
522-
switch (index) {
523-
case 0:
524-
[weakSelf deleteFile:weakFile fromDisk:NO];
525-
break;
526-
default:
527-
break;
502+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该文件删除?" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
503+
if (index == 0) {
504+
[weakSelf deleteFile:weakFile fromDisk:NO];
528505
}
529506
}];
530-
[actionSheet showInView:kKeyWindow];
531507
}
508+
[actionSheet showInView:kKeyWindow];
532509
}
533510
- (void)deleteFile:(ProjectFile *)file fromDisk:(BOOL)fromDisk{
534511

Coding_iOS/Controllers/FileViewController.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,8 @@ - (void)setupNavigationItem{
210210
- (void)rightNavBtnClicked{
211211
__weak typeof(self) weakSelf = self;
212212
if (self.curFile.preview && self.curFile.preview.length > 0) {
213-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:nil];
214-
[actionSheet bk_addButtonWithTitle:@"保存到相册" handler:nil];
215-
[actionSheet bk_addButtonWithTitle:@"用其他应用打开" handler:nil];
216-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
217-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
213+
214+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"保存到相册", @"用其他应用打开"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
218215
switch (index) {
219216
case 0:
220217
[weakSelf saveCurImg];

Coding_iOS/Controllers/ProjectMemberListViewController.m

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,10 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
285285
}
286286

287287
__weak typeof(self) weakSelf = self;
288-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:@"移除该成员后,他将不再显示在项目中"];
289-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认移除" handler:nil];
290-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
291-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
292-
switch (index) {
293-
case 0:
294-
[weakSelf removeMember:curMember inTableView:tableView];
295-
break;
296-
default:
297-
break;
288+
289+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"移除该成员后,他将不再显示在项目中" buttonTitles:nil destructiveTitle:@"确认移除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
290+
if (index == 0) {
291+
[weakSelf removeMember:curMember inTableView:tableView];
298292
}
299293
}];
300294
[actionSheet showInView:kKeyWindow];

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ + (void)presentLinkStr:(NSString *)linkStr{
137137
[self presentViewController:vc];
138138
}else{
139139
//网页
140-
NSURL *linkUrl = [NSURL URLWithString:linkStr];
141-
if (linkUrl) {
142-
WebViewController *vc = [WebViewController webVCWithUrl:linkUrl];
143-
[self presentViewController:vc];
144-
}
140+
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
141+
[self presentViewController:webVc];
145142
}
146143
}
147144

Coding_iOS/Controllers/RootControllers/Message_RootViewController.m

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,9 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
250250
PrivateMessage *msg = [_myPriMsgs.list objectAtIndex:indexPath.row-3];
251251

252252
__weak typeof(self) weakSelf = self;
253-
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetWithTitle:[NSString stringWithFormat:@"这将删除你和 %@ 的所有私信", msg.friend.name]];
254-
[actionSheet bk_setDestructiveButtonWithTitle:@"确认删除" handler:nil];
255-
[actionSheet bk_setCancelButtonWithTitle:@"取消" handler:nil];
256-
[actionSheet bk_setDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
257-
switch (index) {
258-
case 0:
259-
[weakSelf removeConversation:msg inTableView:tableView];
260-
break;
261-
default:
262-
break;
253+
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:[NSString stringWithFormat:@"这将删除你和 %@ 的所有私信", msg.friend.name] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
254+
if (index == 0) {
255+
[weakSelf removeConversation:msg inTableView:tableView];
263256
}
264257
}];
265258
[actionSheet showInView:kKeyWindow];

0 commit comments

Comments
 (0)