| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- //
- // LogRichText.m
- // IBOSS
- //
- // Created by guan hong hou on 15/11/12.
- // Copyright © 2015年 elongtian. All rights reserved.
- //
- #define kTextFont [UIFont systemFontOfSize:14]
- #define commentTextFont [UIFont systemFontOfSize:12]
- #define logContentTextFont [UIFont systemFontOfSize:13]
- #import "LogCell.h"
- #define PhotoCollectionViewCellIdentifier @"PhotoCollectionViewCellIdentifier"
- #import "AlbumPhotoCollectionViewCell.h"
- #import "XHImageViewer.h"
- #import "XHAlbumCollectionViewFlowLayout.h"
- #import "UIImageView+AsyncDownload.h"
- #import "ImageModel.h"
- #import "ReplyInfoCell.h"
- #import "DKPhotoPickerBrowserViewController.h"
- #import "DKPhotoPickerCustomToolBarView.h"
- #import "SoundCell.h"
- #import "Sound.h"
- #import "ReplyFrame.h"
- #import "AsyncSound.h"
- @interface AlbumCollectionView : UICollectionView
- @end
- @implementation AlbumCollectionView
- @end
- @interface SoundTabView: UITableView
- @end
- @implementation SoundTabView
- @end
- @interface ReplyInfoTableView: UITableView
- @end
- @implementation ReplyInfoTableView
- @end
- @interface LogCell () <UICollectionViewDelegate, UICollectionViewDataSource,UITableViewDataSource,UITableViewDelegate,ProgressHUDDelegate,TableViewCellDelegate>
- @property (nonatomic, strong) AlbumCollectionView *sharePhotoCollectionView;
- @property (nonatomic, strong) ReplyInfoTableView *replyInfoTableView;
- @property (nonatomic,strong)SoundTabView *logSoundView;
- @end
- @implementation LogCell
- #pragma mark -公有方法
- //布局frame初始化方法
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- // [self setup];
- }
- return self;
- }
- #pragma mark -委托方法
- //相册collectionview每个分区的项数
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return [self.currentLog.log.imagePathArray count];
- }
- //相册加载cellectionviewcell
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- AlbumPhotoCollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier forIndexPath:indexPath];
-
- cell1.indexPath = indexPath;
- ImageModel *image = self.currentLog.log.imagePathArray[indexPath.row];
- NSString *imagepath=[image imageName];
- if(imagepath!=nil&&[imagepath length]>0){
-
- // Regiser for HUD callbacks so we can remove it from the window at the right time
- _hud.delegate = self;
-
- NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath];
- NSURL *url = [NSURL URLWithString:imageUrl];
- [cell1.photoImageView downloadImageWithURL:url];
- }
-
-
- return cell1;
- }
- //点击图片放大
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
- [self showImageViewerAtIndexPath:indexPath];
- }
- //图片放大方法
- - (void)showImageViewerAtIndexPath:(NSIndexPath *)indexPath {
- AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[self.sharePhotoCollectionView cellForItemAtIndexPath:indexPath];
-
- NSMutableArray *imageViews = [NSMutableArray array];
- NSArray *visibleCell = [self.sharePhotoCollectionView visibleCells];
-
- NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"indexPath" ascending:YES];
-
- visibleCell = [visibleCell sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
-
- [visibleCell enumerateObjectsUsingBlock:^(AlbumPhotoCollectionViewCell *cell, NSUInteger idx, BOOL *stop) {
- [imageViews addObject:[[cell.contentView subviews] lastObject]];
- }];
-
- XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
- [imageViewer showWithImageViews:imageViews selectedView:[[cell.contentView subviews] lastObject]];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
-
- }
- //语音显示
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if([tableView isEqual:_logSoundView]){
- NSString *CellIdentifier=@"soundcell";
- SoundCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil){
- cell = [[SoundCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- NSMutableArray *soundPathArray= [self.currentLog.log soundArray];
- Sound *sound= [soundPathArray objectAtIndex:indexPath.row];
- NSString *soundPath=[sound soundPath];
- NSString *duration=[sound duration];
- NSString *filePath;
- if(soundPath!=nil&&[soundPath length]>0){
- NSString *soundUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,soundPath];
- NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
- NSRange range = [soundUrl rangeOfString:@"/" options:NSBackwardsSearch];
- NSString *filename = [soundUrl substringFromIndex:range.location+1];
- filePath=[docPath stringByAppendingPathComponent:filename];
- AsyncSound *asyncSound=[[AsyncSound alloc] init];
- [asyncSound asyncLoad:soundUrl localPath:filePath];
- [cell setPath:filePath :duration];
-
- }
-
- return cell;
-
- }
- else if([tableView isEqual:_replyInfoTableView]){
- NSString *CellIdentifier=@"replyInfoCell";
- ReplyInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if(cell==nil){
- cell = [[ReplyInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
-
- cell.delegate = self;
- }
-
- ReplyFrame *replyInfoFrame= [[_currentLog.log replyArray] objectAtIndex:indexPath.row];
- [cell setReplyInfoData:replyInfoFrame ];
-
- return cell;
-
- }
- return nil;
-
- }
- //语音单元格高度
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if([tableView isEqual:_logSoundView]){
-
- return 60;
- }
- else if([tableView isEqual:_replyInfoTableView]){
- ReplyFrame *replyInfoFrame= [[_currentLog.log replyArray] objectAtIndex:indexPath.row];
- CGFloat cellHeight=[replyInfoFrame cellHeight];
- return cellHeight;
- }
- return 0;
- }
- //语音的个数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if([tableView isEqual:_logSoundView]){
-
- return [[self.currentLog.log soundArray] count];
- }
- else if([tableView isEqual:_replyInfoTableView]){
- return [[self.currentLog.log replyArray] count];
- }
- return 0;
- }
- #pragma mark -私有方法
- // 设置日志布局
- - (void)setCurrentLog:(LogFrame*)displayLog {
-
- _currentLog=displayLog;
- _headerImgView=[[UIImageView alloc] init];
- _headerImgView.frame=[_currentLog headImgF];
- _headerImgView.image=[UIImage imageNamed:@"icon_username"];
- [self.contentView addSubview:_headerImgView];
- _userNameLabel=[[UILabel alloc]init];
- _userNameLabel.backgroundColor = [UIColor clearColor];
- _userNameLabel.frame=[_currentLog userNameLabelF];
- _userNameLabel.textColor = [UIColor blackColor];
- _userNameLabel.font =kTextFont;
- [self.contentView addSubview:_userNameLabel];
- _recordStatusLabel=[[UILabel alloc]init];
- _recordStatusLabel.frame=[_currentLog commentFlagLabelF];
- _recordStatusLabel.backgroundColor=[UIColor clearColor];
- _recordStatusLabel.font=kTextFont;
- [self.contentView addSubview:_recordStatusLabel];
- _contentLabel=[[UILabel alloc]init];
- _contentLabel.backgroundColor=[UIColor clearColor];
- _contentLabel.frame=[_currentLog contentLabelF];
- _contentLabel.textColor=[UIColor blackColor];
- _contentLabel.font=logContentTextFont;
- [self.contentView addSubview:_contentLabel];
- _createTimeLabel=[[UILabel alloc]init];
- _createTimeLabel.backgroundColor = [UIColor clearColor];
- _createTimeLabel.frame=[_currentLog dateLabelF];
- _createTimeLabel.textColor = LabelGrayTextColor;
- _createTimeLabel.font =commentTextFont;
- [self.contentView addSubview:_createTimeLabel];
- _userNameLabel.text=_currentLog.log.userName;
- _recordStatus= [_currentLog.log recordStatus];
- _recordStatusLabel.text=_recordStatus;
- _contentLabel.numberOfLines=0;
- _contentLabel.text=[_currentLog.log content];
- NSString *checker= [_currentLog.log checker];
- if([_currentLog.log remarks]!=nil&&[_currentLog.log remarks].length>0){
- _checkerLabel=[[UILabel alloc]init];
- _checkerLabel.frame=[_currentLog reviewerF];
- _checkerLabel.backgroundColor=[UIColor clearColor];
- _checkerLabel.textColor=LabelGrayTextColor;
- _checkerLabel.font=kTextFont;
- [self.contentView addSubview:_checkerLabel];
- _commentContentView=[[UIView alloc]init];
- _commentContentView.layer.cornerRadius=2;
- _commentContentView.frame=[_currentLog logCommentF];
- _commentContentView.backgroundColor=[UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:235.0/255.0 alpha:1];
- _commentContent=[[UILabel alloc]init];
- _commentContent.frame=CGRectMake(5,10, _commentContentView.frame.size.width,20);
- _commentContent.textColor=LabelGrayTextColor;
-
- _commentContent.numberOfLines=0;
- _commentContent.font=commentTextFont;
- [_commentContentView addSubview:_commentContent];
- [self.contentView addSubview:_commentContentView];
- _commentTime=[[UILabel alloc]init];
- _commentTime.frame=[_currentLog commentDateF];
- _commentTime.backgroundColor=[UIColor clearColor];
- _commentTime.textColor=LabelGrayTextColor;
- _commentTime.font=commentTextFont;
- [self.contentView addSubview:_commentTime];
-
- _checkerLabel.text=[NSString stringWithFormat:@"以下是%@%@",checker,@"的评论:"];
- _commentContent.text=[_currentLog.log remarks];
- _commentTime.text=[_currentLog.log commentUpdateTime];
- }
-
- _commentUserCode=[_currentLog.log commentUserCode];
- if(_currentLog.log.imagePathArray!=nil &&_currentLog.log.imagePathArray.count>0){
- _sharePhotoCollectionView = [[AlbumCollectionView alloc] initWithFrame:[_currentLog logImageF] collectionViewLayout:[[XHAlbumCollectionViewFlowLayout alloc] init]];
- _sharePhotoCollectionView.backgroundColor =[UIColor clearColor];
- [_sharePhotoCollectionView registerClass:[AlbumPhotoCollectionViewCell class] forCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier];
- _sharePhotoCollectionView.scrollEnabled=NO;
- _sharePhotoCollectionView.delegate = self;
- _sharePhotoCollectionView.dataSource = self;
- [self.contentView addSubview:self.sharePhotoCollectionView];
-
- [self.sharePhotoCollectionView reloadData];
- }
- if(self.currentLog.log.soundArray!=nil &&self.currentLog.log.soundArray.count>0){
- _logSoundView =[[SoundTabView alloc]initWithFrame:[_currentLog logSoundF]style:UITableViewStylePlain];
- _logSoundView.estimatedRowHeight =50;
- _logSoundView.rowHeight = UITableViewAutomaticDimension;
- _logSoundView.backgroundColor =[UIColor clearColor];
- _logSoundView.delegate = self;
- _logSoundView.dataSource = self;
- _logSoundView.separatorStyle=UITableViewCellSeparatorStyleNone;
- _logSoundView.scrollEnabled=NO;
- [self.contentView addSubview:_logSoundView];
- [self.logSoundView reloadData];
- }
- if([_currentLog.log location]!=nil&&[_currentLog.log location].length>0){
- _locationImgView=[[UIImageView alloc]init];
- _locationImgView.frame=[_currentLog locationImgF];
- _locationImgView.image=[UIImage imageNamed:@"icon_position"];
- [self.contentView addSubview:_locationImgView];
- _locationLabel=[[UILabel alloc]init];
- _locationLabel.frame=[_currentLog locationContentF];
- _locationLabel.numberOfLines=0;
- _locationLabel.backgroundColor=[UIColor clearColor];
- _locationLabel.textColor=LabelGrayTextColor;
- _locationLabel.font=commentTextFont;
- [self.contentView addSubview:_locationLabel];
- _locationLabel.text=_currentLog.log.location;
-
- }
- if(self.currentLog.log.replyArray!=nil&&self.currentLog.log.replyArray.count>0){
- _replyInfoTableView=[[ReplyInfoTableView alloc] initWithFrame:[_currentLog logReplyContentF]];
- _replyInfoTableView.backgroundColor =[UIColor clearColor];
- _replyInfoTableView.estimatedRowHeight =42;
- _replyInfoTableView.rowHeight = UITableViewAutomaticDimension;
- _replyInfoTableView.delegate = self;
- _replyInfoTableView.dataSource = self;
- _replyInfoTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- _replyInfoTableView.scrollEnabled=NO;
- [self.contentView addSubview: _replyInfoTableView];
- [self.replyInfoTableView reloadData];
- }
-
- _createTimeLabel.text=_currentLog.log.createTime;
- _answerImgView=[UIButton buttonWithType:UIButtonTypeCustom];
- _answerImgView.frame=[_currentLog replyImgF];
- [_answerImgView setImage:[UIImage imageNamed:@"icon_answer"] forState:UIControlStateNormal];
- [self.contentView addSubview:_answerImgView];
- [_answerImgView addTarget:self action:@selector(answerButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
- _answerLabel=[UIButton buttonWithType:UIButtonTypeCustom];
- _answerLabel.frame=[_currentLog replyWordF];
- _answerLabel.backgroundColor=[UIColor clearColor];
- [ _answerLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [ _answerLabel setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- _answerLabel.titleLabel.font=kTextFont;
- [_answerLabel setTitle:@"回复" forState:UIControlStateNormal];
- [self.contentView addSubview:_answerLabel];
- [_answerLabel addTarget:self action:@selector(answerButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
- _commentImgView=[UIButton buttonWithType:UIButtonTypeCustom];
- _commentImgView.frame=[_currentLog commentBtnImgF];
- if([_recordStatus isEqualToString:@"(未点评)"]){
- _recordStatusLabel.textColor=LabelGrayTextColor;
- [_commentImgView setImage:[UIImage imageNamed:@"news_comment"] forState:UIControlStateNormal];
- }
- else{
- _recordStatusLabel.textColor=[UIColor colorWithRed:255.0/255.0 green:101.0/255.0 blue:38.0/255.0 alpha:1];
- [_commentImgView setImage:[UIImage imageNamed:@"news_comment2"] forState:UIControlStateNormal];
- }
-
- _recordStatusLabel.textAlignment=NSTextAlignmentRight;
- [self.contentView addSubview:_commentImgView];
- [_commentImgView addTarget:self action:@selector(commentButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
- _commentLabel=[UIButton buttonWithType:UIButtonTypeCustom];
- _commentLabel.frame=[_currentLog commentWordF];
- _commentLabel.backgroundColor=[UIColor clearColor];
- [ _commentLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [ _commentLabel setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- _commentLabel.titleLabel.font=kTextFont;
- [_commentLabel setTitle:@"点评" forState:UIControlStateNormal];
- [self.contentView addSubview:_commentLabel];
- [_commentLabel addTarget:self action:@selector(commentButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
- _separatorsView=[[UIImageView alloc]init];
- _separatorsView.frame=[_currentLog separatorsF];
- _separatorsView.backgroundColor=LineBackgroundColor;
- [self.contentView addSubview:_separatorsView];
-
- }
- //评论按钮点击事件
- - (void)commentButtonDidClicked:(UIButton *)sender {
- if([_recordStatus isEqualToString:@"(未点评)"]){
- if(_commentUserCode==nil||_commentUserCode.length==0){
- [self showAlertViewText:@"该日志没有权限进行评论"];
- return;
- }
- NSString *userCode=kkUserCode;
- BOOL result = [_commentUserCode caseInsensitiveCompare:userCode]== NSOrderedSame;
- if(result){
- if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
- [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:1 replyInfo:nil];
- }
- }
- else{
- [self showAlertViewText:@"该日志没有权限进行评论"];
- return;
- }
- }
- else{
- [self showAlertViewText:@"该日志已评论,不能进行重复评论"];
- return;
- }
-
- }
- //日志回复点击
- - (void)answerButtonDidClicked:(UIButton *)sender {
-
- if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
- [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:2 replyInfo:nil];
- }
- }
- - (void)ShowOperationView:(UIButton *)sender replyInfo :(ReplyInfo*)replyInfo{
-
- if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
- [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:3 replyInfo:replyInfo];
- }
-
- }
- //消息弹出控件
- -(void)showAlertViewText:(NSString *)text
- {
- UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
- message:text
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
-
-
- }
- @end
|