Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,13 @@
//
// IfishInformationViewController.h
// Ifish
//
// Created by imac on 17/3/13.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "BaseVIewContorller.h"
@interface IfishInformationViewController : BaseVIewContorller
@end
@@ -0,0 +1,421 @@
//
// IfishInformationViewController.m
// Ifish
//
// Created by imac on 17/3/13.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishInformationViewController.h"
#import "IfishInformationListViewCell.h"
#import "IfishZiXunAdViewCell.h"
#import "PushMasssageWebViewController.h"
#import "IfishInformations.h"
#import "PushMasssageWebViewController.h"
#import "JHRefresh.h"
#import "IfishUserDefaultHelper.h"
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import "IfishAlibcWebViewController.h"
@interface IfishInformationViewController ()<UITableViewDelegate,UITableViewDataSource>
{
BOOL _isPush;
BOOL _isRefreshing;
BOOL _isLoadMore;
}
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *bannerDataArr;
@property (nonatomic,strong) NSMutableArray *listDataArr;
@property(nonatomic,copy) NSString* total;
@property(nonatomic) int page;
@property(nonatomic)BOOL isRefreshing;
@property(nonatomic)BOOL isLoadMore;
@property(nonatomic) NSIndexPath *didSelectIndexPath;
@end
@implementation IfishInformationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"资讯"];
_isPush = NO;
_bannerDataArr = [[NSMutableArray alloc] init];
_listDataArr = [[NSMutableArray alloc] init];
[self creatTab];
[self initBannerData];
[self initInformations];
[self creatReatRefreshView];
}
-(void)initInformations
{
//NSArray *arr = [[IfishDatabaseManager sharedManager] readInformations];
//IfishInformations *mode = arr[0];
//NSLog(@"arr##%@",arr);
//NSLog(@"IfishInformations0## mode.title:%@ , mode.clickNum:%d",mode.title,mode.clickNum);
[self loadDataWith:0 pageSize:10 isRefres:NO];
}
-(void)creatTab{
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = RGB(242, 242, 242);
[self.view addSubview:_tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section ==0) {
return 1;
}
return _listDataArr.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
IfishZiXunAdViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishZiXunAdViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"IfishZiXunAdViewCell" owner:self options:nil] lastObject];
}
if (_bannerDataArr.count !=0) {
NSArray *ads =self.bannerDataArr;
NSMutableArray *imgs = [[NSMutableArray alloc] init];
[ads enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[IfishBannerData class]]) {
IfishBannerData *banner = (IfishBannerData *)obj;
[imgs addObject:banner.adImage];
}
}];
cell.newsAdview.adList = imgs;
__weak typeof (self)weakSelf = self;
cell.newsAdview.tapActionBlock =^(LXAdScrollView *adScrollView) {
IfishBannerData *bdata = _bannerDataArr[adScrollView.currentPage];
[weakSelf tapAdWithLink:bdata.adLink];
};
}else{
//默认加载本地
cell.newsAdview.adList = @[@"Ifishbanner_zixun.jpg"];
cell.newsAdview.tapActionBlock =^(LXAdScrollView *adScrollView) {
};
}
return cell;
}
IfishInformationListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishInformationListViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"IfishInformationListViewCell" owner:self options:nil] lastObject];
}
IfishInformations *model =_listDataArr[indexPath.row];
[cell loadCellDataWith:model];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
return self.view.frame.size.width * 0.427;//320/750
}
return 95;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.01f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section !=0) {
//每日打开资讯链接 加金币
[[IfishUserObsever sharedInstance] addGoldWith:READINFORMATION addType:IFISHADDGOLDTYPE0];
_isPush = YES;
PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
webVC.pushtitle = @"资讯详情";
IfishInformations *model =_listDataArr[indexPath.row];
webVC.pushlink = model.link;
//观看数加一 不考虑打开成功与否
model.clickNum ++;
_didSelectIndexPath = indexPath;
[self addClicknumber:model.infoId];
NSString *infoIdstr = [NSString stringWithFormat:@"%d",model.infoId];
//首页资讯红点标志位
//是否比当前值大 大则存储
NSString *oldId = [IfishUserDefaultHelper getDefualtInfoId];
if (!oldId) {
oldId = @"";
}
if (infoIdstr.intValue >= oldId.intValue) {
[IfishUserDefaultHelper saveinfoId:infoIdstr];
}
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:webVC animated:YES];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_isPush) {
//NSIndexSet *asset = [NSIndexSet indexSetWithIndex:0];
//[self.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:0 inSection:0];
NSArray *arr =nil;
if (_didSelectIndexPath) {
arr =@[indexPath,_didSelectIndexPath];
}else{
arr =@[indexPath];
}
[self.tableView reloadRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationNone];
}
}
-(void)initBannerData
{
__weak typeof (self)weakSelf = self;
[AFHttpTool getIfishBannerData:IfishAdTypeZiXun success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]) {
NSArray *data= reDic[@"data"];
if (data&&data.count!=0) {
for (NSDictionary *dic in data) {
IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic];
[_bannerDataArr addObject:bannerdata];
}
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:0 inSection:0];
NSArray *arr=@[indexPath];
[weakSelf.tableView reloadRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationNone];
}
}else{
//[weakSelf.view makeToast:@"广告位获取失败"];
}
} failure:^(NSError *err) {
}];
}
#pragma mark - banner 点击事件
-(void)tapAdWithLink:(NSString *)pushlink
{
if (![pushlink isKindOfClass:[NSNull class]] &&pushlink && ![pushlink isEqualToString:@""]) {
_isPush = YES;
//字条串是否包含有某字符串
if ([pushlink rangeOfString:@"taobao"].location == NSNotFound) {
self.hidesBottomBarWhenPushed = YES;
PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
webVC.pushlink =pushlink;
webVC.pushtitle = @"详情";
[self.navigationController pushViewController:webVC animated:YES];
} else {
[self openAliBCWithLink:pushlink];
}
}
}
-(void)openAliBCWithLink:(NSString *)linkUrl{
//535991514644
//根据商品ID
//id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"535991514644"];
//根据链接打开页面
id<AlibcTradePage> page = [AlibcTradePageFactory page:linkUrl];
AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
//app 内闭环交易 强制H5 打开
showParam.openType = AlibcOpenTypeH5;
//AlibcWebViewController* myView = [[AlibcWebViewController alloc] init];
//自定义web
IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init];
NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
} tradeProcessFailedCallback:^(NSError * _Nullable error) {
}]; //返回1,说明h5打开,否则不应该展示页面
if (ret == 1) {
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myView animated:YES];
}
}
#pragma mark 刷新 加载时更多
-(void)creatReatRefreshView{
__weak typeof (self)weskSelf=self;
// 下拉刷新
[weskSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
if (weskSelf.isRefreshing) {
return ;
}
weskSelf.isRefreshing=YES;
_page=0;
NSInteger firstResult = 0;
NSInteger pageSize = 10;
[weskSelf addRefreshHeaderTaskWithFirst:firstResult pageSize:pageSize isRefresh:YES];
}];
//上拉加载更多
[weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
if (weskSelf.isLoadMore) {
return ;
}
weskSelf.isLoadMore=YES;
NSInteger pagecount =[self.total integerValue]/10+1;
if (weskSelf.page<pagecount-1) {
weskSelf.page++;
NSInteger first=(NSInteger)weskSelf.page*10;
NSInteger pageSize = 10;
[weskSelf addRefreshFooterTaskWithFirst:first pageSize:pageSize isRefres:YES];
}else{
[weskSelf endRefreshing];
[weskSelf.view makeToast:@"已无更多数据"];
}
}];
}
-(void)endRefreshing{
if (self.isRefreshing) {
self.isRefreshing=NO;
[self.tableView headerEndRefreshingWithResult:JHRefreshResultNone];
}
if (self.isLoadMore) {
self.isLoadMore=NO;
[self.tableView footerEndRefreshing];
}
}
#pragma mark -刷新
-(void)addRefreshHeaderTaskWithFirst:(NSInteger)firstResult pageSize:(NSInteger)pageSize isRefresh:(BOOL)isRefresh{
[self loadDataWith:firstResult pageSize:pageSize isRefres:isRefresh];
}
#pragma mark -加载更多
-(void)addRefreshFooterTaskWithFirst:(NSInteger)firstResult pageSize:(NSInteger)pageSize isRefres:(BOOL)isRefresh
{
[self loadDataWith:firstResult pageSize:pageSize isRefres:isRefresh];
}
-(void)loadDataWith:(NSInteger)firstResult pageSize:(NSInteger)pageSize isRefres:(BOOL)isRefresh
{
__weak typeof (self)weakSelf = self;
NSString *userId= [dataContorl dataControlGetUserIdInfo];
[AFHttpTool ifishGetInformations:firstResult pageSize:pageSize userId:userId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
_total = reDic[@"total"];
if ([result isEqualToString:@"100"]) {
NSArray *dataarr =reDic[@"data"];
if (self.isRefreshing&&isRefresh) {
[_listDataArr removeAllObjects];
}
for (NSDictionary *dic in dataarr) {
IfishInformations *info =[[IfishInformations alloc] initWithDict:dic];
[_listDataArr addObject:info];
//[[IfishDatabaseManager sharedManager] insertIfishInformations:model];
}
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:1];
[weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
}
[weakSelf endRefreshing];
} failure:^(NSError *err) {
[weakSelf endRefreshing];
}];
}
#pragma mark - 增加点击数
-(void)addClicknumber:(int)infoId{
[AFHttpTool ifishAdditionClickNum:infoId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]) {
//NSDictionary *dict = reDic[@"data"];
//int clickNum = [[dict objectForKey:@"clickNum"] intValue];
//int infoId = [[dict objectForKey:@"infoId"] intValue];
}
} failure:^(NSError *err) {
}];
}
/*
#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