TopNoticeViewController.m
10.7 KB
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
//
// TopNoticeViewController.m
// SCIOLiveCN
//
// Created by huayu on 16/5/31.
// Copyright © 2016年 huayu. All rights reserved.
//
#import "JSONKit.h"
#import "TopNoticeViewController.h"
//#import <ShareSDKUI/ShareSDK+SSUI.h>
//#import <ShareSDK/ShareSDK.h>
@interface TopNoticeViewController ()<WKNavigationDelegate>
@property (nonatomic, strong) NSArray *fontArray;
@property (nonatomic, assign) NSInteger fontIndex;
@end
@implementation TopNoticeViewController
#pragma mark - Data
- (void)loadTrailerData {
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
return;
}
[AlertViewTool showHUDView];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:yugao parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject){
[AlertViewTool hideHUDView];
// 请求成功,解析数据
NSString * jsonString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"jsonString == %@",jsonString);
NSArray *arr = [jsonString objectFromJSONString];
NSDictionary *dic = [arr objectAtIndex:0];
// NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><p><font style=\"font-size:20px;\"><strong>%@</strong></font><br>%@</p><body>",[dic objectForKey:@"Tittle"],[dic objectForKey:@"PublishDateTime"]];
NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><p><font style=\"font-size:20px;\"><strong>%@</strong></font><br>%@</p><style type=\"text/css\"> img{width: 100%% !important; height: auto !important;}</style><body>",[dic objectForKey:@"Tittle"],[dic objectForKey:@"PublishDateTime"]];
NSString* htmlBody = [dic objectForKey:@"Content"];
NSString* htmlFooter = @"</body></html>";
NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@%@",htmlHeader,htmlBody,htmlFooter];
[self->_webView loadHTMLString:strHtml baseURL:nil];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (void)loadData {
NSString *strUrl = @"http://app.phonemovie.cnlive.com/gxb/api/cataloglatest";
//NSLog(@"%@",strUrl);
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"wz/fbhgg/\",\"page\":\"1\",\"pageSize\":\"1\"}"];
//NSLog(@"%@",categoryId);
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
return;
}
NSDictionary *parameters = @{@"params":categoryId};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:strUrl parameters:parameters headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
// 请求成功,解析数据
self->_dictionary = [NSDictionary dictionaryWithDictionary:responseObject];
dispatch_async(dispatch_get_main_queue(), ^{
[self loadShareView];
});
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_fontArray = @[@"16",@"20",@"24"];
_fontIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
[self setUpNavigationBar];
[self loadTrailerData];
[self loadData];
[self setUpUI];
}
#pragma mark - UI
- (void)setUpNavigationBar{
self.navigationController.navigationBar.barTintColor = Color_Blue;
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:18]};
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
headerButton.layer.cornerRadius = 2.0;
headerButton.layer.masksToBounds = true;
[headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
[headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
self.navigationItem.title = CustomStr(@"Announcements");
}
- (void)setUpUI{
if (iPhoneX) {
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 88 - 44 - 34)];
} else {
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44)];
}
_webView.scrollView.backgroundColor = [UIColor whiteColor];
_webView.backgroundColor = [UIColor whiteColor];
// _webView.scalesPageToFit = YES;
_webView.opaque = NO;
_webView.navigationDelegate = self;
[self.view addSubview:_webView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadShareView {
UIImageView *lineImage = [[UIImageView alloc] init];
if (iPhoneX) {
lineImage.frame = CGRectMake(0, MainScreenHeight - 44 - 34 - 88, MainScreenWidth, 1);
} else {
lineImage.frame = CGRectMake(0, MainScreenHeight - 64 - 44, MainScreenWidth, 1);
}
lineImage.backgroundColor = Color_Line;
[self.view addSubview:lineImage];
//字体按钮
UIButton *fontSizeButton = [UIButton buttonWithType:UIButtonTypeCustom];
fontSizeButton.tag = 10000;
[fontSizeButton setImage:[UIImage imageNamed:@"cnlive_fontsize"] forState:UIControlStateNormal];
if (iPhoneX) {
[fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
} else {
[fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44 - 64 + (44 - 22)/2, 33, 22)];
}
[fontSizeButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:fontSizeButton];
//收藏按钮
UIButton *isFavoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
isFavoriteButton.tag = 20000;
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary[@"programs"][0]];
BOOL isIn = [[DBAction sharedDBAction] isInTable:notice];
if (isIn) {
[isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
} else {
[isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
if (iPhoneX) {
[isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
} else {
[isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44 - 64 + (44 - 22)/2, 33, 22)];
}
[isFavoriteButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:isFavoriteButton];
//分享按钮
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
shareButton.tag = 30000;
[shareButton setImage:[UIImage imageNamed:@"cnlive_share"] forState:UIControlStateNormal];
if (iPhoneX) {
[shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
} else {
[shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 - 64 + (44 - 22)/2, 33, 22)];
}
[shareButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:shareButton];
}
- (void)shareButtonTaped:(id)sender {
UIButton *btn = (UIButton *)sender;
if (10000 == btn.tag) {
if ([_fontArray count] - 1 == _fontIndex) {
_fontIndex = 0;
} else {
_fontIndex++;
}
if (0 == _fontIndex) {
[_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:nil];
} else if (1 == _fontIndex) {
[_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'" completionHandler:nil];
} else if (2 == _fontIndex) {
[_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '140%'" completionHandler:nil];
}
} else if (20000 == btn.tag) {
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary[@"programs"][0]];
BOOL isIn = [[DBAction sharedDBAction] isInTable:notice];
if (!isIn) {
BOOL isInsert = [[DBAction sharedDBAction] insertTable:notice];
if (isInsert) {
[AlertViewTool showHUDViewText:CustomStr(@"CollectSuccess")];
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
}
} else {
BOOL isDelete = [[DBAction sharedDBAction] deleteTable:notice];
if (isDelete) {
[AlertViewTool showHUDViewText:CustomStr(@"CancelCollect")];
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
}
} else if (30000 == btn.tag) {
NSString *img = [NSString stringWithFormat:@"%@",_dictionary[@"programs"][0][@"img"]];
NSString *title = [NSString stringWithFormat:@"%@",_dictionary[@"programs"][0][@"title"]];
NSString *text = [NSString stringWithFormat:@"%@",!_dictionary[@"programs"][0][@"desc"]||[_dictionary[@"programs"][0][@"desc"] isEqualToString:@""]?title:_dictionary[@"programs"][0][@"desc"]];
NSString *url = [NSString stringWithFormat:@"%@",_dictionary[@"programs"][0][@"pageUrl"]];
[[TemplateShareManager manager] shareImage:img title:title text:text url:url controller:self];
return;
}
}
@end