|
//
// readHistoryController.m
// ThePaperBase
//
// Created by liyuan on 15/10/19.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "readHistoryController.h"
#import "readHistoryViewModel.h"
#import "MLNavigationController.h"
#import "collectContentCell.h"
@interface readHistoryController ()<readHistoryViewModelDelegate>
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)NSMutableArray *dataList;
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *noDataLabel;
@property(nonatomic, strong)readHistoryViewModel *readModel;
@end
@implementation readHistoryController
static NSString *readCellID = @"collectContentCell";
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height);
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
[self.view addSubview:self.backView];
self.closeBtn.frame = CGRectMake(0, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
80);
[self.view addSubview:self.backView];
self.tableView.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height-80);
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.clipsToBounds = YES;
[self.backView addSubview:self.tableView];
[self configCanRefresh:NO canLoad:YES];
[self.tableView registerClass:[collectContentCell class] forCellReuseIdentifier:readCellID];
//阅读历史:阅读历史中查看一篇新闻后返回,上拉加载时阅读历史会重新加载(bug:6079)
self.readModel = [readHistoryViewModel new];
self.readModel.delegate = self;
[self.readModel getReadHistoryWithURL:nil];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - add Widget
- (UIButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal];
[_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted];
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.text = @"阅读历史";
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = appFont(30, NO);
}
return _titleLabel;
}
- (UILabel*)noDataLabel{
if (!_noDataLabel) {
_noDataLabel = [[UILabel alloc] init];
_noDataLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_noDataLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
_noDataLabel.textAlignment = NSTextAlignmentCenter;
_noDataLabel.lineBreakMode = NSLineBreakByWordWrapping;
_noDataLabel.numberOfLines = 0;
_noDataLabel.backgroundColor = [UIColor clearColor];
_noDataLabel.text = @"没有阅读历史";
_noDataLabel.hidden = YES;
}
return _noDataLabel;
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectMake(0,80, loginPopUpSize.width, loginPopUpSize.height-80)];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}
#pragma mark - pull
-(void)pullLoadMoreHander{
if (isBlankString(self.nextUrl)) {
[self loadSuccess];
return;
}
[self.readModel getReadHistoryWithURL:self.nextUrl];
}
#pragma mark - uitableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.dataList || self.dataList.count == 0) {
return 0;
}else {
return 85;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
collectContentCell *cell = [tableView dequeueReusableCellWithIdentifier:readCellID];
if (nil == cell) {
cell = [[collectContentCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:readCellID];
}
listContObjectVO* listBO = self.dataList[indexPath.row];
[cell setListBO:listBO];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([self.delegate respondsToSelector:@selector(readToReadInfo:)]) {
[self.delegate readToReadInfo:self.dataList[indexPath.row]];
}
}
#pragma mark - check data
- (void)checkDataList {
if (self.dataList.count > 0) {
self.tableView.hidden =NO;
self.noDataLabel.hidden = YES;
}
else {
self.tableView.hidden =YES;
self.noDataLabel.hidden =NO;
}
[self.tableView reloadData];
}
#pragma mark - viewmodel delegate
-(void)returnReadHistoryList:(NSMutableArray *)data nextUrl:(NSString *)url{
NSMutableArray *array = [NSMutableArray arrayWithArray:self.dataList];
[array addObjectsFromArray:data];
self.dataList = array;
self.nextUrl = url;
[self checkDataList];
}
-(void)returnErrorMessage:(NSString *)msg{
ShowTextMessage(msg);
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
|