|
//
// pushMsgController.m
// ThePaperHD
//
// Created by liyuan on 15/7/20.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "pushMsgController.h"
#import "messageViewModel.h"
#import "pushMsgCell.h"
#import "MLNavigationController.h"
#import "KGModal.h"
@interface pushMsgController ()<messageViewModelDelegate>{
NSMutableArray *heightArray;
}
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)messageViewModel *model;
@property(nonatomic, strong)NSMutableArray *dataList;
@end
@implementation pushMsgController
@synthesize dataList = _dataList;
static NSString *pushMsgCellID = @"pushMsgCellID";
- (void)viewDidLoad {
[super viewDidLoad];
[MobClick event:@"53"];//【需求】统计-iPad
self.view.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.hidden = YES;
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
self.closeBtn.frame = CGRectMake(hotAskListPopUpSize.width/2 - messagePopSize.width/2, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
hotAskListPopUpSize.width,
80);
[self.view addSubview:self.backView];
self.tableView.frame =self.backView.bounds;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.clipsToBounds = YES;
[self configCanRefresh:YES canLoad:YES];
[self.tableView registerClass:[pushMsgCell class] forCellReuseIdentifier:pushMsgCellID];
self.tableView.refreshControl.frame = CGRectMake(0,
self.tableView.refreshControl.frame.origin.y,
1164/2,
self.tableView.refreshControl.frame.size.height);
self.tableView.refreshControl.originalContentInsectY = 0;
[self.backView addSubview:self.tableView];
self.model = messageViewModel.new;
self.model.delegate = self;
// self.model.pushMsgDic = nil;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self manualRefresh];
});
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[KGModal sharedInstance].tapOutsideToDismiss = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)pullRefreshHandler{
self.model.pushMsgDic = nil;
}
-(void)pullLoadMoreHander{
if (!self.nextUrl) {
// TPLOG(@"数据有问题,无法获取新数据");
[self loadSuccess];
return;
}else{
self.model.pushMsgUrl = self.nextUrl;
}
}
#pragma mark -- view
- (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;
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectMake(hotAskListPopUpSize.width/2 - messagePopSize.width/2, CGRectGetMaxY(self.titleLabel.frame),messagePopSize.width, messagePopSize.height-80)];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
#pragma mark -- set data
-(void)setDataList:(NSMutableArray *)list{
_dataList = list;
heightArray = [NSMutableArray array];
if (_dataList.count>0) {
[_dataList enumerateObjectsUsingBlock:^(letterBO *bo, NSUInteger idx, BOOL *stop) {
letterBO *letterBo = bo;
//正文与顶部30,文字时间13,时间高度10,时间与分割线13
CGFloat titleHeight = returnTextHeightWithRTLabel(letterBo.summary, messagePopSize.width-30, appFont(TEXT_TWO_LEVELSIZE, NO), 8);
[heightArray addObject:@(titleHeight+67)];
}];
[self.tableView reloadData];
}
}
#pragma mark -- tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [heightArray[indexPath.row] floatValue];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
pushMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:pushMsgCellID];
if (nil == cell) {
cell = [[pushMsgCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pushMsgCellID];
}
cell.data = _dataList[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.pushDelegate respondsToSelector:@selector(pushMsgToNotification:)]) {
[self.pushDelegate pushMsgToNotification:_dataList[indexPath.row]];
}
// pushLetterPageWithLetterBO(self.navigationController, _dataList[indexPath.row]);
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}
#pragma mark -- viewModel return data
-(void)returnPushMsgList:(NSMutableArray *)data nextUrl:(NSString *)url{
self.dataList = data;
self.nextUrl = url;
[self endRefresh];
}
-(void)returnPushMsgNextUrl:(NSMutableArray *)data nextUrl:(NSString *)url{
NSMutableArray *oldData = [NSMutableArray arrayWithArray:self.dataList];
[oldData addObjectsFromArray:data];
self.dataList = oldData;
[self loadSuccess];
self.nextUrl = url;
}
@end
|