admin
2022-01-17 b63ed504f6d1e652d9fbd67c1490e7821b159c75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
//
//  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