MORoomSetBaseView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //
  2. // MORoomSetBaseView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/13.
  6. //
  7. #import "MORoomSetBaseView.h"
  8. @interface MORoomSetBaseView ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
  9. @property (weak, nonatomic) IBOutlet UIView *bgView;
  10. @property (nonatomic, strong) JXCategoryTitleView *titleCategoryView;
  11. @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
  12. @property (weak, nonatomic) IBOutlet UIButton *sureBtn;
  13. @end
  14. @implementation MORoomSetBaseView
  15. + (instancetype)moRoomSetBaseView{
  16. return [[[NSBundle mainBundle] loadNibNamed:@"MORoomSetBaseView" owner:self options:nil] firstObject];
  17. }
  18. - (void)awakeFromNib{
  19. [super awakeFromNib];
  20. self.bgView.layer.cornerRadius = 16.0;
  21. self.bgView.layer.masksToBounds = YES;
  22. self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  23. self.sureBtn.layer.cornerRadius = 25.0;
  24. self.sureBtn.layer.masksToBounds = YES;
  25. self.sureBtn.hidden = YES;
  26. NSArray *titleDataArr = @[NSLocalString(@"mimo_create_live_set_left"),NSLocalString(@"mimo_create_live_set_right")];
  27. [self.bgView addSubview:self.titleCategoryView];
  28. [self.titleCategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.right.equalTo(self.bgView).offset(0.0);
  30. make.top.equalTo(self.bgView).offset(15.0);
  31. make.height.equalTo(@30.0);
  32. }];
  33. self.titleCategoryView.titles = titleDataArr;
  34. self.titleCategoryView.titleColor = [MOTools colorWithHexString:@"#8E8A99" alpha:1.0];
  35. self.titleCategoryView.titleSelectedColor = [MOTools colorWithHexString:@"#000000" alpha:1.0];
  36. self.titleCategoryView.titleFont = [MOTextTools getTheFontWithSize:16.0 AndFontName:kTypeOneTitleFontStr];
  37. self.titleCategoryView.titleSelectedFont = [MOTextTools getTheFontWithSize:16.0 AndFontName:kTypeOneTitleFontStr];
  38. self.titleCategoryView.backgroundColor = [UIColor clearColor];
  39. self.titleCategoryView.cellSpacing = 15.0;
  40. JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
  41. backgroundView.indicatorHeight = 8.5;
  42. backgroundView.indicatorWidth = 50.0;
  43. backgroundView.indicatorWidthIncrement = 0;
  44. backgroundView.indicatorColor = [UIColor clearColor];
  45. backgroundView.componentPosition = JXCategoryComponentPosition_Bottom;
  46. backgroundView.verticalMargin = -5.0;
  47. UIImageView *imgBgView = [[UIImageView alloc] init];
  48. imgBgView.contentMode = UIViewContentModeScaleToFill;
  49. [imgBgView setImage:[UIImage imageNamed:@"icon_square_line_new"]];
  50. [backgroundView addSubview:imgBgView];
  51. [imgBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.edges.equalTo(backgroundView);
  53. }];
  54. self.titleCategoryView.indicators = @[backgroundView];
  55. [self.bgView addSubview:self.listContainerView];
  56. [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.equalTo(self.titleCategoryView.mas_bottom).offset(13.0);
  58. make.left.right.bottom.equalTo(self.bgView);
  59. }];
  60. self.titleCategoryView.listContainer = self.listContainerView;
  61. [self.bgView bringSubviewToFront:self.sureBtn];
  62. [self.sureBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  63. }
  64. - (IBAction)closeBtnClick:(id)sender {
  65. [self dismissRoomSetBaseView];
  66. //如何取消了改变 - 则改为以前的
  67. self.changeTheSettingInfo ? self.changeTheSettingInfo(self.settingInfo) : nil;
  68. }
  69. - (void)setRoomId:(NSString *)roomId{
  70. _roomId = roomId;
  71. if(roomId.length > 0){
  72. self.sureBtn.hidden = NO;
  73. }
  74. }
  75. - (IBAction)sureBtnClick:(id)sender {
  76. if(!self.theSettingInfo || self.roomId.length == 0){
  77. return;
  78. }
  79. WEAKSELF
  80. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  81. [dict setObject:self.roomId forKey:@"roomId"];
  82. [dict setObject:@(self.theSettingInfo.linkMicNum) forKey:@"linkMicNum"];
  83. NSDictionary *themeDict = @{@"background":(self.theSettingInfo.backgrounds.id ? self.theSettingInfo.backgrounds.id : @""),
  84. @"microLayout":(self.theSettingInfo.microLayout.id ? self.theSettingInfo.microLayout.id : @""),
  85. @"microStyle":(self.theSettingInfo.microStyleModel.id ? self.theSettingInfo.microStyleModel.id : @""),
  86. @"soundRipple":(self.theSettingInfo.soundRipple.id ? self.theSettingInfo.soundRipple.id : @"")};
  87. [dict setObject:themeDict forKey:@"theme"];
  88. NSDictionary *privilegeDict = @{@"fans":@(self.theSettingInfo.privilegeDefaultModel.fans),
  89. @"level5":@(self.theSettingInfo.privilegeDefaultModel.level5),
  90. @"audit":@(self.theSettingInfo.privilegeDefaultModel.audit),
  91. @"manage":@(self.theSettingInfo.privilegeDefaultModel.manage),
  92. @"video":@(self.theSettingInfo.privilegeDefaultModel.video),
  93. @"silence":@(self.theSettingInfo.privilegeDefaultModel.silence),
  94. @"onlyInvite":@(self.theSettingInfo.privilegeDefaultModel.onlyInvite),
  95. @"camera":@(self.theSettingInfo.privilegeDefaultModel.camera)};
  96. [dict setObject:privilegeDict forKey:@"privilege"];
  97. [kHttpManager toChangeTheMultipleDataWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  98. if(kCode_Success){
  99. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  100. MOSettingInfo *baseModel = [MOSettingInfo modelObjectWithDictionary:data[@"data"]];
  101. weakSelf.changeTheSettingInfo ? weakSelf.changeTheSettingInfo(baseModel) : nil;
  102. [weakSelf dismissRoomSetBaseView];
  103. }
  104. else{
  105. MOLogV(@"toChangeTheMultipleDataWithParams 接口报错了");
  106. kShowNetError(data)
  107. }
  108. }];
  109. }
  110. // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  111. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
  112. MOLogV(@"变换了");
  113. }
  114. #pragma mark - JXCategoryListContainerViewDelegate
  115. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView{
  116. return self.titleCategoryView.titles.count;
  117. }
  118. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
  119. WEAKSELF
  120. if(index == 0){
  121. MORoomThemeBaseView *view = [[MORoomThemeBaseView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREENWIDTH, 402.0)];
  122. view.baseData = self.voiceConfigData;
  123. view.backgroundSelectBlock = ^(MOMicroStyleModel * _Nonnull cellModel) {
  124. weakSelf.backgroundSelectBlock ? weakSelf.backgroundSelectBlock(cellModel) : nil;
  125. if(weakSelf.settingInfo){
  126. for (MOMicroStyleModel *model in weakSelf.voiceConfigData.backgrounds) {
  127. if([model.id isEqualToString:cellModel.id]){
  128. model.isChoose = YES;
  129. }
  130. else{
  131. model.isChoose = NO;
  132. }
  133. }
  134. weakSelf.theSettingInfo.backgrounds = [cellModel copy];
  135. weakSelf.changeTheSettingInfo ? weakSelf.changeTheSettingInfo(weakSelf.theSettingInfo) : nil;
  136. }
  137. };
  138. view.styleSelectBlock = ^(MOMicroStyleModel * _Nonnull cellModel) {
  139. weakSelf.styleSelectBlock ? weakSelf.styleSelectBlock(cellModel) : nil;
  140. if(weakSelf.settingInfo){
  141. for (MOMicroStyleModel *model in weakSelf.voiceConfigData.microStyleModel) {
  142. if([model.id isEqualToString:cellModel.id]){
  143. model.isChoose = YES;
  144. }
  145. else{
  146. model.isChoose = NO;
  147. }
  148. }
  149. weakSelf.theSettingInfo.microStyleModel = [cellModel copy];
  150. weakSelf.changeTheSettingInfo ? weakSelf.changeTheSettingInfo(weakSelf.theSettingInfo) : nil;
  151. }
  152. };
  153. view.rippleSelectBlock = ^(MOMicroStyleModel * _Nonnull cellModel) {
  154. weakSelf.rippleSelectBlock ? weakSelf.rippleSelectBlock(cellModel) : nil;
  155. if(weakSelf.settingInfo){
  156. for (MOMicroStyleModel *model in weakSelf.voiceConfigData.soundRipple) {
  157. if([model.id isEqualToString:cellModel.id]){
  158. model.isChoose = YES;
  159. }
  160. else{
  161. model.isChoose = NO;
  162. }
  163. }
  164. weakSelf.theSettingInfo.soundRipple = [cellModel copy];
  165. weakSelf.changeTheSettingInfo ? weakSelf.changeTheSettingInfo(weakSelf.theSettingInfo) : nil;
  166. }
  167. };
  168. return view;
  169. }
  170. else{
  171. MORoomSettingsView *view = [[MORoomSettingsView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREENWIDTH, 402.0)];
  172. view.voiceConfigData = self.voiceConfigData;
  173. view.cancelBtnClickBlock = ^{
  174. [weakSelf dismissRoomSetBaseView];
  175. };
  176. view.sureBtnClickBlock = ^(NSArray * _Nonnull dataArr) {
  177. weakSelf.sureBtnClickBlock ? weakSelf.sureBtnClickBlock(dataArr) : nil;
  178. [weakSelf dismissRoomSetBaseView];
  179. };
  180. view.theModelChangeBlock = ^(MOPrivilegeDefaultModel * _Nonnull model) {
  181. weakSelf.theSettingInfo.privilegeDefaultModel = [model copy];
  182. };
  183. return view;
  184. }
  185. }
  186. - (void)setSettingInfo:(MOSettingInfo *)settingInfo{
  187. _settingInfo = settingInfo;
  188. self.theSettingInfo = [settingInfo copy];
  189. }
  190. - (void)getTheConfigData{
  191. WEAKSELF
  192. [kHttpManager toGetTheLiveRoomCongifThemeWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  193. if(kCode_Success){
  194. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  195. MOVoiceThemeData *baseData = [MOVoiceThemeData modelObjectWithDictionary:data[@"data"]];
  196. for (MOMicroStyleModel * object in baseData.backgrounds) {
  197. if([object.id isEqualToString:weakSelf.theSettingInfo.backgrounds.id]){
  198. object.isChoose = YES;
  199. break;
  200. }
  201. }
  202. for (MOMicroStyleModel * object in baseData.microStyleModel) {
  203. if([object.id isEqualToString:weakSelf.theSettingInfo.microStyleModel.id]){
  204. object.isChoose = YES;
  205. break;
  206. }
  207. }
  208. for (MOMicroStyleModel * object in baseData.soundRipple) {
  209. if([object.id isEqualToString:weakSelf.theSettingInfo.soundRipple.id]){
  210. object.isChoose = YES;
  211. break;
  212. }
  213. }
  214. baseData.privilegeDefaultModel = [weakSelf.theSettingInfo.privilegeDefaultModel copy];
  215. weakSelf.voiceConfigData = baseData;
  216. [weakSelf.titleCategoryView reloadData];
  217. }
  218. else{
  219. MOLogV(@"toGetTheLiveRoomCongifThemeWithParams 接口报错了");
  220. kShowNetError(data)
  221. }
  222. }];
  223. }
  224. - (void)showRoomSetBaseView{
  225. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  226. CGRect actionViewRect = self.bgView.frame;
  227. actionViewRect.origin.y = SCREENHEIGHT;
  228. self.bgView.frame = actionViewRect;
  229. WEAKSELF
  230. [UIView animateWithDuration:0.3 animations:^{
  231. CGRect actionViewRect = weakSelf.bgView.frame;
  232. actionViewRect.origin.y = SCREENHEIGHT - 436.0;
  233. weakSelf.bgView.frame = actionViewRect;
  234. }];
  235. }
  236. - (void)dismissRoomSetBaseView{
  237. //完成下移动画
  238. WEAKSELF
  239. [UIView animateWithDuration:0.3 animations:^
  240. {
  241. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  242. actionSheetViewRect.origin.y = SCREENHEIGHT;
  243. weakSelf.bgView.frame = actionSheetViewRect;
  244. } completion:^(BOOL finished)
  245. {
  246. [self removeFromSuperview];
  247. }];
  248. }
  249. #pragma mark - Lazy
  250. - (JXCategoryTitleView *)titleCategoryView{
  251. if(!_titleCategoryView){
  252. _titleCategoryView = [[JXCategoryTitleView alloc] init];
  253. _titleCategoryView.delegate = self;
  254. _titleCategoryView.backgroundColor = [UIColor whiteColor];
  255. }
  256. return _titleCategoryView;
  257. }
  258. - (JXCategoryListContainerView *)listContainerView{
  259. if(!_listContainerView){
  260. _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
  261. }
  262. return _listContainerView;
  263. }
  264. @end