ifish/Ifish/controllers/IfishTabControllers/设备/QianDao/ViewControlller/QianDaoViewController.m

405 lines
14 KiB
Objective-C

//
// QianDaoViewController.m
// Ifish
//
// Created by imac on 17/3/6.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "QianDaoViewController.h"
#import "QianDaoGongLueViewCell.h"
#import "QianDaoTimeLineView.h"
#import "QianDaoTimeViewCell.h"
#import "QianDaoBannerViewCell.h"
#import "QianDaoWayTitleViewCell.h"
#import "UIControl+YT.h"
#import "RenQuYinDaoVIew.h"
#import "QianDaoGiftView.h"
#import "WoDeRenWuViewController.h"
#import "IfishUserDefaultHelper.h"
#import "PushMasssageWebViewController.h"
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import "IfishAlibcWebViewController.h"
@interface QianDaoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic) BOOL isPushNext;
@property (nonatomic,strong) NSMutableArray *bannerDataArr;
@end
@implementation QianDaoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:@"签到"];
_bannerDataArr = [[NSMutableArray alloc] init];
_isPushNext = NO;
UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"我的任务" style:UIBarButtonItemStyleDone target:self action:@selector(wodeRenWuAction)];
self.navigationItem.rightBarButtonItem= rightItem;
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[self creatTab];
BOOL isshow = [IfishUserDefaultHelper digisShowTaskLead];
if (!isshow) {
[self initYinDaoView];
}
[self testCanGetGiftView];
//banner 数据
[self initBannerData];
//[self testdocu];
}
-(void)testdocu{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:documentsDirectory];
NSString *path;
while ((path = [dirEnum nextObject]) != nil) {
NSLog(@"path:%@", path);
}
}
-(void)initBannerData
{
__weak typeof (self)weakSelf = self;
[AFHttpTool getIfishBannerData:IfishAdTypeQianDao 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];
}
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:1];
[weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
}
}else{
//[weakSelf.view makeToast:@"广告位获取失败"];
}
} failure:^(NSError *err) {
}];
}
-(void)testCanGetGiftView
{
IfishUserAsset *userAsset = [dataContorl getAllIfishUserAsset];
if (!userAsset.isHitGoldenEgg) {
[self showGiftView];
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (_isPushNext) {
//广告栏bug 返回不显示
NSIndexSet *set = [NSIndexSet indexSetWithIndex:1];
[self.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationNone];
}
}
-(void)initYinDaoView{
RenQuYinDaoVIew *yinDaoVIew =[[RenQuYinDaoVIew alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
[[UIApplication sharedApplication].keyWindow addSubview:yinDaoVIew];
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-TOP_HEIGHT) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
UIButton *qiandaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
CGFloat btnH = self.view.frame.size.width * 0.13;
qiandaoBtn.frame = CGRectMake(0,0, self.view.frame.size.width, btnH);
IfishUserAsset *asset = [dataContorl getAllIfishUserAsset];
qiandaoBtn.backgroundColor = asset.toDaySignin ? RGB(221, 221,221):RGB(0, 184, 329);
qiandaoBtn.userInteractionEnabled = asset.toDaySignin ? NO:YES;
[qiandaoBtn addTarget:self action:@selector(qiandaoAction:) forControlEvents:UIControlEventTouchUpInside];
qiandaoBtn.yt_acceptEventInterval = 5;
if (asset.toDaySignin) {
[qiandaoBtn setTitle:@"已签到" forState:UIControlStateNormal];
}else{
[qiandaoBtn setTitle:@"立即签到" forState:UIControlStateNormal];
}
[qiandaoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.tableView.tableFooterView = qiandaoBtn;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0 || section == 2) {
return 1;
}
return 2;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
QianDaoTimeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QianDaoTimeViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"QianDaoTimeViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setQianDaoData];
return cell;
}else if (indexPath.section ==1&&indexPath.row ==0){
QianDaoBannerViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QianDaoBannerViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"QianDaoBannerViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
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.adView.adList = imgs;
__weak typeof (self)weakSelf = self;
cell.adView.tapActionBlock =^(LXAdScrollView *adScrollView) {
IfishBannerData *bdata = _bannerDataArr[adScrollView.currentPage];
[weakSelf tapAdWithLink:bdata.adLink];
};
}else{
//默认加载本地
cell.adView.adList = @[@"signin_banner.png"];
cell.adView.tapActionBlock =^(LXAdScrollView *adScrollView) {
};
}
return cell;
}else if (indexPath.section ==1&&indexPath.row ==1){
QianDaoWayTitleViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QianDaoWayTitleViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"QianDaoWayTitleViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if (indexPath.section ==2&&indexPath.row ==0){
QianDaoGongLueViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QianDaoGongLueViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"QianDaoGongLueViewCell" owner:self options:nil]lastObject];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
return nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0&&indexPath.row ==0) {
return self.view.frame.size.width * 0.36;
}else if (indexPath.section ==1&&indexPath.row ==0){
return self.view.frame.size.width * 0.48;
}else if (indexPath.section ==1&&indexPath.row ==1){
return 44;
}else if (indexPath.section ==2&&indexPath.row ==0){
return 108;
}
return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section ==0) {
return 5;
}else if (section ==1){
return 10;
}
return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *holdView =[[UIView alloc] init];
holdView.backgroundColor = JWUIColorFromRGB(0xf2f2f2);
return holdView;
}
/*
#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.
}
*/
#pragma mark - 签到
-(void)qiandaoAction:(UIButton*)btn{
NSString *userId = [dataContorl dataControlGetUserIdInfo] ;
__weak typeof (self) weakself = self;
[AFHttpTool ifishSignIn:userId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
btn.backgroundColor = RGB(221, 221, 221);
btn.userInteractionEnabled = NO;
[btn setTitle:@"已签到" forState:UIControlStateNormal];
NSDictionary *userAssetDic = reDic[@"data"];
IfishUserAsset *userAsset =[[IfishUserAsset alloc] initWithDict:userAssetDic];
[dataContorl resetUserAsset:userAsset];
NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
[weakself.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationNone];
[weakself.view makeToast: @"签到成功"];
//签到成功 tost加金币
NSString *addValue = [NSString stringWithFormat:@"%ld",(long)userAsset.addValue];
[[IfishUserObsever sharedInstance] showAddGoldWith:addValue];
//更新任务列表数据
[IfishHelperUtils updateTask:EVERYDAYSIGNIN];
//连续签到七天神秘礼物(用是否砸过金蛋字段 1 砸guo)
if (!userAsset.isHitGoldenEgg) {
[weakself showGiftView];
}
}else if ([reDic[@"result"] isEqualToString:@"402"]){
[weakself.view makeToast: @"签到失败402"];
}else{
[weakself.view makeToast: @"签到失败101"];
}
} failure:^(NSError *err) {
[weakself.view makeToast: @"网络异常"];
}];
}
#pragma mark - 连续签到礼物
-(void)showGiftView{
QianDaoGiftView *levelUpView =[[QianDaoGiftView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
[[UIApplication sharedApplication].keyWindow addSubview:levelUpView];
}
#pragma mark - 我的任务
-(void)wodeRenWuAction
{
_isPushNext = YES;
WoDeRenWuViewController *wodeRenWuVC = [[WoDeRenWuViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:wodeRenWuVC animated:YES];
}
#pragma mark - banner 点击事件
-(void)tapAdWithLink:(NSString *)pushlink
{
if (![pushlink isKindOfClass:[NSNull class]] &&pushlink && ![pushlink isEqualToString:@""]) {
_isPushNext = 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 = AlibcOpenTypeNative;
//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];
self.hidesBottomBarWhenPushed = NO;
}
}
@end