214 lines
7.2 KiB
Objective-C
214 lines
7.2 KiB
Objective-C
//
|
|
// XPMonentsViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/11.
|
|
//
|
|
|
|
#import "XPMonentsViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
///Tool
|
|
#import "AttachMentModel.h"
|
|
#import "MonentsUnReadModel.h"
|
|
///View
|
|
#import "XPMonentsRecommendViewController.h"
|
|
#import "XPMonentsAttentionViewController.h"
|
|
#import "XPMonentsLatestViewController.h"
|
|
#import "XPMonentsInteractiveViewController.h"
|
|
|
|
@interface XPMonentsViewController ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
|
|
///标题
|
|
@property (nonatomic,strong) NSArray<NSString *> *titles;
|
|
///导航栏
|
|
@property (nonatomic,strong) UIView * navView;
|
|
///显示小红点
|
|
@property (nonatomic,strong) UIView * dotView;
|
|
///消息的
|
|
@property (nonatomic,strong) UIButton *messageButton;
|
|
///滑块
|
|
@property (nonatomic,strong) JXCategoryTitleView *titleView;
|
|
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
|
@end
|
|
|
|
@implementation XPMonentsViewController
|
|
|
|
- (void)dealloc {
|
|
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.navView];
|
|
[self.view addSubview:self.listContainerView];
|
|
|
|
[self.navView addSubview:self.titleView];
|
|
[self.navView addSubview:self.messageButton];
|
|
[self.navView addSubview:self.dotView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.navView);
|
|
make.height.mas_equalTo(20);
|
|
make.top.mas_equalTo(self.navView).offset(kSafeAreaTopHeight + 40);
|
|
}];
|
|
|
|
[self.messageButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.titleView);
|
|
make.right.mas_equalTo(self.navView).offset(-15);
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
}];
|
|
|
|
[self.dotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(10, 10));
|
|
make.centerY.mas_equalTo(self.messageButton.mas_top);
|
|
make.centerX.mas_equalTo(self.messageButton.mas_right);
|
|
}];
|
|
|
|
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.navView.mas_bottom);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContainerViewDelegate
|
|
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
|
return self.titles.count;
|
|
}
|
|
|
|
// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
|
|
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
|
if (index == 0) {
|
|
XPMonentsAttentionViewController * attentionVC = [[XPMonentsAttentionViewController alloc] init];
|
|
return attentionVC;
|
|
}else if (index == 1) {
|
|
XPMonentsRecommendViewController * recommendVC = [[XPMonentsRecommendViewController alloc] init];
|
|
return recommendVC;
|
|
} else if(index == 2) {
|
|
XPMonentsLatestViewController * latestVC = [[XPMonentsLatestViewController alloc] init];
|
|
return latestVC;
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
|
|
}
|
|
|
|
#pragma mark -NIMSystemNotificationManagerDelegate
|
|
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
|
|
if (notification.receiverType == NIMSessionTypeP2P) {
|
|
if (notification.content != nil) {
|
|
AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content];
|
|
if (attachment.first == CustomMessageType_Monents && attachment.second == Custom_Message_Sub_Monents_Unread_Update) {
|
|
MonentsUnReadModel * unreadModel = [MonentsUnReadModel modelWithDictionary:attachment.data];
|
|
if (unreadModel.total > 0) {
|
|
self.dotView.hidden = NO;
|
|
} else {
|
|
self.dotView.hidden = YES;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)messageButtonAction:(UIButton *)sender {
|
|
XPMonentsInteractiveViewController * messageVC = [[XPMonentsInteractiveViewController alloc] init];
|
|
[self.navigationController pushViewController:messageVC animated:YES];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryListContainerView *)listContainerView {
|
|
if (!_listContainerView) {
|
|
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_listContainerView.listCellBackgroundColor = [UIColor clearColor];
|
|
}
|
|
return _listContainerView;
|
|
}
|
|
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectZero];
|
|
_titleView.backgroundColor =[UIColor clearColor];
|
|
_titleView.delegate = self;
|
|
_titleView.titleColor = [ThemeColor secondTextColor];
|
|
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
|
|
_titleView.titleFont = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];
|
|
_titleView.titleSelectedFont = [UIFont systemFontOfSize:20 weight:UIFontWeightHeavy];
|
|
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
|
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
|
_titleView.averageCellSpacingEnabled = NO;
|
|
_titleView.defaultSelectedIndex = 0;
|
|
_titleView.cellSpacing = 20;
|
|
_titleView.titles = self.titles;
|
|
_titleView.listContainer = self.listContainerView;
|
|
_titleView.defaultSelectedIndex = 1;
|
|
CGFloat itemWidth = [@"推荐" boundingRectWithSize:CGSizeMake(100, CGFLOAT_MAX) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20 weight:UIFontWeightHeavy]} context:nil].size.width;
|
|
_titleView.cellWidth = itemWidth;
|
|
_titleView.contentEdgeInsetLeft = (KScreenWidth - itemWidth * self.titles.count - 20 * (self.titles.count - 1))/ 2;
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (UIView *)navView {
|
|
if (!_navView) {
|
|
_navView = [[UIView alloc] init];
|
|
_navView.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
}
|
|
return _navView;
|
|
}
|
|
|
|
- (NSArray<NSString *> *)titles {
|
|
if (!_titles) {
|
|
_titles = @[@"关注",@"推荐", @"最新"];
|
|
}
|
|
return _titles;
|
|
}
|
|
|
|
- (UIButton *)messageButton {
|
|
if (!_messageButton) {
|
|
_messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_messageButton setImage:[UIImage imageNamed:@"monents_nav_interavtive_message"] forState:UIControlStateNormal];
|
|
[_messageButton setImage:[UIImage imageNamed:@"monents_nav_interavtive_message"] forState:UIControlStateSelected];
|
|
[_messageButton addTarget:self action:@selector(messageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _messageButton;
|
|
}
|
|
|
|
- (UIView *)dotView {
|
|
if (!_dotView) {
|
|
_dotView = [[UIView alloc] init];
|
|
_dotView.backgroundColor = UIColorFromRGB(0xFF2D55);
|
|
_dotView.layer.masksToBounds = YES;
|
|
_dotView.layer.cornerRadius = 5;
|
|
_dotView.hidden = YES;
|
|
}
|
|
return _dotView;
|
|
}
|
|
|
|
@end
|