308 lines
11 KiB
Objective-C
308 lines
11 KiB
Objective-C
//
|
|
// XPMonentsTooBarView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/12.
|
|
//
|
|
|
|
#import "XPMonentsTooBarView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "TTPopup.h"
|
|
#import "XPHtmlUrl.h"
|
|
#import "XPShareView.h"
|
|
#import "XCHUDTool.h"
|
|
#import "XPMacro.h"
|
|
#import "ApiHost.h"
|
|
#import "XPHtmlUrl.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "Api+Monents.h"
|
|
///Model
|
|
#import "MonentsInfoModel.h"
|
|
///View
|
|
#import "XPWebViewController.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
|
|
@interface XPMonentsTooBarView ()<XCShareViewDelegate>
|
|
///举报
|
|
@property (nonatomic,strong) UIButton *reportButton;
|
|
///喜欢的容器
|
|
@property (nonatomic,strong) UIView * likeView;
|
|
///喜欢
|
|
@property (nonatomic,strong) UIButton *likeButton;
|
|
///喜欢的个数
|
|
@property (nonatomic,strong) UILabel *likeLabel;
|
|
///评论的容器
|
|
@property (nonatomic,strong) UIView * commentView;
|
|
///评论
|
|
@property (nonatomic,strong) UIButton *commentButton;
|
|
///评论数
|
|
@property (nonatomic,strong) UILabel *commentLabel;
|
|
///分享
|
|
@property (nonatomic,strong) UIButton *shareButton;
|
|
///分割线
|
|
@property (nonatomic,strong) UIView * lineView;
|
|
|
|
@end
|
|
|
|
@implementation XPMonentsTooBarView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.reportButton];
|
|
[self addSubview:self.likeView];
|
|
[self addSubview:self.commentView];
|
|
[self addSubview:self.shareButton];
|
|
[self addSubview:self.lineView];
|
|
|
|
[self.likeView addSubview:self.likeButton];
|
|
[self.likeView addSubview:self.likeLabel];
|
|
[self.commentView addSubview:self.commentButton];
|
|
[self.commentView addSubview:self.commentLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self).offset(70);
|
|
make.top.mas_equalTo(self).offset(24);
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
}];
|
|
|
|
[self.likeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.likeButton.mas_left);
|
|
make.height.mas_equalTo(22);
|
|
make.centerY.mas_equalTo(self.reportButton);
|
|
make.right.mas_equalTo(self.commentView.mas_left).offset(-12);
|
|
}];
|
|
|
|
[self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.likeView.mas_right).offset(-3);
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
}];
|
|
|
|
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
make.right.mas_equalTo(self.likeLabel.mas_left).offset(-3);
|
|
}];
|
|
|
|
[self.commentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.commentButton.mas_left).offset(-2);
|
|
make.height.mas_equalTo(22);
|
|
make.centerY.mas_equalTo(self.reportButton);
|
|
make.right.mas_equalTo(self.shareButton.mas_left).offset(-12);
|
|
}];
|
|
|
|
|
|
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.right.mas_equalTo(self.commentLabel.mas_left).offset(-2);
|
|
}];
|
|
|
|
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.commentView.mas_right).offset(-3);
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
}];
|
|
|
|
[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.right.mas_equalTo(self).offset(-32);
|
|
make.centerY.mas_equalTo(self.reportButton);
|
|
}];
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(16);
|
|
make.bottom.mas_equalTo(self);
|
|
make.height. mas_equalTo(1);
|
|
}];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)commonButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTooBarView:didClickCommon:)]) {
|
|
self.commentButton.userInteractionEnabled = YES;
|
|
[self.delegate xPMonentsTooBarView:self didClickCommon:self.monentsInfo];
|
|
} else {
|
|
self.commentButton.userInteractionEnabled = NO;
|
|
}
|
|
}
|
|
|
|
- (void)likeButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTooBarView:didClickLike:)]) {
|
|
[self.delegate xPMonentsTooBarView:self didClickLike:self.monentsInfo];
|
|
}
|
|
}
|
|
|
|
- (void)reportButtonAction:(UIButton *)sender {
|
|
TTActionSheetConfig *action;
|
|
if (self.monentsInfo.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
|
|
action = [TTActionSheetConfig normalTitle:@"删除" clickAction:^{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTooBarView:didClickDelete:)]) {
|
|
[self.delegate xPMonentsTooBarView:self didClickDelete:self.monentsInfo];
|
|
}
|
|
}];
|
|
} else {
|
|
action = [TTActionSheetConfig normalTitle:@"举报" clickAction:^{
|
|
NSString * url= [NSString stringWithFormat:@"%@?reportUid=%@&source=%@", URLWithType(kReportRoomURL),self.monentsInfo.uid, @"WORLDDYNAMIC"];
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
|
webVC.url = url;
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
|
}];
|
|
}
|
|
[TTPopup actionSheetWithItems:@[action]];
|
|
}
|
|
|
|
- (void)shareButtonAction:(UIButton *)sender {
|
|
XPShareItem *friend = [XPShareItem itemWitTag:XPShareItemTagAppFriends title:@"好友" imageName:@"share_friend" disableImageName:@"share_friend"];
|
|
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
|
|
XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagWeChat title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
|
|
XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagQQ title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
|
|
XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagQQZone title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
|
|
NSArray * items = @[friend,wechat,cycle, qq, qqzone];
|
|
CGFloat margin = 15;
|
|
CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65);
|
|
XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init];
|
|
NSString * title= self.monentsInfo.nick;
|
|
if (self.monentsInfo.nick.length > 6) {
|
|
title = [title substringToIndex:6];
|
|
}
|
|
shareInfo.nick = title;
|
|
shareInfo.content = self.monentsInfo.content;
|
|
shareInfo.imageUrl = self.monentsInfo.avatar;
|
|
shareInfo.shareTitle = [NSString stringWithFormat:@"%@发布了一条动态", title];
|
|
shareInfo.shareContent = self.monentsInfo.content;
|
|
shareInfo.shareImageUrl = self.monentsInfo.avatar;
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString *urlStr = [NSString stringWithFormat:@"%@/%@?uid=%@&dynamicId=%@&worldId=%ld",API_HOST_URL, URLWithType(kMonentsShareURL), uid, self.monentsInfo.dynamicId, self.monentsInfo.worldId];
|
|
shareInfo.shareUrl = urlStr;
|
|
shareInfo.dynamicId = self.monentsInfo.dynamicId;
|
|
shareInfo.uid = self.monentsInfo.uid;
|
|
shareInfo.worldId = [NSString stringWithFormat:@"%ld", self.monentsInfo.worldId];
|
|
XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo];
|
|
shareView.delegate = self;
|
|
[TTPopup popupView:shareView style:TTPopupStyleActionSheet];
|
|
}
|
|
|
|
#pragma mark - #pragma mark - XCShareViewDelegate
|
|
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message {
|
|
[TTPopup dismiss];
|
|
[XCHUDTool showErrorWithMessage:message];
|
|
}
|
|
|
|
- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo{
|
|
[Api userShareMonents:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
} dynamicId:shareInfo.dynamicId uid:shareInfo.uid worldId:shareInfo.worldId shareUid:[AccountInfoStorage instance].getUid];
|
|
[TTPopup dismiss];
|
|
}
|
|
|
|
- (void)shareViewDidClickCancel:(XPShareView *)shareView {
|
|
[TTPopup dismiss];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
|
|
_monentsInfo = monentsInfo;
|
|
if (_monentsInfo) {
|
|
self.likeButton.selected = _monentsInfo.isLike;
|
|
self.likeLabel.text = _monentsInfo.likeCount.length > 0 ? _monentsInfo.likeCount : @"0";
|
|
self.commentLabel.text = _monentsInfo.commentCount.length > 0 ? _monentsInfo.commentCount : @"0";
|
|
}
|
|
}
|
|
|
|
- (UIView *)likeView {
|
|
if (!_likeView) {
|
|
_likeView = [[UIView alloc] init];
|
|
_likeView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _likeView;
|
|
}
|
|
|
|
- (UIButton *)likeButton {
|
|
if (!_likeButton) {
|
|
_likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_normal"] forState:UIControlStateNormal];
|
|
[_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_select"] forState:UIControlStateSelected];
|
|
[_likeButton addTarget:self action:@selector(likeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _likeButton;
|
|
}
|
|
|
|
- (UILabel *)likeLabel {
|
|
if (!_likeLabel) {
|
|
_likeLabel = [[UILabel alloc] init];
|
|
_likeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_likeLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _likeLabel;
|
|
}
|
|
|
|
|
|
- (UIView *)commentView {
|
|
if (!_commentView) {
|
|
_commentView = [[UIView alloc] init];
|
|
_commentView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _commentView;
|
|
}
|
|
|
|
- (UIButton *)commentButton {
|
|
if (!_commentButton) {
|
|
_commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_commentButton setImage:[UIImage imageNamed:@"monents_info_comment_count"] forState:UIControlStateNormal];
|
|
[_commentButton setImage:[UIImage imageNamed:@"monents_info_comment_count"] forState:UIControlStateSelected];
|
|
[_commentButton addTarget:self action:@selector(commonButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _commentButton;
|
|
}
|
|
|
|
- (UILabel *)commentLabel {
|
|
if (!_commentLabel) {
|
|
_commentLabel = [[UILabel alloc] init];
|
|
_commentLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_commentLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _commentLabel;
|
|
}
|
|
|
|
- (UIButton *)reportButton {
|
|
if (!_reportButton) {
|
|
_reportButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_reportButton setImage:[UIImage imageNamed:@"monents_info_like_report"] forState:UIControlStateNormal];
|
|
[_reportButton setImage:[UIImage imageNamed:@"monents_info_like_report"] forState:UIControlStateSelected];
|
|
[_reportButton addTarget:self action:@selector(reportButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _reportButton;
|
|
}
|
|
|
|
- (UIButton *)shareButton {
|
|
if (!_shareButton) {
|
|
_shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_shareButton setImage:[UIImage imageNamed:@"monents_info_like_share"] forState:UIControlStateNormal];
|
|
[_shareButton setImage:[UIImage imageNamed:@"monents_info_like_share"] forState:UIControlStateSelected];
|
|
[_shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _shareButton;
|
|
}
|
|
|
|
- (UIView *)lineView {
|
|
if (!_lineView) {
|
|
_lineView = [[UIView alloc] init];
|
|
_lineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _lineView;
|
|
}
|
|
|
|
@end
|