Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/MessageContentTextClickable.m
2025-02-28 19:04:09 +08:00

265 lines
9.9 KiB
Objective-C

//
// MessageContentTextClickable.m
// YUMI
//
// Created by zu on 2022/1/24.
//
#import "MessageContentTextClickable.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NSObject+MJExtension.h"
#import "XCCurrentVCStackManager.h"
#import "Api.h"
#import "AccountInfoStorage.h"
#import "XNDJTDDLoadingTool.h"
#import "NSObject+MJExtension.h"
#import "ClientConfig.h"
///Model
#import "UserInfoModel.h"
#import "ContentSecretaryModel.h"
#import "MessageTextClickModel.h"
///View
#import "XPRoomViewController.h"
#import "XPWebViewController.h"
#import "XPIAPRechargeViewController.h"
#import "XPMineUserInfoViewController.h"
#import "MyDressingViewController.h"
#import "ShoppingMallViewController.h"
#import "XPMineLoginPasswordViewController.h"
#import "XPMomentTopicContainerViewController.h"
#import "VIPCenterViewController.h"
///P
#import "RoomHostDelegate.h"
@interface MessageContentTextClickable()
/**
消息文本
*/
@property (nonatomic, strong) UILabel * messageText;
///获取的模型
@property (nonatomic,strong) ContentSecretaryModel *contentInfo;
///分割线
@property (nonatomic,strong) UIView * lineView;
///查看详情
@property (nonatomic,strong) UIButton *checkButton;
@end
@implementation MessageContentTextClickable
- (void)initSubViews {
[super initSubViews];
[self.backView addSubview:self.messageText];
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.checkButton];
}
- (void)initSubViewConstraints {
[super initSubViewConstraints];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(280);
make.bottom.mas_equalTo(self.checkButton);
}];
[self.messageText mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.equalTo(self.backView);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.backView);
make.height.mas_equalTo(0.5);
make.top.mas_equalTo(self.messageText.mas_bottom).offset(5);
}];
[self.checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.backView);
make.top.mas_equalTo(self.lineView.mas_bottom).offset(10);
make.height.mas_equalTo(20);
}];
}
- (void)render:(nonnull MessageBaseModel *)message {
MessageTextClickModel * textModel = (MessageTextClickModel *)message;
_messageText.attributedText = textModel.attributedText;
_contentInfo = textModel.contentInfo;
}
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes:(UIFont *)font color:(UIColor *)color {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:2.5];
return @{
NSFontAttributeName:font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName:color
};
}
- (void)checkButtonAction:(UIButton *)gesture {
SecretaryRouterType type = self.contentInfo.routerType;
NSString * value = self.contentInfo.routerValue;
switch (type) {
case SecretaryRouterType_H5: {
if (value.length) {
XPWebViewController * webVC =[[XPWebViewController alloc] initWithRoomUID:nil];
webVC.url = value;
[self.nim_viewController.navigationController pushViewController:webVC animated:YES];
}
}
break;
case SecretaryRouterType_Room:
{
if (value.length > 0) {
UIViewController * controllerView = [XCCurrentVCStackManager shareManager].getCurrentVC;
//退出原来的房间 如果有的话 TODO 总感觉这种处理不太优雅 进房入口多了 怎么办 进房需要整合
[controllerView.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[XPRoomViewController class]]) {
[controllerView.navigationController popToRootViewControllerAnimated:NO];
XPRoomViewController<RoomHostDelegate> * rooomVC = obj;
[rooomVC exitRoom];
*stop = YES;
}
}];
[XPRoomViewController openRoom:value viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
}
}
break;
case SecretaryRouterType_Purse:
case SecretaryRouterType_Recharge:
{
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];
}
break;
case SecretaryRouterType_UserInfo:
{
if (value.length > 0) {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = value.integerValue;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:userInfoVC animated:YES];
}
}
break;
case SecretaryRouterType_Car:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = 1;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_Headwear:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = 0;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_Nameplate:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = 2;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_Nobel_Bubble:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = 4;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_User_Card:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = 3;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_Set_Password:
{
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
UserInfoModel * userInfo = [UserInfoModel modelWithDictionary:data.data];
if (!userInfo.isBindPhone) {
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"MessageContentTextClickable0")];
return;
}
//登录密码
if (userInfo.isBindPasswd) {
XPMineLoginPasswordViewController *vc = [[XPMineLoginPasswordViewController alloc] init];
vc.userInfo = userInfo;
vc.isModifiPwd = YES;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
} else {
XPMineLoginPasswordViewController *vc = [[XPMineLoginPasswordViewController alloc] init];
vc.userInfo = userInfo;
vc.isModifiPwd = NO;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
}
} uid:[AccountInfoStorage instance].getUid];
}
break;
case SecretaryRouterType_Dressup_Shop:
{
ShoppingMallViewController *vc = [[ShoppingMallViewController alloc] init];
// vc.currentIndex = [value integerValue];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES];
}
break;
case SecretaryRouterType_My_Dressup:
{
MyDressingViewController * dressUpVC = [[MyDressingViewController alloc] init];
// dressUpVC.currentIndex = [value integerValue];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:dressUpVC animated:YES];
}
break;
case SecretaryRouterType_Square_Topic:
{
XPMomentTopicContainerViewController *topicVC = [[XPMomentTopicContainerViewController alloc] init];
topicVC.worldId = value;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:topicVC animated:YES];
}
break;
case SecretaryRouterType_Nobel_Center:
{
VIPCenterViewController *nobleCenter = [[VIPCenterViewController alloc] initWithRoomUid:-1];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:nobleCenter animated:YES];
break;
}
default:
break;
}
}
- (UILabel *)messageText {
if (!_messageText) {
_messageText = [[UILabel alloc]initWithFrame:CGRectZero];
_messageText.preferredMaxLayoutWidth = CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2;
_messageText.textColor = DJDKMIMOMColor.mainTextColor;
_messageText.numberOfLines = 0;
}
return _messageText;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [DJDKMIMOMColor dividerColor];
}
return _lineView;
}
- (UIButton *)checkButton {
if (!_checkButton) {
_checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_checkButton setTitle:YMLocalizedString(@"MessageContentTweetView1") forState:UIControlStateNormal];
[_checkButton setTitleColor:UIColorFromRGB(0x4C5AF1) forState:UIControlStateNormal];
_checkButton.titleLabel.font = [UIFont systemFontOfSize:14];
[_checkButton addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _checkButton;
}
@end