Files
real-e-party-iOS/YuMi/Modules/YMMonents/View/XPMomentsTopicListViewController.m
edwinQQQ a35a711be6 chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
2025-10-09 16:19:14 +08:00

167 lines
5.2 KiB
Objective-C

//
// YMMoentsTopicListViewController.m
// YUMI
//
// Created by YUMI on 2022/8/18.
//
#import "XPMomentsTopicListViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NSArray+Safe.h"
///Model
#import "MomentsTopicModel.h"
///View
#import "XPMomentTopicContainerViewController.h"
///P
#import "XPMomentsTopicListPresenter.h"
#import "XPMomentsTopicListProtocol.h"
@interface XPMomentsTopicListViewController ()<UITableViewDelegate, UITableViewDataSource, XPMomentsTopicListProtocol>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *datasource;
@property (nonatomic,assign) int page;
@end
@implementation XPMomentsTopicListViewController
- (__kindof id)createPresenter {
return [[XPMomentsTopicListPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRefresh];
[self initSubViews];
[self initSubViewConstraints];
}
- (void)initHeaderAndFooterRefresh {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
header.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
self.tableView.mj_header = header;
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.tableView.mj_footer = footer;
[self headerRefresh];
}
- (void)headerRefresh {
self.page = 1;
[self.presenter getMoentsTopicList:self.page pageSize:20 state:0];
}
- (void)footerRefresh {
self.page++;
[self.presenter getMoentsTopicList:self.page pageSize:20 state:1];
}
#pragma mark - Private Method
- (void)initSubViews {
self.title = YMLocalizedString(@"XPMoentsTopicListViewController0");
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([UITableViewCell class])];
}
MomentsTopicModel * topicModel = [self.datasource xpSafeObjectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"#%@", topicModel.name];
cell.textLabel.textColor = [DJDKMIMOMColor mainTextColor];
cell.textLabel.font = [UIFont systemFontOfSize:13];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
MomentsTopicModel * topicModel = [self.datasource xpSafeObjectAtIndex:indexPath.row];
XPMomentTopicContainerViewController * topicVC = [[XPMomentTopicContainerViewController alloc] init];
topicVC.worldId = topicModel.tId;
[self.navigationController pushViewController:topicVC animated:YES];
}
}
#pragma mark - XPMonentsTopicListProtocol
- (void)getMomentsTopicListSuccess:(NSArray *)list state:(int)state {
if (state == 0) {
[self.tableView.mj_header endRefreshing];
[self.datasource removeAllObjects];
} else {
if (list.count <= 0) {
[self showErrorToast:YMLocalizedString(@"XPMoentsTopicListViewController1")];
}
[self.tableView.mj_footer endRefreshing];
}
if (list.count > 0) {
[self.datasource addObjectsFromArray:list];
}
[self.tableView reloadData];
}
- (void)getMomentsTopicFail:(NSString *)message state:(int)state {
if (state == 0) {
[self.tableView.mj_header endRefreshing];
} else {
[self.tableView.mj_footer endRefreshing];
}
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end