// // XPSessionMainViewController.m // xplan-ios // // Created by duoban on 2022/10/12. // #import "XPSessionMainViewController.h" ///Tool #import #import #import #import "QEmotionHelper.h" ///vc #import "XPMineAttentionViewController.h" #import "SessionListViewController.h" #import "XPMineFriendViewController.h" #import "XPMineFansViewController.h" #import "MSSessionScrollingView.h" #import "MSSessionScrollingItemView.h" #import "MessagePresenter.h" #import "MessageProtocol.h" #import "MSSessionPublicChatHallVC.h" @interface XPSessionMainViewController () @property (nonatomic, strong) JXCategoryTitleView *titleView; @property (nonatomic, strong) JXCategoryIndicatorImageView *lineView; @property (nonatomic, strong) JXPagerView *pagingView; @property (nonatomic, strong) NSArray *titles; @property (nonatomic,strong) UIView *headView; @property (nonatomic,strong) UIImageView *headBgImageView; @property (nonatomic,strong) SessionListViewController *sessionListVC; ///好友 @property (nonatomic,strong) XPMineFriendViewController *friendVC; ///关注 @property (nonatomic,strong) XPMineAttentionViewController *attentionVC; ///粉丝 @property (nonatomic,strong) XPMineFansViewController *fansVC; ///清除已读 @property (nonatomic,strong) UIButton * allCleanBtn; @property(nonatomic,strong) MSSessionScrollingView *scrollingView; @property(nonatomic,strong) UIButton *clickBnt; @end @implementation XPSessionMainViewController - (MessagePresenter *)createPresenter { return [[MessagePresenter alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; [self initSubViews]; [self initSubViewConstraints]; [self getDataList]; } - (BOOL)isHiddenNavBar { return YES; } -(void)dealloc{ [[NSNotificationCenter defaultCenter]removeObserver:self]; } -(void)getDataList{ [self.presenter getPublicChatHallList]; } -(void)getPublicChatHallListSuccess:(NSArray *)list{ for (MSSessionScrollingModel *model in list) { CGSize dstRect = CGSizeMake(model.width, MAXFLOAT); QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper]; NSMutableAttributedString * attribute = [faceManager attributedStringByText:model.content font:kFontMedium(12)]; [attribute addAttributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0xFFFCED)} range:[attribute.string rangeOfString:attribute.string]]; YYTextContainer *container = [YYTextContainer containerWithSize:dstRect]; container.maximumNumberOfRows = 1; YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attribute]; model.width = layout.textBoundingSize.width; model.attribute = attribute; } self.scrollingView.modelList = [[NSMutableArray alloc]initWithArray:list]; } #pragma mark - Private Method - (void)initSubViews { [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getTabBarItemBadge:) name:@"kGetTabBarItemBadge" object:nil]; self.view.backgroundColor = [UIColor clearColor]; self.headView = [UIView new]; [self.view addSubview:self.headBgImageView]; [self.view addSubview:self.pagingView]; [self.view addSubview:self.allCleanBtn]; ; [self.view addSubview:self.scrollingView]; [self.scrollingView addSubview:self.clickBnt]; } - (void)initSubViewConstraints { [self.headBgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.top.trailing.equalTo(self.view); make.height.mas_equalTo(kGetScaleWidth(223)); }]; [self.scrollingView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kStatusBarHeight); make.height.mas_equalTo(kGetScaleWidth(112)); make.leading.trailing.equalTo(self.view); }]; [self.clickBnt mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.scrollingView); }]; [self.pagingView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.equalTo(self.view); make.bottom.mas_equalTo(-1); make.top.equalTo(self.scrollingView.mas_bottom).mas_offset(-50); }]; [self.allCleanBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(30); make.top.mas_equalTo(67+kGetScaleWidth(115)); make.trailing.mas_equalTo(-15); }]; UIView *lineView = [UIView new]; lineView.backgroundColor = UIColorFromRGB(0xF5F6FA); [self.view addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.leading.trailing.equalTo(self.view); make.height.mas_equalTo(1); }]; } #pragma mark - SessionListViewController通知 -(void)getTabBarItemBadge:(NSNotification *)not{ NSInteger badgeValue = [not.userInfo[@"BadgeValue"] integerValue]; if (badgeValue > 0) { [self.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", badgeValue]]; } else { [self.tabBarItem setBadgeValue:nil]; } } #pragma mark - JXCategoryViewDelegate - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return 57; } - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return self.headView; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 50; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.titleView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { return self.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { UIViewController *viewController; if (index == 0) { return self.sessionListVC; }else if (index == 1){ return self.friendVC; } else if (index == 2){ return self.attentionVC; }else{ return self.fansVC; } return (id )viewController; } - (NSArray *)titles { if (!_titles) { _titles = @[YMLocalizedString(@"XPSessionMainViewController0"), YMLocalizedString(@"XPSessionMainViewController1"),YMLocalizedString(@"XPSessionMainViewController2"),YMLocalizedString(@"XPSessionMainViewController3")]; } return _titles; } #pragma mark- 清除消息 - (void)allReadButtonClick:(UIButton *)sender { [[NSNotificationCenter defaultCenter]postNotificationName:@"kAllReadAction" object:nil]; } -(void)clickPublicChatHallAction{ MSSessionPublicChatHallVC *vc =[MSSessionPublicChatHallVC new]; [self.navigationController pushViewController:vc animated:YES]; } -(NSTimeInterval)curTime { static double time = 0; time += 0.1 ; return time; } #pragma mark -懒加载 - (JXCategoryTitleView *)titleView { if (!_titleView) { _titleView = [[JXCategoryTitleView alloc] init]; _titleView.delegate = self; _titleView.backgroundColor = [UIColor clearColor]; _titleView.titleColor = UIColorFromRGB(0x6D6B89); _titleView.titleSelectedColor = UIColorFromRGB(0x1F1A4E); _titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16]; _titleView.titleSelectedFont = [UIFont boldSystemFontOfSize:22]; _titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter; _titleView.contentScrollViewClickTransitionAnimationEnabled = NO; _titleView.defaultSelectedIndex = 0; _titleView.averageCellSpacingEnabled = NO; _titleView.contentEdgeInsetLeft = 20; _titleView.titles = self.titles; _titleView.cellSpacing = 20; _titleView.titles = self.titles; _titleView.listContainer = (id)self.pagingView.listContainerView; JXCategoryIndicatorImageView *lineView = [[JXCategoryIndicatorImageView alloc] init]; lineView.indicatorImageViewSize = CGSizeMake(24, 7); // lineView.verticalMargin = 10; lineView.indicatorImageView.layer.masksToBounds = YES; lineView.indicatorImageView.layer.cornerRadius = 3; lineView.indicatorImageView.image = [UIImage imageNamed:@"ms_login_choose_phone_icon"]; lineView.contentMode = UIViewContentModeScaleAspectFit; _titleView.indicators = @[lineView]; } return _titleView; } - (JXPagerView *)pagingView { if (!_pagingView) { _pagingView = [[JXPagerView alloc] initWithDelegate:self listContainerType:0]; _pagingView.backgroundColor = [UIColor clearColor]; _pagingView.listContainerView.backgroundColor = [UIColor clearColor]; _pagingView.mainTableView.backgroundColor = [UIColor clearColor]; _pagingView.listContainerView.listCellBackgroundColor = UIColor.clearColor; _pagingView.pinSectionHeaderVerticalOffset = 57; _pagingView.isListHorizontalScrollEnabled = NO; _pagingView.mainTableView.gestureDelegate = self; } return _pagingView; } -(UIImageView *)headBgImageView{ if (!_headBgImageView){ _headBgImageView = [UIImageView new]; _headBgImageView.image = [UIImage imageNamed:@"home_top_bg"]; } return _headBgImageView; } - (XPMineAttentionViewController *)attentionVC { if (!_attentionVC) { _attentionVC = [[XPMineAttentionViewController alloc] init]; _attentionVC.type = ContactUseingType_In_Session; _attentionVC.isClearColor = YES; } return _attentionVC; } - (XPMineFriendViewController *)friendVC { if (!_friendVC) { _friendVC = [[XPMineFriendViewController alloc] init]; _friendVC.isClearColor = YES; _friendVC.type = ContactUseingType_In_Session; } return _friendVC; } - (XPMineFansViewController *)fansVC { if (!_fansVC) { _fansVC = [[XPMineFansViewController alloc] init]; _fansVC.type = ContactUseingType_In_Session; _fansVC.isClearColor = YES; } return _fansVC; } - (SessionListViewController *)sessionListVC{ if (!_sessionListVC){ _sessionListVC = [[SessionListViewController alloc]init]; } return _sessionListVC; } - (UIButton *)allCleanBtn{ if (!_allCleanBtn){ _allCleanBtn = [UIButton new]; [_allCleanBtn setCornerWithLeftTopCorner:10 rightTopCorner:10 bottomLeftCorner:10 bottomRightCorner:10 size:CGSizeMake(30, 30)]; [_allCleanBtn setImage:[UIImage imageNamed:@"sessionList_clear"] forState:UIControlStateNormal]; [_allCleanBtn addTarget:self action:@selector(allReadButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _allCleanBtn; } - (MSSessionScrollingView *)scrollingView{ if(!_scrollingView){ _scrollingView = [[MSSessionScrollingView alloc]initWithFrame:CGRectZero]; } return _scrollingView; } - (UIButton *)clickBnt{ if(!_clickBnt){ _clickBnt = [UIButton new]; [_clickBnt addTarget:self action:@selector(clickPublicChatHallAction) forControlEvents:UIControlEventTouchUpInside]; } return _clickBnt; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end