306 lines
10 KiB
Mathematica
306 lines
10 KiB
Mathematica
|
|
//
|
||
|
|
// YYJYSimiRoomView.m
|
||
|
|
// YaYin
|
||
|
|
//
|
||
|
|
// Created by bj_szd on 2023/7/14.
|
||
|
|
// Copyright © 2023 YaYin. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "YYJYSimiRoomView.h"
|
||
|
|
#import "YYJYSimiGiftCell.h"
|
||
|
|
#import "ZWTimer.h"
|
||
|
|
#import "UIButton+BAKit.h"
|
||
|
|
|
||
|
|
@interface YYJYSimiRoomView ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, ZWTimerDelegate>
|
||
|
|
|
||
|
|
@property (nonatomic, assign) NSInteger topicType;
|
||
|
|
|
||
|
|
@property (nonatomic, strong) NSArray *dataArray;
|
||
|
|
|
||
|
|
@property (nonatomic, copy) NSString *mine_uid;//自己的uid
|
||
|
|
@property (nonatomic, copy) NSString *receive_uid;//对方的uid
|
||
|
|
|
||
|
|
@property (nonatomic, strong) ZWTimer *timer;
|
||
|
|
@property (nonatomic, assign) NSInteger leftSecond;
|
||
|
|
|
||
|
|
@property (nonatomic, strong) SVGAPlayer *gqSvgaPlayer_1;
|
||
|
|
@property (nonatomic, strong) SVGAParser *gqParser_1;
|
||
|
|
|
||
|
|
@property (nonatomic, strong) SVGAPlayer *gqSvgaPlayer_2;
|
||
|
|
@property (nonatomic, strong) SVGAParser *gqParser_2;
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation YYJYSimiRoomView
|
||
|
|
|
||
|
|
- (void)awakeFromNib {
|
||
|
|
[super awakeFromNib];
|
||
|
|
|
||
|
|
[self createUI];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)createUI {
|
||
|
|
[self.rollBtn ba_button_setButtonLayoutType:BAKit_ButtonLayoutTypeCenterImageTop padding:4];
|
||
|
|
|
||
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||
|
|
layout.itemSize = CGSizeMake(80, 130);
|
||
|
|
layout.minimumInteritemSpacing = 7;
|
||
|
|
layout.minimumLineSpacing = 7;
|
||
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
|
||
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||
|
|
|
||
|
|
_collectionView.collectionViewLayout = layout;
|
||
|
|
_collectionView.delegate = self;
|
||
|
|
_collectionView.dataSource = self;
|
||
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"YYJYSimiGiftCell" bundle:nil] forCellWithReuseIdentifier:@"YYJYSimiGiftCell"];
|
||
|
|
|
||
|
|
WEAK_SELF
|
||
|
|
[self.bgView insertSubview:self.gqSvgaPlayer_1 belowSubview:_avatarImgV_1];
|
||
|
|
[self.gqSvgaPlayer_1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.top.equalTo(_avatarImgV_1).offset(-25);
|
||
|
|
make.left.equalTo(_avatarImgV_1).offset(-25);
|
||
|
|
make.right.equalTo(_avatarImgV_1).offset(25);
|
||
|
|
make.bottom.equalTo(_avatarImgV_1).offset(25);
|
||
|
|
}];
|
||
|
|
[self.gqParser_1 parseWithNamed:@"guangquan" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
||
|
|
if (videoItem != nil) {
|
||
|
|
weakSelf.gqSvgaPlayer_1.videoItem = videoItem;
|
||
|
|
}
|
||
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
|
||
|
|
[self.bgView insertSubview:self.gqSvgaPlayer_2 belowSubview:_avatarImgV_2];
|
||
|
|
[self.gqSvgaPlayer_2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.top.equalTo(_avatarImgV_2).offset(-25);
|
||
|
|
make.left.equalTo(_avatarImgV_2).offset(-25);
|
||
|
|
make.right.equalTo(_avatarImgV_2).offset(25);
|
||
|
|
make.bottom.equalTo(_avatarImgV_2).offset(25);
|
||
|
|
}];
|
||
|
|
[self.gqParser_2 parseWithNamed:@"guangquan" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
||
|
|
if (videoItem != nil) {
|
||
|
|
weakSelf.gqSvgaPlayer_2.videoItem = videoItem;
|
||
|
|
}
|
||
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)setPrid:(NSString *)prid {
|
||
|
|
_prid = prid;
|
||
|
|
|
||
|
|
[self fetchData];
|
||
|
|
|
||
|
|
self.topicType = 1;
|
||
|
|
[self.zhenxinBtn styleGradiBlueColor];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)fetchData {
|
||
|
|
NSDictionary *params = @{@"prid":C_string(self.prid)};
|
||
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/dating_room/get_privacy_room_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
|
||
|
|
[self onUpdateUIWith:responseDic[@"data"]];
|
||
|
|
|
||
|
|
NSArray *arr = [YYJYSimiGiftModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"][@"gift_list"]];
|
||
|
|
self.dataArray = arr;
|
||
|
|
[self.collectionView reloadData];
|
||
|
|
} Failure:^(id _Nonnull errorData) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onUpdateUIWith:(NSDictionary *)dataDict {
|
||
|
|
self.leftSecond = [dataDict safeIntForKey:@"surplus_time"];
|
||
|
|
[self.timer startTimer:1 delegate:self repeats:YES];
|
||
|
|
|
||
|
|
NSString *head_pic_1 = [dataDict[@"user_info"] safeStringForKey:@"head_pic"];
|
||
|
|
NSString *nick_name_1 = [dataDict[@"user_info"] safeStringForKey:@"nick_name"];
|
||
|
|
NSString *head_pic_2 = [dataDict[@"receive_info"] safeStringForKey:@"head_pic"];
|
||
|
|
NSString *nick_name_2 = [dataDict[@"receive_info"] safeStringForKey:@"nick_name"];
|
||
|
|
|
||
|
|
[self.avatarImgV_1 sd_setImageWithURL:[NSURL URLWithString:head_pic_1] placeholderImage:kDefaultUserIcon];
|
||
|
|
self.nicknameLab_1.text = nick_name_1;
|
||
|
|
|
||
|
|
[self.avatarImgV_2 sd_setImageWithURL:[NSURL URLWithString:head_pic_2] placeholderImage:kDefaultUserIcon];
|
||
|
|
self.nicknameLab_2.text = nick_name_2;
|
||
|
|
|
||
|
|
self.mine_uid = [dataDict[@"user_info"] safeStringForKey:@"uid"];
|
||
|
|
self.receive_uid = [dataDict[@"receive_info"] safeStringForKey:@"uid"];
|
||
|
|
|
||
|
|
self.zhenxinContentLab.text = [dataDict[@"topic_card_info"] safeStringForKey:@"content"];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onUpdateSurplusTime:(NSInteger)second {
|
||
|
|
self.leftSecond = second;
|
||
|
|
[self.timer startTimer:1 delegate:self repeats:YES];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onUpdateZhenxinContent:(NSString *)content {
|
||
|
|
self.zhenxinContentLab.text = content;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onUpdateGuangquanWith:(NSString *)uid {
|
||
|
|
if ([uid isEqualToString:self.mine_uid]) {
|
||
|
|
[self.gqSvgaPlayer_1 startAnimation];
|
||
|
|
}else if ([uid isEqualToString:self.receive_uid]) {
|
||
|
|
[self.gqSvgaPlayer_2 startAnimation];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onBack:(id)sender {
|
||
|
|
[self onCloseSimiRoom];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onClose:(id)sender {
|
||
|
|
[self onCloseSimiRoom];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onCloseSimiRoom {
|
||
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定退出私密小屋吗?退出后不能重新进入" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
||
|
|
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
|
|
NSDictionary *params = @{@"prid":C_string(self.prid)};
|
||
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/dating_room/end_room_privacy" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
|
||
|
|
|
||
|
|
} Failure:^(id _Nonnull errorData) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}]];
|
||
|
|
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
|
||
|
|
[[self getCurrentVC] presentViewController:alert animated:YES completion:nil];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onSelZhenxin:(id)sender {
|
||
|
|
self.topicType = 1;
|
||
|
|
[self.zhenxinBtn styleGradiBlueColor];
|
||
|
|
self.huatiBtn.backgroundColor = HEXCOLORA(0xFFFFFF, 0.06);
|
||
|
|
|
||
|
|
[self.zhenxinBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||
|
|
[self.huatiBtn setTitleColor:HEXCOLORA(0xFFFFFF, 0.6) forState:UIControlStateNormal];
|
||
|
|
|
||
|
|
[self onFetchZhenxinData];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onSelHuati:(id)sender {
|
||
|
|
self.topicType = 2;
|
||
|
|
[self.huatiBtn styleGradiBlueColor];
|
||
|
|
self.zhenxinBtn.backgroundColor = HEXCOLORA(0xFFFFFF, 0.06);
|
||
|
|
|
||
|
|
[self.huatiBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||
|
|
[self.zhenxinBtn setTitleColor:HEXCOLORA(0xFFFFFF, 0.6) forState:UIControlStateNormal];
|
||
|
|
|
||
|
|
[self onFetchZhenxinData];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onFetchZhenxinData {
|
||
|
|
NSString *urlStr = self.topicType == 1 ? @"/api/dating_room/get_truth_or_dare_list" : @"/api/dating_room/get_topic_card_list";
|
||
|
|
NSDictionary *params = @{@"prid":C_string(self.prid)};
|
||
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:urlStr Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
|
||
|
|
self.zhenxinContentLab.text = [responseDic[@"data"] safeStringForKey:@"content"];
|
||
|
|
} Failure:^(id _Nonnull errorData) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onRandomNext:(id)sender {
|
||
|
|
[self onFetchZhenxinData];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)onRoll:(id)sender {
|
||
|
|
if (self.onRollTouziBlock) {
|
||
|
|
self.onRollTouziBlock();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
- (IBAction)onSimi:(id)sender {
|
||
|
|
_simiBtn.selected = !_simiBtn.selected;
|
||
|
|
if (self.onChangeSimiBlock) {
|
||
|
|
self.onChangeSimiBlock(_simiBtn.selected);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
|
||
|
|
|
||
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||
|
|
{
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
YYJYSimiGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYJYSimiGiftCell" forIndexPath:indexPath];
|
||
|
|
YYJYSimiGiftModel *model = self.dataArray[indexPath.row];
|
||
|
|
cell.model = model;
|
||
|
|
WEAK_SELF
|
||
|
|
[cell.sendBtn buttonAddTaget:^(UIButton *btn) {
|
||
|
|
[weakSelf onSendSimiGiftWith:model.gid];
|
||
|
|
} forControlEvents:UIControlEventTouchUpInside];
|
||
|
|
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onSendSimiGiftWith:(NSString *)gid {
|
||
|
|
NSDictionary *params = @{@"prid":C_string(self.prid), @"receive_uid":C_string(self.receive_uid), @"gid":gid, @"num":@"1"};
|
||
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/dating_room/send_gift" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
|
||
|
|
|
||
|
|
} Failure:^(id _Nonnull errorData) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)onTimerFired:(ZWTimer *)timer {
|
||
|
|
self.leftSecond -= 1;
|
||
|
|
if (self.leftSecond < 0) {
|
||
|
|
self.leftSecond = 0;
|
||
|
|
[self.timer stopTimer];
|
||
|
|
}
|
||
|
|
|
||
|
|
self.surplusTimeLab.text = [NSString stringWithFormat:@"%02ld:%02ld", self.leftSecond/60%60, self.leftSecond%60];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (ZWTimer *)timer {
|
||
|
|
if (!_timer) {
|
||
|
|
_timer = [[ZWTimer alloc] init];
|
||
|
|
}
|
||
|
|
return _timer;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (SVGAPlayer *)gqSvgaPlayer_1 {
|
||
|
|
if (!_gqSvgaPlayer_1) {
|
||
|
|
_gqSvgaPlayer_1 = [[SVGAPlayer alloc] init];
|
||
|
|
_gqSvgaPlayer_1.clearsAfterStop = YES;
|
||
|
|
_gqSvgaPlayer_1.contentMode = UIViewContentModeScaleAspectFit;
|
||
|
|
_gqSvgaPlayer_1.userInteractionEnabled = NO;
|
||
|
|
_gqSvgaPlayer_1.loops = 1;
|
||
|
|
}
|
||
|
|
return _gqSvgaPlayer_1;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (SVGAParser *)gqParser_1 {
|
||
|
|
if (!_gqParser_1) {
|
||
|
|
_gqParser_1 = [[SVGAParser alloc] init];
|
||
|
|
}
|
||
|
|
return _gqParser_1;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (SVGAPlayer *)gqSvgaPlayer_2 {
|
||
|
|
if (!_gqSvgaPlayer_2) {
|
||
|
|
_gqSvgaPlayer_2 = [[SVGAPlayer alloc] init];
|
||
|
|
_gqSvgaPlayer_2.clearsAfterStop = YES;
|
||
|
|
_gqSvgaPlayer_2.contentMode = UIViewContentModeScaleAspectFit;
|
||
|
|
_gqSvgaPlayer_2.userInteractionEnabled = NO;
|
||
|
|
_gqSvgaPlayer_2.loops = 1;
|
||
|
|
}
|
||
|
|
return _gqSvgaPlayer_2;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (SVGAParser *)gqParser_2 {
|
||
|
|
if (!_gqParser_2) {
|
||
|
|
_gqParser_2 = [[SVGAParser alloc] init];
|
||
|
|
}
|
||
|
|
return _gqParser_2;
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|