LogCell.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. //
  2. // LogRichText.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 15/11/12.
  6. // Copyright © 2015年 elongtian. All rights reserved.
  7. //
  8. #define kTextFont [UIFont systemFontOfSize:14]
  9. #define commentTextFont [UIFont systemFontOfSize:12]
  10. #define logContentTextFont [UIFont systemFontOfSize:13]
  11. #import "LogCell.h"
  12. #define PhotoCollectionViewCellIdentifier @"PhotoCollectionViewCellIdentifier"
  13. #import "AlbumPhotoCollectionViewCell.h"
  14. #import "XHImageViewer.h"
  15. #import "XHAlbumCollectionViewFlowLayout.h"
  16. #import "UIImageView+AsyncDownload.h"
  17. #import "ImageModel.h"
  18. #import "ReplyInfoCell.h"
  19. #import "DKPhotoPickerBrowserViewController.h"
  20. #import "DKPhotoPickerCustomToolBarView.h"
  21. #import "SoundCell.h"
  22. #import "Sound.h"
  23. #import "ReplyFrame.h"
  24. #import "AsyncSound.h"
  25. @interface AlbumCollectionView : UICollectionView
  26. @end
  27. @implementation AlbumCollectionView
  28. @end
  29. @interface SoundTabView: UITableView
  30. @end
  31. @implementation SoundTabView
  32. @end
  33. @interface ReplyInfoTableView: UITableView
  34. @end
  35. @implementation ReplyInfoTableView
  36. @end
  37. @interface LogCell () <UICollectionViewDelegate, UICollectionViewDataSource,UITableViewDataSource,UITableViewDelegate,ProgressHUDDelegate,TableViewCellDelegate>
  38. @property (nonatomic, strong) AlbumCollectionView *sharePhotoCollectionView;
  39. @property (nonatomic, strong) ReplyInfoTableView *replyInfoTableView;
  40. @property (nonatomic,strong)SoundTabView *logSoundView;
  41. @end
  42. @implementation LogCell
  43. #pragma mark -公有方法
  44. //布局frame初始化方法
  45. - (id)initWithFrame:(CGRect)frame {
  46. self = [super initWithFrame:frame];
  47. if (self) {
  48. // [self setup];
  49. }
  50. return self;
  51. }
  52. #pragma mark -委托方法
  53. //相册collectionview每个分区的项数
  54. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  55. return [self.currentLog.log.imagePathArray count];
  56. }
  57. //相册加载cellectionviewcell
  58. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  59. AlbumPhotoCollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier forIndexPath:indexPath];
  60. cell1.indexPath = indexPath;
  61. ImageModel *image = self.currentLog.log.imagePathArray[indexPath.row];
  62. NSString *imagepath=[image imageName];
  63. if(imagepath!=nil&&[imagepath length]>0){
  64. // Regiser for HUD callbacks so we can remove it from the window at the right time
  65. _hud.delegate = self;
  66. NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath];
  67. NSURL *url = [NSURL URLWithString:imageUrl];
  68. [cell1.photoImageView downloadImageWithURL:url];
  69. }
  70. return cell1;
  71. }
  72. //点击图片放大
  73. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  74. [self showImageViewerAtIndexPath:indexPath];
  75. }
  76. //图片放大方法
  77. - (void)showImageViewerAtIndexPath:(NSIndexPath *)indexPath {
  78. AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[self.sharePhotoCollectionView cellForItemAtIndexPath:indexPath];
  79. NSMutableArray *imageViews = [NSMutableArray array];
  80. NSArray *visibleCell = [self.sharePhotoCollectionView visibleCells];
  81. NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"indexPath" ascending:YES];
  82. visibleCell = [visibleCell sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
  83. [visibleCell enumerateObjectsUsingBlock:^(AlbumPhotoCollectionViewCell *cell, NSUInteger idx, BOOL *stop) {
  84. [imageViews addObject:[[cell.contentView subviews] lastObject]];
  85. }];
  86. XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
  87. [imageViewer showWithImageViews:imageViews selectedView:[[cell.contentView subviews] lastObject]];
  88. }
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  90. {
  91. return 1;
  92. }
  93. //语音显示
  94. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. if([tableView isEqual:_logSoundView]){
  97. NSString *CellIdentifier=@"soundcell";
  98. SoundCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  99. if (cell == nil){
  100. cell = [[SoundCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  101. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  102. }
  103. NSMutableArray *soundPathArray= [self.currentLog.log soundArray];
  104. Sound *sound= [soundPathArray objectAtIndex:indexPath.row];
  105. NSString *soundPath=[sound soundPath];
  106. NSString *duration=[sound duration];
  107. NSString *filePath;
  108. if(soundPath!=nil&&[soundPath length]>0){
  109. NSString *soundUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,soundPath];
  110. NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  111. NSRange range = [soundUrl rangeOfString:@"/" options:NSBackwardsSearch];
  112. NSString *filename = [soundUrl substringFromIndex:range.location+1];
  113. filePath=[docPath stringByAppendingPathComponent:filename];
  114. AsyncSound *asyncSound=[[AsyncSound alloc] init];
  115. [asyncSound asyncLoad:soundUrl localPath:filePath];
  116. [cell setPath:filePath :duration];
  117. }
  118. return cell;
  119. }
  120. else if([tableView isEqual:_replyInfoTableView]){
  121. NSString *CellIdentifier=@"replyInfoCell";
  122. ReplyInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  123. if(cell==nil){
  124. cell = [[ReplyInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  125. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  126. cell.delegate = self;
  127. }
  128. ReplyFrame *replyInfoFrame= [[_currentLog.log replyArray] objectAtIndex:indexPath.row];
  129. [cell setReplyInfoData:replyInfoFrame ];
  130. return cell;
  131. }
  132. return nil;
  133. }
  134. //语音单元格高度
  135. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  136. {
  137. if([tableView isEqual:_logSoundView]){
  138. return 60;
  139. }
  140. else if([tableView isEqual:_replyInfoTableView]){
  141. ReplyFrame *replyInfoFrame= [[_currentLog.log replyArray] objectAtIndex:indexPath.row];
  142. CGFloat cellHeight=[replyInfoFrame cellHeight];
  143. return cellHeight;
  144. }
  145. return 0;
  146. }
  147. //语音的个数
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  149. {
  150. if([tableView isEqual:_logSoundView]){
  151. return [[self.currentLog.log soundArray] count];
  152. }
  153. else if([tableView isEqual:_replyInfoTableView]){
  154. return [[self.currentLog.log replyArray] count];
  155. }
  156. return 0;
  157. }
  158. #pragma mark -私有方法
  159. // 设置日志布局
  160. - (void)setCurrentLog:(LogFrame*)displayLog {
  161. _currentLog=displayLog;
  162. _headerImgView=[[UIImageView alloc] init];
  163. _headerImgView.frame=[_currentLog headImgF];
  164. _headerImgView.image=[UIImage imageNamed:@"icon_username"];
  165. [self.contentView addSubview:_headerImgView];
  166. _userNameLabel=[[UILabel alloc]init];
  167. _userNameLabel.backgroundColor = [UIColor clearColor];
  168. _userNameLabel.frame=[_currentLog userNameLabelF];
  169. _userNameLabel.textColor = [UIColor blackColor];
  170. _userNameLabel.font =kTextFont;
  171. [self.contentView addSubview:_userNameLabel];
  172. _recordStatusLabel=[[UILabel alloc]init];
  173. _recordStatusLabel.frame=[_currentLog commentFlagLabelF];
  174. _recordStatusLabel.backgroundColor=[UIColor clearColor];
  175. _recordStatusLabel.font=kTextFont;
  176. [self.contentView addSubview:_recordStatusLabel];
  177. _contentLabel=[[UILabel alloc]init];
  178. _contentLabel.backgroundColor=[UIColor clearColor];
  179. _contentLabel.frame=[_currentLog contentLabelF];
  180. _contentLabel.textColor=[UIColor blackColor];
  181. _contentLabel.font=logContentTextFont;
  182. [self.contentView addSubview:_contentLabel];
  183. _createTimeLabel=[[UILabel alloc]init];
  184. _createTimeLabel.backgroundColor = [UIColor clearColor];
  185. _createTimeLabel.frame=[_currentLog dateLabelF];
  186. _createTimeLabel.textColor = LabelGrayTextColor;
  187. _createTimeLabel.font =commentTextFont;
  188. [self.contentView addSubview:_createTimeLabel];
  189. _userNameLabel.text=_currentLog.log.userName;
  190. _recordStatus= [_currentLog.log recordStatus];
  191. _recordStatusLabel.text=_recordStatus;
  192. _contentLabel.numberOfLines=0;
  193. _contentLabel.text=[_currentLog.log content];
  194. NSString *checker= [_currentLog.log checker];
  195. if([_currentLog.log remarks]!=nil&&[_currentLog.log remarks].length>0){
  196. _checkerLabel=[[UILabel alloc]init];
  197. _checkerLabel.frame=[_currentLog reviewerF];
  198. _checkerLabel.backgroundColor=[UIColor clearColor];
  199. _checkerLabel.textColor=LabelGrayTextColor;
  200. _checkerLabel.font=kTextFont;
  201. [self.contentView addSubview:_checkerLabel];
  202. _commentContentView=[[UIView alloc]init];
  203. _commentContentView.layer.cornerRadius=2;
  204. _commentContentView.frame=[_currentLog logCommentF];
  205. _commentContentView.backgroundColor=[UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:235.0/255.0 alpha:1];
  206. _commentContent=[[UILabel alloc]init];
  207. _commentContent.frame=CGRectMake(5,10, _commentContentView.frame.size.width,20);
  208. _commentContent.textColor=LabelGrayTextColor;
  209. _commentContent.numberOfLines=0;
  210. _commentContent.font=commentTextFont;
  211. [_commentContentView addSubview:_commentContent];
  212. [self.contentView addSubview:_commentContentView];
  213. _commentTime=[[UILabel alloc]init];
  214. _commentTime.frame=[_currentLog commentDateF];
  215. _commentTime.backgroundColor=[UIColor clearColor];
  216. _commentTime.textColor=LabelGrayTextColor;
  217. _commentTime.font=commentTextFont;
  218. [self.contentView addSubview:_commentTime];
  219. _checkerLabel.text=[NSString stringWithFormat:@"以下是%@%@",checker,@"的评论:"];
  220. _commentContent.text=[_currentLog.log remarks];
  221. _commentTime.text=[_currentLog.log commentUpdateTime];
  222. }
  223. _commentUserCode=[_currentLog.log commentUserCode];
  224. if(_currentLog.log.imagePathArray!=nil &&_currentLog.log.imagePathArray.count>0){
  225. _sharePhotoCollectionView = [[AlbumCollectionView alloc] initWithFrame:[_currentLog logImageF] collectionViewLayout:[[XHAlbumCollectionViewFlowLayout alloc] init]];
  226. _sharePhotoCollectionView.backgroundColor =[UIColor clearColor];
  227. [_sharePhotoCollectionView registerClass:[AlbumPhotoCollectionViewCell class] forCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier];
  228. _sharePhotoCollectionView.scrollEnabled=NO;
  229. _sharePhotoCollectionView.delegate = self;
  230. _sharePhotoCollectionView.dataSource = self;
  231. [self.contentView addSubview:self.sharePhotoCollectionView];
  232. [self.sharePhotoCollectionView reloadData];
  233. }
  234. if(self.currentLog.log.soundArray!=nil &&self.currentLog.log.soundArray.count>0){
  235. _logSoundView =[[SoundTabView alloc]initWithFrame:[_currentLog logSoundF]style:UITableViewStylePlain];
  236. _logSoundView.estimatedRowHeight =50;
  237. _logSoundView.rowHeight = UITableViewAutomaticDimension;
  238. _logSoundView.backgroundColor =[UIColor clearColor];
  239. _logSoundView.delegate = self;
  240. _logSoundView.dataSource = self;
  241. _logSoundView.separatorStyle=UITableViewCellSeparatorStyleNone;
  242. _logSoundView.scrollEnabled=NO;
  243. [self.contentView addSubview:_logSoundView];
  244. [self.logSoundView reloadData];
  245. }
  246. if([_currentLog.log location]!=nil&&[_currentLog.log location].length>0){
  247. _locationImgView=[[UIImageView alloc]init];
  248. _locationImgView.frame=[_currentLog locationImgF];
  249. _locationImgView.image=[UIImage imageNamed:@"icon_position"];
  250. [self.contentView addSubview:_locationImgView];
  251. _locationLabel=[[UILabel alloc]init];
  252. _locationLabel.frame=[_currentLog locationContentF];
  253. _locationLabel.numberOfLines=0;
  254. _locationLabel.backgroundColor=[UIColor clearColor];
  255. _locationLabel.textColor=LabelGrayTextColor;
  256. _locationLabel.font=commentTextFont;
  257. [self.contentView addSubview:_locationLabel];
  258. _locationLabel.text=_currentLog.log.location;
  259. }
  260. if(self.currentLog.log.replyArray!=nil&&self.currentLog.log.replyArray.count>0){
  261. _replyInfoTableView=[[ReplyInfoTableView alloc] initWithFrame:[_currentLog logReplyContentF]];
  262. _replyInfoTableView.backgroundColor =[UIColor clearColor];
  263. _replyInfoTableView.estimatedRowHeight =42;
  264. _replyInfoTableView.rowHeight = UITableViewAutomaticDimension;
  265. _replyInfoTableView.delegate = self;
  266. _replyInfoTableView.dataSource = self;
  267. _replyInfoTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  268. _replyInfoTableView.scrollEnabled=NO;
  269. [self.contentView addSubview: _replyInfoTableView];
  270. [self.replyInfoTableView reloadData];
  271. }
  272. _createTimeLabel.text=_currentLog.log.createTime;
  273. _answerImgView=[UIButton buttonWithType:UIButtonTypeCustom];
  274. _answerImgView.frame=[_currentLog replyImgF];
  275. [_answerImgView setImage:[UIImage imageNamed:@"icon_answer"] forState:UIControlStateNormal];
  276. [self.contentView addSubview:_answerImgView];
  277. [_answerImgView addTarget:self action:@selector(answerButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  278. _answerLabel=[UIButton buttonWithType:UIButtonTypeCustom];
  279. _answerLabel.frame=[_currentLog replyWordF];
  280. _answerLabel.backgroundColor=[UIColor clearColor];
  281. [ _answerLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  282. [ _answerLabel setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  283. _answerLabel.titleLabel.font=kTextFont;
  284. [_answerLabel setTitle:@"回复" forState:UIControlStateNormal];
  285. [self.contentView addSubview:_answerLabel];
  286. [_answerLabel addTarget:self action:@selector(answerButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  287. _commentImgView=[UIButton buttonWithType:UIButtonTypeCustom];
  288. _commentImgView.frame=[_currentLog commentBtnImgF];
  289. if([_recordStatus isEqualToString:@"(未点评)"]){
  290. _recordStatusLabel.textColor=LabelGrayTextColor;
  291. [_commentImgView setImage:[UIImage imageNamed:@"news_comment"] forState:UIControlStateNormal];
  292. }
  293. else{
  294. _recordStatusLabel.textColor=[UIColor colorWithRed:255.0/255.0 green:101.0/255.0 blue:38.0/255.0 alpha:1];
  295. [_commentImgView setImage:[UIImage imageNamed:@"news_comment2"] forState:UIControlStateNormal];
  296. }
  297. _recordStatusLabel.textAlignment=NSTextAlignmentRight;
  298. [self.contentView addSubview:_commentImgView];
  299. [_commentImgView addTarget:self action:@selector(commentButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  300. _commentLabel=[UIButton buttonWithType:UIButtonTypeCustom];
  301. _commentLabel.frame=[_currentLog commentWordF];
  302. _commentLabel.backgroundColor=[UIColor clearColor];
  303. [ _commentLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  304. [ _commentLabel setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  305. _commentLabel.titleLabel.font=kTextFont;
  306. [_commentLabel setTitle:@"点评" forState:UIControlStateNormal];
  307. [self.contentView addSubview:_commentLabel];
  308. [_commentLabel addTarget:self action:@selector(commentButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  309. _separatorsView=[[UIImageView alloc]init];
  310. _separatorsView.frame=[_currentLog separatorsF];
  311. _separatorsView.backgroundColor=LineBackgroundColor;
  312. [self.contentView addSubview:_separatorsView];
  313. }
  314. //评论按钮点击事件
  315. - (void)commentButtonDidClicked:(UIButton *)sender {
  316. if([_recordStatus isEqualToString:@"(未点评)"]){
  317. if(_commentUserCode==nil||_commentUserCode.length==0){
  318. [self showAlertViewText:@"该日志没有权限进行评论"];
  319. return;
  320. }
  321. NSString *userCode=kkUserCode;
  322. BOOL result = [_commentUserCode caseInsensitiveCompare:userCode]== NSOrderedSame;
  323. if(result){
  324. if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
  325. [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:1 replyInfo:nil];
  326. }
  327. }
  328. else{
  329. [self showAlertViewText:@"该日志没有权限进行评论"];
  330. return;
  331. }
  332. }
  333. else{
  334. [self showAlertViewText:@"该日志已评论,不能进行重复评论"];
  335. return;
  336. }
  337. }
  338. //日志回复点击
  339. - (void)answerButtonDidClicked:(UIButton *)sender {
  340. if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
  341. [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:2 replyInfo:nil];
  342. }
  343. }
  344. - (void)ShowOperationView:(UIButton *)sender replyInfo :(ReplyInfo*)replyInfo{
  345. if ([self.delegate respondsToSelector:@selector(didShowOperationView:indexPath:logFrame:tag:replyInfo:)]) {
  346. [self.delegate didShowOperationView:sender indexPath:self.indexPath logFrame:_currentLog tag:3 replyInfo:replyInfo];
  347. }
  348. }
  349. //消息弹出控件
  350. -(void)showAlertViewText:(NSString *)text
  351. {
  352. UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
  353. message:text
  354. delegate:nil
  355. cancelButtonTitle:@"确定"
  356. otherButtonTitles:nil];
  357. [alert show];
  358. }
  359. @end