376 lines
15 KiB
Objective-C
376 lines
15 KiB
Objective-C
//
|
|
// XPMonentsTooBarView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/12.
|
|
//
|
|
|
|
#import "XPMomentsTooBarView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
///Tool
|
|
#import "TTPopup.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "Api+Moments.h"
|
|
///Model
|
|
#import "MomentsInfoModel.h"
|
|
///View
|
|
#import "XPWebViewController.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
|
|
#import "ShareHelder.h"
|
|
|
|
@interface XPMomentsTooBarView ()
|
|
///喜欢的容器
|
|
@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) UIView * lineView;
|
|
///举报
|
|
@property (nonatomic,strong) UIButton *reportButton;
|
|
///是不是我的动态
|
|
@property (nonatomic,assign) BOOL isMyMonents;
|
|
@end
|
|
|
|
@implementation XPMomentsTooBarView
|
|
|
|
- (instancetype)initDynamicWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
self.isMyMonents = YES;
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
|
|
- (void)setIsInUserDetail:(BOOL)isInUserDetail {
|
|
_isInUserDetail = isInUserDetail;
|
|
if (isInUserDetail) {
|
|
self.likeLabel.textColor = [UIColor whiteColor];
|
|
self.commentLabel.textColor = [UIColor whiteColor];
|
|
[self.reportButton setImage:[UIImage imageNamed:@"monents_info_like_report_new"] forState:UIControlStateNormal];
|
|
[self.reportButton setImage:[UIImage imageNamed:@"monents_info_like_report_new"] forState:UIControlStateSelected];
|
|
[self.commentButton setImage:[UIImage imageNamed:@"monents_info_comment_count_new"] forState:UIControlStateNormal];
|
|
[self.commentButton setImage:[UIImage imageNamed:@"monents_info_comment_count_new"] forState:UIControlStateSelected];
|
|
[self.likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_normal_new"] forState:UIControlStateNormal];
|
|
[self.likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_select_new"] forState:UIControlStateSelected];
|
|
}
|
|
}
|
|
|
|
- (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.likeView];
|
|
[self addSubview:self.commentView];
|
|
[self addSubview:self.lineView];
|
|
[self addSubview:self.reportButton];
|
|
|
|
[self.likeView addSubview:self.likeButton];
|
|
[self.likeView addSubview:self.likeLabel];
|
|
[self.commentView addSubview:self.commentButton];
|
|
[self.commentView addSubview:self.commentLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
if (self.isMyMonents) {
|
|
[self.likeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(12);
|
|
make.height.mas_equalTo(18);
|
|
make.top.mas_equalTo(self).offset(0);
|
|
make.width.greaterThanOrEqualTo(@62);
|
|
}];
|
|
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(18, 18));
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
make.leading.mas_equalTo(self.likeView);
|
|
}];
|
|
[self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(self.likeButton.mas_trailing).mas_offset(4);
|
|
make.trailing.equalTo(self.likeView);
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
}];
|
|
|
|
[self.commentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.height.mas_equalTo(self.likeView);
|
|
make.width.greaterThanOrEqualTo(@62);
|
|
make.leading.mas_equalTo(self.likeView.mas_trailing).offset(5);
|
|
}];
|
|
|
|
|
|
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(18, 18));
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.leading.mas_equalTo(self.commentView);
|
|
}];
|
|
|
|
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.commentButton.mas_trailing).offset(4);
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.trailing.equalTo(self.commentView);
|
|
}];
|
|
|
|
[self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(self).offset(-12);
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
}];
|
|
} else {
|
|
self.lineView.hidden = YES;
|
|
[self.likeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(18);
|
|
make.height.mas_equalTo(18);
|
|
make.top.mas_equalTo(self).offset(10);
|
|
make.width.greaterThanOrEqualTo(@62);
|
|
}];
|
|
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(18, 18));
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
make.leading.mas_equalTo(self.likeView);
|
|
}];
|
|
[self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(self.likeButton.mas_trailing).mas_offset(4);
|
|
make.trailing.equalTo(self.likeView);
|
|
make.centerY.mas_equalTo(self.likeView);
|
|
}];
|
|
|
|
[self.commentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.height.mas_equalTo(self.likeView);
|
|
make.width.greaterThanOrEqualTo(@62);
|
|
make.leading.mas_equalTo(self.likeView.mas_trailing).offset(5);
|
|
}];
|
|
|
|
|
|
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(18, 18));
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.leading.mas_equalTo(self.commentView);
|
|
}];
|
|
|
|
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.commentButton.mas_trailing).offset(4);
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.trailing.equalTo(self.commentView);
|
|
}];
|
|
|
|
[self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(self).offset(-18);
|
|
make.centerY.mas_equalTo(self.commentView);
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
}];
|
|
}
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)reportButtonAction:(UIButton *)sender {
|
|
|
|
NSMutableArray *array = [NSMutableArray array];
|
|
TTActionSheetConfig *action1;
|
|
if (self.momentsInfo.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
|
|
action1 = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMonentsTooBarView0") clickAction:^{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPMomentsTooBarView:didClickDelete:)]) {
|
|
[self.delegate XPMomentsTooBarView:self didClickDelete:self.momentsInfo];
|
|
}
|
|
}];
|
|
[TTPopup actionSheetWithItems:@[action1]];
|
|
} else {
|
|
NSString * url= [NSString stringWithFormat:@"%@?reportUid=%@&source=%@", URLWithType(kReportRoomURL),self.momentsInfo.uid, @"WORLDDYNAMIC"];
|
|
[ShareHelder shareImage:kImage(@"luck_package_bag_lv4")
|
|
url:url
|
|
fromController:[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController];
|
|
|
|
return;
|
|
TTActionSheetConfig *action = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMonentsTooBarView8") clickAction:^{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPMomentsTooBarView:didClickShielding:)]) {
|
|
[self.delegate XPMomentsTooBarView:self didClickShielding:self.momentsInfo];
|
|
}
|
|
}];
|
|
|
|
TTActionSheetConfig *black = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoViewController1") clickAction:^{
|
|
[self addOrRemoveBlack:NO uid:self.momentsInfo.uid];
|
|
}];
|
|
|
|
[array addObjectsFromArray:@[action, black]];
|
|
|
|
BOOL isInBlackList = [[NIMSDK sharedSDK]. userManager isUserInBlackList:self.momentsInfo.uid] || [self isSystemAccount];
|
|
if (isInBlackList) {
|
|
[array removeObject:black];
|
|
}
|
|
action1 = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMonentsTooBarView1") clickAction:^{
|
|
NSString * url= [NSString stringWithFormat:@"%@?reportUid=%@&source=%@", URLWithType(kReportRoomURL),self.momentsInfo.uid, @"WORLDDYNAMIC"];
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] initWithRoomUID:nil];
|
|
webVC.url = url;
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
|
}];
|
|
[array addObject:action1];
|
|
[TTPopup actionSheetWithItems:array];
|
|
}
|
|
|
|
}
|
|
- (BOOL)isSystemAccount {
|
|
return [KeyWithType(KeyType_SecretaryUidKey) isEqualToString:[NSString stringWithFormat:@"%@", self.momentsInfo.uid]] || [KeyWithType(KeyType_SystemNotifiUidKey) isEqualToString:[NSString stringWithFormat:@"%@", self.momentsInfo.uid]] || [KeyWithType(KeyType_GuildUidKey) isEqualToString:[NSString stringWithFormat:@"%@", self.momentsInfo.uid]];
|
|
}
|
|
|
|
//加入黑名单
|
|
- (void)addOrRemoveBlack:(BOOL)isRemove uid:(NSString *)uid {
|
|
NSString *title;
|
|
NSString *message;
|
|
if (isRemove) {
|
|
title = YMLocalizedString(@"XPMineUserInfoViewController2");
|
|
message = YMLocalizedString(@"XPMineUserInfoViewController3");
|
|
}else{
|
|
title = YMLocalizedString(@"XPMineUserInfoViewController4");
|
|
message = YMLocalizedString(@"XPMineUserInfoViewController5");
|
|
}
|
|
|
|
TTAlertConfig *config = [[TTAlertConfig alloc] init];
|
|
config.title = title;
|
|
config.message = message;
|
|
|
|
[TTPopup alertWithConfig:config confirmHandler:^{
|
|
if (isRemove) {
|
|
[[NIMSDK sharedSDK].userManager removeFromBlackBlackList:uid completion:^(NSError * _Nullable error) {
|
|
if (error == nil) {
|
|
|
|
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"XPMineUserInfoViewController6")];
|
|
|
|
|
|
}
|
|
}];
|
|
} else {
|
|
[[NIMSDK sharedSDK].userManager addToBlackList:uid completion:^(NSError * _Nullable error) {
|
|
if (error == nil) {
|
|
|
|
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"XPMineUserInfoViewController7")];
|
|
|
|
}
|
|
}];
|
|
}
|
|
} cancelHandler:^{
|
|
}];
|
|
}
|
|
|
|
- (void)commonButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPMomentsTooBarView:didClickCommon:)]) {
|
|
self.commentButton.userInteractionEnabled = YES;
|
|
[self.delegate XPMomentsTooBarView:self didClickCommon:self.momentsInfo];
|
|
} else {
|
|
self.commentButton.userInteractionEnabled = NO;
|
|
}
|
|
}
|
|
|
|
- (void)likeButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(XPMomentsTooBarView:didClickLike:)]) {
|
|
[self.delegate XPMomentsTooBarView:self didClickLike:self.momentsInfo];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setMomentsInfo:(MomentsInfoModel *)monentsInfo {
|
|
_momentsInfo = monentsInfo;
|
|
if (_momentsInfo) {
|
|
self.likeButton.selected = _momentsInfo.isLike;
|
|
self.likeLabel.text = _momentsInfo.likeCount.length > 0 ? _momentsInfo.likeCount : @"0";
|
|
self.commentLabel.text = _momentsInfo.commentCount.length > 0 ? _momentsInfo.commentCount : @"0";
|
|
self.reportButton.hidden = _momentsInfo.dynamicId == nil;
|
|
}
|
|
}
|
|
|
|
- (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];
|
|
[_likeButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
}
|
|
return _likeButton;
|
|
}
|
|
|
|
- (UILabel *)likeLabel {
|
|
if (!_likeLabel) {
|
|
_likeLabel = [[UILabel alloc] init];
|
|
_likeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_likeLabel.textColor = [DJDKMIMOMColor 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];
|
|
[_commentButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
}
|
|
return _commentButton;
|
|
}
|
|
|
|
- (UILabel *)commentLabel {
|
|
if (!_commentLabel) {
|
|
_commentLabel = [[UILabel alloc] init];
|
|
_commentLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_commentLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
}
|
|
return _commentLabel;
|
|
}
|
|
|
|
- (UIView *)lineView {
|
|
if (!_lineView) {
|
|
_lineView = [[UIView alloc] init];
|
|
_lineView.backgroundColor = [DJDKMIMOMColor dividerColor];
|
|
_lineView.hidden = YES;
|
|
}
|
|
return _lineView;
|
|
}
|
|
- (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];
|
|
[_reportButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
}
|
|
return _reportButton;
|
|
}
|
|
|
|
@end
|