Skip to content

Commit

Permalink
Update Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Mar 21, 2018
1 parent 2c095db commit c6b5b30
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@implementation SJVideoModel

/// test test test test test
+ (NSArray<SJVideoModel *> *)videoModelsWithTapActionDelegate:(id<NSAttributedStringTappedDelegate>)actionDelegate {
NSArray<SJUserModel *> *users = [SJUserModel userModels];
NSArray<NSString *> *titles =
Expand All @@ -34,7 +35,7 @@ @implementation SJVideoModel


// prepare test data
for ( int i = 0 ; i < 88 ; ++ i ) {
for ( int i = 0 ; i < 100 ; ++ i ) {
SJVideoModel *model =
[[SJVideoModel alloc] initWithTitle:titles[arc4random() % titles.count]
videoId:i
Expand All @@ -43,10 +44,9 @@ @implementation SJVideoModel
playURLStr:@"http://video.cdn.lanwuzhe.com/14945858406905f0c"
coverURLStr:coverURLStrs[arc4random() % coverURLStrs.count]];

// make video title layout
[SJVideoListTableViewCell sync_makeVideoContent:^(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor) {
// `string regular`
NSString *actionStrRexp = @"([@][^\\s]+\\s)|([#][^#]+#)|((http)[^\\s]+\\s)";
// make `attributes string`
NSString *actionStrRexp = @"([@][^\\s]+\\s)|([#][^#]+#)|((http)[^\\s]+\\s)"; // `string regular`
NSMutableAttributedString *attrStr = sj_makeAttributesString(^(SJAttributeWorker * _Nonnull make) {
make.font(font).textColor(textColor);
make.insert(model.title, 0);
Expand All @@ -59,18 +59,21 @@ @implementation SJVideoModel
model.videoContentLayout = sj_layout(contentMaxWidth, attrStr);
}];

[SJVideoListTableViewCell sync_makeNickName:^(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor) {
// make nickname layout
[SJVideoListTableViewCell sync_makeNickname:^(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor) {
NSMutableAttributedString *attrStr = sj_makeAttributesString(^(SJAttributeWorker * _Nonnull make) {
make.font(font).textColor(textColor);
make.insert(model.creator.nickname, 0);
});
model.nicknameLayout = sj_layout(contentMaxWidth, attrStr);
}];

// make video create time layout
[SJVideoListTableViewCell sync_makeCreateTime:^(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor) {
NSMutableAttributedString *attrStr = sj_makeAttributesString(^(SJAttributeWorker * _Nonnull make) {
make.font(font).textColor(textColor);
make.insert(sj_processTime(model.createTime, [NSDate date].timeIntervalSince1970), 0) ; // this test time
// this test time
make.insert(sj_processTime(model.createTime, [NSDate date].timeIntervalSince1970), 0) ;
});
model.createTimeLayout = sj_layout(contentMaxWidth, attrStr);
}];
Expand Down Expand Up @@ -175,10 +178,10 @@ @implementation SJUserModel
return testUsersM;
}

- (instancetype)initWithNickname:(NSString *)nickName avatar:(NSString *)avatar {
- (instancetype)initWithNickname:(NSString *)nickname avatar:(NSString *)avatar {
self = [super init];
if ( !self ) return nil;
_nickname = nickName;
_nickname = nickname;
_avatar = avatar;
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,30 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
@class SJVideoModel;

@protocol SJVideoListTableViewCellDelegate, NSAttributedStringTappedDelegate;

@interface SJVideoListTableViewCell : UITableViewCell
typedef void(^SJTextAppearance)(CGFloat maxWidth, UIFont *font, UIColor *textColor);

@property (nonatomic, weak) id<SJVideoListTableViewCellDelegate> delegate;
@interface SJVideoListTableViewCell : UITableViewCell

// cell height
+ (CGFloat)heightWithContentHeight:(CGFloat)contentHeight;

+ (void)sync_makeVideoContent:(void(^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block;
+ (void)sync_makeVideoContent:(SJTextAppearance)block;

+ (void)sync_makeNickName:(void (^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block;
+ (void)sync_makeNickname:(SJTextAppearance)block;

+ (void)sync_makeCreateTime:(void (^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block;
+ (void)sync_makeCreateTime:(SJTextAppearance)block;

// data source
@property (nonatomic, strong) SJVideoModel *model;
@property (nonatomic, strong, nullable) SJVideoModel *model;
@property (nonatomic, weak, nullable) id<SJVideoListTableViewCellDelegate> delegate;

@end

@protocol SJVideoListTableViewCellDelegate <NSObject>

@protocol SJVideoListTableViewCellDelegate <NSObject>
@optional
- (void)clickedPlayOnTabCell:(SJVideoListTableViewCell *)cell playerParentView:(UIView *)playerParentView;

@end
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,20 @@ + (CGFloat)contentMaxWidth {
return SJScreen_W() - 12 * 2;
}

+ (void)sync_makeVideoContent:(void(^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block {
+ (void)sync_makeVideoContent:(SJTextAppearance)block {
if ( block ) block([self contentMaxWidth], [UIFont boldSystemFontOfSize:14], [UIColor blackColor]);
}

+ (void)sync_makeNickName:(void (^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block {
+ (void)sync_makeNickname:(SJTextAppearance)block {
if ( block ) block([self nicknameMaxWidth], [UIFont boldSystemFontOfSize:14], [UIColor blackColor]);
}

+ (void)sync_makeCreateTime:(void (^)(CGFloat contentMaxWidth, UIFont *font, UIColor *textColor))block {
+ (void)sync_makeCreateTime:(SJTextAppearance)block {
if ( block ) block([self nicknameMaxWidth], [UIFont boldSystemFontOfSize:12], [UIColor blackColor]);
}


+ (CGFloat)heightWithContentHeight:(CGFloat)contentHeight {
return 14 + 44 + 8 + contentHeight + 8 + ([self contentMaxWidth] * 9 / 16.0f) + 8;
return 14 + 44 + 8 + contentHeight + 8 + (SJScreen_W() * 9 / 16.0f) + 8;
}


Expand Down Expand Up @@ -140,7 +139,7 @@ - (void)_setupViews {

[_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_contentLabel.mas_bottom).offset(8);
make.leading.trailing.equalTo(_contentLabel);
make.leading.trailing.offset(0);
make.height.equalTo(_coverImageView.mas_width).multipliedBy(9.0f / 16);
}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface NSMutableAttributedString (SJAdd)

/**
* add some tap action. see `NSAttributedStringTappedDelegate` & `YYTapActionLabel`.
* add some tap action. see `NSAttributedStringTappedDelegate` & use `YYTapActionLabel`.
*
* attrStr.tappedDelegate = self;
* attrStr.addTapAction(@"我们"); // 所有的`我们`添加点击事件, 回调将在代理方法`NSAttributedStringActionDelegate`中回调.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ @implementation NSMutableAttributedString (SJAdd)
if ( [self attribute:YYTextBindingAttributeName atIndex:range.location effectiveRange:NULL] ) return;
YYTextBinding *binding = [YYTextBinding bindingWithDeleteConfirm:YES];
[self yy_setTextBinding:binding range:range];
// [self setTextBinding:binding range:range];
// [self setTextBinding:binding range:range];
}];
});
};
Expand Down

0 comments on commit c6b5b30

Please sign in to comment.