//
|
// RecommendController.m
|
// BuWanVideo2.0
|
//
|
// Created by Aeline on 2021/5/23.
|
// Copyright © 2021 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "RecommendMainController.h"
|
|
#import "RecommendController.h"
|
#import "ListController.h"
|
#import <BUAdSDK/BUAdSDK.h>
|
#import "DYGridVideoController.h"
|
|
@interface RecommendMainController () <ZJScrollPageViewDelegate,BUNativeExpressFullscreenVideoAdDelegate>
|
|
@property(nonatomic, nullable, strong) ZJScrollPageView *scrollPageView;
|
@property (nonatomic, strong) UIView *primtView;
|
|
@property (nonatomic, nullable, strong) NSMutableArray *arrayClassName;
|
@property (nonatomic, nullable, strong) NSMutableArray *arrayKeyName;
|
|
@property (nonatomic, assign) BOOL isRequest;
|
|
|
@property (nonatomic, strong)BUNativeExpressFullscreenVideoAd *fullscreenAd;
|
@end
|
|
@implementation RecommendMainController
|
|
- (instancetype)init {
|
self = [super init];
|
if (self) {
|
self.title = @"精选";
|
}
|
return self;
|
}
|
|
- (void)viewWillAppear:(BOOL)animated {
|
NSLog(@"RecommendMainController - viewWillAppear");
|
[super viewWillAppear:animated];
|
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
self.navigationController.navigationBar.translucent = NO;
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
[super viewWillDisappear:animated];
|
}
|
|
- (void)viewDidLoad {
|
NSLog(@"RecommendMainController - viewDidLoad");
|
[super viewDidLoad];
|
[self NetworkMonitoring];
|
[self.view addSubview:self.primtView];
|
[self setuoDataConfig];
|
//[self loadDataFromFile];
|
}
|
|
- (void)setuoDataConfig {
|
}
|
|
-(void)loadDataFromFile {
|
if (_isRequest) {
|
return;
|
}
|
self.isRequest = YES;
|
[[YTHNetInterface startInterface]cancelAll];
|
|
|
[[YTHNetInterface startInterface] getVideoClassWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
|
for (int i = 0; i < [result[@"Data"][@"data"] count]; i++) {
|
[self.arrayClassName addObject:result[@"Data"][@"data"][i][@"Name"]];
|
[self.arrayKeyName addObject:result[@"Data"][@"data"][i]];
|
// if(i==0){
|
// [self.arrayClassName addObject:@"刷一刷"];
|
// [self.arrayKeyName addObject:@{@"Id":@123,@"DataType":@"gridVideo"}];
|
// }
|
}
|
|
|
|
self.primtView.hidden = YES;
|
[self setupViewConfig];
|
self.isRequest = NO;
|
|
} else{
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
[self notHaveNetWork];
|
}
|
self.isRequest = NO;
|
}
|
}];
|
}
|
|
#pragma mark 添加网络监测
|
- (void)NetworkMonitoring{
|
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
selector:@selector(reachabilityChang:)
|
name:AFNetworkingReachabilityDidChangeNotification
|
object:nil];
|
}
|
|
- (void) reachabilityChang: (NSNotification*)note {
|
switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus) {
|
case AFNetworkReachabilityStatusNotReachable:{//无网
|
[YTHsharedManger startManger].NetworkStatus = 0;
|
|
if (self.arrayClassName.count == 0) {
|
self.primtView.hidden = NO;
|
|
} else {
|
[self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWWAN:{//万维网
|
[YTHsharedManger startManger].NetworkStatus = 1;
|
|
if (self.arrayClassName.count == 0) {
|
[self loadDataFromFile];
|
}
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWiFi:{// 使用WiFi网络
|
[YTHsharedManger startManger].NetworkStatus = 2;
|
|
if (self.arrayClassName.count == 0) {
|
[self loadDataFromFile];
|
}
|
}
|
break;
|
case AFNetworkReachabilityStatusUnknown:{// 当前网络未知
|
[YTHsharedManger startManger].NetworkStatus = 3;
|
|
}
|
break;
|
}
|
}
|
|
- (void)notHaveNetWork {
|
self.primtView.hidden = NO;
|
}
|
|
- (void)refreshTaped:(UIButton *)sender {
|
[self loadDataFromFile];
|
|
}
|
|
- (void)setupViewConfig {
|
[self setupContentView];
|
}
|
|
- (void)setupContentView {
|
if (self.scrollPageView) {
|
[self.scrollPageView removeFromSuperview];
|
}
|
ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
|
// 缩放标题
|
style.scaleTitle = YES;
|
// 颜色渐变
|
style.gradualChangeTitleColor = YES;
|
// 选中字体的颜色
|
style.selectedTitleColor = UICOLOR_FROM_RGB(0x159FFF, 1);
|
// 标题一般状态的颜色
|
style.normalTitleColor = UICOLOR_FROM_RGB(0x3B3B3B, 1);
|
// 标题之间的间隙
|
style.titleMargin = 23;
|
// 放大倍数
|
style.titleBigScale = 1.3;
|
// 字体
|
style.titleFont = [UIFont systemFontOfSize:14];
|
// 设置segment的高度
|
style.segmentHeight = 36;
|
style.autoAdjustTitlesWidth = YES;
|
|
// 初始化
|
ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, kStatusBarH + ALNavBarH, KScreenW, KScreenH - kStatusBarH - ALNavBarH - ALTabBar_H) segmentStyle:style titles:self.arrayClassName parentViewController:self delegate:self];
|
self.scrollPageView = scrollPageView;
|
[self.view addSubview:self.scrollPageView];
|
}
|
|
#pragma mark --- ZJScrollPageViewDelegate ---
|
- (NSInteger)numberOfChildViewControllers {
|
return self.arrayClassName.count;
|
}
|
|
- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
|
|
UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
|
if (!childVc) {
|
NSString *type = self.arrayKeyName[index][@"DataType"];
|
if ([type containsString:@"recommend"]) {
|
RecommendController *vc = [[RecommendController alloc] init];
|
vc.parms = _arrayKeyName[index];
|
vc.index = index;
|
childVc = vc;
|
|
} else if ([type containsString:@"class"]) {
|
ListController *vc = [[ListController alloc] init];
|
vc.parms = _arrayKeyName[index];
|
childVc = vc;
|
}else if ([type containsString:@"gridVideo"]) {
|
DYGridVideoController *vc = [[DYGridVideoController alloc] init];
|
childVc = vc;
|
}
|
}
|
return childVc;
|
}
|
|
- (NSMutableArray *)arrayClassName {
|
if (!_arrayClassName) {
|
_arrayClassName = [[NSMutableArray alloc] init];
|
}
|
return _arrayClassName;
|
}
|
|
- (NSMutableArray *)arrayKeyName {
|
if (!_arrayKeyName) {
|
_arrayKeyName = [[NSMutableArray alloc] init];
|
}
|
return _arrayKeyName;
|
}
|
|
- (UIView *)primtView {
|
if (_primtView) {
|
return _primtView;
|
}
|
_primtView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
|
// _primtView .backgroundColor = SJColor(98, 98,86 , 1);
|
_primtView.backgroundColor = [UIColor whiteColor];
|
UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake((KScreenW - KScreenW / 3) / 2, KScreenH / 2 - KScreenW / 3 , KScreenW / 3 , KScreenW / 3)];
|
imageview.image = [UIImage imageNamed: @"nowifi"];
|
// imageview.backgroundColor = [UIColor orangeColor];
|
[_primtView addSubview:imageview];
|
|
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageview.frame), KScreenW , 30)];
|
label.textColor = SJColor(98, 98, 98, 1);
|
label.text = @"无法连接到网络...";
|
label.font = [UIFont boldSystemFontOfSize:18];
|
label.textAlignment = NSTextAlignmentCenter;
|
[_primtView addSubview:label];
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
button.frame = CGRectMake((KScreenW - KScreenW / 3) / 2, CGRectGetMaxY(label.frame) + 15, KScreenW / 3, 30);
|
button.backgroundColor = SJColor(25, 169, 249, 1);
|
button.titleLabel.font = [UIFont systemFontOfSize:16];
|
[button setTitle:@"重新加载" forState:UIControlStateNormal];
|
button.layer.cornerRadius = 5;
|
button.layer.masksToBounds = YES;
|
[button addTarget:self action:@selector(refreshTaped:) forControlEvents:UIControlEventTouchUpInside];
|
[_primtView addSubview:button];
|
_primtView.hidden = YES;
|
return _primtView;
|
}
|
|
|
//加载插屏广告
|
|
- (void)loadFullscreenVideoAd {
|
id interstitial=[YTHsharedManger startManger].ad[@"homeInterstitial"];
|
if(interstitial==nil|| interstitial==[NSNull null] ||interstitial[@"type"]==nil){
|
return;
|
}
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
NSLog(@"广告开始加载-首页插屏");
|
self.fullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:@"947698171"];
|
self.fullscreenAd.delegate = self;
|
[self.fullscreenAd loadAdData];
|
|
});
|
|
}
|
|
//此方法在视频广告素材加载成功时调用。
|
- (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//当视频广告素材加载失败时调用此方法。
|
- (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
|
|
}
|
|
//此方法在成功呈现nativeExpressAdView时调用。
|
- (void)nativeExpressFullscreenVideoAdViewRenderSuccess:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd {
|
|
}
|
|
//当nativeExpressAdView无法呈现时,将调用此方法
|
- (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
|
|
}
|
//当视频缓存成功时调用此方法
|
- (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
[fullscreenVideoAd showAdFromRootViewController:self];
|
}
|
|
//此方法在用户单击“跳过”按钮时调用
|
- (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//此方法在视频广告即将关闭时调用。
|
- (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//关闭视频广告时调用此方法
|
- (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
|
|
}
|
|
//此方法在视频广告播放完成或发生错误时调用。
|
- (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
|
|
|
}
|
|
@end
|