123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- //
- // XYStartVoiceLiveViewController.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/10/25.
- //
- #import "XYStartVoiceLiveViewController.h"
- #import "XYStartVoiceLiveViewModel.h"
- #import "XYVoiceLiveRecordViewController.h"
- @interface XYStartVoiceLiveViewController ()<UITextViewDelegate, SelectImageHandlerDelegate>
- @property (nonatomic, strong) XYStartVoiceLiveViewModel *viewModel;
- @property (nonatomic, strong) UIView *customNavigationView;
- @property (nonatomic, strong) UIButton *backButton;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIButton *rightButton;
- @property (nonatomic, strong) UIView *infoView;
- @property (nonatomic, strong) UIImageView *coverImageView;
- @property (nonatomic, strong) UILabel *coverTipLabel;
- @property (nonatomic, strong) UILabel *tipLabel;
- @property (nonatomic, strong) PlaceholderTextView *titleTextView;
- @property (nonatomic, strong) UIView *line;
- @property (nonatomic, strong) UILabel *familyNameLabel;
- @property (nonatomic, strong) UIButton *categoryButton;
- @property (nonatomic, strong) UIButton *starLiveButton;
- @property (nonatomic, strong) UIButton *agreementBoxButton;
- @property (nonatomic, strong) UILabel *agreementLabel;
- @property (nonatomic, strong) SelectImageHandler *selectImageHandler;
- @end
- @implementation XYStartVoiceLiveViewController
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- #pragma mark - Override
- - (void)bindViewModel {
- self.viewModel = [XYStartVoiceLiveViewModel new];
- }
- - (void)requestRemoteData {
- [self.viewModel getInitValueRequestCompleted:^(NSError * _Nonnull error) {
- if (error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- return;
- }
-
- [self updateView];
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.title = @"开播";
-
- [self setupUI];
- }
- - (void)setupUI {
-
- self.view.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT) direction:GradientChangeDirectionVertical colors:@[ColorFromHexString(@"#A988E5"), ColorFromHexString(@"#7F71DD"), ColorFromHexString(@"#3E4FD2")]];
-
- // 导航设置
- [self setupNavationView];
-
- [self.view addSubview:self.infoView];
-
- [self.infoView addSubview:self.coverImageView];
- [self.infoView addSubview:self.coverTipLabel];
- [self.infoView addSubview:self.tipLabel];
- [self.infoView addSubview:self.titleTextView];
- [self.infoView addSubview:self.line];
- [self.infoView addSubview:self.familyNameLabel];
- [self.infoView addSubview:self.categoryButton];
-
- [self.view addSubview:self.starLiveButton];
- [self.view addSubview:self.agreementBoxButton];
- [self.view addSubview:self.agreementLabel];
-
- // [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.view).offset(8.0f + NAVGATION_HEIGHT);
- // make.left.equalTo(self.view).offset(16.0f);
- // make.right.equalTo(self.view).offset(-16.0f);
- // make.height.equalTo(@120.0f);
- // }];
- [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.infoView).offset(8.0f);
- make.centerY.equalTo(self.infoView);
- make.width.height.equalTo(@104.0f);
- }];
- [self.coverTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.coverImageView);
- make.height.equalTo(@18.0f);
- }];
- [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.coverImageView.mas_right).offset(8.0f);
- make.top.equalTo(self.infoView).offset(8.0f);
- make.width.equalTo(@138.0f);
- make.height.equalTo(@18.0f);
- }];
- // [self.titleTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.equalTo(self.coverImageView.mas_right).offset(8.0f);
- // make.right.equalTo(self.infoView.mas_right).offset(-8.0f);
- // make.top.equalTo(self.tipLabel.mas_bottom).offset(8.0f);
- // make.height.equalTo(@44.0f);
- // }];
- [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.coverImageView.mas_right).offset(8.0f);
- make.right.equalTo(self.infoView.mas_right).offset(-8.0f);
- make.bottom.equalTo(self.infoView.mas_bottom).offset(-33.0f);
- make.height.equalTo(@1.0f);
- }];
- [self.familyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.coverImageView.mas_right).offset(8.0f);
- make.top.equalTo(self.line.mas_bottom).offset(8.0f);
- make.height.equalTo(@17.0f);
- }];
- [self.categoryButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.familyNameLabel.mas_right).offset(8.0f);
- make.top.equalTo(self.line.mas_bottom);
- make.bottom.equalTo(self.infoView);
- make.width.equalTo(@38.0f);
- }];
-
- [self.starLiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view).offset(28.0f);
- make.right.equalTo(self.view).offset(-28.0f);
- make.bottom.equalTo(self.view).offset(-(HOME_INDICATOR_HEIGHT+90.0f));
- make.height.equalTo(@48.0f);
- }];
- [self.agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.view);
- make.top.equalTo(self.starLiveButton.mas_bottom).offset(16.0f);
- make.width.equalTo(@225.0f);
- make.height.equalTo(@17.0f);
- }];
- [self.agreementBoxButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.agreementLabel.mas_left).offset(-4.0f);
- make.centerY.equalTo(self.agreementLabel);
- make.width.height.equalTo(@20.0f);
- }];
-
- [self.infoView addViewBorder:Color_Clear redian:4];
- [self.coverImageView addViewBorder:Color_Clear redian:4];
- [self.starLiveButton addViewBorder:Color_Clear redian:48/2];
- }
- - (void)setupNavationView {
-
- [self.view addSubview:self.customNavigationView];
- [self.customNavigationView addSubview:self.backButton];
- [self.customNavigationView addSubview:self.titleLabel];
- [self.customNavigationView addSubview:self.rightButton];
-
- [self.customNavigationView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self.view);
- make.height.equalTo(@(NAVGATION_HEIGHT));
- }];
- [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.customNavigationView).offset(5.0f);
- make.bottom.equalTo(self.customNavigationView);
- make.width.height.equalTo(@44.0f);
- }];
- [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.customNavigationView).offset(-5.0f);
- make.bottom.equalTo(self.customNavigationView);
- make.height.equalTo(@44.0f);
- make.width.equalTo(@70.0f);
- }];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.left.right.equalTo(self.customNavigationView);
- make.height.equalTo(@44.0f);
- }];
- }
- - (void)updateView {
-
- if (self.viewModel.passType != 1) {
- NSString *text = @"";
- switch (self.viewModel.passType) {
- case 2:
- text = @"手机号不通过";
- break;
- case 3:
- text = @"实名不通过";
- break;
- case 4:
- text = @"加入家族不通过";
- break;
- case 5:
- text = @"其他原因不通过";
- break;
- default:
- break;
- }
-
- [SVProgressHUD showInfoWithStatus:text];
- return;
- }
-
- // 封面
- if (StringIsNotEmpty(self.viewModel.liveInfoModel.roomCover)) {
- [self.coverImageView sd_setImageWithURL:UrlForString(self.viewModel.liveInfoModel.roomCover) placeholderImage:placeholderImage()];
- }else {
- [self.coverImageView sd_setImageWithURL:UrlForString([XYUserInfoManager nowUser].userAvatar) placeholderImage:placeholderImage() completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- if (image) {
- self.viewModel.coverImage = image;
- }
- }];
- }
-
- // 标题
- if (StringIsNotEmpty(self.viewModel.liveInfoModel.roomName)) {
- self.titleTextView.text = self.viewModel.liveInfoModel.roomName;
- }
-
- // 家族
- if (StringIsNotEmpty(self.viewModel.liveInfoModel.familyName)) {
- self.familyNameLabel.text = self.viewModel.liveInfoModel.familyName;
- }
-
- // 房间标签
- [self updateCategoryData:self.viewModel.selectedTagModel];
- }
- /// 设置房间类别
- - (void)updateCategoryData:(XYVoiceRoomTagModel *)model {
-
- self.viewModel.selectedTagModel = model;
-
- [self.categoryButton setTitle:model.categoryName forState:UIControlStateNormal];
- [self.categoryButton setImage:ImageNamed(@"white_rightarrow") forState:UIControlStateNormal];
-
- CGFloat buttonWidth = [self.categoryButton.titleLabel sizeThatFits:CGSizeMake(MAXFLOAT, 17.0f)].width;
- buttonWidth += (2.0f + 12.0f);
- [self.categoryButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(buttonWidth));
- }];
-
- // 整条图片和文字位置
- [self.categoryButton buttonDistance:2 direction:right];
- }
- #pragma mark - Action
- - (void)backAction:(id)sender {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)rightItemAction:(id)sender {
- [self.navigationController pushViewController:XYVoiceLiveRecordViewController.new animated:YES];
- }
- /// 选择图片
- - (void)selectedCoverTapAction:(id)sedner {
- self.selectImageHandler.allowSquareCrop = NO;
- self.selectImageHandler.allowHorizontalCrop = NO;
- [self.selectImageHandler showImagePickerControllerWithMaxCount:1 parentController:self];
- }
- /// 选择直播房间类别
- - (void)selectedLiveRoomCategoryAction:(id)sender {
- NSMutableArray *categoryNames = [NSMutableArray array];
- for (XYVoiceRoomTagModel *categoryModel in self.viewModel.voiceRoomCategoryModels) {
- [categoryNames addObject:categoryModel.categoryName];
- }
- if (categoryNames.count == 0) {
- return;
- }
- WeakSelf
- BasePickerViewController *tagPicker = [[BasePickerViewController alloc] initWithTitle:@"房间标签" dataArray:categoryNames target:self sureBlock:^(NSInteger index, id _Nonnull info) {
- NSLog(@"tagPicker:%@ 索引:%ld", info, (long)index);
- XYVoiceRoomTagModel *model = [self.viewModel.voiceRoomCategoryModels objectAtIndex:index];
- [weakSelf updateCategoryData:model];
- }];
- [tagPicker show];
- }
- /// 开始直播
- - (void)starLiveButtonAction:(id)sender {
-
- // 同意协议
- if (!self.agreementBoxButton.selected) {
- [SVProgressHUD showInfoWithStatus:@"请先同意协议"];
- return;
- }
- // 房间标题
- if (StringIsEmpty(self.viewModel.liveInfoModel.roomName)) {
- [SVProgressHUD showInfoWithStatus:@"请输入房间标题"];
- return;
- }
- // 房间类型必须选择
- if (self.viewModel.selectedTagModel == nil) {
- [SVProgressHUD showInfoWithStatus:@"请选择房间类型"];
- return;
- }
- WeakSelf
- if (self.viewModel.coverImage) {
- [SVProgressHUD showWithStatus:@"上传中..."];
- [self.viewModel uploadCoverImageCompleted:^(NSError * _Nonnull error) {
- if (error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- return;
- }
- [SVProgressHUD showWithStatus:@"开播中..."];
- [self.viewModel startLiveCompleted:^(NSError * _Nonnull error) {
- if (error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- return;
- }
- [SVProgressHUD dismiss];
- // 进入直播间
- [[XYChatRoomManager sharedInstance] showChatRoomWithRoomId:self.viewModel.liveInfoModel.roomId roomCoverUrl:self.viewModel.liveInfoModel.roomCover completion:^{
- // 刷新info
- [weakSelf requestRemoteData];
- }];
- }];
- }];
- }else {
- [SVProgressHUD show];
- [self.viewModel startLiveCompleted:^(NSError * _Nonnull error) {
- if (error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- return;
- }
- [SVProgressHUD dismiss];
- // 进入直播间
- [[XYChatRoomManager sharedInstance] showChatRoomWithRoomId:self.viewModel.liveInfoModel.roomId roomCoverUrl:self.viewModel.liveInfoModel.roomCover completion:^{
- // 刷新info
- [weakSelf requestRemoteData];
- }];
- }];
- }
- }
- /// 同意协议
- - (void)agreementBoxButtonAction:(UIButton *)sender {
- sender.selected = !sender.selected;
- }
- /// 查看协议
- - (void)lookAgreementActionWithAgreementName:(NSString *)name {
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.requestUrl = App_User_Url;
- controller.title = name;
- [self.navigationController pushViewController:controller animated:YES];
- }
- #pragma mark - UITextViewDelegate
- - (void)textViewDidChange:(UITextView *)textView {
- self.viewModel.liveInfoModel.roomName = textView.text;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView {
- // 结束编辑
- self.viewModel.liveInfoModel.roomName = textView.text;
- }
- #pragma mark - SelectImageHandlerDelegate
- - (void)didFinishPickingPhotos:(NSArray<UIImage *>*)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
- if (photos.count == 0) {
- return;
- }
- UIImage *image = [photos firstObject];
- self.coverImageView.image = self.viewModel.coverImage = image;
- }
- #pragma mark - 懒加载
- - (UIView *)customNavigationView {
- if (_customNavigationView == nil) {
- _customNavigationView = [[UIView alloc] init];
- _customNavigationView.backgroundColor = Color_Clear;
- }
- return _customNavigationView;
- }
- - (UIButton *)backButton {
- if (_backButton == nil) {
- _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_backButton setImage:ImageNamed(@"icon_back_bai") forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (UILabel *)titleLabel {
- if (_titleLabel == nil) {
- _titleLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(16)];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.text = @"开播";
- }
- return _titleLabel;
- }
- - (UIButton *)rightButton {
- if (_rightButton == nil) {
- _rightButton = [UIButton createButtonTextColor:Color_White textFont:Font(16)];
- [_rightButton setTitle:@"开播记录" forState:UIControlStateNormal];
- [_rightButton addTarget:self action:@selector(rightItemAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _rightButton;
- }
- - (UIView *)infoView {
- if (_infoView == nil) {
- _infoView = [[UIView alloc] initWithFrame:CGRectMake(16.0f, NAVGATION_HEIGHT+8.0f, SCREEN_WIDTH - 16.0f * 2, 120.0f)];
- _infoView.backgroundColor = ColorFromHexStringWithAlpha(@"#000000", 0.35f);
- }
- return _infoView;
- }
- - (UIImageView *)coverImageView {
- if (_coverImageView == nil) {
- _coverImageView = [UIImageView new];
- _coverImageView.clipsToBounds = YES;
- _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
-
- // 添加点击事件
- _coverImageView.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectedCoverTapAction:)];
- [_coverImageView addGestureRecognizer:tap];
- }
- return _coverImageView;
- }
- - (UILabel *)coverTipLabel {
- if (_coverTipLabel == nil) {
- _coverTipLabel = [UILabel createLabelTextColor:Color_White fount:Font(12)];
- _coverTipLabel.text = @"点击更换封面";
- _coverTipLabel.textAlignment = NSTextAlignmentCenter;
- _coverTipLabel.backgroundColor = ColorFromHexStringWithAlpha(@"#000000", 0.35f);
- }
- return _coverTipLabel;
- }
- - (UILabel *)tipLabel {
- if (_tipLabel == nil) {
- _tipLabel = [UILabel createLabelTextColor:ColorFromHexString(@"#E89C38") fount:Font(10)];
- _tipLabel.backgroundColor = ColorFromHexStringWithAlpha(@"#E89C38", 0.1f);
- _tipLabel.text = @"优质的封面和标题更吸引用户";
- _tipLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _tipLabel;
- }
- - (PlaceholderTextView *)titleTextView {
- if (_titleTextView == nil) {
- _titleTextView = [[PlaceholderTextView alloc] initWithFrame:CGRectMake(120.0f, 34.0f, SCREEN_WIDTH - 16.0f - 120.0f - 8.0f - 16.0f, 50.0f)];
- _titleTextView.font = Font(16);
- _titleTextView.textColor = Color_White;
- _titleTextView.placeholder = @"设置一个标题吧~";
- _titleTextView.placeholderTextColor = Color_White;
- _titleTextView.delegate = self;
- _titleTextView.contentInset = UIEdgeInsetsMake(-8.f, 0.f, -8.f, 0.f);
- _titleTextView.backgroundColor = Color_Clear;
- }
- return _titleTextView;
- }
- - (UIView *)line {
- if (_line == nil) {
- _line = [UIView new];
- _line.backgroundColor = ColorFromHexStringWithAlpha(@"#FFFFFF", 0.05f);
- }
- return _line;
- }
- - (UILabel *)familyNameLabel {
- if (_familyNameLabel == nil) {
- _familyNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(12)];
- }
- return _familyNameLabel;
- }
- - (UIButton *)categoryButton {
- if (_categoryButton == nil) {
- _categoryButton = [UIButton createButtonTextColor:Color_White textFont:Font(12)];
- [_categoryButton addTarget:self action:@selector(selectedLiveRoomCategoryAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _categoryButton;
- }
- - (UIButton *)starLiveButton {
- if (_starLiveButton == nil) {
- _starLiveButton = [UIButton createButtonTextColor:Color_White textFont:Font(16)];
- [_starLiveButton setTitle:@"开始直播" forState:UIControlStateNormal];
- _starLiveButton.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(SCREEN_WIDTH - 28.0f * 2, 48.0f) direction:GradientChangeDirectionLevel startColor:ColorFromHexString(@"#FF3355") endColor:ColorFromHexString(@"#FF808A")];
- [_starLiveButton addTarget:self action:@selector(starLiveButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _starLiveButton;
- }
- - (UIButton *)agreementBoxButton {
- if (_agreementBoxButton == nil) {
- _agreementBoxButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_agreementBoxButton setImage:ImageNamed(@"xy_live_agreement_unselected") forState:UIControlStateNormal];
- [_agreementBoxButton setImage:ImageNamed(@"xy_live_agreement_selected") forState:UIControlStateSelected];
- _agreementBoxButton.selected = YES;
- [_agreementBoxButton addTarget:self action:@selector(agreementBoxButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _agreementBoxButton;
- }
- - (UILabel *)agreementLabel {
- if (_agreementLabel == nil) {
- _agreementLabel = [UILabel createLabelTextColor:Color_White fount:Font(12)];
- _agreementLabel.textAlignment = NSTextAlignmentCenter;
-
- NSString *agreementName = @"《用户协议&免责声明》";
- NSString *content = [NSString stringWithFormat:@"我已经阅读并同意%@", agreementName];
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:content];
- // 设置字体颜色
- [attributedString addAttribute:NSForegroundColorAttributeName value:Color_White range:NSMakeRange(0, content.length)];
- // 设置字体
- [attributedString addAttribute:NSFontAttributeName value:Font(12) range:NSMakeRange(0, content.length)];
- // 下划线
- [attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(content.length-agreementName.length+1, agreementName.length-2)];
-
- _agreementLabel.attributedText = attributedString;
-
- WeakSelf
- [_agreementLabel yb_addAttributeTapActionWithStrings:@[agreementName] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
- [weakSelf lookAgreementActionWithAgreementName:agreementName];
- }];
- // 点击效果关闭
- _agreementLabel.enabledTapEffect = NO;
- }
- return _agreementLabel;
- }
- - (SelectImageHandler *)selectImageHandler {
- if (!_selectImageHandler) {
- _selectImageHandler = [[SelectImageHandler alloc] init];
- _selectImageHandler.delegate = self;
- _selectImageHandler.maxImagesCount = 1;
- }
- return _selectImageHandler;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|