MOLiveMenuView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. //
  2. // MOLiveMenuView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/11/22.
  6. //
  7. #import "MOLiveMenuView.h"
  8. #import "MOShareMenuCell.h"
  9. @implementation MOLiveMenuCollectionReusableView
  10. - (UILabel *)titleLab{
  11. if(!_titleLab){
  12. _titleLab = [[UILabel alloc] init];
  13. _titleLab.font = [MOTextTools poppinsSemiBoldFont:16.0];
  14. _titleLab.textColor = kBaseTextColor_1;
  15. _titleLab.textAlignment = NSTextAlignmentLeft;
  16. [self addSubview:_titleLab];
  17. [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  18. make.left.equalTo(self).offset(12.0);
  19. make.centerY.equalTo(self.mas_centerY);
  20. }];
  21. }
  22. return _titleLab;
  23. }
  24. @end
  25. @interface MOLiveMenuView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  26. @property (weak, nonatomic) IBOutlet UIView *bgView;
  27. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeight;
  28. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  29. @property (nonatomic, strong) NSMutableArray *shareTitleArr;
  30. @property (nonatomic, strong) NSMutableArray *shareImgArr;
  31. @end
  32. @implementation MOLiveMenuView
  33. + (instancetype)moLiveMenuView{
  34. return [[[NSBundle mainBundle] loadNibNamed:@"MOLiveMenuView" owner:self options:nil] firstObject];
  35. }
  36. - (void)awakeFromNib{
  37. [super awakeFromNib];
  38. self.bgView.layer.cornerRadius = 16.0;
  39. self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  40. self.bgView.layer.masksToBounds = YES;
  41. self.bgViewHeight.constant = [MOLiveMenuView theViewHeight];
  42. self.collectionView.contentInset = UIEdgeInsetsMake(9.0, 0, 0, 0);
  43. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  44. CGFloat width = (SCREENWIDTH - 12.0 * 2) / 5.0;
  45. CGFloat height = 12.0 + width + 16.0 ;
  46. flow.itemSize = CGSizeMake(width, height);
  47. flow.minimumLineSpacing = 0.0;//行间距
  48. flow.minimumInteritemSpacing = 0.0;//列间距
  49. [self.collectionView setCollectionViewLayout:flow];
  50. self.collectionView.delegate = self;
  51. self.collectionView.dataSource = self;
  52. [self.collectionView registerNib:[UINib nibWithNibName:@"MOShareMenuCell" bundle:nil] forCellWithReuseIdentifier:MOShareMenuCell_ID];
  53. [self.collectionView registerClass:[MOLiveMenuCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID"];
  54. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"];
  55. }
  56. + (CGFloat)theViewHeight{
  57. CGFloat width = (SCREENWIDTH - 9.0 * 4 - 10.0 * 2) / 4.0;
  58. CGFloat height = width + 10.0;
  59. CGFloat viewHeight = height * 3.0 + 50.0 + 20.0;
  60. return viewHeight;
  61. }
  62. - (void)setIsCreatLive:(BOOL)isCreatLive{
  63. _isCreatLive = isCreatLive;
  64. NSString *miniTitleStr;
  65. NSString *miniImgStr;
  66. NSString *giftTitleStr;
  67. NSString *giftImgStr;
  68. NSString *openResult = [[NSUserDefaults standardUserDefaults] valueForKey:@"kLiveSetMinimizeKey"];
  69. if (openResult == nil || [openResult isEqualToString:@"open"]){
  70. miniTitleStr = NSLocalString(@"mimo_2_live_menu_minimalkan");
  71. miniImgStr = @"icon_live_minimize";
  72. }
  73. else{
  74. miniTitleStr = NSLocalString(@"mimo_2_live_menu_minimalkan_no");
  75. miniImgStr = @"icon_live_minimize_no";
  76. }
  77. NSString *giftResult = [[NSUserDefaults standardUserDefaults] valueForKey:kLiveSetHideGiftKey];
  78. if (giftResult == nil || [giftResult isEqualToString:@"close"]){
  79. giftTitleStr = NSLocalString(@"mimo_2_live_menu_hide_gift");
  80. giftImgStr = @"icon_live_menu_gift";
  81. }
  82. else{
  83. giftTitleStr = NSLocalString(@"mimo_2_live_menu_hide_gift_no");
  84. giftImgStr = @"icon_live_menu_gift_no";
  85. }
  86. if(isCreatLive){
  87. //Pk 连麦时的 功能按钮
  88. if(self.isPkStatus){
  89. self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy;
  90. self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy;
  91. }
  92. else{
  93. NSString *suspendTitle = (self.statusInfo.roomStatus.suspendExpire == 0) ? NSLocalString(@"room_menu_pause_live") : NSLocalString(@"room_menu_resume_live");
  94. NSString *suspendImageStr = (self.statusInfo.roomStatus.suspendExpire == 0) ? @"icon_live_menu_pend" : @"icon_live_menu_live";
  95. if(self.roomType == 1){
  96. //非PK或连麦情况下的 - 菜单
  97. self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),suspendTitle,NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy;
  98. self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",suspendImageStr,@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy;
  99. }
  100. else{
  101. //非PK或连麦情况下的 - 菜单
  102. self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),suspendTitle,NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy;
  103. self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",suspendImageStr,@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy;
  104. }
  105. }
  106. if(self.statusInfo.roomStatus.linkMics.count > 0){
  107. //移除暂停直播
  108. if([self.shareTitleArr[0] containsObject:NSLocalString(@"room_menu_pause_live")]){
  109. [self.shareTitleArr[0] removeObject:NSLocalString(@"room_menu_pause_live")];
  110. }
  111. if([self.shareImgArr[0] containsObject:@"icon_live_menu_pend"]){
  112. [self.shareImgArr[0] removeObject:@"icon_live_menu_pend"];
  113. }
  114. [self.shareTitleArr[0] addObject:NSLocalString(@"room_menu_room_set")];
  115. [self.shareImgArr[0] addObject:@"c_m_btn_room_setting"];
  116. }
  117. [self.collectionView reloadData];
  118. }
  119. else{
  120. if(self.isManager){
  121. self.shareTitleArr = @[@[NSLocalString(@"room_menu_share"),@"Mall",NSLocalString(@"room_menu_message"),NSLocalString(@"room_menu_clear_screen"), @"Minimize"],@[@"LuckyWheel"]].mutableCopy;
  122. self.shareImgArr = @[@[@"icon_live_menu_share",@"icon_live_menu_mall",@"icon_live_menu_information",@"icon_live_menu_clean", @"icon_live_minimize"],@[@"icon_live_menu_lucky"]].mutableCopy;
  123. }
  124. else{
  125. BOOL isShowWame = [MOTools toJudgeShowWame];
  126. NSMutableArray *titleSecondTwoArr = @[NSLocalString(@"mimo_2_live_menu_pesan"),miniTitleStr,NSLocalString(@"mimo_2_live_menu_hide_chat"),giftTitleStr,NSLocalString(@"mimo_2_live_menu_gagikan")].mutableCopy;
  127. NSMutableArray *imgSecondTwoArr = @[@"icon_live_menu_information",miniImgStr,@"icon_live_menu_clean",giftImgStr,@"icon_live_menu_share"].mutableCopy;
  128. if(self.isWhiteList){
  129. [titleSecondTwoArr addObject:NSLocalString(@"mimo_2_translate")];
  130. [imgSecondTwoArr addObject:@"menu_icon_translation"];
  131. }
  132. if(isShowWame){
  133. NSString *wames = [MOTextAESTools smallSixTip];
  134. self.shareTitleArr = @[@[NSLocalString(@"mimo_2_live_menu_angpao"),wames,NSLocalString(@"mimo_2_live_menu_mall")],titleSecondTwoArr].mutableCopy;
  135. self.shareImgArr = @[@[@"icon_live_menu_red",@"icon_live_menu_wame",@"icon_live_menu_mall"],imgSecondTwoArr].mutableCopy;
  136. }
  137. else{
  138. self.shareTitleArr = @[@[NSLocalString(@"mimo_2_live_menu_angpao"),NSLocalString(@"mimo_2_live_menu_mall")],titleSecondTwoArr].mutableCopy;
  139. self.shareImgArr = @[@[@"icon_live_menu_red",@"icon_live_menu_mall"],imgSecondTwoArr].mutableCopy;
  140. }
  141. }
  142. [self.collectionView reloadData];
  143. }
  144. }
  145. #pragma mark --UICollectionViewDatasource & delegate
  146. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  147. return 2;
  148. }
  149. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  150. NSArray *modelArr = self.shareTitleArr[section];
  151. return modelArr.count;
  152. }
  153. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  154. NSString *titleString = self.shareTitleArr[indexPath.section][indexPath.row];
  155. NSString *imgString = self.shareImgArr[indexPath.section][indexPath.row];
  156. MOShareMenuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOShareMenuCell_ID forIndexPath:indexPath];
  157. cell.titleStr = titleString;
  158. cell.titleLab.text = titleString;
  159. [cell.iconBtn setImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal];
  160. if(indexPath.section == 0){
  161. cell.iconBtn.backgroundColor = [UIColor clearColor];
  162. }
  163. else{
  164. cell.iconBtn.backgroundColor = [MOTools colorWithHexString:@"#F6F7FB" alpha:1.0];
  165. }
  166. cell.cellIndexPath = indexPath;
  167. WEAKSELF
  168. cell.iconClickBlock = ^(NSString * _Nonnull titleStr, NSIndexPath * _Nonnull cellIndexPath) {
  169. [weakSelf dismissMenuView];
  170. weakSelf.menuBtnClickBlock ? weakSelf.menuBtnClickBlock(titleStr,cellIndexPath,weakSelf.isPkStatus) : nil;
  171. };
  172. cell.switchChangeBlock = ^(NSString * _Nonnull titleStr, MOShareMenuCell * _Nonnull cell, UISwitch *switchView) {
  173. if (self.switchOpenBlock) {
  174. self.switchOpenBlock(titleStr, cell, switchView);
  175. }
  176. };
  177. if ([titleString isEqualToString:@"Minimize"]) {
  178. cell.mySwitch.hidden = NO;
  179. cell.iconClickBlock = nil;//移除按钮点击block
  180. NSString *openResult = [[NSUserDefaults standardUserDefaults] valueForKey:@"kLiveSetMinimizeKey"];
  181. if (openResult == nil || [openResult isEqualToString:@"open"]) {
  182. [cell.mySwitch setOn:YES];
  183. cell.titleLab.text = NSLocalString(@"mimo_live_enable_minimize");
  184. } else {
  185. [cell.mySwitch setOn:NO];
  186. cell.titleLab.text = NSLocalString(@"mimo_live_disable_minimize");
  187. }
  188. } else {
  189. cell.mySwitch.hidden = YES;
  190. cell.switchChangeBlock = nil;//移除开关点击block
  191. }
  192. //information 红点逻辑
  193. if([titleString isEqualToString:NSLocalString(@"room_menu_message")] || [titleString isEqualToString:NSLocalString(@"mimo_2_live_menu_pesan")]){
  194. NSInteger redNum = [MOSvgaSourceManage shareManager].theUserRedNum;
  195. if(redNum > 0){
  196. cell.redNumLab.hidden = NO;
  197. cell.redNumLab.text = [NSString stringWithFormat:@"%zd",redNum];
  198. CGFloat redNumNeedWidth = [MOTools getWidthWithString:[NSString stringWithFormat:@"%zd",redNum] font:[MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr]] + 4.0;
  199. if(redNumNeedWidth < 12.0){
  200. redNumNeedWidth = 12.0;
  201. }
  202. cell.redNumLabWidth.constant = redNumNeedWidth;
  203. }
  204. else{
  205. cell.redNumLab.hidden = YES;
  206. cell.redNumLabWidth.constant = 12.0;
  207. }
  208. }
  209. else{
  210. cell.redNumLab.hidden = YES;
  211. cell.redNumLabWidth.constant = 12.0;
  212. }
  213. return cell;
  214. }
  215. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  216. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  217. }
  218. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  219. {
  220. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  221. MOLiveMenuCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID" forIndexPath:indexPath];
  222. headView.backgroundColor = [UIColor clearColor];
  223. headView.titleLab.font = [MOTextTools semiboldFont:16.0];
  224. headView.titleLab.textColor = kBaseTextColor_1;
  225. if(self.isCreatLive){
  226. if(indexPath.section == 0){
  227. headView.titleLab.text = NSLocalString(@"room_menu_live_tools");
  228. }
  229. else{
  230. headView.titleLab.text = NSLocalString(@"room_menu_base");
  231. }
  232. }
  233. else{
  234. if(indexPath.section == 0){
  235. headView.titleLab.text = NSLocalString(@"mimo_2_live_menu_title_1");
  236. }
  237. else{
  238. headView.titleLab.text = NSLocalString(@"mimo_2_live_menu_title_2");
  239. }
  240. }
  241. return headView;
  242. }
  243. else{
  244. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot" forIndexPath:indexPath];
  245. return view;
  246. }
  247. }
  248. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  249. return CGSizeMake(SCREENWIDTH, 30.0);
  250. }
  251. - (IBAction)dismissBtnClick:(id)sender {
  252. [self dismissMenuView];
  253. }
  254. - (void)showMenuView{
  255. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  256. CGRect actionViewRect = self.bgView.frame;
  257. actionViewRect.origin.y = SCREENHEIGHT;
  258. self.bgView.frame = actionViewRect;
  259. WEAKSELF
  260. [UIView animateWithDuration:0.3 animations:^{
  261. CGRect actionViewRect = weakSelf.bgView.frame;
  262. actionViewRect.origin.y = SCREENHEIGHT - [MOLiveMenuView theViewHeight];
  263. weakSelf.bgView.frame = actionViewRect;
  264. }];
  265. //不能滑动
  266. SendNotification(@"MOShowLivePagesVCCannotScroll")
  267. }
  268. - (void)dismissMenuView{
  269. //完成下移动画
  270. WEAKSELF
  271. [UIView animateWithDuration:0.3 animations:^
  272. {
  273. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  274. actionSheetViewRect.origin.y = SCREENHEIGHT;
  275. weakSelf.bgView.frame = actionSheetViewRect;
  276. } completion:^(BOOL finished)
  277. {
  278. [self removeFromSuperview];
  279. }];
  280. if (self.dismissBlock) {
  281. self.dismissBlock();
  282. }
  283. //可以滑动
  284. SendNotification(@"MOShowLivePagesVCCanScroll")
  285. }
  286. #pragma mark - Lazy
  287. - (NSMutableArray *)shareTitleArr{
  288. if(!_shareTitleArr){
  289. _shareTitleArr = [NSMutableArray array];
  290. }
  291. return _shareTitleArr;
  292. }
  293. - (NSMutableArray *)shareImgArr{
  294. if(!_shareImgArr){
  295. _shareImgArr = [NSMutableArray array];
  296. }
  297. return _shareImgArr;
  298. }
  299. @end