123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- //
- // YMHomeController.m
- // MSYOUPAI
- //
- // Created by You on 2024/4/18.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomeController.h"
- #import "YMHomePageViewModel.h"
- #import "YMHomePageBannerView.h"
- #import "YMHomeChildController.h"
- #import "YMSheetPopupView.h" // 添加底部弹窗组件导入
- #import "YMPopupView.h" // 添加弹窗管理器导入
- #import "YMGroupGreetingPopupView.h"
- #import "YMGroupGreetingViewModel.h"
- #import "YMSheetPopupView.h" // 添加底部弹窗组件导入
- #import "YMPopupView.h" // 添加弹窗管理器导入
- #define LZCategoryViewHeight 54.0f
- @interface YMHomeController ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
- {
- dispatch_source_t _timer;
- }
- /// 首页VM
- @property (nonatomic, strong) YMHomePageViewModel *viewModel;
- @property (nonatomic, strong) YMGroupGreetingViewModel *groupGreetingViewModel;
- @property (nonatomic, strong) YMGroupGreetingPopupView *greetingView;
- @property (nonatomic, strong) YMPopupView *greetingPopupView;
- /// 首页Banner视图
- @property (nonatomic, strong) YMHomePageBannerView *bannerView;
- @property (nonatomic, strong) JXCategoryTitleView *categoryView;
- /// 搜索按钮
- @property (nonatomic, strong) UILabel *searchLabel;
- /// 搜索按钮
- @property (nonatomic, strong) UIButton *searchBtn;
- @property (nonatomic, strong) UIButton *zhidingBtn;
- /// banner视图高度
- @property (nonatomic, assign) CGFloat bannerViewHeight;
- @property (nonatomic, assign) NSInteger selectIndex;
- @end
- @implementation YMHomeController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavHidden:YES];
- self.selectIndex = 0;
- [OCNotificationCenter addObserver:self selector:@selector(updateOnline) name:@"youpaifuserOnlineUpdate" object:nil];
-
- UIView *categoryBgV = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth,[self preferredCategoryViewHeight])];
- [self.view addSubview:categoryBgV];
-
- // UIImageView *homeImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth,adapt(170))];
- // homeImgV.userInteractionEnabled = true;
- // homeImgV.image = [UIImage imageNamed:@"home_top_bg"];
- // [categoryBgV addSubview:homeImgV];
-
- JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0.0f, StatusBarHeight, KScreenWidth - 16 * 2.0f - 24, LZCategoryViewHeight)];
- categoryView.backgroundColor = [UIColor clearColor];
- categoryView.titles = self.titles;
- categoryView.delegate = self;
- categoryView.titleSelectedColor = DecColorFromRGBA(0, 0, 0, 1);
- categoryView.titleColor = DecColorFromRGBA(0, 0, 0, 0.5);
- categoryView.titleColorGradientEnabled = YES;
- categoryView.titleFont = LCFont(18.0f);
- categoryView.titleSelectedFont = LCBoldFont(18.0f);
- categoryView.cellWidth = adapt(53);
- categoryView.cellSpacing = 0;
- categoryView.contentEdgeInsetLeft = 15;
- categoryView.averageCellSpacingEnabled = NO;
- [categoryBgV addSubview:categoryView];
- self.categoryView = categoryView;
-
- JXCategoryIndicatorImageView *indicatorImageView = [[JXCategoryIndicatorImageView alloc] init];
- indicatorImageView.indicatorImageViewSize = CGSizeMake(adapt(68), 44);
- UIImageView *indicatorImgv = [[UIImageView alloc] init];
- indicatorImgv.image = [UIImage imageNamed:@"home_indicator_img"];
- indicatorImgv.contentMode = UIViewContentModeScaleAspectFit;
- [indicatorImageView addSubview:indicatorImgv];
- [indicatorImgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(indicatorImageView);
- make.width.mas_equalTo(46);
- make.height.mas_equalTo(32);
- }];
- categoryView.indicators = @[indicatorImageView];
-
-
-
- // UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, StatusBarHeight + LZCategoryViewHeight, KScreenWidth, (adapt(90) + adapt(56) + 30))];
- // [categoryBgV addSubview:topView];
- // self.bannerView.frame = topView.bounds;
- // [topView addSubview: self.bannerView];
- // self.bannerView.frame = CGRectZero;
- // self.bannerView.hidden = YES;
-
-
- JXCategoryListContainerView *listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self];
- // listContainerView.listCellBackgroundColor = [UIColor whiteColor];
-
- listContainerView.frame = CGRectMake(0.0f,categoryBgV.mj_h, KScreenWidth, KScreenHeight - categoryBgV.mj_h - TabbarHeight);
- [self.view addSubview:listContainerView];
- categoryView.listContainer = listContainerView;
-
- // self.zhidingBtn.frame = CGRectMake(KScreenWidth - 16 - 24 - 10 - 24,(LZCategoryViewHeight - 44) / 2.0f + StatusBarHeight + 13,26,26);
- // [categoryBgV addSubview: self.zhidingBtn];
-
-
- self.searchBtn.frame = CGRectMake(KScreenWidth - 16 - 69,(LZCategoryViewHeight - 44) / 2.0f + StatusBarHeight,69,44);
- [categoryBgV addSubview:self.searchBtn];
- [self.searchBtn addSubview:self.searchLabel];
- [self.searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.searchBtn).offset(8);
- make.centerY.equalTo(self.searchBtn).offset(3);
- }];
-
- }
- - (CGFloat)preferredCategoryViewHeight {
- //return (LZCategoryViewHeight + StatusBarHeight + adapt(90) + adapt(56) + 30);
- return (LZCategoryViewHeight + StatusBarHeight);
- }
- -(void)zhidingClick{
- [self.categoryView reloadData];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- // self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.viewModel judgementsIsOpenAdolescentModel];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- - (void)ym_setupViews{
- [self.view setNeedsUpdateConstraints];
- [self.view updateConstraintsIfNeeded];
- }
- - (void)updateViewConstraints{
-
- // [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.view).offset(kYMStatusBarHeight);
- // make.left.equalTo(self.view);
- // make.right.equalTo(self.view);
- // make.bottom.equalTo(self.view);
- // }];
-
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel{
- [self.bannerView ym_bindViewModel:self.viewModel.bannerVM];
- self.viewModel.refreshHomeListData = ^{
- NSLog(@"刷新首页数据");
- [OCNotificationCenter postNotificationName:REFRESH_HOME_NOTIFICATION object:nil userInfo:@{}];
- };
- [[YMGlobalUtils shared] getConfig];
- // if([self.viewModel isFemaleGender]){
- // self.zhidingBtn.hidden = false;
- // }else{
- // self.zhidingBtn.hidden = true;
- // }
- [self headerRefreshing];
-
- }
- /// 更新在线状态
- - (void)updateOnline{
- if (self->_timer) {
- dispatch_source_cancel(self->_timer);
- }
- if ([LCSaveData getTokenString] == nil) {
- return;
- }
- [LCHttpHelper requestWithURLString:onlineUpdate parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSInteger user_online_open = [[[dict objectForKey:@"data"]objectForKey:@"user_online_open"] integerValue];
- int user_online_time = [[[dict objectForKey:@"data"]objectForKey:@"user_online_time"] intValue];
- if (user_online_open == 1) {
- __block int timeout= user_online_time;
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- self->_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(self->_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(self->_timer, ^{
- if(timeout<=0){
- dispatch_source_cancel(self->_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- [self updateOnline];
- });
- }else{
- // NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- //NSLog(@"strTime strTime %@",strTime);
- //NSLog(@"当前时间挫%lld",[[LCTools getCurrentTimestamp] longLongValue]);
- });
- timeout--;
- }});
- dispatch_resume(self->_timer);
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)headerRefreshing{
- [self.viewModel getAdvertData];
- // [self.viewModel getLevelIconData];
- [self.viewModel getBadgesAndNobilityIconData];
- [self.viewModel.bannerVM getOnTvData];
- [OCNotificationCenter postNotificationName:REFRESH_HOME_NOTIFICATION object:nil userInfo:@{}];
- }
- - (YMHomePageBannerView *)bannerView{
- if (!_bannerView) {
- _bannerView = [[YMHomePageBannerView alloc]init];
- @weakify(self)
- _bannerView.bannerViewHeightBlock = ^(CGFloat bannerViewHeight) {
- @strongify(self)
- self.bannerViewHeight = bannerViewHeight;
- };
- }
- return _bannerView;
- }
- - (UILabel *)searchLabel {
- if (!_searchLabel) {
- _searchLabel = [[UILabel alloc] init];
- _searchLabel.text = @"寻找";
- _searchLabel.textColor = UIColor.whiteColor;
- _searchLabel.font = LCFont(11);
- }
- return _searchLabel;
- }
- - (UIButton *)searchBtn{
- if (!_searchBtn) {
- _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_searchBtn setImage:ImageByName(@"ym_home_page_xunzhao") forState:UIControlStateNormal];
- WS(weakSelf)
- [[[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf.viewModel gotoSearchUser];
- }];
- }
- return _searchBtn;
- }
- - (UIButton *)zhidingBtn{
- if (!_zhidingBtn) {
- _zhidingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_zhidingBtn setImage:ImageByName(@"home_msg_zhiding") forState:UIControlStateNormal];
- _zhidingBtn.hidden = true;
- WS(weakSelf)
- [[[_zhidingBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf showZhidingBottomSheet];
- }];
- }
- return _zhidingBtn;
- }
- /**
- * 显示置顶功能底部选择弹窗
- * 包含自动置顶、群打招呼、取消三个选项
- */
- - (void)showZhidingBottomSheet {
- // 创建底部弹窗视图
- YMSheetPopupView *sheetView = [[YMSheetPopupView alloc] init];
-
- // 配置弹窗选项列表
- NSArray *optionList = @[
- @"自动置顶",
- @"群打招呼"
- ];
-
- // 配置弹窗数据
- [sheetView configutationWithItemList:optionList];
-
- // 设置选择回调
- WS(weakSelf)
- sheetView.selectIndexBlock = ^(NSInteger index) {
- [weakSelf handleZhidingSelection:index];
- };
-
- // 设置关闭回调(对应"取消"选项)
- sheetView.closeBlock = ^{
- // 用户点击取消按钮
- NSLog(@"用户取消了置顶操作");
- [YMPopupView removeLastPopView];
- };
-
- // 创建弹窗管理器并显示
- YMPopupView *popupView = [YMPopupView initWithCustomView:sheetView];
- popupView.popDuration = 0.3; // 弹出动画时间
- popupView.positionStyle = YMPositionStyleBottom; // 底部弹出
- popupView.popStyle = YMPopupStyleSmoothFromBottom; // 从底部滑入动画
- popupView.dismissStyle = YMDismissStyleSmoothToBottom; // 滑出到底部动画
- popupView.isClickBgDismiss = YES; // 点击背景关闭
- popupView.bgAlpha = 0.5; // 背景透明度
-
- // 显示弹窗
- [popupView pop];
- }
- /**
- * 处理置顶选择结果
- * @param index 选择的选项索引(0:自动置顶, 1:群打招呼)
- */
- - (void)handleZhidingSelection:(NSInteger)index {
- switch (index) {
- case 0:
- // 自动置顶
- NSLog(@"选择了:自动置顶");
- [self performAutoZhiding];
- break;
- case 1:
- // 群打招呼
- NSLog(@"选择了:群打招呼");
- [self performGroupGreeting];
- break;
- default:
- break;
- }
-
- // 关闭弹窗
- [YMPopupView removeLastPopView];
- }
- /**
- * 执行自动置顶功能
- */
- - (void)performAutoZhiding {
- // 调用原有的置顶数据方法
- [self.viewModel zhidingData];
-
- // 可以添加额外的自动置顶逻辑
- // 例如:显示成功提示、刷新列表等
- NSLog(@"自动置顶功能已执行");
- }
- /**
- * 执行群打招呼功能
- */
- - (void)performGroupGreeting {
- // 先请求获取推荐用户列表
- [self requestGroupGreetingUserList:YES];
-
- }
- /**
- * 请求群打招呼用户列表
- */
- - (void)requestGroupGreetingUserList:(BOOL)isNew {
- WS(weakSelf)
- [self.groupGreetingViewModel getGroupGreetingDataIsNew:isNew completion:^(BOOL isSuccess) {
- if (isSuccess) {
- [weakSelf showGroupGreetingPopupView];
- }
- }];
-
- }
- /**
- * 显示群打招呼弹窗
- */
- - (void)showGroupGreetingPopupView {
- [_greetingPopupView dismiss];
-
- // 创建群打招呼弹窗
- _greetingView = [[YMGroupGreetingPopupView alloc] initWithFrame:UIScreen.mainScreen.bounds];
- [_greetingView configureWithUserList:self.groupGreetingViewModel.listDataArray];
-
- WS(weakSelf)
-
- // 设置换一换回调
- _greetingView.refreshBlock = ^{
- [weakSelf requestGroupGreetingUserList:NO];
- };
-
- // 设置发送打招呼回调
- _greetingView.sendBlock = ^{
- [weakSelf sendGroupGreetingRequest];
- };
-
- _greetingView.clickBlankAreaBlock = ^{
- [weakSelf.greetingPopupView dismiss];
- };
-
- // 使用YMPopupView显示弹窗
- _greetingPopupView = [YMPopupView initWithCustomView:_greetingView];
- _greetingPopupView.positionStyle = YMPositionStyleCenter;
- _greetingPopupView.popDuration = 0.3; // 弹出动画时间
- _greetingPopupView.popStyle = YMPopupStyleFade; // 从底部滑入动画
- _greetingPopupView.dismissStyle = YMDismissStyleFade; // 滑出到底部动画
- _greetingPopupView.isClickBgDismiss = YES; // 点击背景关闭
- _greetingPopupView.bgAlpha = 0.5; // 背景透明度
- // 设置关闭回调
- _greetingView.closeBlock = ^{
- [weakSelf.greetingPopupView dismiss];
- };
-
- [_greetingPopupView pop];
- }
- /**
- * 发送群打招呼请求
- */
- - (void)sendGroupGreetingRequest {
- // 显示加载提示
- [ZCHUDHelper show];
-
- NSArray *arr = self.groupGreetingViewModel.listDataArray;
- NSString *str = @"";
- for (int i = 0; i < arr.count; i++) {
- YMGroupGreetingUserModel *model = arr[i];
- str = [str stringByAppendingString:[NSString stringWithFormat:@"%@",@(model.userId)]];
- if (i != arr.count - 1) {
- str = [str stringByAppendingString:@","];
- }
- }
- str = [NSString stringWithFormat:@"[%@]",str];
-
- // 请求参数
- NSDictionary *params = @{
- @"user_ids": str
- };
-
- [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- [ZCHUDHelper dismiss];
-
- NSDictionary *dict = (NSDictionary *)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
-
- if (code == 0) {
- //NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送成功"];
- [ZCHUDHelper showTitle:@"打招呼成功" showtime:2];
- [self.greetingPopupView dismiss];
- //[self.greetingView makeToast:@"打招呼成功" duration:2 position:CSToastPositionCenter];
- } else {
- NSString *message = [dict stringValueForKey:@"message" defaultValue:@"打招呼发送失败"];
- //[ZCHUDHelper showTitle:message];
- [ZCHUDHelper showTitle:message];
- //[self.greetingView makeToast:message duration:2 position:CSToastPositionCenter];
- }
-
- } failure:^(NSError *error) {
- [ZCHUDHelper dismiss];
- [ZCHUDHelper showTitle:@"网络请求失败"];
- }];
- }
- - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
- return self.titles.count;
- }
- - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
- YMHomeChildController *childVC = [[YMHomeChildController alloc] initWithViewModel:self.viewModel.homePageVMListDataArray[index]];
- childVC.jxCategoryPageIndex = index;
- return childVC;
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
- self.selectIndex = index;
- }
- - (NSArray <NSString *> *)titles{
- BOOL isFemaleGender = [OCUserDefaults boolForKey:kIS_FEMALE_GENDER];
- if (isFemaleGender) {
- return @[@"男神",@"在线"];
- } else {
- return @[@"推荐",@"在线"];
- }
- }
- @end
|