BGRoomBGImageViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // BGRoomBGImageViewController.m
  3. // UniversalApp
  4. //
  5. // Created by bugu on 2020/3/24.
  6. // Copyright © 2020 voidcat. All rights reserved.
  7. //
  8. #import "BGRoomBGImageViewController.h"
  9. #import "BGRoomBGImageCollectCell.h"
  10. #import "RoomModel.h"
  11. #import "RoomBGImageModel.h"
  12. #import "UIViewController+Bogo.h"
  13. @interface BGRoomBGImageViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  14. @property(nonatomic, strong) NSMutableArray *dataArray;
  15. @property(nonatomic, strong) UICollectionView *collectionView;
  16. @property(nonatomic, strong) UIButton *confirmBtn;
  17. @end
  18. @implementation BGRoomBGImageViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. self.title = ASLocalizedString(@"背景选择");
  23. [self setUpView];
  24. [self requestData];
  25. }
  26. - (void)backBtnClicked
  27. {
  28. [self dismissViewControllerAnimated:NO completion:nil];
  29. [self.navigationController popViewControllerAnimated:NO];
  30. }
  31. - (void)setUpView {
  32. //返回按钮
  33. [self addBackButton];
  34. [self.view addSubview:self.collectionView];
  35. self.collectionView.frame = CGRectMake(0, 0, kScreenW, kScreenH - kStatusBarHeight - kNavigationBarHeight);
  36. self.collectionView.delegate = self;
  37. self.collectionView.dataSource = self;
  38. self.collectionView.mj_header = nil;
  39. self.collectionView.mj_footer = nil;
  40. self.collectionView.backgroundColor = kWhiteColor;
  41. [self.collectionView registerClass:[BGRoomBGImageCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([BGRoomBGImageCollectCell class])];
  42. [self.view addSubview:self.confirmBtn];
  43. self.confirmBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  44. }
  45. - (void)btnAction {
  46. if (!StrValid(self.selectModel.image)) {
  47. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"请选择房间背景")];
  48. return;
  49. }
  50. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  51. [dict setValue:@"voice" forKey:@"ctl"];
  52. [dict setValue:@"selected_voice_bg" forKey:@"act"];
  53. [dict setValue:self.room_id forKey:@"room_id"];
  54. [dict setValue:self.selectModel.id forKey:@"voice_bg"];
  55. // [dict setValue:wheat_id forKey:@"wheat_id"];
  56. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  57. NSLog(@"104responseJson%@",responseJson);
  58. [[BGHUDHelper sharedInstance] syncStopLoading];
  59. self.editRoomBGChangedCallBack(self.selectModel);
  60. [self dismissViewControllerAnimated:NO completion:nil];
  61. [self.navigationController popViewControllerAnimated:NO];
  62. } FailureBlock:^(NSError *error) {
  63. [[BGHUDHelper sharedInstance] syncStopLoading];
  64. }];
  65. }
  66. - (void)requestData{
  67. __weak __typeof(self)weakSelf = self;
  68. //http://www.bogo.voice.broadcast/mapi/public/index.php/api/Voice_api/get_voice_bg
  69. [[BGHUDHelper sharedInstance] syncLoading];
  70. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  71. [dict setValue:@"voice" forKey:@"ctl"];
  72. [dict setValue:@"get_voice_bg_list" forKey:@"act"];
  73. // [dict setValue:self.live_info.room_id forKey:@"room_id"];
  74. // [dict setValue:wheat_id forKey:@"wheat_id"];
  75. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  76. NSLog(@"104responseJson%@",responseJson);
  77. __strong __typeof(weakSelf)strongSelf = weakSelf;
  78. for (NSDictionary *dict in responseJson[@"data"]) {
  79. RoomBGImageModel *model = [RoomBGImageModel mj_objectWithKeyValues:dict];
  80. if ([model.image isEqualToString:self.selectModel.image]) {
  81. model.selected = YES;
  82. }
  83. [strongSelf.dataArray addObject:model];
  84. }
  85. [strongSelf.collectionView reloadData];
  86. [[BGHUDHelper sharedInstance] syncStopLoading];
  87. } FailureBlock:^(NSError *error) {
  88. [[BGHUDHelper sharedInstance] syncStopLoading];
  89. }];
  90. // NSString *url = [[CYURLUtils sharedCYURLUtils] makeVoiceURLWithC:@"Voice_api" A:@"get_voice_bg"];
  91. // [CYNET POSTv2:url parameters:@{@"id":StrValid(self.model.voice.id)?self.model.voice.id : [IMAPlatform sharedInstance].host.userId} responseCache:^(id responseObject) {
  92. // //do nothing
  93. // } success:^(id responseObject) {
  94. // if ([[responseObject objectForKey:@"code"] integerValue] == 1) {
  95. // __strong __typeof(weakSelf)strongSelf = weakSelf;
  96. // for (NSDictionary *dict in responseObject[@"voice_bg_list"]) {
  97. // RoomBGImageModel *model = [RoomBGImageModel mj_objectWithKeyValues:dict];
  98. // if ([model.image isEqualToString:self.selectModel.image]) {
  99. // model.selected = YES;
  100. // }
  101. // [strongSelf.dataArray addObject:model];
  102. // }
  103. // [strongSelf.collectionView reloadData];
  104. // }
  105. // } failure:^(NSString *error) {
  106. // [[HUDHelper sharedInstance] tipMessage:error];
  107. // } hasCache:NO];
  108. }
  109. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  110. return 1;
  111. }
  112. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  113. return self.dataArray.count;
  114. }
  115. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  116. BGRoomBGImageCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([BGRoomBGImageCollectCell class]) forIndexPath:indexPath];
  117. RoomBGImageModel *model = self.dataArray[indexPath.item];
  118. [cell setModel:model];
  119. return cell;
  120. }
  121. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  122. return CGSizeMake((kScreenW - 40-15) / 2, kRealValue(260)+ 40);
  123. }
  124. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  125. return 15;
  126. }
  127. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  128. return 15;
  129. }
  130. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  131. return UIEdgeInsetsMake(20, 20, 20, 20);
  132. }
  133. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  134. BGRoomBGImageCollectCell *cell = (BGRoomBGImageCollectCell *)[collectionView cellForItemAtIndexPath:indexPath];
  135. // cell.selected = YES;
  136. self.selectModel = self.dataArray[indexPath.item];
  137. for (RoomBGImageModel *model in self.dataArray) {
  138. model.selected = model == self.selectModel;
  139. }
  140. [collectionView reloadData];
  141. // RoomBGPreviewViewController *previewVC = [[RoomBGPreviewViewController alloc]init];
  142. // previewVC.imageModel = self.dataArray[indexPath.item];
  143. // previewVC.model = self.model;
  144. // [self.navigationController pushViewController:previewVC animated:NO];
  145. }
  146. - (NSMutableArray *)dataArray{
  147. if (!_dataArray) {
  148. _dataArray = [NSMutableArray array];
  149. }
  150. return _dataArray;
  151. }
  152. - (UIButton *)confirmBtn{
  153. if (!_confirmBtn) {
  154. _confirmBtn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenW-150)/2, kScreenH - 84 - kTabBarHeight - kTopHeight , 150, 40)];
  155. [_confirmBtn setTitle:ASLocalizedString(@"选择") forState:UIControlStateNormal];
  156. _confirmBtn.backgroundColor = kBlueColor;
  157. [_confirmBtn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
  158. ViewRadius(_confirmBtn, 20);
  159. }
  160. return _confirmBtn;
  161. }
  162. - (UICollectionView *)collectionView
  163. {
  164. if (_collectionView == nil) {
  165. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  166. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenW , kScreenH - kTopHeight - kTabBarHeight) collectionViewLayout:flow];
  167. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefreshing)];
  168. header.automaticallyChangeAlpha = YES;
  169. header.lastUpdatedTimeLabel.hidden = NO;
  170. _collectionView.mj_header = header;
  171. //底部刷新
  172. _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefreshing)];
  173. //#ifdef kiOS11Before
  174. //
  175. //#else
  176. // _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  177. // _collectionView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
  178. // _collectionView.scrollIndicatorInsets = _collectionView.contentInset;
  179. //#endif
  180. _collectionView.backgroundColor=kWhiteColor;
  181. _collectionView.scrollsToTop = YES;
  182. }
  183. return _collectionView;
  184. }
  185. -(void)headerRefreshing{
  186. }
  187. -(void)footerRefreshing{
  188. // [_tableView.mj_footer endRefreshing];
  189. }
  190. @end