251 lines
8.3 KiB
Objective-C
251 lines
8.3 KiB
Objective-C
//
|
|
// YMMonentsMineViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/8/18.
|
|
//
|
|
|
|
#import "XPMomentsMineViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "XPMomentsLayoutConfig.h"
|
|
#import "TTPopup.h"
|
|
#import "NSArray+Safe.h"
|
|
#import "ClientConfig.h"
|
|
///Model
|
|
#import "MomentsListInfoModel.h"
|
|
///P
|
|
#import "XPMomentMinePresenter.h"
|
|
#import "XPMomentsMineProtocol.h"
|
|
///View
|
|
#import "XPMomentsTableViewCell.h"
|
|
#import "XPMomentsEmptyTableViewCell.h"
|
|
#import "XPMomentsDetailViewController.h"
|
|
#import "XPMomentsSimpleDetailViewController.h"
|
|
|
|
@interface XPMomentsMineViewController ()<UITableViewDelegate, UITableViewDataSource, XPMomentsTableViewCellDelegate, XPMomentsMineProtocol, XPMomentsDetailViewControllerDelegate>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///数据源
|
|
@property (nonatomic,strong) NSMutableArray<MomentsInfoModel *> *datasource;
|
|
///是否有更多的数据
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
///数据信息
|
|
@property (nonatomic,strong) MomentsListInfoModel *listInfo;
|
|
@end
|
|
|
|
@implementation XPMomentsMineViewController
|
|
|
|
- (__kindof id)createPresenter {
|
|
return [[XPMomentMinePresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[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 > 0 ? self.datasource.count : 1;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
MomentsInfoModel * momentInfo= [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
[XPMomentsLayoutConfig layoutMomentsModel:momentInfo];
|
|
return momentInfo.rowHeight;
|
|
}
|
|
return KScreenHeight - kNavigationHeight - 49 - kSafeAreaBottomHeight;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
XPMomentsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMomentsTableViewCell class])];
|
|
MomentsInfoModel * momentInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
cell.delegate = self;
|
|
cell.momentsInfo = momentInfo;
|
|
return cell;
|
|
}
|
|
XPMomentsEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMomentsEmptyTableViewCell class])];
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (self.datasource.count > 0) {
|
|
MomentsInfoModel * momentInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
if(momentInfo.dynamicId == nil) {
|
|
return;
|
|
}
|
|
XPMomentsDetailViewController * detailVC = [[XPMomentsDetailViewController alloc] init];
|
|
detailVC.momentsInfo = momentInfo;
|
|
detailVC.delegate = self;
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
}
|
|
}
|
|
#pragma mark - XPMomentsTableViewCellDelegate
|
|
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClickLike:(MomentsInfoModel *)momentInfo {
|
|
if(momentInfo.dynamicId == nil){
|
|
[self showErrorToast:YMLocalizedString(@"XPMineUserDataViewController4")];
|
|
return;
|
|
}
|
|
[self.presenter likeMoment:momentInfo.dynamicId
|
|
status:!momentInfo.isLike
|
|
likedUid:momentInfo.uid
|
|
worldId:[NSString stringWithFormat:@"%ld", momentInfo.worldId]];
|
|
}
|
|
///点击了评论
|
|
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicCommon:(MomentsInfoModel *)momentInfo{
|
|
if(momentInfo.dynamicId == nil){
|
|
[self showErrorToast:YMLocalizedString(@"XPMineUserDataViewController5")];
|
|
return;
|
|
}
|
|
XPMomentsDetailViewController * detailVC = [[XPMomentsDetailViewController alloc] init];
|
|
detailVC.momentsInfo = momentInfo;
|
|
detailVC.delegate = self;
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
}
|
|
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicDelete:(MomentsInfoModel *)momentInfo {
|
|
[TTPopup alertWithMessage:YMLocalizedString(@"XPMomentsMineViewController2") confirmHandler:^{
|
|
[self.presenter deleteMoments:momentInfo.dynamicId
|
|
worldId:[NSString stringWithFormat:@"%ld", momentInfo.worldId]];
|
|
} cancelHandler:^{
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicFold:(MomentsInfoModel *)momentsInfo {
|
|
__block MomentsInfoModel * momentsInfos;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == momentsInfo.dynamicId.integerValue) {
|
|
momentsInfos = obj;
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
if (momentsInfos) {
|
|
NSInteger row = [self.datasource indexOfObject:momentsInfos];
|
|
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPMomentsDetailViewControllerDelegate
|
|
- (void)XPMomentsDetailViewController:(XPMomentsDetailViewController *)view deleteMoments:(NSString *)dynamicId {
|
|
__block MomentsInfoModel * deleteInfo;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _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 - XPMomentsMineProtocol
|
|
- (void)likeMomentsSuccess:(NSString *)dynamicId status:(BOOL)status {
|
|
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _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)deleteMomentsSuccess:(NSString *)momentsInfo {
|
|
[self showSuccessToast:YMLocalizedString(@"XPMomentsMineViewController1")];
|
|
__block MomentsInfoModel * deleteInfo;
|
|
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.dynamicId.integerValue == momentsInfo.integerValue) {
|
|
deleteInfo = obj;
|
|
}
|
|
}];
|
|
|
|
if (deleteInfo) {
|
|
[self.datasource removeObject:deleteInfo];
|
|
[self.tableView reloadData];
|
|
}
|
|
}
|
|
|
|
- (void)requesstShieldingSuccess:(NSString *)monentsInfo {
|
|
|
|
}
|
|
|
|
#pragma mark - JXPagingViewListViewDelegate
|
|
- (UIScrollView *)listScrollView {
|
|
return self.tableView;
|
|
}
|
|
|
|
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
|
self.scrollCallback = callback;
|
|
}
|
|
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
self.scrollCallback(scrollView);
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setDynamicInfo:(NSArray<MomentsInfoModel *> *)dynamicInfo {
|
|
[self.datasource removeAllObjects];
|
|
[self.datasource addObjectsFromArray:dynamicInfo];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (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:[XPMomentsTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMomentsTableViewCell class])];
|
|
[_tableView registerClass:[XPMomentsEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMomentsEmptyTableViewCell class])];
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
|
|
- (NSMutableArray<MomentsInfoModel *> *)datasource {
|
|
if (!_datasource) {
|
|
_datasource = [NSMutableArray array];
|
|
}
|
|
return _datasource;
|
|
}
|
|
|
|
@end
|