346 lines
13 KiB
Objective-C
346 lines
13 KiB
Objective-C
//
|
|
// XPMonentsRecommendViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/11.
|
|
//
|
|
|
|
#import "XPMonentsRecommendViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
///Tool
|
|
|
|
|
|
#import "XPMonentsLayoutConfig.h"
|
|
#import "TTPopup.h"
|
|
///Model
|
|
#import "MonentsInfoModel.h"
|
|
#import "MonentsTopicModel.h"
|
|
///P
|
|
#import "XPMonentsRecommendPresenter.h"
|
|
#import "XPMonentsRecommendProtocol.h"
|
|
///View
|
|
#import "XPMonentsTableViewCell.h"
|
|
#import "XPMonentsEmptyTableViewCell.h"
|
|
#import "XPMonentsRecommendHeaderView.h"
|
|
#import "XPMonentsDetailViewController.h"
|
|
#import "XPMonentTopicContainerViewController.h"
|
|
#import "XPMoentsTopicListViewController.h"
|
|
|
|
UIKIT_EXTERN NSString *kRequestRicket;
|
|
@interface XPMonentsRecommendViewController ()<UIGestureRecognizerDelegate,UITableViewDelegate, UITableViewDataSource,XPMonentsRecommendProtocol, XPMonentsTableViewCellDelegate,XPMonentsRecommendHeaderViewDelegate, XPMonentsDetailViewControllerDelegate>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///数据源
|
|
@property (nonatomic,strong) NSMutableArray<MonentsInfoModel *> *datasource;
|
|
///当前的页数
|
|
@property (nonatomic,assign) NSInteger page;
|
|
///是否有更多的数据
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
///顶部视图
|
|
@property (nonatomic,strong) XPMonentsRecommendHeaderView *headerView;
|
|
@end
|
|
|
|
@implementation XPMonentsRecommendViewController
|
|
-(void)dealloc{
|
|
[[NSNotificationCenter defaultCenter]removeObserver:self];
|
|
}
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (__kindof id)createPresenter {
|
|
return [[XPMonentsRecommendPresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initHeaderAndFooterRrfresh];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.tableView];
|
|
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
|
|
self.tableView.tableHeaderView = self.headerView;
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(requestRicketSuccess:) name:kRequestRicket object:nil];
|
|
|
|
}
|
|
-(void)requestRicketSuccess:(NSNotification *)not{
|
|
if([not.object isKindOfClass:[NSDictionary class]])return;
|
|
BOOL is = [not.object boolValue];
|
|
if(is == YES){
|
|
[self headerRefresh];
|
|
}else{
|
|
[XNDJTDDLoadingTool hideOnlyView:self.tabBarController.view];
|
|
}
|
|
}
|
|
|
|
#pragma mark - 下拉刷新
|
|
- (void)initHeaderAndFooterRrfresh {
|
|
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];
|
|
}
|
|
|
|
#pragma mark - 刷新的fangfa
|
|
- (void)headerRefresh {
|
|
[XNDJTDDLoadingTool showOnlyView:self.tabBarController.view];
|
|
if([AccountInfoStorage instance].isRequestRicket == YES){
|
|
return;
|
|
}
|
|
self.page = 1;
|
|
[self.presenter getMonentsRecommendList:self.page pageSize:20 state:0];
|
|
[self.presenter getMonentsTopicList:self.page pageSize:20];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
if([AccountInfoStorage instance].isRequestRicket == YES)return;
|
|
if (self.hasNoMoreData) {
|
|
[self showErrorToast:YMLocalizedString(@"XPMonentsRecommendViewController0")];
|
|
[self.tableView.mj_footer endRefreshing];
|
|
return;
|
|
}
|
|
self.page++;
|
|
[self.presenter getMonentsRecommendList:self.page pageSize:20 state:1];
|
|
}
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.datasource.count > 0 ? self.datasource.count : 1;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
MonentsInfoModel * monentInfo= [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
[XPMonentsLayoutConfig layoutMonentsModel:monentInfo];
|
|
|
|
if(monentInfo.squareTop && monentInfo.content.length == 0){
|
|
return monentInfo.rowHeight + 20 ;
|
|
}else{
|
|
return monentInfo.rowHeight;
|
|
}
|
|
|
|
}
|
|
return KScreenHeight - kNavigationHeight - 49 - kSafeAreaBottomHeight;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
XPMonentsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsTableViewCell class])];
|
|
MonentsInfoModel * monentsInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
cell.monentsInfo = monentsInfo;
|
|
cell.delegate = self;
|
|
return cell;
|
|
}
|
|
XPMonentsEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsEmptyTableViewCell class])];
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (self.datasource.count > 0) {
|
|
XPMonentsDetailViewController * detailVC = [[XPMonentsDetailViewController alloc] init];
|
|
MonentsInfoModel * monentsInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
detailVC.monentsInfo = monentsInfo;
|
|
detailVC.delegate = self;
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
}
|
|
}
|
|
#pragma mark - XPMonentsDetailViewControllerDelegate
|
|
- (void)xPMonentsDetailViewController:(XPMonentsDetailViewController *)view deleteMonents:(NSString *)dynamicId {
|
|
__block MonentsInfoModel * deleteInfo;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MonentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == dynamicId.integerValue) {
|
|
deleteInfo = obj;
|
|
}
|
|
}];
|
|
|
|
if (deleteInfo) {
|
|
[self.datasource removeObject:deleteInfo];
|
|
[self.tableView reloadData];
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPMonentsTableViewCellDelegate
|
|
|
|
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClicShielding:(MonentsInfoModel *)monentsInfo{
|
|
[self showLoading];
|
|
[self.presenter requesstShieldingWtihType:@"0" objId:monentsInfo.dynamicId];
|
|
}
|
|
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClickLike:(MonentsInfoModel *)monentsInfo {
|
|
[self.presenter likeMonent:monentsInfo.dynamicId status:!monentsInfo.isLike likedUid:monentsInfo.uid worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
|
|
}
|
|
|
|
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClicDelete:(MonentsInfoModel *)monentsInfo {
|
|
[TTPopup alertWithMessage:YMLocalizedString(@"XPMonentsRecommendViewController1") confirmHandler:^{
|
|
[self.presenter deleteMonents:monentsInfo.dynamicId worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
|
|
} cancelHandler:^{
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClicFold:(MonentsInfoModel *)monentsInfo {
|
|
__block MonentsInfoModel * monentsInfos;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MonentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == monentsInfo.dynamicId.integerValue) {
|
|
monentsInfos = obj;
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
if (monentsInfos) {
|
|
NSInteger row = [self.datasource indexOfObject:monentsInfo];
|
|
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPMonentsRecommendHeaderViewDelegate
|
|
- (void)xPMonentsRecommendHeaderView:(XPMonentsRecommendHeaderView *)view didSelectItem:(MonentsTopicModel *)info {
|
|
XPMonentTopicContainerViewController * topicVC = [[XPMonentTopicContainerViewController alloc] init];
|
|
topicVC.worldId = info.tId;
|
|
[self.navigationController pushViewController:topicVC animated:YES];
|
|
}
|
|
|
|
- (void)xPMonentsRecommendHeaderView:(XPMonentsRecommendHeaderView *)view didClickMoreTopic:(UIButton *)sender {
|
|
XPMoentsTopicListViewController * topicListVC = [[XPMoentsTopicListViewController alloc] init];
|
|
[self.navigationController pushViewController:topicListVC animated:YES];
|
|
}
|
|
|
|
#pragma mark -JXCategoryListContainerViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - XPMonentsRecommendProtocol
|
|
- (void)getMonentsRecommendListSuccess:(NSArray *)array state:(int)state {
|
|
if (state == 0) {
|
|
[self.datasource removeAllObjects];
|
|
}
|
|
if (array.count > 0) {
|
|
[self.datasource addObjectsFromArray:array];
|
|
}
|
|
|
|
if (state == 0) {
|
|
self.hasNoMoreData = NO;
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
if (array.count > 0) {
|
|
self.hasNoMoreData = NO;
|
|
} else {
|
|
self.hasNoMoreData = YES;
|
|
}
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
[XNDJTDDLoadingTool hideOnlyView:self.tabBarController.view];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)getMonentsRecommendListFail:(NSString *)msg state:(int)state {
|
|
[XNDJTDDLoadingTool hideOnlyView:self.tabBarController.view];
|
|
if (state == 0) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
}
|
|
|
|
- (void)monentsTopicListSuccess:(NSArray *)array {
|
|
self.headerView.topicList = array;
|
|
}
|
|
|
|
- (void)likeMonentsSuccess:(NSString *)dynamicId status:(BOOL)status {
|
|
[self.datasource enumerateObjectsUsingBlock:^(MonentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj.dynamicId isEqualToString:dynamicId]) {
|
|
if (status) {
|
|
obj.isLike += 1;
|
|
} else {
|
|
obj.isLike -= 1;
|
|
}
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
[self.tableView reloadData];
|
|
}
|
|
-(void)requesstShieldingSuccess:(NSString *)monentsInfo{
|
|
[self hideHUD];
|
|
[self showSuccessToast:YMLocalizedString(@"XPMonentsMineViewController2")];
|
|
__block MonentsInfoModel * deleteInfo;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MonentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == monentsInfo.integerValue) {
|
|
deleteInfo = obj;
|
|
}
|
|
}];
|
|
if (deleteInfo) {
|
|
[self.datasource removeObject:deleteInfo];
|
|
[self.tableView reloadData];
|
|
}
|
|
}
|
|
- (void)deleteMonentsSuccess:(NSString *)monentsInfo {
|
|
[self showSuccessToast:YMLocalizedString(@"XPMonentsRecommendViewController2")];
|
|
__block MonentsInfoModel * deleteInfo;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MonentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == monentsInfo.integerValue) {
|
|
deleteInfo = obj;
|
|
}
|
|
}];
|
|
if (deleteInfo) {
|
|
[self.datasource removeObject:deleteInfo];
|
|
[self.tableView reloadData];
|
|
}
|
|
}
|
|
|
|
#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 = UITableViewCellSeparatorStyleNone;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
if (@available(iOS 11.0, *)) {
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
[_tableView registerClass:[XPMonentsTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsTableViewCell class])];
|
|
[_tableView registerClass:[XPMonentsEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsEmptyTableViewCell class])];
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
|
|
- (NSMutableArray<MonentsInfoModel *> *)datasource {
|
|
if (!_datasource) {
|
|
_datasource = [NSMutableArray array];
|
|
}
|
|
return _datasource;
|
|
}
|
|
|
|
- (XPMonentsRecommendHeaderView *)headerView {
|
|
if (!_headerView) {
|
|
_headerView = [[XPMonentsRecommendHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 145)];
|
|
_headerView.delegate = self;
|
|
}
|
|
return _headerView;
|
|
}
|
|
|
|
@end
|