From 715b6a254650e837ec68c82cc0f31002f615abc6 Mon Sep 17 00:00:00 2001 From: chenguilong <598604202@qq.com> Date: Wed, 26 Jan 2022 15:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BF=E5=AE=A2=E8=AE=B0=E5=BD=95=E5=B0=8F?= =?UTF-8?q?=E5=9C=86=E7=82=B9=E8=A7=92=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xplan-ios.xcodeproj/project.pbxproj | 6 ++ xplan-ios/Global/XPConstant.h | 1 + xplan-ios/Global/XPConstant.m | 2 + xplan-ios/Main/IM/Model/AttachmentModel.h | 8 +++ .../Model/Visitor/XPMineVisitorUnReadModel.h | 18 +++++ .../Model/Visitor/XPMineVisitorUnReadModel.m | 12 ++++ xplan-ios/Main/Mine/Model/XPMineItemModel.h | 3 + xplan-ios/Main/Mine/Presenter/XPMinePresent.m | 2 + .../Mine/View/Cell/XPMineMenuTableViewCell.m | 71 ++++++++++++++++++- .../Main/Mine/View/XPMineViewController.m | 38 ++++++++++ .../Main/Room/View/XPGlobalMessageManager.m | 8 +++ 11 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.h create mode 100644 xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.m diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index 80daf8ff..b97b1951 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -204,6 +204,7 @@ 9BD9A17C27A0EE24004186FE /* XPMineVisitorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BD9A17B27A0EE24004186FE /* XPMineVisitorViewController.m */; }; 9BD9A18027A0EFC7004186FE /* XPMineVisitorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BD9A17F27A0EFC7004186FE /* XPMineVisitorTableViewCell.m */; }; 9BD9A18427A0F128004186FE /* XPMineVisitorItemModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BD9A18327A0F128004186FE /* XPMineVisitorItemModel.m */; }; + 9BD9A18727A120FD004186FE /* XPMineVisitorUnReadModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BD9A18627A120FD004186FE /* XPMineVisitorUnReadModel.m */; }; E80487652717DDD9008595F2 /* XPRoomMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E80487642717DDD9008595F2 /* XPRoomMenuItem.m */; }; E80CBDE627D0C1CF001E1EC2 /* HomeMenuSourceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E80CBDE527D0C1CF001E1EC2 /* HomeMenuSourceModel.m */; }; E80CBDEA27D0C53F001E1EC2 /* XPWeakTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = E80CBDE927D0C53F001E1EC2 /* XPWeakTimer.m */; }; @@ -942,6 +943,8 @@ 9BD9A17F27A0EFC7004186FE /* XPMineVisitorTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineVisitorTableViewCell.m; sourceTree = ""; }; 9BD9A18227A0F128004186FE /* XPMineVisitorItemModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineVisitorItemModel.h; sourceTree = ""; }; 9BD9A18327A0F128004186FE /* XPMineVisitorItemModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineVisitorItemModel.m; sourceTree = ""; }; + 9BD9A18527A120FD004186FE /* XPMineVisitorUnReadModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineVisitorUnReadModel.h; sourceTree = ""; }; + 9BD9A18627A120FD004186FE /* XPMineVisitorUnReadModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineVisitorUnReadModel.m; sourceTree = ""; }; B66633E061B1B34177CD011C /* Pods-xplan-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.release.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.release.xcconfig"; sourceTree = ""; }; CACF623970097D653132D69A /* Pods_xplan_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_xplan_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E80487632717DDD9008595F2 /* XPRoomMenuItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomMenuItem.h; sourceTree = ""; }; @@ -2868,6 +2871,8 @@ children = ( 9BD9A18227A0F128004186FE /* XPMineVisitorItemModel.h */, 9BD9A18327A0F128004186FE /* XPMineVisitorItemModel.m */, + 9BD9A18527A120FD004186FE /* XPMineVisitorUnReadModel.h */, + 9BD9A18627A120FD004186FE /* XPMineVisitorUnReadModel.m */, ); path = Visitor; sourceTree = ""; @@ -4718,6 +4723,7 @@ 9BBC028E2786FA060007C24B /* NobleCardModel.m in Sources */, E8E70D7E26F2F19D00F03460 /* Api+Mine.m in Sources */, E8E5E19427C36BA600F457D8 /* XPHomeBannerTableViewCell.m in Sources */, + 9BD9A18727A120FD004186FE /* XPMineVisitorUnReadModel.m in Sources */, E824543D26F58C3A00BE8163 /* XPLoginBindSuccessView.m in Sources */, E8A6C29527CF441200AC7442 /* XPHomeAttentionCollectionViewCell.m in Sources */, E8EEB8F726FC2673007C6EBA /* UserPhoto.m in Sources */, diff --git a/xplan-ios/Global/XPConstant.h b/xplan-ios/Global/XPConstant.h index b88b9ae3..6c352c01 100644 --- a/xplan-ios/Global/XPConstant.h +++ b/xplan-ios/Global/XPConstant.h @@ -15,6 +15,7 @@ UIKIT_EXTERN NSString * const kWeChatNumber; UIKIT_EXTERN NSString * const kTeenagerAlertDatekey; UIKIT_EXTERN NSString * const kRoomMiniNotificationKey; UIKIT_EXTERN NSString * const kRoomReleaseRadioNotificationKey; +UIKIT_EXTERN NSString * const kVisitorUnReadCountNotificationKey; typedef NS_ENUM(NSUInteger, KeyType) { KeyType_PasswordEncode,///密码 des 加密的 diff --git a/xplan-ios/Global/XPConstant.m b/xplan-ios/Global/XPConstant.m index 8f08e48d..be41f748 100644 --- a/xplan-ios/Global/XPConstant.m +++ b/xplan-ios/Global/XPConstant.m @@ -16,6 +16,8 @@ NSString * const kRoomGiftEffectUpdateNotificationKey = @"RoomGiftEffectUpdateNo NSString * const kRoomRoomSettingNotificationKey = @"kRoomRoomSettingNotificationKey"; NSString * const kHomeMoreScrollPageKey = @"kHomeMoreScrollPageKey"; NSString * const kRoomReleaseRadioNotificationKey = @"kRoomReleaseRadioNotificationKey"; +NSString * const kVisitorUnReadCountNotificationKey = @"kVisitorUnReadCountNotificationKey"; + ///在里面进行判断当前环境是什么 NSString * const KeyWithType(KeyType type) { BOOL isRelase = NO; diff --git a/xplan-ios/Main/IM/Model/AttachmentModel.h b/xplan-ios/Main/IM/Model/AttachmentModel.h index 6b21942d..17b9f394 100644 --- a/xplan-ios/Main/IM/Model/AttachmentModel.h +++ b/xplan-ios/Main/IM/Model/AttachmentModel.h @@ -44,6 +44,8 @@ typedef NS_ENUM(NSUInteger, CustomMessageType) { CustomMessageType_RoomPlay_Dating = 72, ///首充奖励 CustomMessageType_First_Recharge_Reward = 76, + ///访客记录 + CustomMessageType_First_VisitorRecord = 78, ///贵族VIP CustomMessageType_Noble_VIP = 85, ///个播房观众点击空坑位,房主收到请求上麦提示 @@ -230,6 +232,12 @@ typedef NS_ENUM(NSUInteger, CustomMessageSubNobleVIP) { Custom_Message_Sub_AllRoom_Noble_LevelUp_Suspend = 856, }; +/// 访客记录 +typedef NS_ENUM(NSUInteger, CustomMessageSubVisitorRecord) { + /// 访客记录 + Custom_Message_Sub_Visitor_Record = 781, +}; + @interface AttachmentModel : NSObject @property (nonatomic,assign) int first; @property (nonatomic,assign) int second; diff --git a/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.h b/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.h new file mode 100644 index 00000000..aa463684 --- /dev/null +++ b/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.h @@ -0,0 +1,18 @@ +// +// XPMineVisitorUnReadModel.h +// xplan-ios +// +// Created by GreenLand on 2022/1/26. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface XPMineVisitorUnReadModel : NSObject + +@property (nonatomic, assign) NSInteger visitNum; + +@end + +NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.m b/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.m new file mode 100644 index 00000000..666f7afa --- /dev/null +++ b/xplan-ios/Main/Mine/Model/Visitor/XPMineVisitorUnReadModel.m @@ -0,0 +1,12 @@ +// +// XPMineVisitorUnReadModel.m +// xplan-ios +// +// Created by GreenLand on 2022/1/26. +// + +#import "XPMineVisitorUnReadModel.h" + +@implementation XPMineVisitorUnReadModel + +@end diff --git a/xplan-ios/Main/Mine/Model/XPMineItemModel.h b/xplan-ios/Main/Mine/Model/XPMineItemModel.h index 8c358bb4..b5c2ecfe 100644 --- a/xplan-ios/Main/Mine/Model/XPMineItemModel.h +++ b/xplan-ios/Main/Mine/Model/XPMineItemModel.h @@ -42,6 +42,9 @@ typedef NS_ENUM(NSInteger, XPMineItemType) { @property (nonatomic,assign) XPMineItemType type; ///圆角 @property (nonatomic, assign) UIRectCorner cornerType; +///未读消息 +@property (nonatomic, assign) NSInteger unReadCount; + @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Mine/Presenter/XPMinePresent.m b/xplan-ios/Main/Mine/Presenter/XPMinePresent.m index 561b963f..ba81ce34 100644 --- a/xplan-ios/Main/Mine/Presenter/XPMinePresent.m +++ b/xplan-ios/Main/Mine/Presenter/XPMinePresent.m @@ -79,6 +79,8 @@ visitorItem.itemName = @"访客记录"; visitorItem.itemImageName = @"mine_normal_visitor"; visitorItem.type = XPMineItemType_Visitor; + BaseViewController *vc = [self getView]; + visitorItem.unReadCount = [vc.tabBarItem.badgeValue integerValue]; NSArray * array = @[myRoomItem,teenagerItem, myDressUp, inviteFriend, visitorItem, realNameItem]; diff --git a/xplan-ios/Main/Mine/View/Cell/XPMineMenuTableViewCell.m b/xplan-ios/Main/Mine/View/Cell/XPMineMenuTableViewCell.m index 54cec6ca..eb953caa 100644 --- a/xplan-ios/Main/Mine/View/Cell/XPMineMenuTableViewCell.m +++ b/xplan-ios/Main/Mine/View/Cell/XPMineMenuTableViewCell.m @@ -8,6 +8,7 @@ #import "XPMineMenuTableViewCell.h" ///Third #import +#import ///Tool #import "ThemeColor.h" #import "XPMacro.h" @@ -25,7 +26,10 @@ @property (nonatomic,strong) UILabel *titleLabel; ///箭头 @property (nonatomic,strong) UIButton *arrowButton; - +///分割线 +@property (nonatomic,strong) UIView * partLineView; +//访客记录未读数量 +@property (nonatomic, strong) UILabel *unReadLabel; @end @implementation XPMineMenuTableViewCell @@ -49,6 +53,7 @@ [self.stackView addArrangedSubview:self.logoImageView]; [self.stackView addArrangedSubview:self.titleLabel]; + [self.stackView addArrangedSubview:self.unReadLabel]; [self.stackView addArrangedSubview:self.arrowButton]; } @@ -66,6 +71,13 @@ [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(24, 24)); }]; + + [self.unReadLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(5); + make.height.mas_equalTo(15); + make.centerY.mas_equalTo(self.logoImageView.mas_centerY); + make.width.mas_equalTo(15); + }]; } - (void)applyRoundCorners:(UIRectCorner)corners radius:(CGFloat)radius @@ -76,6 +88,23 @@ self.backView.layer.mask = maskLayer; } +- (NSAttributedString *)attributedStringWithLineSpace:(CGFloat)lineSpace str:(NSString *)str{ + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; + NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xffffff), NSFontAttributeName: [UIFont systemFontOfSize:11]}]; + [attributedString appendAttributedString:title]; + attributedString.yy_alignment = NSTextAlignmentCenter; + return attributedString; +} + +- (CGFloat)getWidthWithContent:(NSString *)content height:(CGFloat)height font:(CGFloat)font{ + + CGRect rect = [content boundingRectWithSize:CGSizeMake(999, height) + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} + context:nil]; + return rect.size.width; +} + #pragma mark - Getters And Setters - (void)setItemModel:(XPMineItemModel *)itemModel { _itemModel = itemModel; @@ -85,6 +114,24 @@ if (itemModel.cornerType) { [self applyRoundCorners:itemModel.cornerType radius:10]; } + [self.titleLabel sizeToFit]; + if (itemModel.unReadCount) { + self.unReadLabel.hidden = NO; + } else { + self.unReadLabel.hidden = YES; + } + + self.unReadLabel.attributedText = [self attributedStringWithLineSpace:10 str:[NSString stringWithFormat:@"%zd", itemModel.unReadCount]]; + CGFloat width = [self getWidthWithContent:[NSString stringWithFormat:@"%zd", itemModel.unReadCount] height:15 font:11]; + if (itemModel.unReadCount < 10) { + width = 7; + } + [self.unReadLabel mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(5); + make.height.mas_equalTo(15); + make.centerY.mas_equalTo(self.logoImageView.mas_centerY); + make.width.mas_equalTo(width + 8); + }]; } } @@ -135,4 +182,26 @@ return _arrowButton; } +- (UIView *)partLineView { + if (!_partLineView) { + _partLineView = [[UIView alloc] init]; + _partLineView.backgroundColor = [ThemeColor dividerColor]; + } + return _partLineView; +} + +- (UILabel *)unReadLabel { + if (!_unReadLabel) { + _unReadLabel = [[UILabel alloc] init]; + _unReadLabel.font = [UIFont systemFontOfSize:11]; + _unReadLabel.textColor = [UIColor whiteColor]; + _unReadLabel.backgroundColor = UIColorFromRGB(0xFF5B55); + _unReadLabel.layer.cornerRadius = 7.5; + _unReadLabel.layer.masksToBounds = YES; + _unReadLabel.textAlignment = NSTextAlignmentCenter; + [_unReadLabel sizeToFit]; + } + return _unReadLabel ; +} + @end diff --git a/xplan-ios/Main/Mine/View/XPMineViewController.m b/xplan-ios/Main/Mine/View/XPMineViewController.m index bd1cb6f2..f5bc2738 100644 --- a/xplan-ios/Main/Mine/View/XPMineViewController.m +++ b/xplan-ios/Main/Mine/View/XPMineViewController.m @@ -14,9 +14,11 @@ #import "XPHtmlUrl.h" #import "UIButton+EnlargeTouchArea.h" #import "StatisticsServiceHelper.h" +#import "XPConstant.h" ///Model #import "XPMineItemModel.h" #import "UserInfoModel.h" +#import "XPMineVisitorUnReadModel.h" ///P #import "XPMineProtocol.h" #import "XPMinePresent.h" @@ -64,6 +66,11 @@ @implementation XPMineViewController + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + - (BOOL)isHiddenNavBar { return YES; } @@ -72,6 +79,13 @@ return [[XPMinePresent alloc] init];; } +- (instancetype)init { + if (self = [super init]) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVisitorUnReadCountUpdate:) name:kVisitorUnReadCountNotificationKey object:nil]; + } + return self; +} + - (void)viewDidLoad { [super viewDidLoad]; [self initSubViews]; @@ -221,6 +235,12 @@ break; case XPMineItemType_Visitor: { + [self.tabBarItem setBadgeValue:nil]; + for (XPMineItemModel * model in self.datasource) { + if (model.type == XPMineItemType_Visitor) { + model.unReadCount = 0; + } + } XPMineVisitorViewController *visitorVC = [[XPMineVisitorViewController alloc] init]; [self.navigationController pushViewController:visitorVC animated:YES]; } @@ -348,6 +368,24 @@ [self pushViewControllerWithType:item.type]; } +#pragma mark - NSNotification +- (void)onVisitorUnReadCountUpdate:(NSNotification *)noti { + XPMineVisitorUnReadModel *model = (XPMineVisitorUnReadModel *)noti.object; + if (model.visitNum > 0) { + [self.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", model.visitNum]]; + } else { + [self.tabBarItem setBadgeValue:nil]; + } + + for (int i = 0; i @@ -55,6 +57,12 @@ // 青少年模式下,房间在线时长达到上限 if ([dic[@"second"] integerValue] == 481) { } + } else if ([dic[@"first"] integerValue] == CustomMessageType_First_VisitorRecord){//访客记录数量更新提示 + AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content]; + XPMineVisitorUnReadModel *model = [XPMineVisitorUnReadModel modelWithJSON:attachment.data]; + if ([model isKindOfClass:XPMineVisitorUnReadModel.class]) { + [[NSNotificationCenter defaultCenter] postNotificationName:kVisitorUnReadCountNotificationKey object:model]; + } } } } else if (notification.receiverType == NIMSessionTypeTeam) {