
通过 [ClientConfig shareConfig].canOpen 控制页面,现在已没有相关配置,删除/调整相关内容,[ClientConfig shareConfig].canOpen == YES 的部分将保留等价逻辑/代码
274 lines
9.6 KiB
Objective-C
274 lines
9.6 KiB
Objective-C
//
|
|
// YMMomentListViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by XY on 2023/2/16.
|
|
//
|
|
|
|
#import "XPMomentListViewController.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import <Masonry.h>
|
|
#import <MJRefresh.h>
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "NSArray+Safe.h"
|
|
#import "ClientConfig.h"
|
|
|
|
#import "MonentsListInfoModel.h"
|
|
|
|
#import "XPMomentListCollectionViewCell.h"
|
|
#import "XPButton.h"
|
|
|
|
#import "XPMonentsLatestPresenter.h"
|
|
#import "XPMonentsLatestProtocol.h"
|
|
|
|
#import "XPMonentsDetailViewController.h"
|
|
#import "XPMonentsPublishViewController.h"
|
|
#import "XPMomentsSimpleDetailViewController.h"
|
|
|
|
@interface XPMomentListViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, XPMonentsLatestProtocol, XPMonentsDetailViewControllerDelegate>
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
|
|
/// 自定义导航栏
|
|
@property (nonatomic, strong) UIView *customNav;
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
/// 发布
|
|
@property (nonatomic, strong) XPButton *publishBtn;
|
|
|
|
///数据源
|
|
@property (nonatomic,strong) NSMutableArray<MonentsInfoModel *> *datasource;
|
|
///当前的页数
|
|
@property (nonatomic,assign) NSInteger page;
|
|
///是否有更多的数据
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
///数据信息
|
|
@property (nonatomic,strong) MonentsListInfoModel *listInfo;
|
|
|
|
@end
|
|
|
|
@implementation XPMomentListViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (__kindof id)createPresenter {
|
|
return [[XPMonentsLatestPresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self createUI];
|
|
|
|
[self initHeaderAndFooterRrfresh];
|
|
}
|
|
|
|
- (void)createUI {
|
|
[self.view addSubview:self.customNav];
|
|
[self.customNav addSubview:self.titleLabel];
|
|
[self.view addSubview:self.collectionView];
|
|
[self.view addSubview:self.publishBtn];
|
|
|
|
[self.customNav mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kStatusBarHeight);
|
|
make.leading.trailing.mas_equalTo(0);
|
|
make.height.mas_equalTo(44);
|
|
}];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.customNav);
|
|
}];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.customNav.mas_bottom);
|
|
make.leading.trailing.mas_equalTo(0);
|
|
make.bottom.mas_equalTo(0);
|
|
}];
|
|
[self.publishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(-108);
|
|
make.trailing.mas_equalTo(0);
|
|
make.width.height.mas_equalTo(70);
|
|
}];
|
|
}
|
|
|
|
/// 发布
|
|
- (void)publishBtnAction {
|
|
XPMonentsPublishViewController * publishVC = [[XPMonentsPublishViewController alloc] init];
|
|
[self.navigationController pushViewController:publishVC animated:YES];
|
|
}
|
|
|
|
#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.collectionView.mj_header = header;
|
|
|
|
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
|
|
footer.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
|
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
footer.ignoredScrollViewContentInsetBottom = self.collectionView.contentInset.bottom;
|
|
self.collectionView.mj_footer = footer;
|
|
|
|
[self headerRefresh];
|
|
}
|
|
|
|
#pragma mark - 刷新的fangfa
|
|
- (void)headerRefresh {
|
|
self.page = 1;
|
|
[self.presenter getMonentsLatestListPageSize:20 dynamicId:@"" state:0];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
if (self.hasNoMoreData) {
|
|
[self showErrorToast:YMLocalizedString(@"XPMomentListViewController0")];
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
return;
|
|
}
|
|
self.page++;
|
|
[self.presenter getMonentsLatestListPageSize:20 dynamicId:self.listInfo.nextDynamicId state:1];
|
|
}
|
|
|
|
#pragma mark - XPMonentsLatestProtocol
|
|
- (void)getMonentsLatestListSuccess:(MonentsListInfoModel *)listInfo state:(int)state{
|
|
self.listInfo = listInfo;
|
|
if (state == 0) {
|
|
[self.datasource removeAllObjects];
|
|
}
|
|
if (listInfo.dynamicList.count > 0) {
|
|
[self.datasource addObjectsFromArray:listInfo.dynamicList];
|
|
}
|
|
|
|
if (state == 0) {
|
|
self.hasNoMoreData = NO;
|
|
[self.collectionView.mj_header endRefreshing];
|
|
} else {
|
|
if (listInfo.dynamicList.count > 0) {
|
|
self.hasNoMoreData = NO;
|
|
} else {
|
|
self.hasNoMoreData = YES;
|
|
}
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
- (void)getMonentsLatestListFail:(NSString *)msg state:(int)state {
|
|
if (state == 0) {
|
|
[self.collectionView.mj_header endRefreshing];
|
|
} else {
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
}
|
|
}
|
|
|
|
#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.collectionView reloadData];
|
|
}
|
|
}
|
|
|
|
#pragma mark - UICollectionView
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.datasource.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPMomentListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(XPMomentListCollectionViewCell.self) forIndexPath:indexPath];
|
|
MonentsInfoModel * monentsInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
cell.monentsInfo = monentsInfo;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
XPMomentsSimpleDetailViewController *detailVC = [[XPMomentsSimpleDetailViewController alloc] init];
|
|
MonentsInfoModel * monentsInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
detailVC.monentsInfo = monentsInfo;
|
|
detailVC.delegate = self;
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
}
|
|
}
|
|
|
|
#pragma mark - 懒加载
|
|
|
|
- (UICollectionView *)collectionView {
|
|
if (!_collectionView) {
|
|
MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init];
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
CGFloat width = (KScreenWidth - 16 -13 -16)/2.0;
|
|
CGFloat height = 220.0/165.0*width;
|
|
layout.itemSize = CGSizeMake(width, height);
|
|
layout.minimumLineSpacing = 12.0;
|
|
layout.minimumInteritemSpacing = 13.0;
|
|
layout.sectionInset = UIEdgeInsetsMake(12, 16, 12, 16);
|
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.backgroundColor = UIColor.clearColor;
|
|
_collectionView.alwaysBounceVertical = YES;
|
|
[_collectionView registerClass:[XPMomentListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass(XPMomentListCollectionViewCell.self)];
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
|
|
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
- (XPButton *)publishBtn {
|
|
if (!_publishBtn) {
|
|
_publishBtn = [XPButton buttonWithType:UIButtonTypeCustom];
|
|
_publishBtn.backgroundColor = UIColorFromRGB(0x0C1430);
|
|
[_publishBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
_publishBtn.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
[_publishBtn setTitle:YMLocalizedString(@"XPMomentListViewController1") forState:UIControlStateNormal];
|
|
[_publishBtn setImage:[UIImage imageNamed:@"moment_camera"] forState:UIControlStateNormal];
|
|
[_publishBtn addTarget:self action:@selector(publishBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
_publishBtn.layer.cornerRadius = 70/2;
|
|
_publishBtn.clipsToBounds = YES;
|
|
_publishBtn.buttonStyle = XPButtonImageTop;
|
|
_publishBtn.padding = 4;
|
|
}
|
|
return _publishBtn;
|
|
}
|
|
|
|
- (UIView *)customNav {
|
|
if (!_customNav) {
|
|
_customNav = [[UIView alloc] init];
|
|
_customNav.backgroundColor = [DJDKMIMOMColor appBackgroundColor];
|
|
}
|
|
return _customNav;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.text = YMLocalizedString(@"XPMomentListViewController2");
|
|
_titleLabel.backgroundColor = [UIColor clearColor];
|
|
_titleLabel.font = [UIFont systemFontOfSize:18.f weight:UIFontWeightMedium];
|
|
_titleLabel.textColor = DJDKMIMOMColor.mainTextColor;
|
|
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (NSMutableArray<MonentsInfoModel *> *)datasource {
|
|
if (!_datasource) {
|
|
_datasource = [NSMutableArray array];
|
|
}
|
|
return _datasource;
|
|
}
|
|
|
|
@end
|