XYVoiceRoomCreateViewModel.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // XYVoiceRoomCreateViewModel.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/7/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYVoiceRoomCreateViewModel.h"
  9. #import "XYVoiceRoomCreateCellModel.h"
  10. @implementation XYVoiceRoomCreateViewModel
  11. - (instancetype)init
  12. {
  13. self = [super init];
  14. if (self) {
  15. }
  16. return self;
  17. }
  18. - (void)getInitValueRequestCompleted:(void(^)(NSError *error))completed {
  19. [[XYVoiceRoomAPIManager new] getAuthRtcConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
  20. // 获取语音房标签
  21. NSArray *rtcRoomCategories = responseModel.data[@"rtcRoomCategories"];
  22. NSMutableArray *tempTags = [NSMutableArray array];
  23. for (NSDictionary *dict in rtcRoomCategories) {
  24. XYVoiceRoomTagModel *model = XYVoiceRoomTagModel.new;
  25. model.tagName = dict[@"categoryName"];
  26. model.tagId = dict[@"categoryId"];
  27. [tempTags addObject:model];
  28. }
  29. self.voiceRoomTagModels = [tempTags copy];
  30. // 获取语音房类型
  31. NSArray *rtcRoomTypes = responseModel.data[@"rtcRoomTypes"];
  32. NSMutableArray *tempTypes = [NSMutableArray array];
  33. for (NSDictionary *dict in rtcRoomTypes) {
  34. XYVoiceRoomTypeModel *model = XYVoiceRoomTypeModel.new;
  35. model.typeName = dict[@"roomTypeName"];
  36. model.typeId = [NSString stringWithFormat:@"%ld", [dict[@"roomType"] integerValue]];
  37. [tempTypes addObject:model];
  38. }
  39. self.voiceRoomTypeModels = [tempTypes copy];
  40. XYVoiceRoomCreateCellModel *nameModel = [XYVoiceRoomCreateCellModel createWithTitle:kLocalizedString(@"房间名称") placeholder:kLocalizedString(@"请输入房间名称") isShowMore:NO isShowBottomLine:YES isInput:YES];
  41. [self.dataSource addObject:nameModel];
  42. XYVoiceRoomCreateCellModel *tagModel = [XYVoiceRoomCreateCellModel createWithTitle:kLocalizedString(@"房间标签") placeholder:kLocalizedString(@"默认") isShowMore:YES isShowBottomLine:YES isInput:NO];
  43. // 获取默认标签
  44. XYVoiceRoomTagModel *categoryModel = [self.voiceRoomTagModels firstObject];
  45. if (categoryModel) {
  46. tagModel.content = categoryModel.tagName;
  47. tagModel.infoId = categoryModel.tagId;
  48. }
  49. [self.dataSource addObject:tagModel];
  50. XYVoiceRoomCreateCellModel *typeModel = [XYVoiceRoomCreateCellModel createWithTitle:kLocalizedString(@"房间类型") placeholder:kLocalizedString(@"默认") isShowMore:YES isShowBottomLine:NO isInput:NO];
  51. // 获取默认标签
  52. XYVoiceRoomTypeModel *roomTypeModel = [self.voiceRoomTypeModels firstObject];
  53. if (roomTypeModel) {
  54. typeModel.content = roomTypeModel.typeName;
  55. typeModel.infoId = roomTypeModel.typeId;
  56. }
  57. [self.dataSource addObject:typeModel];
  58. !completed?:completed(nil);
  59. } failureHandler:^(ZYLNetworkError *error) {
  60. !completed?:completed(error);
  61. }];
  62. }
  63. - (NSArray *)voiceRoomTagModels {
  64. if (!_voiceRoomTagModels) {
  65. _voiceRoomTagModels = [NSArray array];
  66. }
  67. return _voiceRoomTagModels;
  68. }
  69. - (NSArray *)voiceRoomTypeModels {
  70. if (!_voiceRoomTypeModels) {
  71. _voiceRoomTypeModels = [NSArray array];
  72. }
  73. return _voiceRoomTypeModels;
  74. }
  75. @end
  76. @implementation XYVoiceRoomTagModel
  77. @end
  78. @implementation XYVoiceRoomTypeModel
  79. @end