MOSquareListVC.mm 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. //
  2. // MOSquareListVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/17.
  6. //
  7. #define SetBtnWidthAndHeight 26.0
  8. //一页的size
  9. #define kPageSize 30
  10. #define kCollectionViewLeftAndRight 13.0
  11. #define kShowTopRightActivityBubbleKey @"kShowTopRightActivityBubbleKey"
  12. #import <Foundation/Foundation.h>
  13. #import "MOSquareListVC.h"
  14. #import "MOSquareTopMenuView.h"
  15. #import "MONewSquareTopMenuView.h"
  16. #import "MOScrollMenuView.h"
  17. #import "MOLiveCell.h"
  18. #import "MOShowLivePagesVC.h"
  19. #import "MOFollowInfoView.h"
  20. #import "MOFollowNoDataView.h"
  21. #import "MOSquareBaseCollectionView.h"
  22. //Banner
  23. //#import "MOSquareBannerReusableView.h"
  24. #import "MOLiveBase.h"
  25. #import "MOLiveList.h"
  26. #import "MOCountryBaseData.h"
  27. #import "MOCountryList.h"
  28. #import "MOMoreCountryView.h"
  29. #import "MOSearchUserVC.h"
  30. #import "MOWatchHistoryVC.h"
  31. #import "MONoMoreDataView.h"
  32. #import "MOWebViewController.h"
  33. #import "UIDevice+MOAddition.h"
  34. #import "MOWameListVC.h"
  35. #import "MOActivityManageView.h"
  36. #import "MOThemeManager.h"
  37. #import "MOHomeHeaderView.h"
  38. #import "MONewComerGiftView.h"
  39. #import "MOActivityCenterVC.h"
  40. #import "MOTeDownloadView.h"
  41. #import "MOBeautyDownloadManager.h"
  42. #import "MOCreateLiveVC.h"
  43. #import "MOClickConfigManager.h"
  44. #import "MOWebViewController.h"
  45. #import <AVFoundation/AVFoundation.h>
  46. @interface MOSquareListVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
  47. /** 顶部背景*/
  48. @property (nonatomic, strong) UIImageView *topBgView;
  49. @property (nonatomic, strong) MOHomeHeaderView *headerView;
  50. @property (nonatomic, strong) MOJumpList *jumpData;
  51. @property (nonatomic, strong) JXCategoryTitleView *titleCategoryView;
  52. @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
  53. @property (nonatomic, strong) MOSquareBaseCollectionView *hotTabView;//热门tab
  54. /** 右下角入口 */
  55. @property (nonatomic, strong) UIStackView *entranceStackView;
  56. @property (nonatomic, strong) UIButton *rechargeButton;
  57. @property (nonatomic, strong) UIButton *taskButton;
  58. @property (nonatomic, strong) UIButton *liveButton;
  59. @property (nonatomic, copy) NSArray *dialogsArray;//弹窗数据
  60. @property (nonatomic, strong) MOTeDownloadView *downloadView;
  61. @end
  62. @implementation MOSquareListVC
  63. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  64. [super touchesBegan:touches withEvent:event];
  65. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  66. }
  67. - (void)viewWillAppear:(BOOL)animated{
  68. [super viewWillAppear:animated];
  69. [self.navigationController setNavigationBarHidden:YES animated:animated];
  70. [[MOMainTabController sharedSingleton] showTabbarWithAnimation:NO];
  71. [self checkIfNeedShowNewUserGiftView];
  72. if (self.homePageShowBlock) {
  73. self.homePageShowBlock();
  74. }
  75. }
  76. - (void)checkIfNeedShowNewUserGiftView {
  77. MODialogsData *giftModel = (MODialogsData *)[[MODataCache sharedYYCache] objectForKey:kNewUserGiftPack];
  78. if (giftModel) {
  79. [self showNewComerGiftViewWithModel:giftModel];
  80. }
  81. }
  82. - (void)viewWillDisappear:(BOOL)animated {
  83. [super viewWillDisappear:animated];
  84. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  85. }
  86. - (void)viewDidLoad {
  87. [super viewDidLoad];
  88. // Do any additional setup after loading the view.
  89. [self setupUI];
  90. [self addNotification];
  91. }
  92. - (void)viewDidAppear:(BOOL)animated{
  93. [super viewDidAppear:animated];
  94. [self checkHaveActivityView];
  95. }
  96. - (void)addNotification{
  97. ReceiveNotification(@selector(beginRefreshData), @"MOSquareListVC_Refresh")//其他设备登录
  98. ReceiveNotification(@selector(toShowH5VCWith:), @"MOSquareListVC_H5Jump")//H5点击跳转
  99. ReceiveNotification(@selector(toUpdataTheFirstRecharge:), @"MOFirstRecharge_UpdataView")//首冲图层更新
  100. // ReceiveNotification(@selector(updateTheSignInView), @"MOSquareListVC_ShowSignInView")//活动入口
  101. ReceiveNotification(@selector(toShowActivityManageViewWith:), @"Noti_MOActivityManageView")//活动弹窗
  102. ReceiveNotification(@selector(setupUI), @"kNotification_RefreshTheme")//更新主题
  103. ReceiveNotification(@selector(toHandleNewComerGiftNotification:), @"kNotification_ShowNewComerGiftView")//新人礼包弹窗
  104. ReceiveNotification(@selector(updateFirstRechargeWithChangeLanguage), @"kNotification_ChangeLanguage")//改变语言刷新
  105. }
  106. - (void)toHandleNewComerGiftNotification:(NSNotification *)notification {
  107. MODialogsData *model = (MODialogsData *)notification.object;
  108. dispatch_async(dispatch_get_main_queue(), ^{
  109. if (!(self.isViewLoaded && self.view.window)) {//不在当前页面,不弹窗
  110. return;
  111. }
  112. [self showNewComerGiftViewWithModel:model];
  113. });
  114. }
  115. - (void)showNewComerGiftViewWithModel:(MODialogsData *)dialogModel {
  116. MONewComerGiftView *newComerGiftView = [[MONewComerGiftView alloc] init];
  117. WEAKSELF
  118. newComerGiftView.getBlock = ^{
  119. [kHttpManager claimNewUserGiftPackWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  120. if(kCode_Success){
  121. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_2_new_user_get_success")];
  122. } else{
  123. NSString *errorString = [MODataManager objectOrNilForKey:@"msg" fromDictionary:data];
  124. [MBProgressHUD showTipMessageInView:errorString];
  125. }
  126. }];
  127. };
  128. newComerGiftView.dismissBlock = ^{
  129. [weakSelf performSelector:@selector(showEnterRoomGuideView) withObject:nil afterDelay:2.0];
  130. };
  131. newComerGiftView.model = dialogModel;
  132. [newComerGiftView show];
  133. [[MODataCache sharedYYCache] removeObjectForKey:kNewUserGiftPack];
  134. }
  135. - (void)showEnterRoomGuideView {
  136. [self.hotTabView showEnterRoomGuideView];
  137. }
  138. - (void)checkHaveActivityView{
  139. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  140. // 递归遍历所有子视图
  141. for (UIView *subview in keyWindow.subviews) {
  142. if ([subview isKindOfClass:[MOActivityManageView class]]) {
  143. subview.hidden = NO;
  144. [UIView animateWithDuration:0.3 animations:^{
  145. [self.view layoutIfNeeded];
  146. }];
  147. break;
  148. }
  149. }
  150. }
  151. static BOOL MOActivityManageViewTag = NO;
  152. - (void)toShowActivityManageViewWith:(NSNotification *)noti{
  153. NSArray *dataArr = noti.object;
  154. self.dialogsArray = [dataArr copy];
  155. if(MOActivityManageViewTag){
  156. return;
  157. }
  158. MOActivityManageViewTag = YES;
  159. [self performSelector:@selector(updateMOActivityManageViewTag) withObject:nil afterDelay:1.0];
  160. if(self){
  161. MOActivityManageView *view = [MOActivityManageView moActivityManageView];
  162. view.codesArr = dataArr;
  163. [view showActivityManageView];
  164. }
  165. }
  166. - (void)updateMOActivityManageViewTag{
  167. MOActivityManageViewTag = NO;
  168. }
  169. - (void)toUpdataTheFirstRecharge:(NSNotification *)noti{
  170. NSArray *floatingsArr = noti.object;
  171. [self.entranceStackView removeArrangedSubview:self.rechargeButton];
  172. if (floatingsArr.count > 0) {
  173. [self.entranceStackView insertArrangedSubview:self.rechargeButton atIndex:0];
  174. }
  175. }
  176. - (void)updateFirstRechargeWithChangeLanguage {
  177. //置空重新走懒加载方法
  178. _entranceStackView = nil;
  179. [self.view addSubview:self.entranceStackView];
  180. [self.entranceStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.bottom.mas_equalTo(-kBottomSafeAreaInset - 92);
  182. make.right.mas_equalTo(-12);
  183. make.width.mas_equalTo(52);
  184. }];
  185. }
  186. - (void)beginRefreshData{
  187. WEAKSELF
  188. [self.listContainerView.validListDict enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, id<JXCategoryListContentViewDelegate> _Nonnull obj, BOOL * _Nonnull stop) {
  189. NSInteger theIndex = key.integerValue;
  190. if(theIndex == weakSelf.titleCategoryView.selectedIndex){
  191. MOSquareBaseCollectionView *listView = (MOSquareBaseCollectionView *)obj;
  192. [listView toBeginRefresh];
  193. }
  194. }];
  195. }
  196. //- (void)updateTheSignInView{
  197. //
  198. //}
  199. - (void)toShowH5VCWith:(NSNotification *)noti{
  200. MOJumpList *jumpData = noti.object;
  201. self.jumpData = jumpData;
  202. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toShowH5VC) object:nil];
  203. [self performSelector:@selector(toShowH5VC) withObject:nil afterDelay:0.5];
  204. }
  205. - (void)toShowH5VC{
  206. MOJumpList *jumpData = self.jumpData;
  207. if(!jumpData){
  208. return;
  209. }
  210. WEAKSELF
  211. BOOL isURL = [jumpData.jump hasPrefix:@"http://"] || [jumpData.jump hasPrefix:@"https://"];
  212. if(jumpData.jump.length != 0 && isURL){
  213. MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
  214. UINavigationController *nav = mainTabbar.selectedViewController;
  215. UINavigationController *baseNav = nav;
  216. if (nav.presentedViewController) {
  217. if ([nav isKindOfClass:[UINavigationController class]]) {
  218. UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
  219. baseNav = presentingNavigationController;
  220. BOOL isHaveLive = NO;
  221. for (UIViewController *vc in presentingNavigationController.viewControllers) {
  222. if([vc isKindOfClass:[MOShowLivePagesVC class]]){
  223. isHaveLive = YES;
  224. break;
  225. }
  226. }
  227. //直播间的触发逻辑 (例如直播间的快速充值里面的广告栏)
  228. if(isHaveLive){
  229. UINavigationController *presentingNavigationController = (UINavigationController *)nav.presentedViewController;
  230. MOWebViewController *vc = [[MOWebViewController alloc] init];
  231. NSString *urlStr = jumpData.jump;
  232. vc.webUrl = [NSURL URLWithString:urlStr];
  233. if(jumpData.target == 2){
  234. vc.isHalfShow = YES;
  235. UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:vc];
  236. newNav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  237. [presentingNavigationController presentViewController:newNav animated:YES completion:nil];
  238. }
  239. else{
  240. if(jumpData.title.length != 0){
  241. vc.titleStr = jumpData.title;
  242. }
  243. vc.hidesBottomBarWhenPushed = YES;
  244. [presentingNavigationController mo_pushViewController:vc animated:YES];
  245. }
  246. return;
  247. }
  248. }
  249. }
  250. MOWebViewController *vc = [[MOWebViewController alloc] init];
  251. vc.isFirstAdWeb = jumpData.isFirstAdWeb;
  252. NSString *urlStr = jumpData.jump;
  253. vc.webUrl = [NSURL URLWithString:urlStr];
  254. vc.closeViewBlock = ^{
  255. if(weakSelf.jumpData.isFirstAdWeb){
  256. //开屏广告关闭, 需要弹出相应的弹窗
  257. MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
  258. [mainTabbar ChangeNeedShowAlert];
  259. }
  260. };
  261. if(jumpData.target == 2){
  262. vc.isHalfShow = YES;
  263. UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:vc];
  264. newNav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  265. [mainTabbar presentViewController:newNav animated:YES completion:nil];
  266. }
  267. else{
  268. if(jumpData.title.length != 0){
  269. vc.titleStr = jumpData.title;
  270. }
  271. vc.hidesBottomBarWhenPushed = YES;
  272. [baseNav mo_pushViewController:vc animated:YES];
  273. }
  274. }
  275. else if([jumpData.jump containsString:@"mimo://"]){
  276. NSURL *urlUrl = [NSURL URLWithString:jumpData.jump];
  277. if ([[UIApplication sharedApplication] canOpenURL:urlUrl])
  278. {
  279. [[UIApplication sharedApplication] openURL:urlUrl];
  280. }
  281. }
  282. }
  283. - (void)dealloc{
  284. [[NSNotificationCenter defaultCenter] removeObserver:self];
  285. }
  286. #pragma mark - UI
  287. - (void)setupUI{
  288. self.view.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  289. [self.view addSubview:self.topBgView];
  290. [self.topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  291. make.top.left.right.equalTo(self.view);
  292. make.height.mas_equalTo(kScaleWidth(SCREENWIDTH));
  293. }];
  294. if ([MOThemeManager shareManager].canUseTheme && [MOThemeManager shareManager].themeModel.slideBackgroundMain) {
  295. [self.topBgView sd_setImageWithURL:[NSURL URLWithString:[MOThemeManager shareManager].themeModel.slideBackgroundMain]];
  296. } else {
  297. [self.topBgView setImage:[UIImage imageNamed:@"img_home_top_bg"]];
  298. }
  299. [self.view addSubview:self.headerView];
  300. [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  301. make.top.mas_equalTo(kTopSafeAreaInset);
  302. make.left.right.mas_equalTo(0);
  303. make.height.mas_equalTo(48);
  304. }];
  305. // NSArray *titleDataArr = @[NSLocalString(@"mimo_square_Follow"),NSLocalString(@"mimo_square_LIVE"),NSLocalString(@"mimo_square_Newstar")];
  306. NSArray *titleDataArr = @[NSLocalString(@"mimo_square_LIVE"),NSLocalString(@"mimo_square_Newstar"),NSLocalString(@"mimo_square_Follow")];
  307. CGFloat titleWidth = 0.0;
  308. for (NSString *titleStr in titleDataArr) {
  309. CGFloat width = [MOTools getWidthWithString:titleStr font:[MOTextTools poppinsExtraBoldFont:20]];
  310. titleWidth = titleWidth + width + 24.0;
  311. }
  312. [self.view addSubview:self.titleCategoryView];
  313. [self.titleCategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  314. make.left.equalTo(self.view).offset(6.0);
  315. make.top.equalTo(self.headerView.mas_bottom);
  316. make.width.mas_equalTo(titleWidth);
  317. make.height.mas_equalTo(48);
  318. }];
  319. self.titleCategoryView.titles = titleDataArr;
  320. self.titleCategoryView.titleColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.7];
  321. self.titleCategoryView.titleSelectedColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  322. if ([MOThemeManager shareManager].canUseTheme) {
  323. if ([MOThemeManager shareManager].themeModel.titleColor.length > 0) {
  324. self.titleCategoryView.titleColor = [MOTools colorWithHexString:[MOThemeManager shareManager].themeModel.titleColor];
  325. }
  326. if ([MOThemeManager shareManager].themeModel.titleColorOn.length > 0) {
  327. self.titleCategoryView.titleSelectedColor = [MOTools colorWithHexString:[MOThemeManager shareManager].themeModel.titleColorOn];
  328. }
  329. }
  330. self.titleCategoryView.titleFont = [MOTextTools poppinsBoldFont:18];
  331. self.titleCategoryView.titleSelectedFont = [MOTextTools poppinsExtraBoldFont:26];
  332. self.titleCategoryView.backgroundColor = [UIColor clearColor];
  333. self.titleCategoryView.defaultSelectedIndex = 0;
  334. self.titleCategoryView.cellSpacing = 24.0;
  335. self.titleCategoryView.contentEdgeInsetLeft = 12.0;
  336. JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
  337. backgroundView.indicatorHeight = 12;
  338. backgroundView.indicatorWidth = 47.0;
  339. backgroundView.indicatorWidthIncrement = 0;
  340. backgroundView.indicatorColor = [UIColor clearColor];
  341. backgroundView.componentPosition = JXCategoryComponentPosition_Bottom;
  342. backgroundView.verticalMargin = -15.0;
  343. UIImageView *imgBgView = [[UIImageView alloc] init];
  344. imgBgView.contentMode = UIViewContentModeScaleToFill;
  345. [imgBgView setImage:[UIImage imageNamed:@"icon_home_line_bottom"]];
  346. if ([MOThemeManager shareManager].canUseTheme && [MOThemeManager shareManager].themeModel.titleBottom.length > 0) {
  347. [imgBgView sd_setImageWithURL:[NSURL URLWithString:[MOThemeManager shareManager].themeModel.titleBottom]];
  348. }
  349. [backgroundView addSubview:imgBgView];
  350. [imgBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  351. make.edges.equalTo(backgroundView);
  352. }];
  353. self.titleCategoryView.indicators = @[backgroundView];
  354. [self.view addSubview:self.listContainerView];
  355. [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  356. make.top.equalTo(self.titleCategoryView.mas_bottom).offset(10.0);
  357. make.left.right.bottom.equalTo(self.view);
  358. }];
  359. self.titleCategoryView.listContainer = self.listContainerView;
  360. [self.view addSubview:self.entranceStackView];
  361. [self.entranceStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  362. make.bottom.mas_equalTo(-kBottomSafeAreaInset - 92);
  363. make.right.mas_equalTo(-12);
  364. make.width.mas_equalTo(52);
  365. }];
  366. }
  367. // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  368. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
  369. MOLogV(@"变换了");
  370. }
  371. #pragma mark - JXCategoryListContainerViewDelegate
  372. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView{
  373. return self.titleCategoryView.titles.count;
  374. }
  375. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
  376. BOOL isFollow = NO;
  377. if(index == 2){//关注
  378. isFollow = YES;
  379. }
  380. WEAKSELF
  381. MOSquareBaseCollectionView *view = [[MOSquareBaseCollectionView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT) AndIsFollow:isFollow];
  382. view.beginScrollBlock = ^{
  383. [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:@selector(showEnterRoomGuideView) object:nil];
  384. };
  385. if(index == 0){//热门
  386. self.hotTabView = view;
  387. view.searchType = 2;
  388. }
  389. else if (index == 1){//新人
  390. view.searchType = 4;
  391. }
  392. view.isFollow = isFollow;
  393. view.homeVC = self;
  394. return view;
  395. }
  396. - (void)listContainerViewDidScroll:(UIScrollView *)scrollView {
  397. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  398. }
  399. - (void)liveButtonAction {
  400. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  401. BOOL isAnchor = GetIsAnchor;
  402. if (!isAnchor) {
  403. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_live_tip_no_anchor")];
  404. return;
  405. }
  406. [self toOpenTheLiveRoom];
  407. }
  408. - (void)toOpenTheLiveRoom {
  409. //个人信息对象
  410. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  411. if(userInfoData.userProfile.mysterious){
  412. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_2_vip_mystery_man_tip_2")];
  413. return;
  414. }
  415. BOOL isHaveBeautyRes = [TEDownloader toCheckTheBeautyRes];
  416. if(!isHaveBeautyRes){
  417. [[MOBeautyDownloadManager shareManager] checkAndDownloadBeautyData];
  418. WEAKSELF
  419. [MOBeautyDownloadManager shareManager].progressBlock = ^(CGFloat progress) {
  420. weakSelf.downloadView.hidden = NO;
  421. weakSelf.downloadView.progress = progress;
  422. };
  423. [MOBeautyDownloadManager shareManager].completeBlock = ^{
  424. weakSelf.downloadView.hidden = YES;
  425. };
  426. return;
  427. }
  428. WEAKSELF
  429. [kHttpManager theAnchorGetLiveRoomWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  430. if(kCode_Success){
  431. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  432. MOLiveDetail *dataModel = [MOLiveDetail modelObjectWithDictionary:data[@"data"]];
  433. if(dataModel.currentRoom.id.length > 0){
  434. [weakSelf toCloseTheRoomOrContinueWith:dataModel];
  435. }
  436. else{
  437. MOCreateLiveVC *vc = [[MOCreateLiveVC alloc] init];
  438. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  439. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  440. [weakSelf presentViewController:nav animated:YES completion:nil];
  441. }
  442. }
  443. else{
  444. kShowNetError(data)
  445. MOLogV(@"theAnchorGetLiveRoomWithParams 接口报错了");
  446. }
  447. }];
  448. }
  449. - (void)toCloseTheRoomOrContinueWith:(MOLiveDetail *)model{
  450. WEAKSELF
  451. if(model.currentRoom.id.length > 0){
  452. //中心弹窗
  453. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  454. alertView.subTitleLabel.text = NSLocalString(@"mimo_room_living_open_tip");
  455. [alertView.cancelBtn setTitle:NSLocalString(@"mimo_room_living_close_living") forState:UIControlStateNormal];
  456. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_room_living_continue_living") forState:UIControlStateNormal];
  457. alertView.isStrongBg = YES;
  458. alertView.cancelBlock = ^{
  459. [weakSelf toCloseTheLiveRoomWithRoomId:model.currentRoom.id];
  460. };
  461. alertView.confirmBlock = ^{
  462. [weakSelf toShowRoomWith:model];
  463. };
  464. [alertView show];
  465. }
  466. }
  467. //关闭直播间
  468. - (void)toCloseTheLiveRoomWithRoomId:(NSString *)roomId{
  469. WEAKSELF
  470. NSDictionary *dict = @{@"id":roomId};
  471. [kHttpManager toCloseTheLiveRoomWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  472. MOLogV(@"关闭直播间接口调用");
  473. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_room_end_tip_anchor")];
  474. SendNotification(@"MOSquareListVC_Refresh");
  475. }];
  476. }
  477. - (void)toShowRoomWith:(MOLiveDetail *)model{
  478. //MARK 检查用户是否对摄像头麦克风授权,未授权不能调用录制功能
  479. AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  480. AVAuthorizationStatus audioStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
  481. //没有打开摄像头权限
  482. if(videoStatus != AVAuthorizationStatusAuthorized){
  483. [MOCreateLiveVC requestCameraPermissionWithCompletion:^(BOOL open) {
  484. if(!open){
  485. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_video_authority_fail_tip") message:NSLocalString(@"mimo_get_video_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  486. [alert show];
  487. }
  488. }];
  489. return;
  490. }
  491. //没有打开麦克风权限
  492. if(audioStatus != AVAuthorizationStatusAuthorized){
  493. [MOCreateLiveVC requestAudioPermissionWithCompletion:^(BOOL open) {
  494. if(!open){
  495. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_audio_authority_fail_tip") message:NSLocalString(@"mimo_get_audio_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  496. [alert show];
  497. }
  498. }];
  499. return;
  500. }
  501. [MOShowAgoraKitManager shareManager].isCreatLive = YES;
  502. MOClickConfigManager *configManager = [MOClickConfigManager shareManager];
  503. configManager.durationTask = model.durationTask;
  504. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  505. vc.isCreatLive = YES;
  506. vc.userType = MOShowLiveAnchorType;
  507. vc.roomList = @[model.currentRoom].mutableCopy;
  508. vc.liveModel = model;
  509. vc.isNeedSetBeauty = YES;
  510. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  511. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  512. [self presentViewController:nav animated:YES completion:nil];
  513. }
  514. - (void)taskButtonAction {
  515. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  516. MOWebViewController *vc = [[MOWebViewController alloc] init];
  517. NSString *urlStr = [NSString stringWithFormat:@"%@/#/taskCenter?tagName=dailyTasks",kNetPath_Web_Base];
  518. vc.webUrl = [NSURL URLWithString:urlStr];
  519. vc.hidesBottomBarWhenPushed = YES;
  520. [self.navigationController mo_pushViewController:vc animated:YES];
  521. }
  522. - (void)rechargeButtonAction {
  523. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showEnterRoomGuideView) object:nil];
  524. NSMutableArray *dataArr = [NSMutableArray array];
  525. for (MODialogsData *object in self.dialogsArray) {
  526. if(object.type > 0 && object.type < 4){
  527. [dataArr addObject:object];
  528. }
  529. }
  530. NSArray *sortedArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(MODialogsData * obj1, MODialogsData * obj2) {
  531. if (obj1.type == 2 && obj2.type != 2) {
  532. return NSOrderedAscending; // obj1排在前面
  533. }
  534. if (obj2.type == 2 && obj1.type != 2) {
  535. return NSOrderedDescending; // obj2排在前面
  536. }
  537. if (obj1.type == 1 && obj2.type != 1) {
  538. return NSOrderedAscending; // obj1排在前面
  539. }
  540. if (obj2.type == 1 && obj1.type != 1) {
  541. return NSOrderedDescending; // obj2排在前面
  542. }
  543. return NSOrderedSame; // 如果 type 相等,保持原顺序
  544. }];
  545. MOActivityManageView *view = [MOActivityManageView moActivityManageView];
  546. view.codesArr = sortedArray;
  547. [view showActivityManageView];
  548. }
  549. - (void)updateDownloadBeautyData:(CGFloat)progress {
  550. self.downloadView.hidden = NO;
  551. self.downloadView.progress = progress;
  552. }
  553. - (void)downloadBeautyDataSuccess {
  554. self.downloadView.hidden = YES;
  555. }
  556. #pragma mark - Lazy
  557. - (UIImageView *)topBgView{
  558. if (!_topBgView)
  559. {
  560. _topBgView = [[UIImageView alloc] init];
  561. _topBgView.clipsToBounds = YES;
  562. _topBgView.userInteractionEnabled = NO;
  563. _topBgView.contentMode = UIViewContentModeScaleAspectFill;
  564. }
  565. return _topBgView;
  566. }
  567. - (MOHomeHeaderView *)headerView {
  568. if (!_headerView) {
  569. _headerView = [[MOHomeHeaderView alloc] init];
  570. WEAKSELF
  571. _headerView.searchActionBlock = ^{
  572. [weakSelf searchBtnClick];
  573. };
  574. _headerView.historyActionBlock = ^{
  575. [weakSelf historyBtnClick];
  576. };
  577. }
  578. return _headerView;
  579. }
  580. //MARK: 查找页面
  581. - (void)searchBtnClick{
  582. MOSearchUserVC *vc = [[MOSearchUserVC alloc] init];
  583. vc.hidesBottomBarWhenPushed = YES;
  584. [self.navigationController mo_pushViewController:vc animated:YES];
  585. }
  586. //MARK: 历史记录页面
  587. - (void)historyBtnClick{
  588. MOWatchHistoryVC *vc = [[MOWatchHistoryVC alloc] init];
  589. vc.hidesBottomBarWhenPushed = YES;
  590. [self.navigationController mo_pushViewController:vc animated:YES];
  591. }
  592. - (JXCategoryTitleView *)titleCategoryView{
  593. if(!_titleCategoryView){
  594. _titleCategoryView = [[JXCategoryTitleView alloc] init];
  595. _titleCategoryView.delegate = self;
  596. }
  597. return _titleCategoryView;
  598. }
  599. - (JXCategoryListContainerView *)listContainerView{
  600. if(!_listContainerView){
  601. _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
  602. }
  603. return _listContainerView;
  604. }
  605. - (UIStackView *)entranceStackView {
  606. if (!_entranceStackView) {
  607. _entranceStackView = [[UIStackView alloc] init];
  608. _entranceStackView.axis = UILayoutConstraintAxisVertical;
  609. _entranceStackView.spacing = 16;
  610. if ([MOMainTabController sharedSingleton].floatingsArr.count > 0) {
  611. [_entranceStackView addArrangedSubview:self.rechargeButton];
  612. }
  613. [_entranceStackView addArrangedSubview:self.taskButton];
  614. [_entranceStackView addArrangedSubview:self.liveButton];
  615. }
  616. return _entranceStackView;
  617. }
  618. - (UIButton *)liveButton {
  619. if (!_liveButton) {
  620. _liveButton = [[UIButton alloc] init];
  621. [_liveButton setImage:[UIImage imageNamed:@"icon_entrance_live"] forState:UIControlStateNormal];
  622. [_liveButton addTarget:self action:@selector(liveButtonAction) forControlEvents:UIControlEventTouchUpInside];
  623. [_liveButton addSubview:self.downloadView];
  624. [self.downloadView mas_makeConstraints:^(MASConstraintMaker *make) {
  625. make.edges.mas_equalTo(0);
  626. }];
  627. }
  628. return _liveButton;
  629. }
  630. - (MOTeDownloadView *)downloadView{
  631. if(!_downloadView){
  632. _downloadView = [[MOTeDownloadView alloc] initWithFrame:CGRectMake(0.0, 0.0, 52.0, 52.0)];
  633. _downloadView.hidden = YES;
  634. }
  635. return _downloadView;
  636. }
  637. - (UIButton *)taskButton {
  638. if (!_taskButton) {
  639. _taskButton = [[UIButton alloc] init];
  640. [_taskButton setImage:[UIImage imageNamed:@"icon_entrance_task"] forState:UIControlStateNormal];
  641. [_taskButton addTarget:self action:@selector(taskButtonAction) forControlEvents:UIControlEventTouchUpInside];
  642. }
  643. return _taskButton;
  644. }
  645. - (UIButton *)rechargeButton {
  646. if (!_rechargeButton) {
  647. _rechargeButton = [[UIButton alloc] init];
  648. [_rechargeButton setImage:[UIImage imageNamed:@"icon_entrance_recharge"] forState:UIControlStateNormal];
  649. [_rechargeButton addTarget:self action:@selector(rechargeButtonAction) forControlEvents:UIControlEventTouchUpInside];
  650. }
  651. return _rechargeButton;
  652. }
  653. #pragma mark - 横屏
  654. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
  655. return UIInterfaceOrientationMaskPortrait;
  656. }
  657. @end