123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- //
- // YMHomeChildController.m
- // MSYOUPAI
- //
- // Created by You on 2024/4/18.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMHomeChildController.h"
- #import "YMHomePageListViewModel.h"
- #import "YMChatNotificationViewModel.h"
- #import "CHTCollectionViewWaterfallLayout.h"
- #import "YMHomeChildCollectCell.h"
- @interface YMHomeChildController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
- /// 列表VM
- @property (nonatomic, strong) YMHomePageListViewModel *viewModel;
- /// 内容排版
- @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *contentLayout;
- /// 容器列表
- @property (nonatomic, strong) UICollectionView *contentCollectionView;
- @end
- @implementation YMHomeChildController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavHidden:YES];
- [OCNotificationCenter addObserver:self selector:@selector(refreshHomeData:) name:REFRESH_HOME_NOTIFICATION object:nil];
-
- self.viewModel.jxCategoryPageIndex = self.jxCategoryPageIndex;
-
- YMEmptyView *empty = [YMEmptyView emptyActionViewWithImage:ImageByName(@"ym_common_no_data_icon") titleStr:@"开启“个性化推荐”后可启用推荐列表" detailStr:@"" btnTitleStr:@"立即开启" btnClickBlock:^{
- YMChatNotificationViewModel *chatNotificationVM = [[YMChatNotificationViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CHAT_NOTIFICATION) withUserInfo:@{
- RouterViewModel:chatNotificationVM
- } completion:nil];
- }];
- empty.contentViewOffset = adapt(-80);
- empty.imageSize = kEmptyViewSize;
- empty.titleLabFont = LCFont(13);
- empty.titleLabTextColor = HexColorFromRGB(0x9b9b9b);
- empty.actionBtnCornerRadius = adapt(10);
- empty.actionBtnTitleColor = HexColorFromRGB(0xFFFFFF);
- empty.actionBtnBackGroundColor = HexColorFromRGB(0xfd7bc5);
- self.view.ym_emptyView = empty;
- self.view.ym_emptyView.autoShowEmptyView = NO;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self homePageIsHidePersonalizedRecommendationTips];
- }
- - (void)ym_setupViews {
-
- [self.view addSubview:self.contentCollectionView];
- [self.view setNeedsUpdateConstraints];
- [self.view updateConstraintsIfNeeded];
- }
- - (void)updateViewConstraints {
-
- [self.contentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self.view);
- }];
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel {
-
- [self headerRefreshing];
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.contentCollectionView reloadData];
- switch ([result intValue]) {
- case YMHeaderRefresh_HasMoreData:
- case YMHeaderRefresh_HasNoMoreData:
- {
- [self.contentCollectionView.mj_header endRefreshing];
- [self.contentCollectionView.mj_footer endRefreshing];
-
- }
- break;
- case YMFooterRefresh_HasMoreData:
- {
- [self.contentCollectionView.mj_header endRefreshing];
- [self.contentCollectionView.mj_footer endRefreshing];
- if (self.contentCollectionView.mj_footer == self.noLoadMoreFooter) {
- self.contentCollectionView.mj_footer = self.loadMoreFooter;
- }
- }
- break;
- case YMFooterRefresh_HasNoMoreData:
- {
- [self.contentCollectionView.mj_header endRefreshing];
- [self.contentCollectionView.mj_footer endRefreshing];
- if (self.contentCollectionView.mj_footer == self.loadMoreFooter) {
- self.contentCollectionView.mj_footer = self.noLoadMoreFooter;
- }
- }
- break;
- case YMRefreshError: {
- [self.contentCollectionView.mj_header endRefreshing];
- [self.contentCollectionView.mj_footer endRefreshing];
- }
- break;
- default:
- break;
- }
- [self.contentCollectionView ym_endLoading];
- }];
-
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.viewModel.listDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YMHomeChildCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMHomeChildCollectCell class]) forIndexPath:indexPath];
- YMHomePageListCellViewModel *cellVM = self.viewModel.listDataArray[indexPath.item];
- cellVM.jxCategoryPageIndex = self.jxCategoryPageIndex;
- [cellVM updateWithPageIndex];
- @weakify(self)
- cellVM.changeAccostStatusBlock = ^{
- @strongify(self)
- [UIView performWithoutAnimation:^{
- [self.contentCollectionView reloadItemsAtIndexPaths:@[indexPath]];
- }];
- };
- [cell ym_bindViewModel:cellVM];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- UICollectionReusableView *reusableView = nil;
- reusableView.backgroundColor = [UIColor clearColor];
- return reusableView;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
- return CGSizeZero;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if (self.viewModel.listDataArray[indexPath.item].userId != 0) {
- [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)];
- }
-
- }
- #pragma mark - CHTCollectionViewDelegateWaterfallLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(adapt(340), adapt(90));
- }
- ///首页是否隐藏个性化推荐提示
- - (void)homePageIsHidePersonalizedRecommendationTips{
- if ([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]) {
- self.contentCollectionView.hidden = NO;
- [self.view ym_hideEmptyView];
- } else {
- self.contentCollectionView.hidden = YES;
- [self.view ym_showEmptyView];
- }
- }
- - (void)refreshHomeData:(NSNotification *)notice{
- [self headerRefreshing];
- }
- - (void)headerRefreshing{
- [self.contentCollectionView ym_startLoading];
- self.viewModel.currentPage = 1;
- [self.viewModel getHomePageListData];
- }
- - (void)footerRefreshing{
- [self.contentCollectionView ym_startLoading];
- self.viewModel.currentPage++;
- [self.viewModel getHomePageListData];
- }
- - (CHTCollectionViewWaterfallLayout *)contentLayout{
- if (!_contentLayout) {
- _contentLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
- _contentLayout.columnCount = 1;
- _contentLayout.sectionInset = UIEdgeInsetsMake(adapt(5), adapt(15), 0, adapt(15));
- }
- return _contentLayout;
- }
- - (UICollectionView *)contentCollectionView{
- if (!_contentCollectionView) {
- _contentCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.contentLayout];
- _contentCollectionView.delegate = self;
- _contentCollectionView.dataSource = self;
- _contentCollectionView.showsVerticalScrollIndicator = NO;
- _contentCollectionView.showsHorizontalScrollIndicator = NO;
- _contentCollectionView.backgroundColor = UIColor.whiteColor;
- [_contentCollectionView registerClass:[YMHomeChildCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([YMHomeChildCollectCell class])];
- _contentCollectionView.mj_footer = self.noLoadMoreFooter;
- _contentCollectionView.mj_header = self.refreshHeader;
- YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
- empty.imageSize = kEmptyViewSize;
- _contentCollectionView.ym_emptyView = empty;
- _contentCollectionView.ym_emptyView.autoShowEmptyView = NO;
- }
- return _contentCollectionView;
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (UIView *)listView {
- return self.view;
- }
- @end
|