2023-12-07 10:50:21 +08:00
|
|
|
//
|
|
|
|
// DDV2HomeListVC.m
|
|
|
|
// DingDangApp
|
|
|
|
//
|
|
|
|
// Created by apple on 2023/7/1.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DDV2HomeListVC.h"
|
|
|
|
#import "DDRoomPartyModel.h"
|
|
|
|
#import "DDV2HomeVerticalCell.h"
|
|
|
|
#import "DDV2HomeHorizontalCell.h"
|
|
|
|
|
2023-12-12 18:34:26 +08:00
|
|
|
#import "Api+DDHomeApi.h"
|
|
|
|
#import "AccountInfoStorage.h"
|
2023-12-07 10:50:21 +08:00
|
|
|
@interface DDV2HomeListVC () <UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataArr;
|
|
|
|
@property (nonatomic, assign) NSInteger pageNum;
|
|
|
|
@property (nonatomic,assign) BOOL isClick;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DDV2HomeListVC
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
|
|
|
[self initWithSubView];
|
|
|
|
|
|
|
|
self.pageNum = 1;
|
|
|
|
[self requestData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initWithSubView {
|
|
|
|
|
|
|
|
self.view.backgroundColor = DDHEXColor(0xF6F6F6);
|
|
|
|
[self.view addSubview:self.collectionView];
|
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.top.equalTo(self.view).inset(0);
|
|
|
|
make.bottom.mas_equalTo(-KTABBAR_H);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestData {
|
2023-12-12 18:34:26 +08:00
|
|
|
WeakSelf(ws)
|
|
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
2023-12-14 16:36:49 +08:00
|
|
|
[Api dd_getHomePageRecommendListComplection:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
2023-12-12 18:34:26 +08:00
|
|
|
[ws endrefresh];
|
|
|
|
if(code == 200){
|
|
|
|
|
|
|
|
if (self.pageNum == 1) {
|
|
|
|
[ws.dataArr removeAllObjects];
|
|
|
|
}
|
|
|
|
NSArray *list = [DDRoomPartyModel DD_ModelsWithArray:data.data];
|
|
|
|
[ws.dataArr addObjectsFromArray:list];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} uid:uid tabId:self.type pageNum:@(self.pageNum).stringValue pageSize:@"20"];
|
|
|
|
|
|
|
|
return;
|
2023-12-07 10:50:21 +08:00
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
[dic setObject:@(20) forKey:@"current_page"];
|
|
|
|
[dic setObject:@(self.pageNum) forKey:@"page_number"];
|
|
|
|
if ([self.type isEqualToString:@"collect"] || [self.type isEqualToString:@"hot"]) {
|
|
|
|
[dic setObject:self.type forKey:@"scene"];
|
|
|
|
}else{
|
|
|
|
[dic setObject:@"type" forKey:@"scene"];
|
|
|
|
[dic setObject:self.type forKey:@"type_id"];
|
|
|
|
}
|
|
|
|
|
2023-12-14 19:08:53 -08:00
|
|
|
/// /room/list
|
|
|
|
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"U7Vw0Xckn7CQFkKrvg3Lzw=="];
|
|
|
|
[NetworkRequest requestPOST:url parameters:dic block:^(BaseResponse * _Nonnull response) {
|
2023-12-07 10:50:21 +08:00
|
|
|
if (response.isSuccess) {
|
|
|
|
if ([ToolsObject IsNullWithObject:response.data]) {
|
|
|
|
[ws endrefresh];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self.pageNum == 1) {
|
|
|
|
[ws.dataArr removeAllObjects];
|
|
|
|
}
|
|
|
|
[ws.dataArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDRoomPartyModel.class json:response.data[@"record"]]];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
});
|
|
|
|
if ([response.data[@"next"]integerValue] == 0) {
|
|
|
|
[self.collectionView.mj_footer endRefreshingWithNoMoreData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)endrefresh
|
|
|
|
{
|
|
|
|
[self.collectionView.mj_header endRefreshing];
|
|
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - <UICollectionViewDataSource, UICollectionViewDelegate>
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
return self.dataArr.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
if(indexPath.item<3){
|
|
|
|
return CGSizeMake((kWidth-50)/3, (kWidth-50)/3+50);
|
|
|
|
}else{
|
|
|
|
return CGSizeMake(kWidth - 30, 110);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.row < 3) {
|
|
|
|
DDV2HomeVerticalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DDV2HomeVerticalCell" forIndexPath:indexPath];
|
|
|
|
if (indexPath.row < self.dataArr.count) {
|
|
|
|
DDRoomPartyModel *model = self.dataArr[indexPath.row];
|
|
|
|
cell.model = model;
|
|
|
|
}
|
|
|
|
cell.contentView.backgroundColor = UIColor.clearColor;
|
|
|
|
return cell;
|
|
|
|
} else {
|
|
|
|
DDV2HomeHorizontalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DDV2HomeHorizontalCell" forIndexPath:indexPath];
|
|
|
|
if (indexPath.row < self.dataArr.count) {
|
|
|
|
DDRoomPartyModel *model = self.dataArr[indexPath.row];
|
|
|
|
cell.model = model;
|
|
|
|
}
|
|
|
|
cell.contentView.backgroundColor = UIColor.clearColor;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (self.isClick) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
self.isClick = YES;
|
|
|
|
DDRoomPartyModel *model = self.dataArr[indexPath.item];
|
|
|
|
[[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]];
|
|
|
|
|
|
|
|
WeakSelf(ws)
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
|
|
ws.isClick = NO;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
-(NSMutableArray *)dataArr
|
|
|
|
{
|
|
|
|
if (!_dataArr) {
|
|
|
|
_dataArr = [NSMutableArray array];
|
|
|
|
}
|
|
|
|
return _dataArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UICollectionView *)collectionView {
|
|
|
|
if (!_collectionView) {
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
|
|
|
|
layout.minimumLineSpacing = 12;
|
|
|
|
layout.minimumInteritemSpacing = 7;
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
|
|
layout.sectionInset = UIEdgeInsetsMake(10, 16, 0, 16);
|
|
|
|
|
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
|
|
_collectionView.backgroundColor = UIColor.clearColor;
|
|
|
|
_collectionView.showsVerticalScrollIndicator = NO;
|
|
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
|
|
_collectionView.delegate = self;
|
|
|
|
_collectionView.dataSource = self;
|
|
|
|
_collectionView.layer.masksToBounds = YES;
|
|
|
|
_collectionView.layer.cornerRadius = 12;
|
|
|
|
[_collectionView registerClass:[DDV2HomeVerticalCell class] forCellWithReuseIdentifier:@"DDV2HomeVerticalCell"];
|
|
|
|
[_collectionView registerClass:[DDV2HomeHorizontalCell class] forCellWithReuseIdentifier:@"DDV2HomeHorizontalCell"];
|
|
|
|
if ([_collectionView respondsToSelector:@selector(setLayoutMargins:)]){
|
|
|
|
[_collectionView setLayoutMargins:UIEdgeInsetsZero];
|
|
|
|
}
|
|
|
|
_collectionView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
[_collectionView adjustedContentInsetDidChange];
|
|
|
|
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
}
|
|
|
|
WeakSelf(ws)
|
|
|
|
// 下拉刷新
|
|
|
|
_collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
|
|
[ws requestData];
|
|
|
|
}];
|
|
|
|
// 上拉加载
|
|
|
|
_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
|
|
ws.pageNum ++ ;
|
|
|
|
[ws requestData];/** 列表 */
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
return _collectionView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|