@@ -12,8 +12,9 @@
# import "Api+Moments.h"
# import "Api+Moments.h"
# import "NetImageView.h"
# import "NetImageView.h"
# import "EPEmotionColorStorage.h"
# import "EPEmotionColorStorage.h"
# import "SDPhotoBrowser.h"
@ interface EPMomentCell ( )
@ interface EPMomentCell ( ) < SDPhotoBrowserDelegate >
// MARK : - UI Components
// MARK : - UI Components
@@ -125,23 +126,13 @@
make . bottom . equalTo ( self . cardView ) . offset ( -8 ) . priority ( UILayoutPriorityDefaultHigh ) ;
make . bottom . equalTo ( self . cardView ) . offset ( -8 ) . priority ( UILayoutPriorityDefaultHigh ) ;
} ] ;
} ] ;
// 点 赞 按 钮
// 点 赞 按 钮 ( 居 左 显 示 , 评 论 功 能 已 隐 藏 )
[ self . actionBar addSubview : self . likeButton ] ;
[ self . actionBar addSubview : self . likeButton ] ;
[ self . likeButton mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
[ self . likeButton mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . leading . equalTo ( self . actionBar ) . offset ( 15 ) ;
make . leading . equalTo ( self . actionBar ) . offset ( 15 ) ;
make . centerY . equalTo ( self . actionBar ) ;
make . centerY . equalTo ( self . actionBar ) ;
make . width . mas_greaterThanOrEqualTo ( 6 0) ;
make . width . mas_greaterThanOrEqualTo ( 8 0) ;
} ] ;
} ] ;
// 评 论 按 钮
[ self . actionBar addSubview : self . commentButton ] ;
[ self . commentButton mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . centerX . equalTo ( self . actionBar ) ;
make . centerY . equalTo ( self . actionBar ) ;
make . width . mas_greaterThanOrEqualTo ( 60 ) ;
} ] ;
// 右 侧 占 位 ( 去 掉 分 享 按 钮 后 , 右 边 保 持 留 白 )
}
}
// MARK : - Public Methods
// MARK : - Public Methods
@@ -161,11 +152,11 @@
// 配 置 图 片 九 宫 格
// 配 置 图 片 九 宫 格
[ self renderImages : model . dynamicResList ] ;
[ self renderImages : model . dynamicResList ] ;
// 配 置 点 赞 / 评 论 数 ( 安 全 整 型 , 避 免 负 数 和 溢 出 )
// 配 置 点 赞 按 钮 状 态 和 数 字
NSInteger likeCnt = MAX ( 0 , model . likeCount . integerValue ) ;
NSInteger likeCnt = MAX ( 0 , model . likeCount . integerValue ) ;
NSInteger cmtCnt = MAX ( 0 , model . commentCount . integerValue ) ;
self . likeButton . selected = model . isLike ;
[ self . likeButton setTitle : [ NSString stringWithFormat : @ "👍 %ld" , ( long ) likeCnt ] forState : UIControlStateNormal ] ;
[ self . likeButton setTitle : [ NSString stringWithFormat : @ " %ld" , ( long ) likeCnt ] forState : UIControlStateNormal ] ;
[ self . comment Button setTitle : [ NSString stringWithFormat : @ "💬 %ld" , ( long ) cmt Cnt] forState : UIControlStateNormal ] ;
[ self . like Button setTitle : [ NSString stringWithFormat : @ " %ld" , ( long ) like Cnt] forState : UIControlStateSelected ] ;
self . avatarImageView . imageUrl = model . avatar ;
self . avatarImageView . imageUrl = model . avatar ;
@@ -234,6 +225,13 @@
iv . layer . cornerRadius = 6 ;
iv . layer . cornerRadius = 6 ;
iv . layer . masksToBounds = YES ;
iv . layer . masksToBounds = YES ;
iv . contentMode = UIViewContentModeScaleAspectFill ;
iv . contentMode = UIViewContentModeScaleAspectFill ;
iv . userInteractionEnabled = YES ;
iv . tag = i ; // 用 于 识 别 点 击 的 图 片 索 引
// 添 加 点 击 手 势
UITapGestureRecognizer * tap = [ [ UITapGestureRecognizer alloc ] initWithTarget : self action : @ selector ( onImageTapped : ) ] ;
[ iv addGestureRecognizer : tap ] ;
[ self . imagesContainer addSubview : iv ] ;
[ self . imagesContainer addSubview : iv ] ;
[ self . imageViews addObject : iv ] ;
[ self . imageViews addObject : iv ] ;
NSInteger row = i / columns ;
NSInteger row = i / columns ;
@@ -289,40 +287,92 @@
- ( void ) onLikeButtonTapped {
- ( void ) onLikeButtonTapped {
if ( ! self . currentModel ) return ;
if ( ! self . currentModel ) return ;
NSLog ( @ "[NewMomentCell] 点赞动态: %@" , self . currentModel . dynamicId ) ;
// 如 果 已 点 赞 , 执 行 取 消 点 赞
if ( self . currentModel . isLike ) {
[ self performLikeAction : NO ] ;
return ;
}
// 审 核 中 的 动 态 不 可 点 赞
if ( self . currentModel . status = = 0 ) {
NSLog ( @ "[EPMomentCell] 动态审核中,无法点赞" ) ;
// TODO : 可 选 择 显 示 提 示 Toast
return ;
}
// 执 行 点 赞
[ self performLikeAction : YES ] ;
}
- ( void ) performLikeAction : ( BOOL ) isLike {
NSLog ( @ "[EPMomentCell] %@ 动态: %@" , isLike ? @ "点赞" : @ "取消点赞" , self . currentModel . dynamicId ) ;
NSString * uid = [ [ AccountInfoStorage instance ] getUid ] ;
NSString * uid = [ [ AccountInfoStorage instance ] getUid ] ;
NSString * dynamicId = self . currentModel . dynamicId ;
NSString * dynamicId = self . currentModel . dynamicId ;
NSString * status = self . currentModel . isLike ? @ "0 " : @ "1 " ; // 0 = 取 消 , 1 = 点 赞
NSString * status = isLike ? @ "1 " : @ "0 " ; // 0 = 取 消 , 1 = 点 赞
NSString * likedUid = self . currentModel . uid ;
NSString * likedUid = self . currentModel . uid ;
NSString * worldId = self . currentModel . worldId > 0 ? @ ( self . currentModel . worldId ) . stringValue : @ "" ;
NSString * worldId = [ NSString stringWithFormat : @ "%ld" , self . currentModel . worldId ] ;
[ Api momentsLike : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
[ Api momentsLike : ^ ( BaseModel * _Nullable data , NSInteger code , NSString * _Nullable msg ) {
if ( code = = 200 ) {
if ( code = = 200 ) {
// 更 新 点 赞 状 态
// 更 新 点 赞 状 态
self . currentModel . isLike = ! self . currentModel . isLike ;
self . currentModel . isLike = isLike ;
NSInteger likeCount = [ self . currentModel . likeCount integerValue ] ;
NSInteger likeCount = [ self . currentModel . likeCount integerValue ] ;
likeCount + = self . currentModel . isLike ? 1 : -1 ;
likeCount + = isLike ? 1 : -1 ;
likeCount = MAX ( 0 , likeCount ) ; // 防 止 负 数
self . currentModel . likeCount = @ ( likeCount ) . stringValue ;
self . currentModel . likeCount = @ ( likeCount ) . stringValue ;
// 更 新 UI
// 更 新 UI
[ self . likeButton setTitle : [ NSString stringWithFormat : @ "👍 %ld" , ( long ) self . currentModel . likeCount ] forState : UIControlStateNormal ] ;
self . likeButton . selected = self . currentModel . isLike ;
[ self . likeButton setTitle : [ NSString stringWithFormat : @ " %ld" , ( long ) likeCount ] forState : UIControlStateNormal ] ;
[ self . likeButton setTitle : [ NSString stringWithFormat : @ " %ld" , ( long ) likeCount ] forState : UIControlStateSelected ] ;
NSLog ( @ "[New MomentCell] 点赞成功 " ) ;
NSLog ( @ "[EP MomentCell] %@ 成功" , isLike ? @ "点赞" : @ "取消 点赞" ) ;
} else {
} else {
NSLog ( @ "[New MomentCell] 点赞 失败: %@" , msg ) ;
NSLog ( @ "[EP MomentCell] %@ 失败: %@" , isLike ? @ "点赞" : @ "取消点赞" , msg ) ;
}
}
} dynamicId : dynamicId uid : uid status : status likedUid : likedUid worldId : worldId ] ;
} dynamicId : dynamicId uid : uid status : status likedUid : likedUid worldId : worldId ] ;
}
}
- ( void ) onCommentButtonTapped {
// 评 论 功 能 已 隐 藏
NSLog ( @ "[NewMomentCell] 评论" ) ;
// - ( void ) onCommentButtonTapped {
// TODO : 实 现 评 论 逻 辑
// NSLog ( @ "[EPMomentCell] 评论" ) ;
// }
- ( void ) onImageTapped : ( UITapGestureRecognizer * ) gesture {
if ( ! self . currentModel || ! self . currentModel . dynamicResList . count ) return ;
NSInteger index = gesture . view . tag ;
NSLog ( @ "[EPMomentCell] 点击图片索引: %ld" , ( long ) index ) ;
SDPhotoBrowser * browser = [ [ SDPhotoBrowser alloc ] init ] ;
browser . sourceImagesContainerView = self . imagesContainer ;
browser . delegate = self ;
browser . imageCount = self . currentModel . dynamicResList . count ;
browser . currentImageIndex = index ;
[ browser show ] ;
}
}
- ( void ) onShareButtonTapped {
# pragma mark - SDPhotoBrowserDelegate
NSLog ( @ "[NewMomentCell] 分享" ) ;
// TODO : 实 现 分 享 逻 辑
- ( NSURL * ) photoBrowser : ( SDPhotoBrowser * ) browser highQualityImageURLForIndex : ( NSInteger ) index {
if ( index >= 0 && index < self . currentModel . dynamicResList . count ) {
id item = self . currentModel . dynamicResList [ index ] ;
NSString * url = nil ;
if ( [ item isKindOfClass : [ NSDictionary class ] ] ) {
url = [ item valueForKey : @ "resUrl" ] ? : [ item valueForKey : @ "url" ] ;
} else if ( [ item respondsToSelector : @ selector ( resUrl ) ] ) {
url = [ item valueForKey : @ "resUrl" ] ;
}
if ( url ) {
return [ NSURL URLWithString : url ] ;
}
}
return nil ;
}
- ( UIImage * ) photoBrowser : ( SDPhotoBrowser * ) browser placeholderImageForIndex : ( NSInteger ) index {
return [ UIImageConstant defaultBannerPlaceholder ] ;
}
}
// MARK : - Lazy Loading
// MARK : - Lazy Loading
@@ -391,21 +441,20 @@
- ( UIButton * ) likeButton {
- ( UIButton * ) likeButton {
if ( ! _likeButton ) {
if ( ! _likeButton ) {
_likeButton = [ self createActionB uttonWithTitl e: @ "👍 0" ] ;
_likeButton = [ UIButton b uttonWithTyp e: UIButtonTypeCustom ] ;
[ _likeButton setImage : [ UIImage imageNamed : @ "monents_info_like_count_normal" ] forState : UIControlStateNormal ] ;
[ _likeButton setImage : [ UIImage imageNamed : @ "monents_info_like_count_select" ] forState : UIControlStateSelected ] ;
[ _likeButton setTitle : @ " 0" forState : UIControlStateNormal ] ;
_likeButton . titleLabel . font = [ UIFont systemFontOfSize : 13 ] ;
[ _likeButton setTitleColor : [ UIColor colorWithWhite : 0.5 alpha : 1.0 ] forState : UIControlStateNormal ] ;
[ _likeButton setTitleColor : [ UIColor colorWithWhite : 0.5 alpha : 1.0 ] forState : UIControlStateSelected ] ;
[ _likeButton addTarget : self action : @ selector ( onLikeButtonTapped ) forControlEvents : UIControlEventTouchUpInside ] ;
[ _likeButton addTarget : self action : @ selector ( onLikeButtonTapped ) forControlEvents : UIControlEventTouchUpInside ] ;
}
}
return _likeButton ;
return _likeButton ;
}
}
// 评 论 按 钮 已 移 除
- ( UIButton * ) commentButton {
- ( UIButton * ) commentButton {
if ( ! _commentButton ) {
_commentButton = [ self createActionButtonWithTitle : @ "💬 0" ] ;
[ _commentButton addTarget : self action : @ selector ( onCommentButtonTapped ) forControlEvents : UIControlEventTouchUpInside ] ;
}
return _commentButton ;
}
- ( UIButton * ) shareButton {
return nil ;
return nil ;
}
}