|
//
// offlineContentListController.m
// ThePaperBase
//
// Created by scar1900 on 15/8/9.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "offlineContentListController.h"
#import "channelListCell.h"
#import "detailContentHomeController.h"
@interface offlineContentListController()
@end
@implementation offlineContentListController
@synthesize dataList = _dataList;
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.clipsToBounds = NO;
[self.view addSubview:self.tableView];
[self.tableView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
[self configCanRefresh:NO canLoad:NO];
self.contentInsetTop = -18;
UIView *footView = [UIView new];
footView.frame = CGRectMake(0, 0, 0, 10);
footView.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = footView;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
- (void)needrefreshNightMode:(id)sender{
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
channelListCell *cell = (channelListCell*)[tableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:0.15 animations:^{
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(0.97, 0.97);
}else {
cell.backView.transform = CGAffineTransformMakeScale(0.97, 0.97);
}
} completion:^(BOOL finished) {
listContObjectVO *listBO = self.dataList[indexPath.row];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *contentPath = [NSString stringWithFormat:@"%@/cont_%@.txt",self.imagePath,listBO.forwordNodeId];
NSString *resourceString = [NSString stringWithContentsOfFile:contentPath encoding:NSUTF8StringEncoding error:nil];
// NSString* responseString = [self dealResponseStringBeforeChange:resourceString];
NSData *preJsonData = [resourceString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *resDic = [self toArrayOrNSDictionary:preJsonData];
contDetailPageVO *detailpageVO = setJsonDicToDataModel(resDic, [contDetailPageVO class]);
dispatch_async(dispatch_get_main_queue(), ^{
detailContentHomeController *detailVC = [detailContentHomeController new];
detailVC.offlineDetailContBO = detailpageVO;
detailVC.nodeID = listBO.forwordNodeId;
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
}else {
cell.backView.transform = CGAffineTransformMakeScale(1.00, 1.00);
}
[self.navigationController pushViewController:detailVC animated:YES];
addHaveReadFlag(listBO.forwordNodeId);
/**
* bug:5119(离线缓存的新闻查看后,在新闻列表页字体未置灰)
*/
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
});
});
}];
}
- (id)toArrayOrNSDictionary:(NSData *)jsonData{
NSError *error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingAllowFragments
error:&error];
if (jsonObject != nil && error == nil){
return jsonObject;
}else{
// 解析错误
return nil;
}
}
//json容错处理
- (NSString*)dealResponseStringBeforeChange:(NSString*)responseString {
responseString = [responseString stringByReplacingOccurrencesOfString:@"\\'" withString:@"'"];
if (![responseString isMatchedByRegex:@"\\\""]) {
responseString = [responseString stringByReplacingOccurrencesOfString:@"\\\\" withString:@"\\"];
}
/**
* bug:5328(224有个话题,进入后提示“服务器连接异常,请检查网络”)
*/
responseString = [responseString stringByReplacingOccurrencesOfString:@"\\'́" withString:@"'́"];
/**
* bug:5208(话题详情页,有一个话题,加载不了)
*/
return responseString;
}
- (void) reachabilityChanged:(NSNotification *)note
{
}
- (void)setDataList:(NSMutableArray *)list {
if (!_dataList || _dataList.count == 0) {
self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
_dataList = list;
[self setTableDataSource:list];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
|