Files
peko-ios/YuMi/Modules/YMMine/View/XPMomentUserDataViewController.m
2025-04-02 11:04:07 +08:00

281 lines
11 KiB
Objective-C

//
// XPMomentUserDataViewController.m
// YuMi
//
// Created by P on 2024/6/24.
//
#import "XPMomentUserDataViewController.h"
#import "XPMomentsDetailViewController.h"
#import "XPMineUserDataPresenter.h"
#import "XPMomentsMineProtocol.h"
#import "XPMomentsLayoutConfig.h"
#import "XPMomentsEmptyTableViewCell.h"
#import "XPMomentsTableViewCell.h"
#import "MomentsInfoModel.h"
@interface XPMomentUserDataViewController () <UITableViewDelegate, UITableViewDataSource, XPMomentsTableViewCellDelegate, XPMomentsMineProtocol, XPMomentsDetailViewControllerDelegate>
@property (nonatomic,strong) NSMutableArray<MomentsInfoModel *> *datasource;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *headView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@end
@implementation XPMomentUserDataViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
- (__kindof id)createPresenter {
return [[XPMineUserDataPresenter alloc] init];
}
- (void)setDynamicInfo:(NSArray<MomentsInfoModel *> *)dynamicInfo {
[self.datasource removeAllObjects];
[self.datasource addObjectsFromArray:dynamicInfo];
[self.tableView reloadData];
}
- (BOOL)isHiddenNavBar {
return YES;
}
#pragma mark - JXPagingViewListViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.scrollCallback(scrollView);
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (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 getNewLayoutMomentsModelWithDynamic:momentInfo];
if(momentInfo.content.length == 0){
return momentInfo.rowHeight + 20;
}
return momentInfo.rowHeight;
}
return KScreenHeight - kNavigationHeight - 49 - kSafeAreaBottomHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.01;
// return self.datasource.count > 0 ? 30 : 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return nil; //self.datasource.count > 0 ? self.headView : nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count > 0) {
XPMomentsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"XPMomentsDynamicTableViewCell" forIndexPath:indexPath];
MomentsInfoModel *monentsInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
cell.delegate = self;
cell.isInUserDetail = YES;
cell.mineMomentsInfo = monentsInfo;
cell.isFillet = indexPath.row == self.datasource.count - 1;
return cell;
}
XPMomentsEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMomentsEmptyTableViewCell class])];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0)return;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
XPMomentsDetailViewController * detailVC = [[XPMomentsDetailViewController alloc] init];
MomentsInfoModel * monentsInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
if(monentsInfo.dynamicId == nil){
return;
}
detailVC.momentsInfo = monentsInfo;
detailVC.delegate = self;
[self.navigationController pushViewController:detailVC animated:YES];
}
}
#pragma mark - XPMomentsTableViewCellDelegate
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClickLike:(MomentsInfoModel *)monentsInfo {
if(monentsInfo.dynamicId == nil){
[self showErrorToast:YMLocalizedString(@"XPMineUserDataViewController2")];
return;
}
[self.presenter likeMonent:monentsInfo.dynamicId status:!monentsInfo.isLike likedUid:monentsInfo.uid worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
}
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicCommon:(MomentsInfoModel *)monentsInfo{
if(monentsInfo.dynamicId == nil){
[self showErrorToast:YMLocalizedString(@"XPMineUserDataViewController3")];
return;
}
XPMomentsDetailViewController * detailVC = [[XPMomentsDetailViewController alloc] init];
detailVC.momentsInfo = monentsInfo;
detailVC.delegate = self;
[self.navigationController pushViewController:detailVC animated:YES];
}
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicDelete:(MomentsInfoModel *)monentsInfo {
[TTPopup alertWithMessage:YMLocalizedString(@"XPMonentsMineViewController0") confirmHandler:^{
[self.presenter deleteMonents:monentsInfo.dynamicId worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
} cancelHandler:^{
}];
}
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicShielding:(nonnull MomentsInfoModel *)monentsInfo{
[self showLoading];
[self.presenter requesstShieldingWtihType:@"0" objId:monentsInfo.dynamicId];
}
- (void)XPMomentsTableViewCell:(XPMomentsTableViewCell *)view didClicFold:(MomentsInfoModel *)monentsInfo {
__block MomentsInfoModel * monentsInfos;
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.dynamicId.integerValue == monentsInfo.dynamicId.integerValue) {
monentsInfos = obj;
*stop = YES;
}
}];
if (monentsInfos) {
NSInteger section = [self.datasource indexOfObject:monentsInfo];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:section inSection:1]] 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)requesstShieldingSuccess:(NSString *)monentsInfo{
[self hideHUD];
[self showSuccessToast:YMLocalizedString(@"XPMomentsMineViewController2")];
__block MomentsInfoModel * deleteInfo;
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _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)likeMomentsSuccess:(NSString *)dynamicId status:(BOOL)status {
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.dynamicId isEqualToString:dynamicId]) {
NSInteger likeCount = obj.likeCount.integerValue;
if (status) {
likeCount += 1;
obj.isLike += 1;
} else {
likeCount -= 1;
obj.isLike -= 1;
}
obj.likeCount = @(likeCount).stringValue;
*stop = YES;
}
}];
[self.tableView reloadData];
}
- (void)deleteMomentsSuccess:(NSString *)monentsInfo {
[self showSuccessToast:YMLocalizedString(@"XPMomentsMineViewController1")];
__block MomentsInfoModel * deleteInfo;
[self.datasource enumerateObjectsUsingBlock:^(MomentsInfoModel * _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 -
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMomentsEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMomentsEmptyTableViewCell class])];
[_tableView registerClass:[XPMomentsTableViewCell class] forCellReuseIdentifier:@"XPMomentsDynamicTableViewCell"];
}
return _tableView;
}
- (NSMutableArray<MomentsInfoModel *> *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
-(UIView *)headView{
if (!_headView){
_headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 30)];
_headView.backgroundColor = [UIColor clearColor];
UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(15, 0, KScreenWidth-30, 30)];
[_headView addSubview:bgView];
bgView.backgroundColor = [UIColor whiteColor];
[bgView setCornerWithLeftTopCorner:8 rightTopCorner:8 bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(KScreenWidth-30, 30)];
UILabel *titleView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineUserDataViewController1") font:kFontMedium(15) textColor:[DJDKMIMOMColor inputTextColor]];
[bgView addSubview:titleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(12);
make.leading.mas_equalTo(12);
}];
}
return _headView;
}
@end