123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // XYVoiceRoomCreateViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/7/7.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYVoiceRoomCreateViewController.h"
- #import "XYVoiceRoomCreateViewModel.h"
- #import "XYVoiceRoomCreateCellModel.h"
- #import "XYVoiceRoomCreateTableViewCell.h"
- #import "XYBankIdentityCardVerIfyViewController.h"
- @interface XYVoiceRoomCreateViewController ()<XYVoiceRoomCreateTableViewCellDelegate>
- @property (nonatomic, strong) XYVoiceRoomCreateViewModel *viewModel;
- @property (nonatomic, strong) UIView *footerView;
- @property (nonatomic, strong) UIButton *commitButton;
- @end
- @implementation XYVoiceRoomCreateViewController
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
-
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
- }
- #pragma mark — Override
- - (void)bindViewModel {
- self.viewModel = XYVoiceRoomCreateViewModel.new;
- }
- - (void)requestRemoteData {
- [self.viewModel getInitValueRequestCompleted:^(NSError * _Nonnull error) {
- [self reloadData];
- }];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- return [XYVoiceRoomCreateTableViewCell cellWithTableView:tableView];
- }
- - (void)configureCell:(XYVoiceRoomCreateTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- cell.delegate = self;
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
- [cell configureModel:object];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 60.0f;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- XYVoiceRoomCreateCellModel *model = self.viewModel.dataSource[indexPath.row];
- WeakSelf
- if ([model.title isEqualToString:kLocalizedString(@"房间标签")]) {
- NSMutableArray *tagNames = [NSMutableArray array];
- for (XYVoiceRoomTagModel *tagsModel in self.viewModel.voiceRoomTagModels) {
- [tagNames addObject:tagsModel.tagName];
- }
- if (tagNames.count == 0) {
- return;
- }
- BasePickerViewController *tagPicker = [[BasePickerViewController alloc] initWithTitle:model.title dataArray:tagNames target:self sureBlock:^(NSInteger index, id _Nonnull info) {
- NSLog(@"tagPicker:%@ 索引:%ld", info, (long)index);
- [weakSelf updateModelWithIndexPath:indexPath valueAtIndex:index];
- }];
- [tagPicker show];
- }
- if ([model.title isEqualToString:kLocalizedString(@"房间类型")]) {
- NSMutableArray *typeNames = [NSMutableArray array];
- for (XYVoiceRoomTypeModel *typeModel in self.viewModel.voiceRoomTypeModels) {
- [typeNames addObject:typeModel.typeName];
- }
- if (typeNames.count == 0) {
- return;
- }
- BasePickerViewController *typePicker = [[BasePickerViewController alloc] initWithTitle:model.title dataArray:typeNames target:self sureBlock:^(NSInteger index, id _Nonnull info) {
- NSLog(@"tagPicker:%@ 索引:%ld", info, (long)index);
- [weakSelf updateModelWithIndexPath:indexPath valueAtIndex:index];
- }];
- [typePicker show];
- }
- }
- - (void)updateModelWithIndexPath:(NSIndexPath *)indexPath valueAtIndex:(NSInteger)index {
- XYVoiceRoomCreateCellModel *model = self.viewModel.dataSource[indexPath.row];
- if ([model.title isEqualToString:kLocalizedString(@"房间标签")]) {
- XYVoiceRoomTagModel *tagModel = self.viewModel.voiceRoomTagModels[index];
- model.content = tagModel.tagName;
- model.infoId = tagModel.tagId;
- }
- if ([model.title isEqualToString:kLocalizedString(@"房间类型")]) {
- XYVoiceRoomTypeModel *typeModel = self.viewModel.voiceRoomTypeModels[index];
- model.content = typeModel.typeName;
- model.infoId = typeModel.typeId;
- }
- // 刷新cell
- [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- }
- #pragma mark — XYVoiceRoomCreateTableViewCellDelegate
- - (void)textChangeWithText:(NSString *)text atIndexPath:(NSIndexPath *)indexPath {
- XYVoiceRoomCreateCellModel *model = self.viewModel.dataSource[indexPath.row];
- if ([model.title isEqualToString:kLocalizedString(@"房间名称")]) {
- model.content = text;
- // 更新可提交状态
- self.commitButton.enabled = StringIsNotEmpty(text);
- }
- }
- #pragma mark - 事件处理Or辅助方法
- // 创建语音房
- - (void)commitButtonAction:(id)sender {
-
- NSInteger roomType = -1;
- NSString *categoryId = @"";
- NSString *roomName = @"";
- NSString *roomCover = [XYUserInfoManager nowUser].userAvatar;
- for (XYVoiceRoomCreateCellModel *model in self.viewModel.dataSource) {
- if ([model.title isEqualToString:kLocalizedString(@"房间名称")]) {
- roomName = model.content;
- }
- if ([model.title isEqualToString:kLocalizedString(@"房间标签")]) {
- categoryId = model.infoId;
- }
- if ([model.title isEqualToString:kLocalizedString(@"房间类型")]) {
- roomType = [model.infoId integerValue];
- }
- }
- if (StringIsEmpty(roomName)) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请输入房间名字")];
- return;
- }
- if (StringIsEmpty(categoryId)) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请选择房间标签")];
- return;
- }
- if (roomType == -1) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请选择房间类型")];
- return;
- }
- [SVProgressHUD show];
- [[XYVoiceRoomAPIManager new] createRoomWithRoomType:roomType categoryId:categoryId roomName:roomName roomCover:roomCover successHandler:^(ZYLResponseModel *responseModel) {
- [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"创建成功")];
- // 回调刷新房间列表
- [[NSNotificationCenter defaultCenter] postNotificationName:@"VOICE_ROOM_CREATE_SUCCESS_NOTIFICATION" object:nil];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.navigationController popViewControllerAnimated:YES];
- });
-
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
-
- NSDictionary *data = error.responseObject;
- if ([data[@"data"][@"goAuth"] isEqualToString:@"1"]) {//需要认证
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:nil message:kLocalizedString(@"根据《网络游戏管理暂行办法》要求,未实名认证部分功能的使用将受到限制") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"去认证")]) {
- XYBankIdentityCardVerIfyViewController *controller = XYBankIdentityCardVerIfyViewController.new;
- controller.targetAction = 2;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }];
- [al show];
- }
- }];
- }
- #pragma mark - 初始化
- - (void)_setup{
- self.title = kLocalizedString(@"创建语音房");
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
- self.tableView.tableFooterView = self.footerView;
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- - (UIView *)footerView {
- if (!_footerView) {
- _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64.0f)];
- _footerView.backgroundColor = Color_Clear;
- [_footerView addSubview:self.commitButton];
- }
- return _footerView;
- }
- - (UIButton *)commitButton {
- if (!_commitButton) {
- _commitButton = [UIButton createButtonTextColor:Color_White textFont:Font_B(16)];
- _commitButton.frame = CGRectMake(32.0f, 22.0f, SCREEN_WIDTH - 32.0f * 2, 42.0f);
- [_commitButton setTitle:kLocalizedString(@"提交") forState:UIControlStateNormal];
- [_commitButton setBackgroundImage:[UIImage commonRedGradientColorImageWithImgSize:_commitButton.size] forState:UIControlStateNormal];
- _commitButton.enabled = NO;
- [_commitButton addViewBorder:Color_Clear redian:21];
- [_commitButton addTarget:self action:@selector(commitButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _commitButton;
- }
- @end
|