Files
yinmeng-ios/xplan-ios/Main/Mine/View/MineInfo/XPMineUserDataViewController.m

261 lines
9.4 KiB
Mathematica
Raw Normal View History

2022-04-14 22:02:15 +08:00
//
// XPMineUserDataViewController.m
// xplan-ios
//
// Created by on 2022/4/14.
//
#import "XPMineUserDataViewController.h"
///Third
#import <Masonry/Masonry.h>
2022-04-15 18:11:39 +08:00
///Tool
#import "AccountInfoStorage.h"
#import "XPMacro.h"
2022-04-14 22:02:15 +08:00
///View
#import "XPMineDataSkillCardTableViewCell.h"
#import "XPMineDataClanTableViewCell.h"
#import "XPMineDataGiftTableViewCell.h"
///Model
#import "ClanDetailInfoModel.h"
#import "UserInfoModel.h"
2022-04-15 18:11:39 +08:00
#import "MineSkillCardListInfoModel.h"
2022-04-14 22:02:15 +08:00
///P
#import "XPMineUserDataPresenter.h"
#import "XPMineUserDataProtocol.h"
///View
#import "XPSkillCardViewController.h"
2022-04-15 18:11:39 +08:00
#import "XPMineUserInfoGiftWallViewController.h"
#import "XPMineClanViewController.h"
#import "XPMineGuildViewController.h"
2022-04-14 22:02:15 +08:00
@interface XPMineUserDataViewController ()<XPMineUserDataProtocol, UITableViewDelegate, UITableViewDataSource, XPMineDataClanTableViewCellDelegate, XPMineDataGiftTableViewCellDelegate, XPMineDataSkillCardTableViewCellDelegate>
///
@property (nonatomic,strong) UITableView *tableView;
///
@property (nonatomic,strong) ClanDetailInfoModel *clanDetailInfo;
///
@property (nonatomic,strong) NSArray *skillArray;
///
@property (nonatomic,assign) BOOL isFold;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
2022-04-15 18:11:39 +08:00
///
@property (nonatomic,assign) BOOL isShowEnterClan;
2022-04-14 22:02:15 +08:00
@end
@implementation XPMineUserDataViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (__kindof id)createPresenter {
return [[XPMineUserDataPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHettpRequest];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Http
- (void)initHettpRequest {
self.isFold = YES;
2022-04-15 18:11:39 +08:00
self.isShowEnterClan = NO;
2022-04-14 22:02:15 +08:00
[self.presenter getUserSkillCardList:self.userUid];
2022-04-15 18:11:39 +08:00
[self.presenter getClanDetailInfo:self.userUid currentUserUid:[AccountInfoStorage instance].getUid];
2022-04-14 22:02:15 +08:00
}
#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)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0) {
return 1;
}else if (section == 1) {
return (self.clanDetailInfo.clan.elderUid.length > 0 || self.clanDetailInfo.hall.ownerUid.length > 0) ? 1 : 0;
} else {
return 1;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
2023-03-10 19:25:37 +08:00
return 133;
2022-04-14 22:02:15 +08:00
} else if(indexPath.section == 1) {
2022-04-15 18:11:39 +08:00
CGFloat itemHeigh = 40 + 15;
2022-04-14 22:02:15 +08:00
if (self.clanDetailInfo.clan.elderUid.length > 0) {
if (self.clanDetailInfo.hall.ownerUid.length > 0) {
2022-04-15 18:11:39 +08:00
return self.isFold ? (itemHeigh + 68) : (itemHeigh + 68 + 60);
2022-04-14 22:02:15 +08:00
}else {
2022-04-15 18:11:39 +08:00
return (itemHeigh + 60);
2022-04-14 22:02:15 +08:00
}
}else {
2022-04-15 18:11:39 +08:00
if (self.clanDetailInfo.hall.ownerUid.length > 0) {
return (itemHeigh + 60);
} else {
return 0;
}
2022-04-14 22:02:15 +08:00
}
} else {
CGFloat itemHeight = 82;
CGFloat topHeight = 100;
return itemHeight * 3 + 12 * 2 + topHeight + 25;
2022-04-14 22:02:15 +08:00
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
XPMineDataSkillCardTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineDataSkillCardTableViewCell class])];
if (cell == nil) {
cell = [[XPMineDataSkillCardTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineDataSkillCardTableViewCell class])];
}
cell.delegate = self;
cell.datasourece = self.skillArray;
return cell;
} else if(indexPath.section == 1) {
XPMineDataClanTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineDataClanTableViewCell class])];
if (cell == nil) {
cell = [[XPMineDataClanTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineDataClanTableViewCell class])];
}
2022-04-15 18:11:39 +08:00
cell.isShowEnterHall = self.isShowEnterClan;
2022-04-14 22:02:15 +08:00
cell.delegate = self;
cell.clanInfo = self.clanDetailInfo;
return cell;
} else {
XPMineDataGiftTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineDataGiftTableViewCell class])];
if (cell == nil) {
cell = [[XPMineDataGiftTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineDataGiftTableViewCell class])];
}
cell.delegate = self;
cell.userGiftWall = self.userInfo.userGiftWall;
cell.userLuckyBagGiftWall = self.userInfo.userLuckyBagGiftWall;
2022-04-14 22:02:15 +08:00
return cell;
}
}
#pragma mark - XPMineDataClanTableViewCellDelegate
- (void)xPMineDataClanTableViewCell:(XPMineDataClanTableViewCell *)view didClickFold:(UIButton *)sender {
2022-04-15 18:11:39 +08:00
self.isFold = !sender.selected;
2022-04-14 22:02:15 +08:00
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)xPMineDataClanTableViewCell:(XPMineDataClanTableViewCell *)view didClickEnter:(ClanDetailInfoModel *)clanInfo {
2022-04-15 18:11:39 +08:00
[self.presenter memberApplyHall:clanInfo.hall.hallId];
}
- (void)xPMineDataClanTableViewCell:(XPMineDataClanTableViewCell *)view didClickClanView:(ClanDetailInfoModel *)clanInfo {
XPMineClanViewController * clanVC = [[XPMineClanViewController alloc] init];
clanVC.uid = self.clanDetailInfo.clan.elderUid;
[self.navigationController pushViewController:clanVC animated:YES];
}
- (void)xPMineDataClanTableViewCell:(XPMineDataClanTableViewCell *)view didClickHallView:(ClanDetailInfoModel *)clanInfo {
XPMineGuildViewController * hallVC = [[XPMineGuildViewController alloc] init];
hallVC.ownerUid = clanInfo.hall.ownerUid;
hallVC.guildId = clanInfo.hall.hallId;
[self.navigationController pushViewController:hallVC animated:YES];
2022-04-14 22:02:15 +08:00
}
#pragma mark - XPMineDataGiftTableViewCellDelegate
- (void)xPMineDataGiftTableViewCell:(XPMineDataGiftTableViewCell *)view didClickMore:(UIButton *)sender {
2022-04-15 18:11:39 +08:00
XPMineUserInfoGiftWallViewController * giftWallVC = [[XPMineUserInfoGiftWallViewController alloc] init];
giftWallVC.userUid = self.userUid;
[self.navigationController pushViewController:giftWallVC animated:YES];
2022-04-14 22:02:15 +08:00
}
#pragma mark - XPMineDataSkillCardTableViewCell
- (void)xPMineDataSkillCardTableViewCell:(XPMineDataSkillCardTableViewCell *)view didSelectItem:(MineSkillCardListInfoModel *)skillInfo {
XPSkillCardViewController *skillCardVC = [[XPSkillCardViewController alloc] init];
skillCardVC.uid = self.userUid.integerValue;
[self.navigationController pushViewController:skillCardVC animated: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 - XPMineUserDataProtocol
- (void)getUserSkillCardListSuccess:(NSArray *)list {
2022-04-15 18:11:39 +08:00
NSMutableArray<MineSkillCardListInfoModel *> * array = [NSMutableArray arrayWithArray:list];
__block MineSkillCardListInfoModel * voiceCard;
[array enumerateObjectsUsingBlock:^(MineSkillCardListInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.cardId isEqualToString:@"8"]) {
voiceCard = obj;
*stop = YES;
}
}];
if (voiceCard) {
[array removeObject:voiceCard];
}
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineUserDataViewController:didGetVoiceSuccess:)]) {
[self.delegate xPMineUserDataViewController:self didGetVoiceSuccess:voiceCard];
}
self.skillArray = [array copy];
2022-04-14 22:02:15 +08:00
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}
2022-04-15 18:11:39 +08:00
- (void)getClanDetailInfoSuccess:(ClanDetailInfoModel *)clanDetailInfo currentUserClanInfo:(ClanDetailInfoModel *)currentUserClanInfo {
self.clanDetailInfo = clanDetailInfo;
if (currentUserClanInfo.clan.elderUid.length <=0 || currentUserClanInfo.hall.ownerUid.length <=0) {
self.isShowEnterClan = YES;
} else {
self.isShowEnterClan = NO;
}
2022-04-14 22:02:15 +08:00
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}
2022-04-15 18:11:39 +08:00
- (void)memberApplyHallSuccess {
[self showSuccessToast:@"申请成功,等待管理员审核"];
}
2022-04-14 22:02:15 +08:00
#pragma mark - Getters And Setters
- (void)setUserInfo:(UserInfoModel *)userInfo {
_userInfo = userInfo;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
}
- (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:[XPMineDataSkillCardTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineDataSkillCardTableViewCell class])];
[_tableView registerClass:[XPMineDataClanTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineDataClanTableViewCell class])];
}
return _tableView;
}
@end