123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- //
- // XYChatRoomCollectionListViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/6/19.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYChatRoomCollectionListViewController.h"
- #import "XYChatRoomListViewModel.h"
- #import "XYChatRoomListModel.h"
- #import "XYChatRoomListCollectionViewCell.h"
- #import "XYChatRoomOneBigImageCollectionViewCell.h"
- #import "XYChatRoomOneGraphicCollectionViewCell.h"
- #import "XYChatRoomCategoriesModel.h"
- #import "XYCarefulPersonCell.h"
- @interface XYChatRoomCollectionListViewController ()
- @property (nonatomic, strong) XYChatRoomListViewModel *viewModel;
- @end
- @implementation XYChatRoomCollectionListViewController
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- }
- return self;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.categoriesModel.chatRoom_Type == XYChatRoom_Type_Collect) {
- // [self collectionViewDidTriggerHeaderRefresh];
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- // 注册cell
- [self.collectionView registerCell:NSStringFromClass([XYCarefulPersonCell class])];
- [self.collectionView registerCell:NSStringFromClass([XYChatRoomListCollectionViewCell class])];
- [self.collectionView registerCell:NSStringFromClass([XYChatRoomOneBigImageCollectionViewCell class])];
- [self.collectionView registerCell:NSStringFromClass([XYChatRoomOneGraphicCollectionViewCell class])];
-
- //[self collectionViewDidTriggerHeaderRefresh];
-
- if (self.categoriesModel.autoLoad) {
- [self base_reloadListData];
- }
-
- }
- #pragma mark — Override
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, TABBAR_HEIGHT, 0);
- }
- - (void)bindViewModel {
- self.viewModel = XYChatRoomListViewModel.new;
- self.viewModel.categoriesModel = self.categoriesModel;
- if (self.categoriesModel.chatRoom_Type == XYChatRoom_Type_Friends) {
- self.viewModel.shouldPullDownToRefresh = YES;
- }
- }
- - (void)base_reloadListData {
- [self collectionViewDidTriggerHeaderRefresh];
- }
- - (void)collectionViewDidTriggerHeaderRefresh {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id _Nullable responseModel) {
- [self collectionViewDidFinishTriggerHeader:YES reload:YES];
- [self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:150.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- if (self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshEnding)]) {
- [self.delegate headerRefreshEnding];
- }
-
- } failure:^(ZYLNetworkError * _Nullable error) {
- [self collectionViewDidFinishTriggerHeader:YES reload:NO];
- [self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:150.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- if (self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshEnding)]) {
- [self.delegate headerRefreshEnding];
- }
- }];
- }
- - (void)collectionViewDidTriggerFooterRefresh {
- [super collectionViewDidTriggerFooterRefresh];
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
- return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomOneGraphicCollectionViewCell class]) forIndexPath:indexPath];
- }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
- return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomOneBigImageCollectionViewCell class]) forIndexPath:indexPath];
- }else {
-
- XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
- if (model.carefulPerson) {
- return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYCarefulPersonCell class]) forIndexPath:indexPath];
- }
-
- return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYChatRoomListCollectionViewCell class]) forIndexPath:indexPath];
- }
- }
- - (void)configureCell:(XYChatRoomOneGraphicCollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell configureModel:object];
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
- return CGSizeMake(SCREEN_WIDTH, 88.0f);
- }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
- return CGSizeMake(SCREEN_WIDTH - 10.0f * 2, 120.0f + 8.0f + 20.0f);
- }else {
- XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
- if (model.carefulPerson) {
- return CGSizeMake(SCREEN_WIDTH - 32.0f , 140.0f);
- }
- CGFloat width = (SCREEN_WIDTH - 32.0f - 7.0f)/2;
- return CGSizeMake(width, width + 8.0f + 20.0f + 8.0f);
- }
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
- return 0.0f;
- }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
- return 16.0f;
- }else {
- return 12.0f;
- }
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
- return 0.0f;
- }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
- return 16.0f;
- }else {
- return 7.0f;
- }
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneGraphic) {
- return UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
- }else if (self.categoriesModel.layout == XYVoiceRoomListLayoutOneBigImage) {
- return UIEdgeInsetsMake(8.0f, 16.0f, 8.0f, 16.0f);
- }else {
- return UIEdgeInsetsMake(8.0f, 16.0f, 0.0f, 16.0f);
- }
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- XYChatRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
- if (model.carefulPerson) {
-
- return;
- }
-
- if ([model.categoryName isEqualToString:kLocalizedString(@"收藏")]) {
- // 派对Tab,点分类-收藏-[房间封面]的次数
- [StatisticsManager event:@"party_sort_collection_roomcover_click"];
- }else if ([model.categoryName isEqualToString:kLocalizedString(@"热门")]) {
- // 派对Tab,点分类-热门-房间封面的次数
- [StatisticsManager event:@"party_sort_hot_roomcover_click"];
- }
- [[XYChatRoomManager sharedInstance] showChatRoomWithRoomId:model.roomId roomCoverUrl:model.roomCover completion:^{
-
- }];
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (UIView *)listView {
- return self.view;
- }
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - 初始化
- - (void)_setup{
- //self.view.backgroundColor = Color_White;
- //self.collectionView.backgroundColor = Color_White;
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
-
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- @end
|