PluginCenterView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // PluginCenterView.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/11/25.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "PluginCenterView.h"
  9. @implementation PluginCenterView
  10. - (void)dealloc
  11. {
  12. [[NSNotificationCenter defaultCenter] removeObserver:self];
  13. }
  14. - (instancetype)initWithFrame:(CGRect)frame
  15. {
  16. if (self = [super initWithFrame:frame])
  17. {
  18. self.userInteractionEnabled = YES;
  19. if (!_dataSource)
  20. {
  21. _dataSource = [[NSMutableArray alloc]init];
  22. }
  23. _httpManager = [NetHttpsManager manager];
  24. _BuguLive = [GlobalVariables sharedInstance];
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(whetherGame) name:@"closeGame" object:nil];
  26. [self initGamesForNetWorking];
  27. [self createCollection];
  28. }
  29. return self;
  30. }
  31. #pragma mark 创建collectionView等
  32. - (void)createCollection
  33. {
  34. // _bgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.size.width, self.size.height)];
  35. //// _bgView.backgroundColor = RGB(213, 214, 216);
  36. // _bgView.image = [UIImage imageNamed:@"lr_plugin_bg"];
  37. // _bgView.layer.cornerRadius = kCornerRadius;
  38. // _bgView.clipsToBounds = YES;
  39. // _bgView.userInteractionEnabled = YES;
  40. // [self addSubview:_bgView];
  41. // 毛玻璃效果
  42. // UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  43. // UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  44. // effectView.frame = CGRectMake(0, 0, _bgView.frame.size.width, _bgView.frame.size.height);
  45. // effectView.userInteractionEnabled = YES;
  46. // [_bgView addSubview:effectView];
  47. _headLab = [[UILabel alloc]initWithFrame:CGRectMake(14, 14, self.size.width-kDefaultMargin*2, pluginTitleHeight-14)];
  48. _headLab.text = ASLocalizedString(@"基础工具");
  49. [_headLab setFont:[UIFont systemFontOfSize:14]];
  50. _headLab.textColor = RGB(255, 255, 255);
  51. _headLab.textAlignment = NSTextAlignmentLeft;
  52. [self addSubview:_headLab];
  53. //基础工具视图
  54. CGFloat height = 200;
  55. if ([GlobalVariables sharedInstance].isOtherPush) {
  56. height = 100;
  57. }
  58. _toolsView = [[ToolsView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_headLab.frame), self.size.width, height)];
  59. _toolsView.toPCVdelegate = self;
  60. _toolsView.userInteractionEnabled = YES;
  61. [self addSubview:_toolsView];
  62. // //线2
  63. // UILabel *secondLine = [[UILabel alloc]initWithFrame:CGRectMake(pluginMargin, CGRectGetMaxY(_toolsView.frame), self.size.width-2*pluginMargin, pluginLineHeight)];
  64. // secondLine.backgroundColor = [kAppPluginSpaceColor colorWithAlphaComponent:0.5];
  65. // [_bgView addSubview:secondLine];
  66. UILabel *secondHeadLab = [[UILabel alloc]initWithFrame:CGRectMake(14, _toolsView.height + _toolsView.frame.origin.y, self.size.width-kDefaultMargin*2, pluginTitleHeight-10)];
  67. secondHeadLab.text = ASLocalizedString(@"游戏与功能列表");
  68. secondHeadLab.font = [UIFont systemFontOfSize:14];
  69. secondHeadLab.textColor = RGB(255, 255, 255);
  70. secondHeadLab.textAlignment = NSTextAlignmentLeft;
  71. [self addSubview:secondHeadLab];
  72. //线3
  73. // UILabel *threeLine = [[UILabel alloc]initWithFrame:CGRectMake(pluginMargin, secondHeadLab.height + secondHeadLab.frame.origin.y, self.size.width-2*pluginMargin, pluginLineHeight)];
  74. // threeLine.backgroundColor = [kAppPluginSpaceColor colorWithAlphaComponent:0.5];
  75. // [_bgView addSubview:threeLine];
  76. //游戏列表
  77. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  78. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  79. layout.itemSize = CGSizeMake((self.size.width - 20 - 20 * 5) / 4 - 1, (self.size.width - 20 - 20 * 5) / 4 - 1);
  80. layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
  81. layout.minimumLineSpacing = 20;
  82. layout.minimumInteritemSpacing = 20;
  83. _gameCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(10, secondHeadLab.height + secondHeadLab.frame.origin.y, self.size.width - 20, self.size.height-CGRectGetMaxY(secondHeadLab.frame)-kDefaultMargin) collectionViewLayout:layout];
  84. _gameCollectionView.alwaysBounceVertical = YES;
  85. _gameCollectionView.userInteractionEnabled = YES;
  86. _gameCollectionView.allowsMultipleSelection = YES; //允许多选
  87. _gameCollectionView.showsVerticalScrollIndicator = NO;
  88. _gameCollectionView.backgroundColor = [UIColor clearColor];
  89. _gameCollectionView.delegate = self;
  90. _gameCollectionView.dataSource = self;
  91. [_gameCollectionView registerNib:[UINib nibWithNibName:@"GamelistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"GamelistCollectionViewCell"];
  92. [self addSubview:_gameCollectionView];
  93. }
  94. #pragma mark --------------------------collectionView代理方法--------------------------
  95. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  96. {
  97. return 1;
  98. }
  99. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  100. {
  101. return _dataSource.count;
  102. }
  103. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. GameModel *model;
  106. if (indexPath.row < _dataSource.count)
  107. {
  108. model = _dataSource[indexPath.row];
  109. }
  110. GamelistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GamelistCollectionViewCell" forIndexPath:indexPath];
  111. [cell creatCellWithModel:model withRow:(int)indexPath.row];
  112. if ([model.is_active isEqualToString:@"0"])
  113. {
  114. cell.gamePlaying_L.hidden = YES;
  115. }
  116. else if ([model.is_active isEqualToString:@"1"])
  117. {
  118. cell.gamePlaying_L.hidden = NO;
  119. if ([model.class_name isEqualToString:@"live_pay"])
  120. {
  121. cell.gamePlaying_L.text = ASLocalizedString(@"使用中");
  122. }
  123. else
  124. {
  125. cell.gamePlaying_L.text = ASLocalizedString(@"使用中");
  126. }
  127. }
  128. return cell;
  129. }
  130. #pragma mark 点击单元格方法
  131. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. //点击返回视图(收起)
  134. if ([self.delegate respondsToSelector:@selector(closeGameList)])
  135. {
  136. [self.delegate closeGameList];
  137. }
  138. if (!SUS_WINDOW.isPushStreamIng)
  139. {
  140. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"直播开启中,请稍候!")];
  141. }
  142. else
  143. {
  144. if ([BGUtils isNetConnected])
  145. {
  146. _HUD = [[BGHUDHelper sharedInstance] loading:@""];
  147. }
  148. __weak MBProgressHUD *hud = _HUD;
  149. GameModel *model;
  150. if (indexPath.row < _dataSource.count)
  151. {
  152. model = _dataSource[indexPath.row];
  153. }
  154. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  155. [dict setValue:@"app" forKey:@"ctl"];
  156. [dict setValue:@"plugin_status" forKey:@"act"];
  157. [dict setValue:[NSString stringWithFormat:@"%@",model.game_id] forKey:@"plugin_id"];
  158. [_httpManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) //通过该网络请求来判断功能插件的开启是否冲突
  159. {
  160. [[BGHUDHelper sharedInstance] stopLoading:hud];
  161. if ([responseJson toInt:@"status"] == 1)
  162. {
  163. if ([responseJson toInt:@"is_enable"] == 1)
  164. {
  165. if (indexPath.row < _dataSource.count)
  166. {
  167. if ([model.class_name isEqualToString:@"live_pay"] || [model.class_name isEqualToString:@"pai"] || [model.class_name isEqualToString:@"shop"] || [model.class_name isEqualToString:@"live_pay_scene"] || [model.class_name isEqualToString:@"podcast_goods"])
  168. {
  169. if (_delegate && [_delegate respondsToSelector:@selector(loadGoldFlowerView:withGameID:)])
  170. {
  171. [_delegate loadGoldFlowerView:model withGameID:0];
  172. }
  173. }
  174. else
  175. {
  176. if (!_isGame)
  177. {
  178. [self startPlayingGameWithStrid:model.child_id];
  179. }
  180. }
  181. }
  182. }else//后台判断当前是否可以继续(比如开了按场付费就不能再开按时付费)
  183. {
  184. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  185. }
  186. }
  187. } FailureBlock:^(NSError *error) {
  188. [[BGHUDHelper sharedInstance] stopLoading:hud];
  189. }];
  190. }
  191. }
  192. #pragma mark ---------------------------------网络请求----------------------------------
  193. #pragma mark 加载插件列表(插件初始化)
  194. - (void)initGamesForNetWorking{
  195. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  196. [dict setValue:@"app" forKey:@"ctl"];
  197. [dict setValue:@"plugin_init" forKey:@"act"];
  198. [_httpManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  199. if ([responseJson toInt:@"status"] == 1) {
  200. [_dataSource removeAllObjects];
  201. NSArray *dataArr = [responseJson valueForKey:@"list"];
  202. if (dataArr && [dataArr isKindOfClass:[NSArray class]])
  203. {
  204. if (dataArr.count)
  205. {
  206. for (NSDictionary *dic in dataArr) {
  207. GameModel *model = [GameModel mj_objectWithKeyValues:dic];
  208. [_dataSource addObject:model];
  209. if ([dic toInt:@"is_active"] == 1) {
  210. _game_id = [dic toString:@"id"];
  211. }
  212. }
  213. }
  214. }
  215. if (_delegate && [_delegate respondsToSelector:@selector(getCount:)]) {
  216. [_delegate getCount:_dataSource];
  217. }
  218. [_gameCollectionView reloadData];
  219. }
  220. } FailureBlock:^(NSError *error) {
  221. }];
  222. }
  223. #pragma mark 开始游戏
  224. - (void)startPlayingGameWithStrid:(NSString *)idStr{
  225. NSMutableDictionary *parameterDic = [NSMutableDictionary new];
  226. [parameterDic setValue:@"games" forKey:@"ctl"];
  227. [parameterDic setValue:@"start" forKey:@"act"];
  228. [parameterDic setValue:@([idStr intValue]) forKey:@"id"];
  229. [_httpManager POSTWithParameters:parameterDic SuccessBlock:^(NSDictionary *responseJson){
  230. if ([responseJson toInt:@"status"] == 1) {
  231. _isGame = YES;
  232. _game_id = idStr;
  233. GameModel *model = [GameModel mj_objectWithKeyValues:responseJson];
  234. if (_delegate && [_delegate respondsToSelector:@selector(loadGoldFlowerView:withGameID:)])
  235. {
  236. [_delegate loadGoldFlowerView:model withGameID:idStr];
  237. }
  238. }
  239. } FailureBlock:^(NSError *error) {
  240. }];
  241. }
  242. #pragma mark “关闭”按钮方法
  243. - (void)closeClick
  244. {
  245. if (_delegate && [_delegate respondsToSelector:@selector(closeGameList)])
  246. {
  247. [_delegate closeGameList];
  248. }
  249. }
  250. - (void)closeSelfView:(ToolsView *)toolsView
  251. {
  252. [self closeClick];
  253. }
  254. - (void)whetherGame
  255. {
  256. _isGame = NO;
  257. }
  258. @end