2025-08-08 10:49:36 +08:00
|
|
|
//
|
|
|
|
|
// QXFindViewController.m
|
|
|
|
|
// QXLive
|
|
|
|
|
//
|
|
|
|
|
// Created by 启星 on 2025/5/27.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "QXFindViewController.h"
|
|
|
|
|
#import "QXDynamicTopicCell.h"
|
|
|
|
|
#import "GKPageControl.h"
|
|
|
|
|
#import "QXDynamicListCell.h"
|
|
|
|
|
#import "QXDynamicNetwork.h"
|
|
|
|
|
#import "QXToppicDynamicViewController.h"
|
|
|
|
|
#import "QXDynamicDetailViewController.h"
|
|
|
|
|
|
|
|
|
|
@interface QXFindViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
|
|
|
|
|
|
|
|
|
|
@property (strong, nonatomic) UICollectionView *collectionView;
|
|
|
|
|
@property (strong, nonatomic) NSMutableArray *hotTopicArray;
|
|
|
|
|
@property (nonatomic,strong)GKPageControl *pageControl;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation QXFindViewController
|
|
|
|
|
-(UIView *)listView{
|
|
|
|
|
return self.view;
|
|
|
|
|
}
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:noticeUserLogin object:nil];
|
|
|
|
|
}
|
|
|
|
|
- (void)initSubViews{
|
|
|
|
|
self.page = 1;
|
|
|
|
|
self.bgImageHidden = YES;
|
|
|
|
|
[self.view addSubview:self.collectionView];
|
|
|
|
|
[self.view addSubview:self.pageControl];
|
|
|
|
|
[self.view addSubview:self.tableView];
|
|
|
|
|
[self getTopicList];
|
|
|
|
|
[self getDynamicList];
|
|
|
|
|
}
|
|
|
|
|
-(void)getTopicList{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork getTopicListWithPage:self.page isTopTopic:YES successBlock:^(NSArray<QXTopicModel *> * _Nonnull hotos) {
|
|
|
|
|
if (weakSelf.page == 1) {
|
|
|
|
|
[weakSelf.hotTopicArray removeAllObjects];
|
|
|
|
|
}
|
|
|
|
|
[weakSelf.hotTopicArray addObjectsFromArray:hotos];
|
|
|
|
|
if (hotos.count == 0) {
|
|
|
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
|
|
|
}else{
|
|
|
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
|
|
|
}
|
|
|
|
|
if (weakSelf.hotTopicArray.count %4 >0) {
|
|
|
|
|
weakSelf.pageControl.numberOfPages = self.hotTopicArray.count/4+1;
|
|
|
|
|
}else{
|
|
|
|
|
weakSelf.pageControl.numberOfPages = self.hotTopicArray.count/4;
|
|
|
|
|
}
|
|
|
|
|
weakSelf.pageControl.currentPage = 0;
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)loginSuccess{
|
|
|
|
|
[self getTopicList];
|
|
|
|
|
[self getDynamicList];
|
|
|
|
|
}
|
|
|
|
|
-(void)getDynamicList{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork getDynamicListWithPage:self.page successBlock:^(NSArray<QXDynamicModel *> * _Nonnull hotos) {
|
|
|
|
|
if (weakSelf.page == 1) {
|
|
|
|
|
[weakSelf.dataArray removeAllObjects];
|
|
|
|
|
}
|
|
|
|
|
[weakSelf.dataArray addObjectsFromArray:hotos];
|
|
|
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
|
|
|
if (hotos.count == 0) {
|
|
|
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
|
|
|
}else{
|
|
|
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
|
|
|
}
|
|
|
|
|
[self.tableView reloadData];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
|
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
#pragma mark - UITableViewDelegate,UITableViewDataSource
|
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
|
|
|
return self.dataArray.count;
|
|
|
|
|
}
|
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
QXDynamicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QXDynamicListCell" forIndexPath:indexPath];
|
|
|
|
|
cell.selectionStyle = NO;
|
|
|
|
|
cell.cellType = QXDynamicListCellDynamic;
|
|
|
|
|
cell.model = self.dataArray[indexPath.row];
|
|
|
|
|
// SPTrendListModel *model = self.dataArray[indexPath.row];
|
|
|
|
|
// cell.model = model;
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
cell.onDeleteBlock = ^(QXDynamicModel * _Nonnull model) {
|
|
|
|
|
[weakSelf.dataArray removeObject:model];
|
|
|
|
|
[weakSelf.tableView reloadSection:indexPath.section withRowAnimation:(UITableViewRowAnimationAutomatic)];
|
|
|
|
|
};
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
2025-08-11 17:02:47 +08:00
|
|
|
if (!QXGlobal.shareGlobal.isLogin) {
|
|
|
|
|
[[QXGlobal shareGlobal] logOut];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-08 10:49:36 +08:00
|
|
|
QXDynamicModel *model = self.dataArray[indexPath.row];
|
|
|
|
|
QXDynamicDetailViewController *vc = [[QXDynamicDetailViewController alloc] init];
|
|
|
|
|
vc.model = model;
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
|
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
|
|
|
return self.hotTopicArray.count;
|
|
|
|
|
}
|
|
|
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
QXDynamicTopicCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXDynamicTopicCell" forIndexPath:indexPath];
|
|
|
|
|
QXTopicModel *model = self.hotTopicArray[indexPath.row];
|
|
|
|
|
cell.model = model;
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
2025-08-11 17:02:47 +08:00
|
|
|
if (!QXGlobal.shareGlobal.isLogin) {
|
|
|
|
|
[[QXGlobal shareGlobal] logOut];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-08 10:49:36 +08:00
|
|
|
QXTopicModel *model = self.hotTopicArray[indexPath.row];
|
|
|
|
|
QXToppicDynamicViewController *vc = [[QXToppicDynamicViewController alloc] init];
|
|
|
|
|
vc.model = model;
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
|
|
|
|
|
if ([scrollView isKindOfClass:[UICollectionView class]]) {
|
|
|
|
|
long offsetX = (long)scrollView.contentOffset.x;
|
|
|
|
|
int width = SCREEN_WIDTH-32;
|
|
|
|
|
int remainder = offsetX % width;
|
|
|
|
|
NSInteger index;
|
|
|
|
|
if (remainder>(width)/2) {
|
|
|
|
|
index = offsetX/width+1;
|
|
|
|
|
}else{
|
|
|
|
|
index = offsetX/width;
|
|
|
|
|
}
|
|
|
|
|
self.pageControl.currentPage = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(UITableView *)tableView{
|
|
|
|
|
if (!_tableView) {
|
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.pageControl.bottom+5, SCREEN_WIDTH, SCREEN_HEIGHT-TabbarContentHeight-self.pageControl.bottom-5-13) style:UITableViewStylePlain];
|
|
|
|
|
self.tableView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
self.tableView.delegate = self;
|
|
|
|
|
self.tableView.dataSource = self;
|
|
|
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"QXDynamicListCell" bundle:nil] forCellReuseIdentifier:@"QXDynamicListCell"];
|
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
|
// self.tableView.estimatedRowHeight = 0;
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
|
|
|
weakSelf.page = 1;
|
|
|
|
|
[weakSelf getDynamicList];
|
|
|
|
|
}];
|
|
|
|
|
_tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
|
|
|
|
weakSelf.page++;
|
|
|
|
|
[weakSelf getDynamicList];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
return _tableView;
|
|
|
|
|
}
|
|
|
|
|
-(UICollectionView *)collectionView{
|
|
|
|
|
if (!_collectionView) {
|
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
|
layout.minimumLineSpacing = 16;
|
|
|
|
|
layout.minimumInteritemSpacing = 16;
|
|
|
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
|
|
|
layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*3)/2, 45);
|
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(16, 13, SCREEN_WIDTH-32, 45*2+16) collectionViewLayout:layout];
|
|
|
|
|
_collectionView.delegate = self;
|
|
|
|
|
_collectionView.dataSource = self;
|
|
|
|
|
_collectionView.pagingEnabled = YES;
|
|
|
|
|
_collectionView.bounces = NO;
|
|
|
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
|
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXDynamicTopicCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXDynamicTopicCell"];
|
|
|
|
|
}
|
|
|
|
|
return _collectionView;
|
|
|
|
|
}
|
|
|
|
|
-(GKPageControl *)pageControl{
|
|
|
|
|
if (!_pageControl) {
|
|
|
|
|
_pageControl = [[GKPageControl alloc] initWithFrame:CGRectMake(0, self.collectionView.bottom+7, SCREEN_WIDTH, 8)];
|
|
|
|
|
_pageControl.style = GKPageControlStyleRectangle;
|
|
|
|
|
_pageControl.dotWidth = 15;
|
|
|
|
|
_pageControl.dotHeight = 5;
|
|
|
|
|
_pageControl.dotMargin = 2;
|
|
|
|
|
_pageControl.pageIndicatorTintColor = UIColor.whiteColor;
|
|
|
|
|
_pageControl.currentPageIndicatorTintColor = QXConfig.textColor;
|
|
|
|
|
}
|
|
|
|
|
return _pageControl;
|
|
|
|
|
}
|
|
|
|
|
-(NSMutableArray *)hotTopicArray{
|
|
|
|
|
if (!_hotTopicArray) {
|
|
|
|
|
_hotTopicArray = [NSMutableArray array];
|
|
|
|
|
}
|
|
|
|
|
return _hotTopicArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@end
|