Skip to content

Commit ea122ea

Browse files
committed
MRPRCommentCell
1 parent 58fb451 commit ea122ea

7 files changed

Lines changed: 232 additions & 1 deletion

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
4E4ABBEA1A653027004760D9 /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E4ABBE91A653027004760D9 /* WebViewController.m */; };
8282
4E4D6A521B1C555400FD2E49 /* MRPRComment.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E4D6A511B1C555400FD2E49 /* MRPRComment.m */; };
8383
4E4D6A551B1C55EB00FD2E49 /* MRPRCommentItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E4D6A541B1C55EB00FD2E49 /* MRPRCommentItem.m */; };
84+
4E4D6A581B1C5DC000FD2E49 /* MRPRCommentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E4D6A571B1C5DC000FD2E49 /* MRPRCommentCell.m */; };
85+
4E4D6A5B1B1C5DDF00FD2E49 /* MRPRCommentCCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E4D6A5A1B1C5DDF00FD2E49 /* MRPRCommentCCell.m */; };
8486
4E53EB521AFA03990034FE1C /* RKSwipeBetweenViewControllers.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E53EB511AFA03990034FE1C /* RKSwipeBetweenViewControllers.m */; };
8587
4E53EB591AFB090E0034FE1C /* nav_page_selected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E53EB571AFB090E0034FE1C /* nav_page_selected@2x.png */; };
8688
4E53EB5A1AFB090E0034FE1C /* nav_page_unselected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E53EB581AFB090E0034FE1C /* nav_page_unselected@2x.png */; };
@@ -769,6 +771,10 @@
769771
4E4D6A511B1C555400FD2E49 /* MRPRComment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRPRComment.m; sourceTree = "<group>"; };
770772
4E4D6A531B1C55EB00FD2E49 /* MRPRCommentItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRPRCommentItem.h; sourceTree = "<group>"; };
771773
4E4D6A541B1C55EB00FD2E49 /* MRPRCommentItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRPRCommentItem.m; sourceTree = "<group>"; };
774+
4E4D6A561B1C5DC000FD2E49 /* MRPRCommentCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRPRCommentCell.h; sourceTree = "<group>"; };
775+
4E4D6A571B1C5DC000FD2E49 /* MRPRCommentCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRPRCommentCell.m; sourceTree = "<group>"; };
776+
4E4D6A591B1C5DDF00FD2E49 /* MRPRCommentCCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MRPRCommentCCell.h; sourceTree = "<group>"; };
777+
4E4D6A5A1B1C5DDF00FD2E49 /* MRPRCommentCCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MRPRCommentCCell.m; sourceTree = "<group>"; };
772778
4E53EB501AFA03990034FE1C /* RKSwipeBetweenViewControllers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKSwipeBetweenViewControllers.h; sourceTree = "<group>"; };
773779
4E53EB511AFA03990034FE1C /* RKSwipeBetweenViewControllers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKSwipeBetweenViewControllers.m; sourceTree = "<group>"; };
774780
4E53EB571AFB090E0034FE1C /* nav_page_selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "nav_page_selected@2x.png"; sourceTree = "<group>"; };
@@ -3180,6 +3186,8 @@
31803186
4E5F39011AC951060010515D /* TaskCommentCCell.m */,
31813187
4E5F39031ACA958C0010515D /* TopicCommentCCell.h */,
31823188
4E5F39041ACA958C0010515D /* TopicCommentCCell.m */,
3189+
4E4D6A591B1C5DDF00FD2E49 /* MRPRCommentCCell.h */,
3190+
4E4D6A5A1B1C5DDF00FD2E49 /* MRPRCommentCCell.m */,
31833191
);
31843192
path = CCell;
31853193
sourceTree = "<group>";
@@ -3300,6 +3308,8 @@
33003308
4ECF702B1B1704C5000280FF /* NProjectItemCell.m */,
33013309
4ECF704A1B1876CB000280FF /* MRPRListCell.h */,
33023310
4ECF704B1B1876CB000280FF /* MRPRListCell.m */,
3311+
4E4D6A561B1C5DC000FD2E49 /* MRPRCommentCell.h */,
3312+
4E4D6A571B1C5DC000FD2E49 /* MRPRCommentCell.m */,
33033313
);
33043314
path = Cell;
33053315
sourceTree = "<group>";
@@ -3738,6 +3748,7 @@
37383748
4ECE8B041A3946C10021E29C /* UnReadManager.m in Sources */,
37393749
4EA679131A1466A6001A0324 /* ProjectFiles.m in Sources */,
37403750
4EBDA87C1A6640340035ED96 /* UIActionSheet+Common.m in Sources */,
3751+
4E4D6A581B1C5DC000FD2E49 /* MRPRCommentCell.m in Sources */,
37413752
B94C1B6E1AC98CCE0000C271 /* NewProjectTypeViewController.m in Sources */,
37423753
4E96E7BB1A1B25D40037C098 /* DirectoryWatcher.m in Sources */,
37433754
EBDD2E4E1AEA159D0024B952 /* ProjectTopicLabelView.m in Sources */,
@@ -3912,6 +3923,7 @@
39123923
3A38784C1AE36EF00078D5DE /* TopicListView.m in Sources */,
39133924
8E1C3DEA19E7D58A00EF3032 /* AbstractActionSheetPicker.m in Sources */,
39143925
8EA6D1AF19E240C40076D59C /* CodingTips.m in Sources */,
3926+
4E4D6A5B1B1C5DDF00FD2E49 /* MRPRCommentCCell.m in Sources */,
39153927
8EF643C219FF7E2900F7EEB0 /* TaskCommentTopCell.m in Sources */,
39163928
8E64ED7D19ED0CE3006E99DA /* QBAssetsCollectionOverlayView.m in Sources */,
39173929
8EA6D14919E240C40076D59C /* UserTweetsViewController.m in Sources */,

Coding_iOS/Models/MRPRCommentItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
@property (strong, nonatomic) NSDate *created_at;
1616
@property (strong, nonatomic) User *author;
1717
@property (strong, nonatomic) NSString *content, *noteable_type;
18+
@property (readwrite, nonatomic, strong) HtmlMedia *htmlMedia;
1819

1920
@end

Coding_iOS/Models/MRPRCommentItem.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
#import "MRPRCommentItem.h"
1010

1111
@implementation MRPRCommentItem
12-
12+
- (void)setContent:(NSString *)content{
13+
if (_content != content) {
14+
_htmlMedia = [HtmlMedia htmlMediaWithString:content showType:MediaShowTypeCode];
15+
_content = _htmlMedia.contentDisplay;
16+
}
17+
}
1318
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// MRPRCommentCCell.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/6/1.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kCCellIdentifier_MRPRCommentCCell @"MRPRCommentCCell"
10+
11+
#import "TaskCommentCCell.h"
12+
13+
@interface MRPRCommentCCell : TaskCommentCCell
14+
15+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// MRPRCommentCCell.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/6/1.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#import "MRPRCommentCCell.h"
10+
11+
@implementation MRPRCommentCCell
12+
13+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// MRPRCommentCell.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/6/1.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kCellIdentifier_MRPRCommentCell @"MRPRCommentCell"
10+
#define kCellIdentifier_MRPRCommentCell_Media @"MRPRCommentCell_Media"
11+
12+
#import <UIKit/UIKit.h>
13+
#import "MRPRCommentItem.h"
14+
15+
@interface MRPRCommentCell : UITableViewCell
16+
@property (strong, nonatomic) MRPRCommentItem *curItem;
17+
@property (strong, nonatomic) UITTTAttributedLabel *contentLabel;
18+
19+
+ (CGFloat)cellHeightWithObj:(id)obj;
20+
21+
@end
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
//
2+
// MRPRCommentCell.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/6/1.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kMRPRCommentCell_FontContent [UIFont systemFontOfSize:15]
10+
11+
#import "MRPRCommentCell.h"
12+
#import "UICustomCollectionView.h"
13+
#import "MRPRCommentCCell.h"
14+
#import "MJPhotoBrowser.h"
15+
16+
@interface MRPRCommentCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
17+
@property (strong, nonatomic) UIImageView *ownerIconView;
18+
@property (strong, nonatomic) UILabel *timeLabel;
19+
@property (strong, nonatomic) UICustomCollectionView *imageCollectionView;
20+
21+
@end
22+
23+
@implementation MRPRCommentCell
24+
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
25+
{
26+
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
27+
if (self) {
28+
// Initialization code
29+
CGFloat curBottomY = 10;
30+
if (!_ownerIconView) {
31+
_ownerIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, curBottomY, 33, 33)];
32+
[_ownerIconView doCircleFrame];
33+
[self.contentView addSubview:_ownerIconView];
34+
}
35+
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
36+
if (!_contentLabel) {
37+
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 40, curBottomY, curWidth, 30)];
38+
_contentLabel.textColor = [UIColor colorWithHexString:@"0x555555"];
39+
_contentLabel.font = kMRPRCommentCell_FontContent;
40+
_contentLabel.linkAttributes = kLinkAttributes;
41+
_contentLabel.activeLinkAttributes = kLinkAttributesActive;
42+
[self.contentView addSubview:_contentLabel];
43+
}
44+
CGFloat commentBtnWidth = 40;
45+
if (!_timeLabel) {
46+
_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth +40, 0, curWidth- commentBtnWidth, 20)];
47+
_timeLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
48+
_timeLabel.font = [UIFont systemFontOfSize:12];
49+
[self.contentView addSubview:_timeLabel];
50+
}
51+
if ([reuseIdentifier isEqualToString:kCellIdentifier_MRPRCommentCell_Media]) {
52+
if (!self.imageCollectionView) {
53+
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
54+
self.imageCollectionView = [[UICustomCollectionView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 40, 0, curWidth, 43) collectionViewLayout:layout];
55+
self.imageCollectionView.scrollEnabled = NO;
56+
[self.imageCollectionView setBackgroundView:nil];
57+
[self.imageCollectionView setBackgroundColor:[UIColor clearColor]];
58+
[self.imageCollectionView registerClass:[MRPRCommentCCell class] forCellWithReuseIdentifier:kCCellIdentifier_MRPRCommentCCell];
59+
self.imageCollectionView.dataSource = self;
60+
self.imageCollectionView.delegate = self;
61+
[self.contentView addSubview:self.imageCollectionView];
62+
}
63+
}
64+
}
65+
return self;
66+
}
67+
68+
- (void)setCurItem:(MRPRCommentItem *)curItem{
69+
_curItem = curItem;
70+
71+
if (!_curItem) {
72+
return;
73+
}
74+
CGFloat curBottomY = 10;
75+
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
76+
[_ownerIconView sd_setImageWithURL:[_curItem.author.avatar urlImageWithCodePathResizeToView:_ownerIconView] placeholderImage:kPlaceholderMonkeyRoundView(_ownerIconView)];
77+
[_contentLabel setLongString:_curItem.content withFitWidth:curWidth];
78+
79+
for (HtmlMediaItem *item in _curItem.htmlMedia.mediaItems) {
80+
if (item.displayStr.length > 0 && !(item.type == HtmlMediaItemType_Code ||item.type == HtmlMediaItemType_EmotionEmoji)) {
81+
[_contentLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
82+
}
83+
}
84+
85+
curBottomY += [_curItem.content getHeightWithFont:kMRPRCommentCell_FontContent constrainedToSize:CGSizeMake(curWidth, CGFLOAT_MAX)] + 5;
86+
87+
NSInteger imagesCount = _curItem.htmlMedia.imageItems.count;
88+
if (imagesCount > 0) {
89+
self.imageCollectionView.hidden = NO;
90+
[self.imageCollectionView setFrame:CGRectMake(kPaddingLeftWidth +40, curBottomY, curWidth, [MRPRCommentCell imageCollectionViewHeightWithCount:imagesCount])];
91+
[self.imageCollectionView reloadData];
92+
}else{
93+
self.imageCollectionView.hidden = YES;
94+
}
95+
96+
curBottomY += [MRPRCommentCell imageCollectionViewHeightWithCount:imagesCount];
97+
98+
[_timeLabel setY:curBottomY];
99+
_timeLabel.text = [NSString stringWithFormat:@"%@ %@", _curItem.author.name, [_curItem.created_at stringTimesAgo]];
100+
}
101+
102+
+ (CGFloat)cellHeightWithObj:(id)obj{
103+
CGFloat cellHeight = 0;
104+
if ([obj isKindOfClass:[MRPRCommentItem class]]) {
105+
MRPRCommentItem *curItem = (MRPRCommentItem *)obj;
106+
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
107+
cellHeight += 10 +[curItem.content getHeightWithFont:kMRPRCommentCell_FontContent constrainedToSize:CGSizeMake(curWidth, CGFLOAT_MAX)] + 5 +20 +10;
108+
cellHeight += [self imageCollectionViewHeightWithCount:curItem.htmlMedia.imageItems.count];
109+
}
110+
return cellHeight;
111+
}
112+
113+
+ (CGFloat)imageCollectionViewHeightWithCount:(NSInteger)countNum{
114+
if (countNum <= 0) {
115+
return 0;
116+
}
117+
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
118+
NSInteger numInOneLine = floorf((curWidth +5)/(33 + 5));
119+
NSInteger numOfline = ceilf(countNum/(float)numInOneLine);
120+
return (43 *numOfline);
121+
}
122+
123+
#pragma mark Collection M
124+
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
125+
return _curItem.htmlMedia.imageItems.count;
126+
}
127+
128+
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
129+
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
130+
MRPRCommentCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_MRPRCommentCCell forIndexPath:indexPath];
131+
ccell.curMediaItem = [_curItem.htmlMedia.imageItems objectAtIndex:indexPath.row];
132+
return ccell;
133+
}
134+
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
135+
return [MRPRCommentCCell ccellSize];
136+
}
137+
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
138+
return UIEdgeInsetsZero;
139+
}
140+
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
141+
return 10;
142+
}
143+
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
144+
return 5;
145+
}
146+
147+
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
148+
// 显示大图
149+
int count = (int)_curItem.htmlMedia.imageItems.count;
150+
NSMutableArray *photos = [NSMutableArray arrayWithCapacity:count];
151+
for (int i = 0; i<count; i++) {
152+
HtmlMediaItem *imageItem = [_curItem.htmlMedia.imageItems objectAtIndex:i];
153+
MJPhoto *photo = [[MJPhoto alloc] init];
154+
photo.url = [NSURL URLWithString:imageItem.src]; // 图片路径
155+
[photos addObject:photo];
156+
}
157+
// 2.显示相册
158+
MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
159+
browser.currentPhotoIndex = indexPath.row; // 弹出相册时显示的第一张图片是?
160+
browser.photos = photos; // 设置所有的图片
161+
[browser show];
162+
}
163+
164+
@end

0 commit comments

Comments
 (0)