474 lines
17 KiB
Objective-C
474 lines
17 KiB
Objective-C
//
|
|
// MewHomeViewController.m
|
|
// mew-ios
|
|
//
|
|
// Created by 触海 on 2023/11/10.
|
|
//
|
|
|
|
#import "MewHomeViewController.h"
|
|
/// View
|
|
#import "MewHeaderView.h"
|
|
#import "MewShowVoiceView.h"
|
|
#import "MewPlayVoiceView.h"
|
|
#import "MewRightFollowVoiceView.h"
|
|
#import "MewPushExclusiveVoiceView.h"
|
|
#import "MewUserIntroductionView.h"
|
|
#import "MewHomeFilterView.h"
|
|
#import "MewVoiceGuideView.h"
|
|
#import "MewMineSettingViewController.h"
|
|
#import "MewMineCollectionViewController.h"
|
|
#import "MewRechargeViewController.h"
|
|
#import "MewSessionViewController.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
/// Tool
|
|
#import "MewMacro.h"
|
|
#import "MewThemeColor.h"
|
|
#import "MewHUDTool.h"
|
|
/// P
|
|
#import "MewHomePresenter.h"
|
|
#import "MewHomeProtocol.h"
|
|
/// Model
|
|
#import "MewFansInfoModel.h"
|
|
#import "MewUserInfoModel.h"
|
|
|
|
#import <IQKeyboardManager/IQKeyboardManager.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
|
|
@interface MewHomeViewController ()<MewHeaderViewDelegate, MewShowVoiceViewDelegate,MewUserIntroductionViewDelegate,MewPushExclusiveVoiceViewDelegate, MewHomeProtocol,MewRightFollowVoiceViewDelegate>
|
|
|
|
/// 引导页
|
|
@property (nonatomic, strong) MewVoiceGuideView *guideView;
|
|
/// 内容
|
|
@property (nonatomic, strong) UIScrollView *containerScrollView;
|
|
/// 背景图片
|
|
@property (nonatomic, strong) UIImageView *containerBgImageView;
|
|
/// 顶部的header
|
|
@property (nonatomic, strong) MewHeaderView *headerView;
|
|
/// 用户的声音
|
|
@property (nonatomic, strong) MewShowVoiceView *showVoiceView;
|
|
/// 右边侧栏
|
|
@property (nonatomic, strong) UIView *rightBgVoiceView;
|
|
@property (nonatomic, strong) UIButton *showRightButton;
|
|
@property (nonatomic, strong) MewRightFollowVoiceView *rightFollowVoiceView;
|
|
|
|
/// 弹出发布声音秀的提示框
|
|
@property (nonatomic, strong) MewPushExclusiveVoiceView *pushExcelusiveVoiceView;
|
|
/// 弹出用户信息的提示框
|
|
@property (nonatomic, strong) MewUserIntroductionView *userIntroductionView;
|
|
/// 当前圆角的视图
|
|
@property (nonatomic, strong) UIView *currentLayerView;
|
|
/// 过滤view
|
|
@property (nonatomic, strong) MewHomeFilterView *filterView;
|
|
|
|
/// 获取的用户数据数组
|
|
@property (nonatomic, strong) NSArray<MewUserInfoModel *> *MewUserInfoModels;
|
|
/// 自己的model
|
|
@property (nonatomic, strong) MewUserInfoModel *selfMineModel;
|
|
/// 点击用户的id
|
|
@property (nonatomic, copy) NSString *targetUid;
|
|
/// 过滤字符串
|
|
@property (nonatomic, copy) NSString *filterString;
|
|
|
|
/// 声音
|
|
@property (nonatomic, copy) NSString *voiceString;
|
|
@property (nonatomic, assign) NSInteger duration;
|
|
|
|
/// 关注
|
|
///当前页数
|
|
@property (nonatomic,assign) int page;
|
|
///更多数据
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
@property (nonatomic, strong) NSMutableArray<MewUserInfoModel *> *fansListModels;
|
|
|
|
@end
|
|
|
|
@implementation MewHomeViewController
|
|
|
|
- (BOOL)mew_isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (MewHomePresenter *)createPresenter {
|
|
return [[MewHomePresenter alloc] init];
|
|
}
|
|
|
|
#pragma mark - Life Cycle
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// [IQKeyboardManager sharedManager].enable = YES;
|
|
// [[IQKeyboardManager sharedManager] setKeyboardDistanceFromTextField:10.0];
|
|
[self mew_initView];
|
|
[self mew_initGuideView];
|
|
//默认选中全部
|
|
self.filterString = nil;
|
|
self.fansListModels = [NSMutableArray array];
|
|
[self mew_loadFollownModelRefresh];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
}
|
|
|
|
#pragma mark - Load Data (获取数据)
|
|
- (void)mew_loadHomeDataWithGender:(NSString *)gender {
|
|
[self.presenter mew_getMewHomeFriendListWithGender:gender];
|
|
}
|
|
|
|
- (void)setFilterString:(NSString *)filterString {
|
|
_filterString = filterString;
|
|
[self.showVoiceView reloadDataWithNormal];
|
|
[self mew_loadHomeDataWithGender:_filterString];
|
|
}
|
|
|
|
|
|
// 关注下拉刷新
|
|
- (void)mew_loadFollownModelRefresh {
|
|
self.page = 1;
|
|
[self.presenter mew_getUserAttentionList:self.page pageSize:20 state:0];
|
|
}
|
|
|
|
// 关注加载更多
|
|
- (void)mew_moreFollownModelRefresh {
|
|
if (self.hasNoMoreData) {
|
|
[self mew_showErrorToast:@"没有更多数据了"];
|
|
return;
|
|
}
|
|
self.page++;
|
|
[self.presenter mew_getUserAttentionList:self.page pageSize:20 state:1];
|
|
}
|
|
|
|
#pragma mark - MewHomeProtocol
|
|
/// 获取用户的信息成功
|
|
- (void)mew_getUserDetailInfoSuccess:(MewUserInfoModel *)userInfo {
|
|
NSLog(@"userInfo: %@",userInfo);
|
|
// [self.userIntroductionView setCurrentUserModel:userInfo];
|
|
}
|
|
|
|
// 关注 || 取消关注成功
|
|
- (void)mew_attentionUserSuccess:(BOOL)status {
|
|
[MewHUDTool showSuccessWithMessage: status ? @"关注成功" : @"取消关注成功"];
|
|
[self.userIntroductionView updateAttentionState:status];
|
|
}
|
|
|
|
// 获取两个人的关注
|
|
- (void)mew_getUserAttentionSuccess:(BOOL)status {
|
|
[self.userIntroductionView updateAttentionState:status];
|
|
}
|
|
|
|
|
|
/// 上传声音秀成功
|
|
- (void)mew_uploadVoiceFileToThirdSuccess:(NSString *)fileUrl {
|
|
|
|
if (self.voiceString.length == 0 || self.voiceString == nil || [self.voiceString isEqualToString:@""]) {
|
|
self.voiceString = @"这个人很懒还没有签名";
|
|
}
|
|
|
|
[self.presenter mewPublishVoiceShowDura:[NSString stringWithFormat:@"%ld",self.duration] desc:self.voiceString gender:self.selfMineModel.gender == GenderType_Male ? @"1" : @"2" url:fileUrl];
|
|
|
|
}
|
|
|
|
/// 上传mew声音秀成功
|
|
- (void)mewPublishVoiceShowSuccess {
|
|
[MewHUDTool showSuccessWithMessage:@"上传音频成功"];
|
|
[MewPushExclusiveVoiceView removeExclusiveViewFromSuperView];
|
|
}
|
|
|
|
/// 上传声音秀失败
|
|
- (void)mew_uploadVoiceFileFail:(NSString *)message {
|
|
[MewHUDTool showSuccessWithMessage:@"上传音频失败,请重新上传"];
|
|
|
|
}
|
|
|
|
- (void)mew_getMewHomeFriendListSuccesss:(NSArray *)array selfMine:(nonnull MewUserInfoModel *)selfMineModel {
|
|
self.MewUserInfoModels = array;
|
|
self.showVoiceView.userInfoArrays = self.MewUserInfoModels;
|
|
self.selfMineModel = selfMineModel;
|
|
}
|
|
|
|
/// 获取关注好友列表
|
|
- (void)mew_getUserAttentionListSuccess:(NSArray *)array state:(int)state {
|
|
if (state == 0) {
|
|
[self.fansListModels removeAllObjects];
|
|
[self.rightFollowVoiceView.followCollectionView.mj_header endRefreshing];
|
|
} else {
|
|
[self.rightFollowVoiceView.followCollectionView.mj_footer endRefreshing];
|
|
}
|
|
if (array.count > 0) {
|
|
self.hasNoMoreData = NO;
|
|
[self.fansListModels addObjectsFromArray:array];
|
|
} else {
|
|
self.hasNoMoreData = YES;
|
|
[self.rightFollowVoiceView.followCollectionView.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
|
|
self.rightFollowVoiceView.fansListModel = [self.fansListModels copy];
|
|
}
|
|
|
|
|
|
#pragma mark - MewHeaderViewDelegate
|
|
/// 选中的是哪个事件
|
|
/// - Parameter target: 0 - 过滤 1-换一换 2-个人中心
|
|
- (void)mew_didSelectWithMewHeaderViewTarget:(NSInteger)target {
|
|
if (target == 0) { //过滤
|
|
self.filterView = [[MewHomeFilterView alloc] initWithPoint:CGPointMake(24, CGRectGetMaxY(self.headerView.frame) - 15.0) completed:^(NSInteger index) {
|
|
if (index == 0) {
|
|
//全部
|
|
self.filterString = nil;
|
|
} else { // 1-男声 2-女声
|
|
self.filterString = [NSString stringWithFormat:@"%ld",index];
|
|
}
|
|
}];
|
|
[self.view addSubview:self.filterView];
|
|
} else if (target == 3) {
|
|
if (self.filterView) {
|
|
[self.filterView removeFromSuperview];
|
|
self.filterView = nil;
|
|
}
|
|
|
|
} else if (target == 1) { //换一换
|
|
//重调接口
|
|
[self.presenter mew_getMewHomeFriendListWithGender:self.filterString];
|
|
|
|
} else { //个人中心
|
|
MewUserIntroductionView *view = [MewUserIntroductionView showUserIntroductionViewWithType:UserIntroductionView_SelfMine delegate: self];
|
|
self.userIntroductionView = view;
|
|
[view setCurrentUserModel:self.selfMineModel];
|
|
[self.view addSubview:view];
|
|
|
|
}
|
|
}
|
|
|
|
#pragma mark - MewShowVoiceViewDelegate (中部用户信息回调)
|
|
/// 点击
|
|
- (void)mew_didSelectMewShowVoiceViewWithTargetIndex:(NSInteger)index {
|
|
[self mew_pushUserInfoView:UserIntroductionView_OtherUser userInfo:self.MewUserInfoModels[index]];
|
|
|
|
}
|
|
/// 发布声音秀
|
|
- (void)mew_didSelectmew_pushVoiceClouseEvent {
|
|
[self mew_pushVoiceClouseEvent];
|
|
}
|
|
|
|
|
|
#pragma mark - MewUserIntroductionViewDelegate
|
|
/// optionType: 0 - 取消关注 1 - 关注 2-聊天
|
|
- (void)mew_userIntrodctionViewWithUserOption:(NSInteger)optionType {
|
|
if (optionType == 2) { //聊天
|
|
NIMSession *session = [NIMSession session:self.targetUid type:NIMSessionTypeP2P];
|
|
MewSessionViewController *vc = [[MewSessionViewController alloc] initWithSession:session];
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
} else {
|
|
|
|
[self.presenter mew_attentionUser:self.targetUid state:optionType == 1];
|
|
}
|
|
}
|
|
|
|
/// selfOptionType: 0 - 钻石充值 1-我的收藏 2-设置
|
|
- (void)mew_userIntroductionWithSelfOption:(NSInteger)selfOptionType {
|
|
if (selfOptionType == 0) {
|
|
//钻石充值
|
|
MewRechargeViewController *rechargeController = [[MewRechargeViewController alloc] init];
|
|
[self.navigationController pushViewController:rechargeController animated:NO];
|
|
|
|
} else if (selfOptionType == 1) {
|
|
//我的收藏
|
|
MewMineCollectionViewController *collectController = [[MewMineCollectionViewController alloc] init];
|
|
[self.navigationController pushViewController:collectController animated:NO];
|
|
} else {
|
|
//设置
|
|
MewMineSettingViewController *setVc = [[MewMineSettingViewController alloc]init];
|
|
[self.navigationController pushViewController:setVc animated:NO];
|
|
}
|
|
}
|
|
|
|
|
|
#pragma mark - MewPushExclusiveVoiceViewDelegate
|
|
/// 上传声音秀
|
|
/// 声音路径,声音介绍
|
|
- (void)mewPushExclusiveVoice:(NSString *)filePath voiceIntroString:(nonnull NSString *)voiceIntroString dura:(NSInteger)dura {
|
|
[MewHUDTool mew_showLoadingWithMessage:@"正在上传音频中请稍等"];
|
|
self.voiceString = voiceIntroString;
|
|
self.duration = dura;
|
|
[self.presenter mew_uploadVoice:filePath];
|
|
}
|
|
|
|
|
|
#pragma mark - MewRightFollowVoiceViewDelegate
|
|
- (void)mew_didSelectRightFollowVoiceUser:(MewUserInfoModel *)userInfo {
|
|
[self mew_pushUserInfoView:UserIntroductionView_OtherUser userInfo:userInfo];
|
|
}
|
|
|
|
|
|
#pragma mark - Action Event
|
|
/// 右边侧栏
|
|
- (void)mew_showRightButtonAction:(UIButton *)sender {
|
|
sender.selected = !sender.selected;
|
|
|
|
//更新右边视图的frame
|
|
CGFloat voiceX = sender.selected ? self.showVoiceView.frame.size.width/3.0 : self.showVoiceView.frame.size.width - 40;
|
|
CGFloat width = 2*self.showVoiceView.frame.size.width/3.0 - 40;
|
|
CGFloat height = self.showVoiceView.viewHieght - 4.0;
|
|
self.rightBgVoiceView.frame = CGRectMake(voiceX + 5.0, CGRectGetMinY(self.showVoiceView.frame) + 2.0, 44, self.showVoiceView.viewHieght - 4.0);
|
|
self.rightFollowVoiceView.frame = CGRectMake(CGRectGetMaxX(self.rightBgVoiceView.frame), self.rightBgVoiceView.frame.origin.y, width, height);
|
|
// 更新右边视图
|
|
self.rightFollowVoiceView.hidden = !sender.selected;
|
|
|
|
if (!self.rightFollowVoiceView.hidden) {
|
|
[self mew_updateBounderRect:self.rightFollowVoiceView];
|
|
} else {
|
|
[self mew_updateBounderRect:self.rightBgVoiceView];
|
|
}
|
|
}
|
|
|
|
/// 发布声音秀
|
|
- (void)mew_pushVoiceClouseEvent {
|
|
self.pushExcelusiveVoiceView = [MewPushExclusiveVoiceView showPushExclusiveVoiceView];
|
|
self.pushExcelusiveVoiceView.delegate = self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)mew_pushUserInfoView:(UserIntroductionType)type userInfo:(MewUserInfoModel *)userInfo {
|
|
MewUserIntroductionView *view = [MewUserIntroductionView showUserIntroductionViewWithType:type delegate:self];
|
|
self.userIntroductionView = view;
|
|
[view setCurrentUserModel:userInfo];
|
|
[self.view addSubview:view];
|
|
// if (self.MewUserInfoModels.count > index) {
|
|
self.targetUid = [NSString stringWithFormat:@"%ld",userInfo.uid];
|
|
// 获取当前用户的详细信息
|
|
[self.presenter mew_getUserDetailInfoWithUid:self.targetUid];
|
|
// 获取与当前用户的关注状态
|
|
[self.presenter mew_getUserAttentionState:self.targetUid];
|
|
// }
|
|
}
|
|
|
|
|
|
#pragma mark - Init
|
|
// 引导页
|
|
- (void)mew_initGuideView {
|
|
BOOL isShowGuide = [[NSUserDefaults standardUserDefaults] boolForKey:@"mew_home_guide"];
|
|
if (isShowGuide) return;
|
|
|
|
|
|
// 判断是否需要展示引导页
|
|
MewVoiceGuideView *guideView = [MewVoiceGuideView showMewVoiceGuideView];
|
|
[self.view addSubview:guideView];
|
|
}
|
|
|
|
- (void)mew_initView {
|
|
[self.view addSubview:self.containerBgImageView];
|
|
[self.view addSubview:self.containerScrollView];
|
|
[self.containerScrollView addSubview:self.headerView];
|
|
[self.containerScrollView addSubview:self.showVoiceView];
|
|
/// 右边侧栏视图
|
|
[self.containerScrollView insertSubview:self.rightBgVoiceView aboveSubview:self.showVoiceView];
|
|
[self.rightBgVoiceView addSubview:self.showRightButton];
|
|
[self.containerScrollView insertSubview:self.rightFollowVoiceView aboveSubview:self.showVoiceView];
|
|
[self mew_mew_initLayoutView];
|
|
}
|
|
- (void)mew_mew_initLayoutView {
|
|
self.containerBgImageView.frame = self.view.frame;
|
|
self.containerScrollView.frame = self.view.frame;
|
|
self.headerView.frame = CGRectMake(0, (kStatusBarHeight + 25.0) * kScreenScale, KScreenWidth, self.headerView.height);
|
|
self.showVoiceView.frame = CGRectMake(12.0, CGRectGetMaxY(self.headerView.frame), KScreenWidth - 28, 600);
|
|
|
|
/// 右边侧栏frame
|
|
self.rightBgVoiceView.frame = CGRectMake(self.showVoiceView.frame.size.width - 40 + 5.0, CGRectGetMinY(self.showVoiceView.frame) + 2.0, 44, self.showVoiceView.viewHieght - 4.0);
|
|
self.showRightButton.frame = CGRectMake((self.rightBgVoiceView.frame.size.width - 24)/2.0, (self.rightBgVoiceView.frame.size.height - 24)/2.0, 24, 24);
|
|
self.containerScrollView.contentSize = CGSizeMake(KScreenWidth, CGRectGetMaxY(self.showVoiceView.frame));
|
|
|
|
[self mew_updateBounderRect:self.rightBgVoiceView];
|
|
}
|
|
|
|
|
|
- (void)mew_updateBounderRect:(UIView *)view {
|
|
if (![view isMemberOfClass:[self.currentLayerView class]]) {
|
|
self.currentLayerView.layer.mask = nil;
|
|
}
|
|
|
|
CAShapeLayer * layer = [CAShapeLayer layer];
|
|
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height) byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(24, 24)];
|
|
layer.path = path.CGPath;
|
|
view.layer.mask = layer;
|
|
self.currentLayerView = view;
|
|
}
|
|
|
|
|
|
#pragma mark - Get
|
|
|
|
- (UIImageView *)containerBgImageView {
|
|
if (!_containerBgImageView) {
|
|
_containerBgImageView = [[UIImageView alloc] init];
|
|
_containerBgImageView.image = [UIImage imageNamed:@"mew_home_bg"];
|
|
}
|
|
return _containerBgImageView;
|
|
}
|
|
- (UIScrollView *)containerScrollView {
|
|
if (!_containerScrollView) {
|
|
_containerScrollView = [[UIScrollView alloc] init];
|
|
_containerScrollView.backgroundColor = UIColor.clearColor;
|
|
}
|
|
return _containerScrollView;
|
|
}
|
|
|
|
- (MewHeaderView *)headerView {
|
|
if (!_headerView) {
|
|
_headerView = [[MewHeaderView alloc] init];
|
|
_headerView.delegate = self;
|
|
}
|
|
return _headerView;
|
|
}
|
|
|
|
- (MewShowVoiceView *)showVoiceView {
|
|
if (!_showVoiceView) {
|
|
_showVoiceView = [[MewShowVoiceView alloc] init];
|
|
_showVoiceView.delegate = self;
|
|
|
|
}
|
|
return _showVoiceView;
|
|
}
|
|
|
|
- (UIView *)rightBgVoiceView {
|
|
if (!_rightBgVoiceView) {
|
|
_rightBgVoiceView = [[UIView alloc] init];
|
|
_rightBgVoiceView.backgroundColor = [MewThemeColor mewColorWithHexString:@"#1D1F33"];
|
|
}
|
|
return _rightBgVoiceView;
|
|
}
|
|
|
|
|
|
- (UIButton *)showRightButton {
|
|
if (!_showRightButton) {
|
|
_showRightButton = [[UIButton alloc] init];
|
|
_showRightButton.selected = NO;
|
|
[_showRightButton addTarget:self action:@selector(mew_showRightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_showRightButton setImage:[UIImage imageNamed:@"mew_home_play_voice_more_left"] forState:UIControlStateNormal];
|
|
[_showRightButton setImage:[UIImage imageNamed:@"mew_home_play_voice_more_right"] forState:UIControlStateSelected];
|
|
}
|
|
return _showRightButton;
|
|
}
|
|
|
|
- (MewRightFollowVoiceView *)rightFollowVoiceView {
|
|
if (!_rightFollowVoiceView) {
|
|
_rightFollowVoiceView = [[MewRightFollowVoiceView alloc] init];
|
|
_rightFollowVoiceView.backgroundColor = [MewThemeColor mewColorWithHexString:@"#050505"];
|
|
_rightFollowVoiceView.hidden = YES;
|
|
_rightFollowVoiceView.delegate = self;
|
|
__weak typeof(self) weakSelf = self;
|
|
_rightFollowVoiceView.loadFollownRefresh = ^{
|
|
//刷新
|
|
[weakSelf mew_loadFollownModelRefresh];
|
|
};
|
|
|
|
_rightFollowVoiceView.moreFollownRefresh = ^{
|
|
//加载更多
|
|
[weakSelf mew_moreFollownModelRefresh];
|
|
};
|
|
|
|
}
|
|
return _rightFollowVoiceView;
|
|
}
|
|
|
|
|
|
|
|
@end
|