CustomPagerController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. #import "CustomPagerController.h"
  2. #import "hotViewControllerHJ.h"
  3. #import "FocusOnViewController.h"
  4. #import "NewestViewController.h"
  5. #import "SSearchVC.h"
  6. #import "LeaderboardViewController.h"
  7. #import "VideoViewController.h"
  8. //#import "EveryDayFirstLoginPopView.h"/**<每日首次登录奖励*/
  9. #import "MGSignHomeSuccessView.h"//每日签到
  10. @interface CustomPagerController ()<CLLocationManagerDelegate,handleMainDelegate,PushToLiveControllerDelegate,UITextFieldDelegate>
  11. @property(nonatomic,strong)NSMutableArray *infoArrays;
  12. @property (nonatomic, strong) NSMutableArray *itemTitleMutableArray; // 完整的分类标题容器
  13. @property (nonatomic, strong) NSMutableArray *classifiedModelMutableArray; // 服务端下发分类的模型容器
  14. @property (nonatomic, strong) NSMutableArray *videoVCMutableArray; // 服务端下发分类的对应的控制器容器
  15. @property(nonatomic, assign) NSInteger currentIndex;
  16. @property(nonatomic, strong) NSString *password;
  17. @property(nonatomic, strong) LivingModel *model;
  18. @property(nonatomic, strong) NSArray *modelArr;
  19. @end
  20. @implementation CustomPagerController{
  21. JSBadgeView *_badge;
  22. }
  23. -(void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:YES];
  25. self.navigationController.navigationBarHidden = YES;
  26. [self loadBtnBadageData];
  27. }
  28. - (void)updateClassiFiedVC
  29. {
  30. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  31. @synchronized (self)
  32. {
  33. if (self.classifiedModelMutableArray.count > 0)
  34. {
  35. }
  36. // 动态添加视频分类
  37. for (VideoClassifiedModel *model in [GlobalVariables sharedInstance].appModel.video_classified)
  38. {
  39. [self.itemTitleMutableArray addObject:model.title];
  40. }
  41. self.classifiedModelMutableArray = [GlobalVariables sharedInstance].appModel.video_classified;
  42. for (NSInteger i = 0; i < self.classifiedModelMutableArray.count; ++i)
  43. {
  44. // 服务端下发的分类的在完整的分类容器中的起点
  45. VideoViewController *videoVC = [[VideoViewController alloc] init];
  46. VideoClassifiedModel * model = [[GlobalVariables sharedInstance].appModel.video_classified objectAtIndex:i];
  47. videoVC.viewFrame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5));
  48. videoVC.view.frame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5));
  49. videoVC.classified_id = model.classified_id;
  50. [self.videoVCMutableArray addObject:videoVC];
  51. }
  52. [self reloadData];
  53. }
  54. }
  55. -(void)viewDidAppear:(BOOL)animated{
  56. [super viewDidAppear:animated];
  57. [self updateContentView];
  58. [self moveToControllerAtIndex:self.curIndex animated:NO];
  59. self.navigationController.navigationBarHidden = YES;
  60. }
  61. -(void)viewWillDisappear:(BOOL)animated{
  62. [super viewWillDisappear:animated];
  63. }
  64. - (void)viewWillLayoutSubviews
  65. {
  66. [super viewWillLayoutSubviews];
  67. self.navigationController.navigationBar.hidden = YES;
  68. }
  69. - (void)viewDidLoad {
  70. [super viewDidLoad];
  71. self.adjustStatusBarHeight = YES;
  72. self.cellSpacing = 8;
  73. [self setView];
  74. // self.curIndex = 3;
  75. [self setBarStyle:TYPagerBarStyleNoneView];
  76. // self.kCollectionViewBarHieght = 44 + 50;
  77. // 50 + 40 + 10;
  78. self.pagerBarView.backgroundColor = kClearColor;
  79. self.collectionLayoutEdging = kRealValue(44 * 2) + kRealValue(20);
  80. // self.bgTopImgView.height = kStatusBarHeight + kRealValue(44) - kRealValue(5);
  81. // self.contentTopEdging = self.bgTopImgView.height;
  82. self.bgTopImgView.height = kTopHeight;
  83. self.contentTopEdging = self.bgTopImgView.height;
  84. if ([GlobalVariables sharedInstance].userModel.user_id.integerValue) {
  85. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  86. [self loadBtnBadageData];
  87. [self requestDataToady];
  88. });
  89. }
  90. // 加载礼物列表
  91. [[GiftListManager sharedInstance] reloadGiftList];
  92. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iMChatHaveNotification:) name:g_notif_chatmsg object:nil];
  93. self.itemTitleMutableArray = [NSMutableArray arrayWithObjects:ASLocalizedString(@"关注"),ASLocalizedString(@"热门"),ASLocalizedString(@"附近"),nil];
  94. self.classifiedModelMutableArray = [NSMutableArray array];
  95. self.videoVCMutableArray = [NSMutableArray array];
  96. self.classifiedModelMutableArray = [GlobalVariables sharedInstance].appModel.video_classified;
  97. FocusOnViewController *focusVC = [[FocusOnViewController alloc]init];
  98. focusVC.delegate = self;
  99. NewestViewController *hotVC = [[NewestViewController alloc]init];
  100. hotVC.types = @"1";
  101. hotVC.delegate = self;
  102. NewestViewController *nearbyVC = [[NewestViewController alloc]init];
  103. nearbyVC.delegate = self;
  104. nearbyVC.types = @"2";
  105. [self.videoVCMutableArray addObject:focusVC];
  106. [self.videoVCMutableArray addObject:hotVC];
  107. [self.videoVCMutableArray addObject:nearbyVC];
  108. // self.currentIndex = 1;
  109. // self.curIndex = 1;
  110. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  111. [parmDict setObject:@"app" forKey:@"ctl"];
  112. [parmDict setObject:@"init" forKey:@"act"];
  113. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  114. if ([responseJson toInt:@"status"] == 1) {
  115. [self updateClassiFiedVC];
  116. }
  117. } FailureBlock:^(NSError *error) {
  118. }];
  119. // focusVC.view.height = self.viewHeight;
  120. // focusVC.view.top = 0;
  121. // focusVC.videoCollectionV.height = self.viewHeight;
  122. //
  123. // hotVC.view.height = self.viewHeight;
  124. // hotVC.videoCollectionV.height = self.viewHeight;
  125. //
  126. // nearbyVC.view.height = self.viewHeight;
  127. // nearbyVC.videoCollectionV.height = self.viewHeight;
  128. // [EveryDayFirstLoginPopView showEveryDayFirstLoginViewScore:@"5" WithComplete:^{
  129. //
  130. // }];
  131. }
  132. -(void)setView{
  133. //
  134. // UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(175))];
  135. // bgImgView.image = [UIImage imageNamed:@"mg_hm_topBgImgView"];
  136. // [self.view addSubview:bgImgView];
  137. //搜索按钮
  138. QMUIButton *searchBTN = [QMUIButton buttonWithType:UIButtonTypeCustom];
  139. searchBTN.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  140. [searchBTN setImage:[UIImage imageNamed:@"hm_search_btn"] forState:UIControlStateNormal];
  141. searchBTN.frame = CGRectMake(10,25,kScreenW - kRealValue(110),kRealValue(30));
  142. [searchBTN addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
  143. [searchBTN setTitle:ASLocalizedString(@"搜索")forState:UIControlStateNormal];
  144. searchBTN.titleLabel.font = [UIFont systemFontOfSize:15];
  145. searchBTN.backgroundColor = kClearColor;
  146. searchBTN.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  147. [searchBTN setBackgroundImage:[UIImage imageNamed:@"hm_search_btn_bgimgView"]];
  148. // [UIColor colorWithRed:255 green:255 blue:255 alpha:0.6];
  149. searchBTN.layer.cornerRadius = kRealValue(30 / 2);
  150. searchBTN.layer.masksToBounds = YES;
  151. searchBTN.spacingBetweenImageAndTitle = 5;
  152. searchBTN.imagePosition = QMUIButtonImagePositionLeft;
  153. [searchBTN setTitleColor:kWhiteColor forState:UIControlStateNormal];
  154. [self.view addSubview:searchBTN];
  155. searchBTN.hidden = YES;
  156. UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  157. privateBtn.frame = CGRectMake(kScreenW - 50,20,30,44);
  158. privateBtn.contentMode = UIViewContentModeScaleAspectFit;
  159. [privateBtn setImage:[UIImage imageNamed:@"hm_private_message"] forState:0];
  160. [privateBtn addTarget:self action:@selector(toChatListVC) forControlEvents:UIControlEventTouchUpInside];
  161. [self.view addSubview:privateBtn];
  162. UIButton *rankBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  163. rankBtn.frame = CGRectMake(privateBtn.left - 50,20,44,44);
  164. rankBtn.contentMode = UIViewContentModeScaleAspectFit;
  165. [rankBtn setImage:[UIImage imageNamed:@"mg_rank_top"] forState:0];
  166. [rankBtn addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
  167. [self.view addSubview:rankBtn];
  168. if (kIsCheckingVersion())
  169. {
  170. rankBtn.hidden = YES;
  171. }
  172. privateBtn.centerY = rankBtn.centerY;
  173. if(isIPhoneX())
  174. {
  175. searchBTN.y += 15;
  176. privateBtn.y += 15;
  177. rankBtn.y += 15;
  178. }
  179. [self initBadgeBtn:privateBtn];
  180. }
  181. - (void)toChatListVC{
  182. BGConversationSegmentController *chatListVC = [[BGConversationSegmentController alloc]init];
  183. [[AppDelegate sharedAppDelegate] pushViewController:chatListVC animated:YES];
  184. }
  185. -(void)toRankVC{
  186. LeaderboardViewController *lbVCtr = [[LeaderboardViewController alloc] init];
  187. lbVCtr.isHiddenTabbar = YES;
  188. [[AppDelegate sharedAppDelegate] pushViewController:lbVCtr animated:YES];
  189. }
  190. #pragma mark - ----------------------- 私信消息、角标 -----------------------
  191. #pragma mark IM
  192. - (void)iMChatHaveNotification:(NSNotification*)notification
  193. {
  194. //all 角标数据
  195. [self loadBtnBadageData];
  196. }
  197. /**
  198. 获取角标的数据: 注意:调All未读/调好友&&非好友方法 算All时,别调后者2各和来算,里面有耗时操作
  199. 使用:1.在willApperar 2.SDK监听会发通知,通知的方法/block 里调用
  200. 给控件初始化一个角标
  201. badage的 数据 获取(个人页面获取所有未读的条数)
  202. 1.在willApear里调用一次 2.SDk消息变化,接受通知,在通知方法还要调用 用于更新 角标数据
  203. */
  204. - (void)loadBtnBadageData
  205. {
  206. [SFriendObj getAllUnReadCountComplete:^(int num) {
  207. //all
  208. int scount = num;
  209. if( scount )
  210. {
  211. if(scount > 98)
  212. {
  213. _badge.badgeText = @"99+";
  214. }
  215. else
  216. {
  217. _badge.badgeText = [NSString stringWithFormat:@"%d",scount];
  218. }
  219. }
  220. else
  221. {
  222. _badge.badgeText = nil;
  223. }
  224. }];
  225. }
  226. /**
  227. 设置 角标
  228. @param sender 对应的控件
  229. */
  230. - (void)initBadgeBtn:(UIButton *)sender
  231. {
  232. //-好友
  233. _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
  234. _badge.badgePositionAdjustment = CGPointMake(0, 12);
  235. }
  236. //进入贡献榜
  237. - (void)Incontribution
  238. {
  239. LeaderboardViewController *vc = [[LeaderboardViewController alloc]init];
  240. // vc.isHiddenTabbar = YES;
  241. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  242. }
  243. -(void)search{
  244. SSearchVC *searchVC = [[SSearchVC alloc]init];
  245. searchVC.searchType = @"0";
  246. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  247. }
  248. #pragma mark - TYPagerControllerDataSource
  249. - (NSInteger)numberOfControllersInPagerController
  250. {
  251. return self.itemTitleMutableArray.count;
  252. }
  253. - (NSString *)pagerController:(TYPagerController *)pagerController titleForIndex:(NSInteger)index
  254. {
  255. return self.itemTitleMutableArray[index];
  256. }
  257. - (UIViewController *)pagerController:(TYPagerController *)pagerController controllerForIndex:(NSInteger)index
  258. {
  259. return self.videoVCMutableArray[index];
  260. }
  261. #pragma mark - override delegate
  262. - (void)pagerController:(TYTabPagerController *)pagerController configreCell:(TYTabTitleViewCell *)cell forItemTitle:(NSString *)title atIndexPath:(NSIndexPath *)indexPath
  263. {
  264. [super pagerController:pagerController configreCell:cell forItemTitle:title atIndexPath:indexPath];
  265. }
  266. #pragma mark 跳转到话题页面和hotTopicViewController二级页面
  267. - (void)pushToNextControllerWithModel:(cuserModel *)model
  268. {
  269. if ([model.cate_id isEqualToString:@"0"])
  270. {
  271. // 暂时不能跳转
  272. }
  273. else
  274. {
  275. NewestViewController *tmpController = [[NewestViewController alloc]init];
  276. tmpController.topicName = model.title;
  277. tmpController.cate_id = model.cate_id;
  278. tmpController.types = @"1";
  279. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  280. }
  281. }
  282. #pragma mark NewestViewController跳转到直播
  283. -(void)pushToLiveController:(LivingModel *)model modelArr:(NSArray *)modelArr isFirstJump:(BOOL)isFirstJump
  284. {
  285. _model = model;
  286. _modelArr = modelArr;
  287. if (![BGUtils isNetConnected])
  288. {
  289. return;
  290. }
  291. if (isFirstJump) {
  292. self.password = @"";
  293. }
  294. if (![BGUtils isBlankString:model.password] && isFirstJump) {
  295. [self clickPasswordActionDelegateWithPassWord:model.password];
  296. return;
  297. }
  298. [[GlobalVariables sharedInstance].newestLivingMArray removeAllObjects];
  299. [[GlobalVariables sharedInstance].newestLivingMArray addObject:model];
  300. if ([self checkUser:[IMAPlatform sharedInstance].host])
  301. {
  302. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  303. item.chatRoomId = model.group_id;
  304. item.avRoomId = model.room_id;
  305. item.title = StringFromInt(model.room_id);
  306. item.vagueImgUrl = model.head_image;
  307. item.is_voice = model.is_voice;
  308. TCShowUser *showUser = [[TCShowUser alloc]init];
  309. showUser.uid = model.user_id;
  310. showUser.avatar = model.head_image;
  311. item.host = showUser;
  312. if (model.live_in == FW_LIVE_STATE_ING)
  313. {
  314. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  315. }
  316. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  317. // {
  318. // item.liveType = FW_LIVE_TYPE_RELIVE;
  319. // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
  320. // }
  321. //先关闭悬浮的直播间
  322. if ([LiveCenterManager sharedInstance].itemModel) {
  323. [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLiveRoomNotification" object:nil];
  324. }
  325. [LiveCenterManager sharedInstance].itemModel=item;
  326. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  327. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:modelArr isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  328. }];
  329. }
  330. else
  331. {
  332. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  333. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  334. } completion:^{
  335. }];
  336. }
  337. }
  338. -(void)clickPasswordActionDelegateWithPassWord:(NSString *)password{
  339. WeakSelf
  340. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请输入房间密码")preferredStyle:UIAlertControllerStyleAlert];
  341. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  342. textField.placeholder = ASLocalizedString(@"请输入密码");
  343. textField.delegate = self;
  344. textField.keyboardType = UIKeyboardTypeNumberPad;
  345. }];
  346. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  347. }];
  348. [alertController addAction:actionCacel];
  349. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  350. NSString *md5Str = [[NSString md5String:self.password] uppercaseString];
  351. //转化为大写
  352. NSLog(@"%@",md5Str);
  353. NSLog(@"%@",password);
  354. if ([md5Str isEqualToString:self.model.password]) {
  355. [self pushToLiveController:_model modelArr:_modelArr isFirstJump:NO];
  356. }else{
  357. [FanweMessage alertHUD:ASLocalizedString(@"密码不正确")];
  358. }
  359. }];
  360. [alertController addAction:actionConfirm];
  361. [self presentViewController:alertController animated:YES completion:nil];
  362. }
  363. -(void)textFieldDidChangeSelection:(UITextField *)textField{
  364. self.password = textField.text;
  365. }
  366. - (BOOL)checkUser:(id<IMHostAble>)user
  367. {
  368. if (![user conformsToProtocol:@protocol(AVUserAble)])
  369. {
  370. return NO;
  371. }
  372. return YES;
  373. }
  374. #pragma mark 跳转HomePageController页面
  375. - (void)goToMainPage:(NSString *)userID
  376. {
  377. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  378. tmpController.user_id = userID;
  379. tmpController.type = 0;
  380. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  381. }
  382. - (void)goToNewestView
  383. {
  384. }
  385. #pragma mark - 判断当日是否签到
  386. - (void)requestDataToady{
  387. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  388. [parmDict setObject:@"index" forKey:@"ctl"];
  389. [parmDict setObject:@"is_signin" forKey:@"act"];
  390. FWWeakify(self)
  391. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  392. FWStrongify(self)
  393. if ([responseJson toInt:@"today_signin"] == 0) {
  394. [MGSignHomeSuccessView showTodaySignSuccessViewGift:@"" frame:CGRectMake(0, 0, kScreenW, kScreenH) WithComplete:^{
  395. }];
  396. }
  397. } FailureBlock:^(NSError *error) {
  398. }];
  399. }
  400. - (UIStatusBarStyle)preferredStatusBarStyle{
  401. if (@available(iOS 13, *)) {
  402. return UIStatusBarStyleLightContent;
  403. }
  404. return UIStatusBarStyleLightContent;
  405. }
  406. @end