From faba5b8c5630d5af636fc8a45fb47a4e0d56bce7 Mon Sep 17 00:00:00 2001 From: wu736139669 Date: Mon, 15 Jun 2015 12:31:13 +0800 Subject: [PATCH] new --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 348 ++++++++++++++++-- Ash_AWord/Utility/Tool/Ash_UIUtil.h | 8 + Ash_AWord/Utility/Tool/Ash_UIUtil.m | 18 +- .../Note/NoteCommentViewController.m | 20 +- .../Note/NoteCommentViewController.xib | 2 +- .../ViewModels/Common/CommentViewModel.h | 12 +- .../ViewModels/Common/CommentViewModel.m | 36 +- Ash_AWord/ViewModels/Common/UserViewModel.m | 15 +- Ash_AWord/Views/Common/CommentTableViewCell.h | 8 +- Ash_AWord/Views/Common/CommentTableViewCell.m | 39 +- .../Views/Common/CommentTableViewCell.xib | 44 +-- Ash_AWord/Views/Common/CommentTextView.h | 4 +- Ash_AWord/Views/Common/CommentTextView.m | 10 +- 13 files changed, 451 insertions(+), 113 deletions(-) diff --git a/Ash_AWord.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Ash_AWord.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 54897f4..9cfafa6 100644 --- a/Ash_AWord.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Ash_AWord.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -1833,11 +1833,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Ash_AWord/Views/Common/CommentTextView.m" - timestampString = "455127399.182315" + timestampString = "456026320.291568" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "26" - endingLineNumber = "26" + startingLineNumber = "27" + endingLineNumber = "27" landmarkName = "-bgBtnClick:" landmarkType = "5"> @@ -1849,31 +1849,15 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Ash_AWord/Views/Common/CommentTextView.m" - timestampString = "455196891.607978" + timestampString = "456034433.97587" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "148" - endingLineNumber = "148" + startingLineNumber = "154" + endingLineNumber = "154" landmarkName = "-dealloc" landmarkType = "5"> - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ash_AWord/Utility/Tool/Ash_UIUtil.h b/Ash_AWord/Utility/Tool/Ash_UIUtil.h index 99da9de..983f79b 100644 --- a/Ash_AWord/Utility/Tool/Ash_UIUtil.h +++ b/Ash_AWord/Utility/Tool/Ash_UIUtil.h @@ -71,7 +71,15 @@ */ +(UIImage*)compressImageDownToPhoneScreenSize:(UIImage*)originImage; +/** + * 根据宽度计算htmlsize + * + * @param width控件宽度 + * @return 大小size + */ ++(CGSize) calculateSizeWithHtmlstring:(NSString *)htmlstr limitWidth:(CGFloat)width withFontSize:(NSInteger)fontSize; ++(NSDictionary*)getHtmlDicWithFontSize:(NSInteger)fontSize; @end @interface UIFont (CustomFont) diff --git a/Ash_AWord/Utility/Tool/Ash_UIUtil.m b/Ash_AWord/Utility/Tool/Ash_UIUtil.m index cfb8c77..b4748b3 100644 --- a/Ash_AWord/Utility/Tool/Ash_UIUtil.m +++ b/Ash_AWord/Utility/Tool/Ash_UIUtil.m @@ -7,7 +7,7 @@ // #import "Ash_UIUtil.h" - +#import @implementation Ash_UIUtil +(CABasicAnimation*)getrotationAnimation @@ -406,7 +406,21 @@ { return kScreenWidth/320; } - ++(CGSize)calculateSizeWithHtmlstring:(NSString *)htmlstr limitWidth:(CGFloat)width withFontSize:(NSInteger)fontSize +{ + NSDictionary* optionsDic = [Ash_UIUtil getHtmlDicWithFontSize:fontSize]; + NSData *data = [htmlstr dataUsingEncoding:NSUTF8StringEncoding]; + NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data options:optionsDic documentAttributes:nil]; + DTAttributedTextContentView *attributedTextContextView = [[DTAttributedTextContentView alloc] initWithFrame:CGRectMake(0, 0, width, 500)]; + attributedTextContextView.attributedString = string; + CGSize size = [attributedTextContextView suggestedFrameSizeToFitEntireStringConstraintedToWidth:width]; + return size; +} ++(NSDictionary*)getHtmlDicWithFontSize:(NSInteger)fontSize +{ + NSDictionary* optionsDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:kCTTextAlignmentLeft],DTDefaultTextAlignment,[UIColor blackColor],DTDefaultTextColor,[NSNumber numberWithInteger:fontSize], DTDefaultFontSize,[[UIFont appFontOfSize:1] fontName],DTDefaultFontName,[UIColor appMainColor],DTDefaultLinkColor, nil]; + return optionsDic; +} @end @implementation UIFont (CustomFont) diff --git a/Ash_AWord/ViewControllers/Note/NoteCommentViewController.m b/Ash_AWord/ViewControllers/Note/NoteCommentViewController.m index c6d2610..78b50c4 100644 --- a/Ash_AWord/ViewControllers/Note/NoteCommentViewController.m +++ b/Ash_AWord/ViewControllers/Note/NoteCommentViewController.m @@ -88,6 +88,7 @@ }]; [self.view addSubview:_commentTextView]; _commentTextView.recordId = _text_image.messageId; + _commentTextView.aothourId = _text_image.ownerId; [_commentTextView setHidden:YES]; @@ -124,7 +125,7 @@ { [MobClick event:kUmen_note]; - PropertyEntity* pro = [CommentViewModel requireLoadCommentWithRecordId:_text_image.messageId withPage:_page withPage_size:DefaultPageSize]; + PropertyEntity* pro = [CommentViewModel requireLoadCommentWithRecordId:_text_image.messageId withPage:_page withPage_size:DefaultPageSize WithType:Image_Type]; [RequireEngine requireWithProperty:pro completionBlock:^(id viewModel) { if ([viewModel success]) { @@ -189,7 +190,11 @@ { CommentInfoViewModel* commentInfoViewModel = [_commentInfoArr objectAtIndex:indexPath.row]; - return [CommentTableViewCell getHeightWithCommentInfoViewModel:commentInfoViewModel]; + BOOL isReplyOwnew = YES; + if (![commentInfoViewModel.toUserId isEqualToString:_text_image.ownerId]) { + isReplyOwnew = NO; + } + return [CommentTableViewCell getHeightWithCommentInfoViewModel:commentInfoViewModel isReplyOwner:isReplyOwnew]; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section @@ -213,11 +218,7 @@ } CommentInfoViewModel* commentInfoViewModel = [_commentInfoArr objectAtIndex:indexPath.row]; - if ([commentInfoViewModel.ownerId isEqualToString:_text_image.ownerId] ) { - [cell setIsAuthor:YES]; - }else{ - [cell setIsAuthor:NO]; - } + cell.ownerId = _text_image.ownerId; [cell setCommentInfoViewModel:commentInfoViewModel]; return cell; @@ -225,6 +226,9 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; + CommentInfoViewModel* commentInfoViewModel = [_commentInfoArr objectAtIndex:indexPath.row]; + [_commentTextView showWithUid:commentInfoViewModel.ownerId]; + } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -242,7 +246,7 @@ */ - (IBAction)commentBtnClick:(id)sender { - [_commentTextView show]; + [_commentTextView showWithUid:_text_image.ownerId]; } @end diff --git a/Ash_AWord/ViewControllers/Note/NoteCommentViewController.xib b/Ash_AWord/ViewControllers/Note/NoteCommentViewController.xib index 3c5a166..6060273 100644 --- a/Ash_AWord/ViewControllers/Note/NoteCommentViewController.xib +++ b/Ash_AWord/ViewControllers/Note/NoteCommentViewController.xib @@ -19,7 +19,7 @@ - + diff --git a/Ash_AWord/ViewModels/Common/CommentViewModel.h b/Ash_AWord/ViewModels/Common/CommentViewModel.h index ab1b85e..b23b982 100644 --- a/Ash_AWord/ViewModels/Common/CommentViewModel.h +++ b/Ash_AWord/ViewModels/Common/CommentViewModel.h @@ -7,7 +7,10 @@ // #import "BaseViewModel.h" - +typedef enum{ + Image_Type = 0, + Voice_Type = 1, +}CommentType; @interface CommentInfoViewModel : BaseViewModel @property (nonatomic, strong) NSString *commentId; @property (nonatomic, strong) NSString *ownerId; @@ -15,12 +18,15 @@ @property (nonatomic, strong) NSString *ownerName; @property (nonatomic, strong) NSString *content; @property (nonatomic, strong) NSString *createTime; +@property (nonatomic, strong) NSString *toUserId; +@property (nonatomic, strong) NSString *toUserName; +@property (nonatomic, assign) CommentType commentType; @end @interface CommentViewModel : BaseViewModel @property (nonatomic, strong)NSArray* commentInfoArr; -+(PropertyEntity*)requireAddCommentWithReconrdId:(NSInteger)recordId withContent:(NSString*)content; ++(PropertyEntity*)requireAddCommentWithReconrdId:(NSInteger)recordId withContent:(NSString*)content WithType:(CommentType)commentType withToUid:(NSString*)otherId; -+(PropertyEntity*)requireLoadCommentWithRecordId:(NSInteger)recordId withPage:(NSInteger)page withPage_size:(NSInteger)page_size; ++(PropertyEntity*)requireLoadCommentWithRecordId:(NSInteger)recordId withPage:(NSInteger)page withPage_size:(NSInteger)page_size WithType:(CommentType)commentType; @end diff --git a/Ash_AWord/ViewModels/Common/CommentViewModel.m b/Ash_AWord/ViewModels/Common/CommentViewModel.m index f2a321f..0dab13a 100644 --- a/Ash_AWord/ViewModels/Common/CommentViewModel.m +++ b/Ash_AWord/ViewModels/Common/CommentViewModel.m @@ -17,6 +17,9 @@ @"ownerId" : @"ownerId", @"ownerFigureurl" : @"ownerFigureurl", @"ownerName" : @"ownerName", + @"commentType": @"type", + @"toUserId":@"toUserId", + @"toUserName":@"toUserName", }; } @end @@ -36,30 +39,35 @@ return [NSValueTransformer mtl_JSONArrayTransformerWithModelClass:CommentInfoViewModel.class]; } -+(PropertyEntity*)requireAddCommentWithReconrdId:(NSInteger)recordId withContent:(NSString *)content ++(PropertyEntity*)requireAddCommentWithReconrdId:(NSInteger)recordId withContent:(NSString *)content WithType:(CommentType)commentType withToUid:(NSString *)otherId { PropertyEntity *pro = [[PropertyEntity alloc] init]; - pro.requireType = HTTPRequestTypeWithPOST; - pro.reqURL = @"rs/text_image/add_comment"; + pro.requireType = HTTPRequestTypeWithPOSTDATA; pro.responesOBJ = self.class; - pro.pro = @{ - @"record_id": [NSString stringWithFormat:@"%ld",recordId], - @"content": content, + NSDictionary* dic = @{ + @"recordId": [NSString stringWithFormat:@"%ld",recordId], + @"content": content, + @"type" : [NSString stringWithFormat:@"%u",commentType], + @"toUserId": otherId, + }; + pro.pro = @{@"root": dic, + @"command": @"10201", }; - return pro; } -+(PropertyEntity*)requireLoadCommentWithRecordId:(NSInteger)recordId withPage:(NSInteger)page withPage_size:(NSInteger)page_size ++(PropertyEntity*)requireLoadCommentWithRecordId:(NSInteger)recordId withPage:(NSInteger)page withPage_size:(NSInteger)page_size WithType:(CommentType)commentType { PropertyEntity *pro = [[PropertyEntity alloc] init]; - pro.requireType = HTTPRequestTypeWithGET; - pro.reqURL = @"rs/text_image/load_comment"; + pro.requireType = HTTPRequestTypeWithPOSTDATA; pro.responesOBJ = self.class; - pro.pro = @{@"record_id": [NSString stringWithFormat:@"%ld",recordId], - @"page": [NSString stringWithFormat:@"%ld",page], - @"page_size": [NSString stringWithFormat:@"%ld",page_size], + NSDictionary* dic = @{@"recordId": [NSString stringWithFormat:@"%ld",recordId], + @"page": [NSString stringWithFormat:@"%ld",page], + @"pageSize": [NSString stringWithFormat:@"%ld",page_size], + @"type" : [NSString stringWithFormat:@"%u",commentType], + }; + pro.pro = @{@"root": dic, + @"command": @"10203", }; - return pro; } @end diff --git a/Ash_AWord/ViewModels/Common/UserViewModel.m b/Ash_AWord/ViewModels/Common/UserViewModel.m index 9ed2254..93f8f86 100644 --- a/Ash_AWord/ViewModels/Common/UserViewModel.m +++ b/Ash_AWord/ViewModels/Common/UserViewModel.m @@ -33,14 +33,17 @@ +(PropertyEntity*)requireLoadPraiseUserWithRecordId:(NSInteger)recordId withPage:(NSInteger)page withPage_size:(NSInteger)page_size { PropertyEntity *pro = [[PropertyEntity alloc] init]; - pro.requireType = HTTPRequestTypeWithGET; - pro.reqURL = @"rs/text_image/load_praise_user"; + pro.requireType = HTTPRequestTypeWithPOSTDATA; pro.responesOBJ = self.class; - pro.pro = @{@"record_id": [NSString stringWithFormat:@"%ld",recordId], - @"page": [NSString stringWithFormat:@"%ld",(long)page], - @"page_size": [NSString stringWithFormat:@"%ld",(long)page_size], - }; + + NSDictionary* dic = @{@"recordId": [NSString stringWithFormat:@"%ld",recordId], + @"page": [NSString stringWithFormat:@"%ld",page], + @"pageSize": [NSString stringWithFormat:@"%ld",page_size], + }; + pro.pro = @{@"root": dic, + @"command": @"20008", + }; return pro; } diff --git a/Ash_AWord/Views/Common/CommentTableViewCell.h b/Ash_AWord/Views/Common/CommentTableViewCell.h index 1db2c89..36b41e6 100644 --- a/Ash_AWord/Views/Common/CommentTableViewCell.h +++ b/Ash_AWord/Views/Common/CommentTableViewCell.h @@ -7,16 +7,16 @@ // #import - +#import @class CommentInfoViewModel; @interface CommentTableViewCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIImageView *avatarImageView; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UILabel *timeLabel; @property (weak, nonatomic) IBOutlet UILabel *floorLabel; -@property (weak, nonatomic) IBOutlet UITextView *contentTextView; +@property (weak, nonatomic) IBOutlet DTAttributedTextView *contentTextView; +@property (strong, nonatomic)NSString* ownerId; -(void)setCommentInfoViewModel:(CommentInfoViewModel*)commentInfoViewModel; --(void)setIsAuthor:(BOOL)isAuthor; -+(CGFloat)getHeightWithCommentInfoViewModel:(CommentInfoViewModel*)commentInfoViewModel; ++(CGFloat)getHeightWithCommentInfoViewModel:(CommentInfoViewModel*)commentInfoViewModel isReplyOwner:(BOOL)isReplyOwner; @end diff --git a/Ash_AWord/Views/Common/CommentTableViewCell.m b/Ash_AWord/Views/Common/CommentTableViewCell.m index 02e4a41..fa12a2d 100644 --- a/Ash_AWord/Views/Common/CommentTableViewCell.m +++ b/Ash_AWord/Views/Common/CommentTableViewCell.m @@ -16,7 +16,6 @@ // Initialization code _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 18.0; - _contentTextView.scrollEnabled = NO; _floorLabel.layer.masksToBounds = YES; _floorLabel.layer.cornerRadius = 8.0; @@ -40,17 +39,41 @@ { [_avatarImageView sd_setImageWithURL:[NSURL URLWithString:commentInfoViewModel.ownerFigureurl] placeholderImage:DefaultUserIcon]; _nameLabel.text = commentInfoViewModel.ownerName; - _contentTextView.text = commentInfoViewModel.content; + + if ([commentInfoViewModel.ownerId isEqualToString:_ownerId] ) { + [self setIsAuthor:YES]; + }else{ + [self setIsAuthor:NO]; + } + NSString* content = commentInfoViewModel.content; + if (![commentInfoViewModel.toUserId isEqualToString:_ownerId]){ + content = [CommentTableViewCell getContentWithCommentInfoViewModel:commentInfoViewModel]; + } + [self setContent:content]; + _timeLabel.text = [CommonUtil timeFromtimeSp:commentInfoViewModel.createTime]; } -+(CGFloat)getHeightWithCommentInfoViewModel:(CommentInfoViewModel *)commentInfoViewModel ++(CGFloat)getHeightWithCommentInfoViewModel:(CommentInfoViewModel *)commentInfoViewModel isReplyOwner:(BOOL)isReplyOwner { - UIFont *font = [UIFont appFontOfSize:13.0]; - CGSize size = CGSizeMake(kScreenWidth - 60,MAXFLOAT); + NSString* content = commentInfoViewModel.content; + if (!isReplyOwner){ + content = [CommentTableViewCell getContentWithCommentInfoViewModel:commentInfoViewModel]; + } + CGFloat height = [Ash_UIUtil calculateSizeWithHtmlstring:content limitWidth:kScreenWidth-50 withFontSize:13].height; + return height+50; +} +-(void)setContent:(NSString*)content +{ + NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding]; + NSAttributedString *percentString = [[NSAttributedString alloc] initWithHTMLData:data options:[Ash_UIUtil getHtmlDicWithFontSize:13] documentAttributes:nil]; + _contentTextView.attributedString = percentString; +} ++(NSString*)getContentWithCommentInfoViewModel:(CommentInfoViewModel*)commentInfoViewModel; +{ + NSString* content = commentInfoViewModel.content; + content = [NSString stringWithFormat:@"回复 %@: %@",commentInfoViewModel.toUserId,commentInfoViewModel.toUserName,content]; - CGRect labelRect = [commentInfoViewModel.content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil]; - - return labelRect.size.height+60; + return content; } @end diff --git a/Ash_AWord/Views/Common/CommentTableViewCell.xib b/Ash_AWord/Views/Common/CommentTableViewCell.xib index e7d47e2..ae1b40a 100644 --- a/Ash_AWord/Views/Common/CommentTableViewCell.xib +++ b/Ash_AWord/Views/Common/CommentTableViewCell.xib @@ -22,68 +22,62 @@ - - - + + - - + + - - - - - + + + - - - - - + + + - + diff --git a/Ash_AWord/Views/Common/CommentTextView.h b/Ash_AWord/Views/Common/CommentTextView.h index 480e68e..bfd5f63 100644 --- a/Ash_AWord/Views/Common/CommentTextView.h +++ b/Ash_AWord/Views/Common/CommentTextView.h @@ -13,7 +13,7 @@ typedef void (^CommentComplete)(void); @interface CommentTextView : UIView @property (nonatomic, assign) NSInteger recordId; - +@property (nonatomic, strong) NSString* aothourId; @property (nonatomic, strong) CommentComplete comentComplete; @property (weak, nonatomic) IBOutlet UITextView *contentTextView; @property (weak, nonatomic) IBOutlet UILabel *tipLabel; @@ -23,6 +23,6 @@ typedef void (^CommentComplete)(void); - (IBAction)bgBtnClick:(id)sender; --(void)show; +-(void)showWithUid:(NSString*)uid;; -(void)hide; @end diff --git a/Ash_AWord/Views/Common/CommentTextView.m b/Ash_AWord/Views/Common/CommentTextView.m index d71ee6a..8128345 100644 --- a/Ash_AWord/Views/Common/CommentTextView.m +++ b/Ash_AWord/Views/Common/CommentTextView.m @@ -13,6 +13,7 @@ @implementation CommentTextView { + NSString* _commentId; } /* // Only override drawRect: if you perform custom drawing. @@ -26,8 +27,9 @@ [self hide]; } --(void)show +-(void)showWithUid:(NSString *)uid { + _commentId = uid; [_contentTextView becomeFirstResponder]; self.hidden = NO; self.alpha = 1; @@ -114,7 +116,11 @@ [MBProgressHUD hudWithView:nil label:@"评论中"]; - PropertyEntity* pro = [CommentViewModel requireAddCommentWithReconrdId:_recordId withContent:_contentTextView.text]; + NSString* commentId = _commentId; + if (!commentId) { + commentId = _aothourId; + } + PropertyEntity* pro = [CommentViewModel requireAddCommentWithReconrdId:_recordId withContent:_contentTextView.text WithType:Image_Type withToUid:commentId]; [RequireEngine requireWithProperty:pro completionBlock:^(id viewModel) { [MBProgressHUD hideAllHUDsForView:nil animated:YES];