ifish/Ifish/controllers/IfishTabControllers/设备/IfishDeviceViewController.m

1807 lines
69 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// IfishDeviceViewController.m
// ifishTabTest
//
// Created by imac on 16/7/25.
// Copyright © 2016年 xiang. All rights reserved.
//
#import "IfishDeviceViewController.h"
#import "TabbarDeiceSecdCell.h"
#import "TabBarDeviceShouYeCell.h"
#import "DXPopover.h"
#import "LXPopView.h"
#import "IfishBindDeviceSelectViewController.h"
#import "IfishDataUnity.h"
#import "IfishP2PMonitorController.h"
#import "RightViewController.h"
#import "UMComLoginDelegate.h"
#import "UMComShowToast.h"
#define UpdateUserProfileSuccess @"update user profile success!"
#import "TabMineDeivceListViewCell.h"
#import "UIImageView+WebCache.h"
#import "FormatTankAddCamera.h"
#import "IfishDataUnity.h"
#import "IfishNewsModel.h"
#import "PushMasssageWebViewController.h"
#import "IfishP2PPlayBackListViewController.h"
#import "ShuoMingShuCell.h"
#import "UINavigationBar+Background.h"
#import "IifshMineDJViewController.h"
#import "QianDaoViewController.h"
#import "IfishUserObsever.h"
#import "IfishMineGoldViewController.h"
#import "IfishUserDefaultHelper.h"
#import "ShouYeAdViewCell.h"
#import "IfishInformationViewController.h"
#import "IfishAiLiShopGoodsViewCell.h"
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import "IfishAlibcWebViewController.h"
#import "MBProgressHUD.h"
#import "RunSunChangeNameViewController.h"
#import "IfishMessageViewController.h"
#import "PushMessageModel.h"
#import "IfishInformationListViewCell.h"//资讯
#import "JHRefresh.h"//refresh
#import "PetStoresViewController.h"
#import "StoreNameView.h"
#import "ConnectingAquarVC.h"
#import "SecondConnectWifiController.h"
#import "InfoByImageViewController.h"
@interface IfishDeviceViewController ()<UITableViewDelegate,UITableViewDataSource,LxPopViewDelegate,ShopTtemListDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong) NSArray *deviceArr;
@property(nonatomic,strong) DXPopover *popover;
@property(nonatomic,strong) NSArray *cameraArr;
@property(nonatomic,strong) NSMutableDictionary *petStores;
@property(nonatomic,strong) UIButton*rightButton;
@property(nonatomic,strong) UIView *tabHeaderImgView;
@property(nonatomic,strong) UIImageView *userImgView;
@property(nonatomic,strong) UILabel *userNameLabel;
@property(nonatomic,strong) UIView *orangeView;
@property(nonatomic,strong) UIButton *qianDaoBtn;
@property(nonatomic,strong) UIView *qianDaoRedPoint;
@property(nonatomic,strong) UIButton *goldBtn;
@property(nonatomic,strong) UIButton *levelBtn;
@property(nonatomic,strong) NSMutableArray *totalArr;
@property(nonatomic,strong) IfishNewsModel *newsModel;
@property (nonatomic) CGPoint inputPoint0;
@property (nonatomic) CGPoint inputPoint1;
@property (nonatomic) UIColor *inputColor0;
@property (nonatomic) UIColor *inputColor1;
@property (nonatomic) CGFloat scrollHeight;
@property (nonatomic,strong) NSMutableArray *adViewData;
@property (nonatomic,strong) NSMutableArray *goodsArr;
@property (nonatomic,strong) MBProgressHUD *progressHud;
@property (nonatomic,strong) UILabel *mesglabel;
@property(nonatomic,assign)NSInteger curDeviceIdx;
Assign NSInteger messageCount;//消息个数
Assign BOOL isLoadMore;
Assign BOOL isPush;
@property (nonatomic,strong) NSMutableArray *listDataArr;
@property(nonatomic,copy) NSString* total;
@property(nonatomic) int page;
@property(nonatomic) NSIndexPath *didSelectIndexPath;
//@property (nonatomic,strong) UIView *redView;
@end
@implementation IfishDeviceViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.messageCount = 0;
self.isPush = NO;
// Do any additional setup after loading the view.
//self.view.backgroundColor = [];
_adViewData = [[NSMutableArray alloc] init];
self.deviceArr = [[NSArray alloc] init];
self.cameraArr = [[NSArray alloc] init];
self.totalArr = [[NSMutableArray alloc] init];
_goodsArr= [[NSMutableArray alloc] init];
[self creatNav];
[self initUI];
[self showProgress];
[self addDataRequestQueue];
[self checkNotification];
[self creatReatRefreshView];//上拉加载更多
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteCurDevice) name:@"DeleteCurDevice" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDevice) name:@"updateDevice" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserInfobyValidation) name:@"updateUserInfobyValidation" object:nil];
}
-(void)updateDevice{
[self.tableView reloadData];
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"DeleteCurDevice" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateDevice" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateUserInfobyValidation" object:nil];
}
-(void)updateUserInfobyValidation
{
[self addDataRequestQueue];
UserModel*model=[dataContorl getUserInfo];
if (model.unionId)
{
[AFHttpTool requestWihtMethod:RequestMethodTypePost
url:kUserWechatValidation
params:@{@"unionId":[CommonUtils getNotNilStr:model.unionId]}
success:^(id response) {
if (!response) {
return ;
}
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=dict[@"result"];
if ([result isEqualToString:@"100"]) {
// 登录成功
NSDictionary*dataDic=dict[@"data"];
NSDictionary *userDic=dataDic[@"userInfo"];
UserModel *model=[[UserModel alloc] initWithDict:userDic];
[[DataCenter defaultDtacenter]setValue:model forKey:@"UserLogIn"];
NSDictionary *userAssetDic=dataDic[@"userAsset"];
IfishUserAsset *userAsset =[[IfishUserAsset alloc] initWithDict:userAssetDic];
[[DataCenter defaultDtacenter]setValue:userAsset forKey:@"IfishUserAsset"];
[self getUsernameAddImg];
}
} failure:^(NSError *err) {
}];
}
}
-(void)addDataRequestQueue
{
//创建异步任务队列 避免UI更新受影响
//串行异步队列
//dispatch_queue_t queue = dispatch_queue_create("com.privateQueue",NULL);
dispatch_async(dispatch_get_main_queue(), ^{
[self getMoreUserData];
[self initBannerData];
[self loadDataWith:0 pageSize:10 isRefres:NO];
});
}
-(void)showProgress{
self.progressHud = [[MBProgressHUD alloc] initWithView:[UIApplication sharedApplication].keyWindow];
self.progressHud.mode=MBProgressHUDModeCustomView;
self.progressHud.customView = [[UIView alloc] init];
//self.progressHud.delegate = self;
self.progressHud.labelText = @"加载中...";
}
//app通过点击通知打开app此处校验通知内容做出相应的跳转
-(void)checkNotification{
//通过点击通知打开app直接跳转到消息列表页面
if ([AppDelegate sharedDefault].remoteNotification) {
IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController];
vc.hidesBottomBarWhenPushed = YES;
[vc.navigationController pushViewController:message animated:YES];
vc.hidesBottomBarWhenPushed = NO;
}
}
//获取未读消息个数
-(void)getMessageCount{
UserModel*userModel=[dataContorl getUserInfo];
NSDictionary *params = @{@"userId":userModel.userId
};
[AFNOHeaderHttpTool requestWihtMethod:RequestTypePost url:Push_Message_UnReadCount params:params success:^(id response) {
if (response) {
id successDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result = [successDic objectForKey:RESPONSE_CODE];
NSDictionary *dic = [successDic objectForKey:RESPONSE_DATA];
if ([result integerValue]==kReqSuccess) {
NSString *count = [dic objectForKey:@"messageNoReadCount"];
self.messageCount = [count integerValue];
}
[self setRedViewData];
}
} failure:^(NSError *err) {
}];
}
#pragma mark - 首页广告位
-(void)initBannerData{
__weak typeof (self)weakSelf = self;
[AFHttpTool getIfishBannerData:IfishAdTypeShouYE success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]) {
NSArray *data= reDic[@"data"];
for (NSDictionary *dic in data) {
IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic];
[self.adViewData addObject:bannerdata];
}
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:1];
[weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
}else{
//[weakSelf.view makeToast:@"广告位获取失败"];
}
} failure:^(NSError *err) {
}];
}
#pragma mark --资讯相关
//获取资讯列表数据
-(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"];
for (NSDictionary *dic in dataarr) {
IfishInformations *info =[[IfishInformations alloc] initWithDict:dic];
[self.listDataArr addObject:info];
//[[IfishDatabaseManager sharedManager] insertIfishInformations:model];
}
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[weakSelf.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
weakSelf.tableView.backgroundColor = RGB(10, 18, 177);
});
}
[weakSelf endRefreshing];
} failure:^(NSError *err) {
[weakSelf endRefreshing];
}];
}
-(void)creatReatRefreshView{
__weak typeof (self)weakSelf=self;
//上拉加载更多
[weakSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
if (weakSelf.isLoadMore) {
return ;
}
weakSelf.isLoadMore=YES;
NSInteger pagecount =[self.total integerValue]/10+1;
if (weakSelf.page<pagecount-1) {
weakSelf.page++;
NSInteger first=(NSInteger)weakSelf.page*10;
NSInteger pageSize = 5;//加载更多每次加5个
[weakSelf loadDataWith:first pageSize:pageSize isRefres:YES];
}else{
[weakSelf endRefreshing];
[weakSelf.view makeToast:@"已无更多数据"];
}
}];
}
//停止刷新
-(void)endRefreshing{
if (self.isLoadMore) {
self.isLoadMore=NO;
[self.tableView footerEndRefreshing];
}
}
#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"]) {
}
} failure:^(NSError *err) {
}];
}
#pragma mark - 获取更多用户数据(新加)
-(void)getMoreUserData{
NSString *userId = [dataContorl dataControlGetUserIdInfo];
__weak typeof (self)weakSelf = self;
[AFHttpTool getMoreUserDataWith:userId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]) {
NSDictionary *dataDic = reDic[@"data"];
//资讯 information
NSDictionary *informationdic=dataDic[@"information"];
if (informationdic) {
IfishNewsModel *newsModel=[[IfishNewsModel alloc] initWithDict:informationdic];
[[DataCenter defaultDtacenter]setValue:newsModel forKey:@"informationNews"];
}
//任务
NSArray*doneTaskArray=dataDic[@"goldTasks"];
if (!doneTaskArray) {
doneTaskArray = [[NSArray alloc] init];
}
NSMutableArray *taskArr = [[NSMutableArray alloc] init];
if (doneTaskArray.count!=0) {
for (NSDictionary *taskDic in doneTaskArray) {
IfishTaskModel *task = [[IfishTaskModel alloc] initWithDict:taskDic];
[taskArr addObject:task];
}
}
[[DataCenter defaultDtacenter]setValue:taskArr forKey:IFISHTASK_ARR];
//自己是商家
NSDictionary *shopsInfoDic=dataDic[@"shopsInfo"];
if (shopsInfoDic.count !=0) {
//空时用的时候对象判空
CertificationShopModel *shopInfo=[[CertificationShopModel alloc] initWithDict:shopsInfoDic];
[[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"];
}else{
CertificationShopModel *shopInfo=[[CertificationShopModel alloc] init];
[[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"];
}
//选择的商家信息
NSDictionary *kanHushopsInfoDic=dataDic[@"shopsInfo2"];
NSLog(@"kanHushopsInfoDic%lu",(unsigned long)kanHushopsInfoDic.count);
if (kanHushopsInfoDic.count != 0) {
//空时用的时候对象判空
CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] initWithDict:kanHushopsInfoDic];
[[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"];
}else{
CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] init];
[[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"];
}
//设备信息
NSArray*deviceArray=dataDic[@"device"];
NSArray*cameraA=dataDic[@"camera"];
//宠物店
NSMutableDictionary*petStores=[NSMutableDictionary dictionary];
NSMutableArray *deviceArr = [[NSMutableArray alloc] init];
if ([deviceArray count]!=0) {
for (NSDictionary*deviceDic in deviceArray) {
DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:deviceDic];
if ([devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO3F])//宠物笼
{
NSString*storeName=devicemodel.storeName;
if ([storeName isKindOfClass:[NSNull class]]||([storeName isKindOfClass: [NSString class]]&&storeName.length==0)) {
storeName=@"宠物店";
}
NSMutableArray*array=petStores[storeName];
if (!array) {
array=[NSMutableArray array];
}
[array insertObject:devicemodel atIndex:0];
petStores[storeName]=array;
}
{
[deviceArr insertObject:devicemodel atIndex:0];
}
}
}
[[DataCenter defaultDtacenter]setValue:deviceArr forKey:@"deviceInfo"];
self.petStores=petStores;
[[DataCenter defaultDtacenter]setValue:petStores forKey:@"petStores"];
//存储摄像头设备信息
NSMutableArray *camras = [[NSMutableArray alloc] init];
if (cameraA .count !=0) {
if ([cameraA count]!=0) {
for (NSDictionary * cameraDic in cameraA) {
IfishCameraModel *camera=[[IfishCameraModel alloc] initWithDict:cameraDic];
[camras insertObject:camera atIndex:0];
}
}
}
//存储摄像头数组
[[DataCenter defaultDtacenter]setValue:camras forKey:@"cameraArr"];
/**
* 设备摄像头关系数组
*/
NSArray*deviceCamera=dataDic[@"deviceCamera"];
NSMutableArray *devicamerArr=[[NSMutableArray alloc] init];
if (deviceCamera) {
for (NSDictionary * deviceCameraDic in deviceCamera) {
DeviceCameraModel *dcmodel=[[DeviceCameraModel alloc] init];
dcmodel.deviceId = deviceCameraDic[@"deviceId"];
dcmodel.cameraId = deviceCameraDic[@"cameraId"];
[devicamerArr addObject:dcmodel];
}
}
//存储摄像头设备关系数组
[[DataCenter defaultDtacenter]setValue:devicamerArr forKey:@"devicamerArr"];
[weakSelf refreshUI];
}else{
[weakSelf.view makeToast:@"户数据获取失败"];
}
} failure:^(NSError *err) {
[weakSelf.view makeToast:@"请求异常"];
}];
}
-(UIView *)tabHeaderImgView{
//1776
if (!_tabHeaderImgView) {
CGFloat headerH = TabContentHeaght *0.245 +64;
_tabHeaderImgView = [[UIView alloc] init];
_tabHeaderImgView.frame = CGRectMake(0, 0, kScreenSize.width, headerH);
//设置渐变色
_inputColor0 = RGB(10, 18, 177);
_inputColor1 = RGB(50, 176, 239);
_inputPoint0 = CGPointMake(0, 0);
_inputPoint1 = CGPointMake(0, 1);
CAGradientLayer *layer = [CAGradientLayer new];
layer.colors = @[(__bridge id)_inputColor0.CGColor, (__bridge id)_inputColor1.CGColor];
layer.startPoint = _inputPoint0;
layer.endPoint = _inputPoint1;
layer.frame = _tabHeaderImgView.bounds;
[_tabHeaderImgView.layer addSublayer:layer];
}
return _tabHeaderImgView;
}
-(UIImageView *)userImgView
{
if (!_userImgView) {
CGFloat userImgViewW = TabContentHeaght*0.068;
_userImgView =[[UIImageView alloc] init];
_userImgView.frame = CGRectMake(kScreenSize.width * 0.04, TabContentHeaght*0.04 +64, userImgViewW, userImgViewW);
_userImgView.layer.masksToBounds = YES;
_userImgView.layer.cornerRadius = userImgViewW * 0.5;
}
return _userImgView;
}
-(UILabel *)userNameLabel{
if (!_userNameLabel) {
CGFloat nameH = 16*KWidth_Scale;
_userNameLabel = [[UILabel alloc] init];
_userNameLabel.frame = CGRectMake(CGRectGetMaxX(_userImgView.frame) + 5 , CGRectGetMidY(_userImgView.frame)-nameH, kScreenSize.width -CGRectGetMaxX(_userImgView.frame) - 5 ,nameH);
_userNameLabel.textAlignment = NSTextAlignmentLeft;
_userNameLabel.textColor = [UIColor whiteColor];
//_userNameLabel.backgroundColor = [UIColor lightGrayColor];
}
return _userNameLabel;
}
-(UIButton *)levelBtn
{
if (!_levelBtn) {
_levelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//_levelBtn.backgroundColor = [UIColor redColor];
[_levelBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
[_levelBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[_levelBtn addTarget:self action:@selector(levelBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _levelBtn;
}
-(UIButton*)qianDaoBtn{
if (!_qianDaoBtn) {
CGFloat btnW = 67*KWidth_Scale;
CGFloat btnH = btnW*0.36;
CGFloat oriX = kScreenSize.width - CGRectGetMinX(_userImgView.frame);
_qianDaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_qianDaoBtn.frame = CGRectMake(oriX - btnW,CGRectGetMinY(_userNameLabel.frame) ,btnW, btnH);
[_qianDaoBtn setBackgroundImage:[UIImage imageNamed:@"home_iocn_signin"] forState:UIControlStateNormal];
[_qianDaoBtn addTarget:self action:@selector(qianDaoBtnAction) forControlEvents:UIControlEventTouchUpInside];
CGFloat pointW = 8;
_qianDaoRedPoint = [[UIView alloc] initWithFrame:CGRectMake(pointW*KWidth_Scale,0, pointW , pointW )];
_qianDaoRedPoint.backgroundColor = RGB(252, 89, 89);
_qianDaoRedPoint.layer.masksToBounds = YES;
_qianDaoRedPoint.layer.cornerRadius = pointW /2;
[_qianDaoBtn addSubview:self.qianDaoRedPoint];
}
return _qianDaoBtn;
}
-(UIButton*)goldBtn{
if (!_goldBtn) {
_goldBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//_goldBtn.backgroundColor = [UIColor blueColor];
CGFloat btnH =40*KWidth_Scale;
CGFloat btnW =100*KWidth_Scale;
_goldBtn.frame = CGRectMake(CGRectGetMinX(_userNameLabel.frame), CGRectGetMaxY(_userNameLabel.frame)+6, btnW, btnH);
[_goldBtn setTitleColor:RGB(252, 217, 94) forState:UIControlStateNormal];
_goldBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[_goldBtn setImage:[UIImage imageNamed:@"home_iocn_gold"] forState:UIControlStateNormal];
[_goldBtn setImageEdgeInsets:UIEdgeInsetsMake(2,0, 0, 0)];
//[_goldBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,0, 0, 0)];
[_goldBtn setTitle:@"222" forState:UIControlStateNormal];
[_goldBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[_goldBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentTop];
[_goldBtn addTarget:self action:@selector(goldBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _goldBtn;
}
-(void)getUsernameAddImg{
IfishUserAsset *userAsset = [dataContorl getAllIfishUserAsset];
UserModel*umodel=[dataContorl getUserInfo];
NSString*wechatImgUrl=[[NSUserDefaults standardUserDefaults] stringForKey:@"wechatImgUrl"];
_userNameLabel.text = umodel.nickName;
[_userNameLabel sizeToFit];
CGFloat btnH = 40*KWidth_Scale;
CGFloat btnW =100*KWidth_Scale;
_levelBtn.frame = CGRectMake(CGRectGetMaxX(_userNameLabel.frame) + 2, CGRectGetMaxY(_userNameLabel.frame) - btnH,btnW, btnH);
NSString *title = [NSString stringWithFormat:@"LV%@",userAsset.gradeNum];
NSAttributedString * str= [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial-BoldItalicMT" size:14],NSForegroundColorAttributeName:RGB(252, 217, 94)}];
[_levelBtn setAttributedTitle:str forState:UIControlStateNormal];
[_levelBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0,10)];
NSString *goldValue = [NSString stringWithFormat:@" 金币 %ld",(long)userAsset.goldValue];
[_goldBtn setTitle:goldValue forState:UIControlStateNormal];
if ([umodel.userImg isKindOfClass:[NSNull class]]) {
[_userImgView setImage:[UIImage imageNamed:@"account"]];
}else if ([umodel.userImg isEqualToString:@""]){
// int i = (arc4random()%11) + 1;// 设置随机头像
// [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"acount%d.png",i]]];
//int i = (arc4random()%7) + 1;// 设置随机头像
int i = 1;
[_userImgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
}else if (wechatImgUrl.length){
[_userImgView sd_setImageWithURL:[NSURL URLWithString:wechatImgUrl]];
}
else{
NSLog(@"%@",[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]);
[_userImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]]];
}
//签到按钮红点
_qianDaoRedPoint.hidden = userAsset.toDaySignin ? YES : NO;
}
-(UIView *)orangeView
{
if (!_orangeView) {
_orangeView =[[UIView alloc] init];
_orangeView.frame = CGRectMake(CGRectGetMinX( _userNameLabel.frame) + 2,CGRectGetMaxY( _userNameLabel.frame) ,28,3);
_orangeView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:219.0/255.0 blue:131.0/255.0 alpha:1];
_orangeView.hidden = YES;
}
return _orangeView;
}
- (NSMutableArray *)listDataArr{
if (!_listDataArr) {
_listDataArr = InitObject(NSMutableArray);
}
return _listDataArr;
}
-(void)newsButtonAction{
[self pushZiXunVC];
}
-(void)newsTitleBtnAction{
[self pushZiXunVC];
}
-(void)pushZiXunVC{
IfishInformationViewController *zixunVC = [[IfishInformationViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:zixunVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
-(void)creatNav{
self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightButton.frame = CGRectMake(0,0,44, 44);
[self.rightButton setImage:[UIImage imageNamed:@"ifish_dropview_add"] forState:UIControlStateNormal];
//self.rightButton.backgroundColor = [UIColor redColor];
[self.rightButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//[self.rightButton setImageEdgeInsets:UIEdgeInsetsMake(0,30, 0, 0)];
[self.rightButton addTarget:self action:@selector(popAppear) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] init];
rightItem.customView =self.rightButton;
//self.navigationItem.rightBarButtonItem = rightItem;
UIButton *navMeaasageBtn =[UIButton buttonWithType:UIButtonTypeCustom];
navMeaasageBtn.frame = CGRectMake(0, 0, 60, 44);
[navMeaasageBtn setImage:[UIImage imageNamed:@"home_nav_news"] forState:UIControlStateNormal];
//[navMeaasageBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
[navMeaasageBtn addTarget:self action:@selector(navMeaasageBtnAction) forControlEvents:UIControlEventTouchUpInside];
//navMeaasageBtn.backgroundColor = [UIColor blueColor];
[navMeaasageBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
UIBarButtonItem *meaasageItem =[[UIBarButtonItem alloc] init];
meaasageItem.customView =navMeaasageBtn;
self.navigationItem.rightBarButtonItems = @[rightItem,meaasageItem];
_mesglabel= [[UILabel alloc] initWithFrame:CGRectMake(60 - 20,0, 16, 16)];
_mesglabel.textColor = [UIColor whiteColor];
_mesglabel.layer.masksToBounds = YES;
_mesglabel.layer.cornerRadius = 8;
_mesglabel.textAlignment = NSTextAlignmentCenter;
_mesglabel.backgroundColor = [UIColor redColor];
[navMeaasageBtn addSubview:_mesglabel];
_mesglabel.font = [UIFont systemFontOfSize:10];
// [self setRedViewData];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = item;
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
#pragma mark - 导航消息数
-(void)setRedViewData{
if (self.messageCount> 0) {
if(self.messageCount>=100){
_mesglabel.frame = RECT(self.mesglabel.frame.origin.x, self.mesglabel.frame.origin.y, 24, 16);
}
_mesglabel.text = [NSString stringWithFormat:@"%ld",(long)self.messageCount];
_mesglabel.hidden = NO;
}else{
_mesglabel.text =@"";
_mesglabel.hidden = YES;
}
}
-(void)popAppear{
[self pushWiFiConnectVC];
}
-(void)disSelectedPopViewIndex:(NSIndexPath *)Index{
[self.popover dismiss];
if (Index.row == 0) {
self.hidesBottomBarWhenPushed = YES;
RightViewController *rightVC=[[RightViewController alloc] init];
[self.navigationController pushViewController:rightVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}else if (Index.row == 1){
[self pushWiFiConnectVC];
}
}
-(void)initUI{
self.automaticallyAdjustsScrollViewInsets = NO;
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
[self.tableView registerNib:[UINib nibWithNibName:@"TabBarDeviceShouYeCell" bundle:nil] forCellReuseIdentifier:@"TabBarDeviceShouYeCell"];
[self.tableView registerNib:[UINib nibWithNibName:@"TabbarDeiceSecdCell" bundle:nil] forCellReuseIdentifier:@"TabbarDeiceSecdCell"];
//CGFloat sapce=TabContentHeaght*0.011;//20/1776
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.tableHeaderView = self.tabHeaderImgView;
[self.tabHeaderImgView addSubview:self.userImgView];
[self.tabHeaderImgView addSubview:self.userNameLabel];
[self.tabHeaderImgView addSubview:self.orangeView];
[self.tabHeaderImgView addSubview:self.goldBtn];
[self.tabHeaderImgView addSubview:self.levelBtn];
[self.tabHeaderImgView addSubview:self.qianDaoBtn];
[self.view addSubview:self.tableView];
UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(addLongPressGesture:)];
[self.tableView addGestureRecognizer:longpress];
_scrollHeight = 64;
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
-(void)addLongPressGesture:(UILongPressGestureRecognizer *)guesture
{
if (guesture.state == UIGestureRecognizerStateBegan) {
CGPoint point = [guesture locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
if (indexPath ==nil) return;
if (indexPath.section!=0) return;
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"确定删除设备?" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:ac animated:YES completion:nil];
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
}]];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
[self removeDeviceAt:indexPath];
}]];
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.translucent = YES;
//设置透明导航栏
[self.navigationController.navigationBar setClearNav];
[self scrollViewDidScroll:self.tableView];
//内容置顶
//[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
[self refreshUI];
//刷新消息数
[self setRedViewData];
[self getMessageCount];
//刷新观看人数
}
-(void)refreshUI{
self.deviceArr =[dataContorl getallDevices];
self.cameraArr =[dataContorl getallCameras];
self.petStores= [[DataCenter defaultDtacenter]valueForKey:@"petStores"];
[self getTotalDeviceArrWith:self.deviceArr addCameraArr:self.cameraArr];
[self.tableView reloadData];
[self getUsernameAddImg];
}
-(void)getTotalDeviceArrWith:(NSArray *)deivceArr addCameraArr:(NSArray *)cameraArr;
{
if (self.totalArr.count !=0) {
[self.totalArr removeAllObjects];
}
for (DeviceModel *device in deivceArr) {
if (![device.type isEqualToString:DECICE_TYPE_XUANDUO3F])
{
FormatTankAddCamera *deviceListModel =[[FormatTankAddCamera alloc] init];
deviceListModel.device = device;
deviceListModel.type = @"tank";
deviceListModel.deviceName = device.showName;
deviceListModel.imgeaName = @"home_iocn_aquarium";
[self.totalArr addObject:deviceListModel];
}
}
for (IfishCameraModel *camera in cameraArr) {
FormatTankAddCamera *deviceListModel =[[FormatTankAddCamera alloc] init];
deviceListModel.camera = camera;
deviceListModel.type = @"camera";
deviceListModel.deviceName = camera.showName;
deviceListModel.imgeaName = @"home_iocn_camera";
[self.totalArr addObject:deviceListModel];
}
for (NSString *store in self.petStores) {
FormatTankAddCamera *deviceListModel =[[FormatTankAddCamera alloc] init];
deviceListModel.list = self.petStores[store];
deviceListModel.type = @"pets";
deviceListModel.deviceName = store;
deviceListModel.imgeaName = @"petsImage";
[self.totalArr addObject:deviceListModel];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//3个section 1headerView
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
NSInteger total = self.totalArr.count;
return total ;
}else if(section==2){
return self.listDataArr.count;
}
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat listrowH=TabContentHeaght*0.074;
//资讯列表
if (indexPath.section ==2){
return 95;
}else if (indexPath.section ==1){
CGFloat wH=kScreenSize.width*0.184;
return wH;
}
return listrowH;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section== 0 ) {
TabMineDeivceListViewCell *tCell=[tableView dequeueReusableCellWithIdentifier:@"TabMineDeivceListViewCell"];
if (tCell==nil) {
tCell= [[[NSBundle mainBundle]loadNibNamed:@"TabMineDeivceListViewCell" owner:self options:nil]lastObject];
}
[tCell setMineDeivceListData:self.totalArr AtIndexPath:indexPath ];
tCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return tCell;
}else if (indexPath.section== 2){//资讯
IfishInformationListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishInformationListViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"IfishInformationListViewCell" owner:self options:nil] lastObject];
}
IfishInformations *model =self.listDataArr[indexPath.row];
[cell loadCellDataWith:model];
return cell;
}else if (indexPath.section== 1){
ShouYeAdViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShouYeAdViewCell"];
if(cell==nil){
cell = [[[NSBundle mainBundle]loadNibNamed:@"ShouYeAdViewCell" owner:self options:nil]lastObject];
cell.backgroundColor = [UIColor whiteColor];
}
if (_adViewData.count !=0) {
NSArray *ads =self.adViewData;
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 = _adViewData[adScrollView.currentPage];
[weakSelf tapAdWithLink:bdata.adLink];
};
}else{
//默认加载本地
cell.adView.adList = @[@"Ifishbanner_shouye.jpg"];
cell.adView.tapActionBlock =^(LXAdScrollView *adScrollView) {
};
}
cell.adView.pageControl.hidden = YES;
return cell;
}
else{
return nil;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0) {
//
CGFloat rowH=TabContentHeaght*0.088;
return rowH;
}else if (section == 2){
CGFloat remaiLabelH= TabContentHeaght * 0.074;
return remaiLabelH;
}else if (section == 1){
return 6;
}
return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if (section == 0) {
//
CGFloat rowH=TabContentHeaght*0.068;
return rowH;
}else if (section == 1){
return 4;
}else if (section==2){
}
return 0;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section == 0) {
//我的设备view
CGFloat rowH=TabContentHeaght*0.088;
UIView *section0headerBackView =[[UIView alloc] initWithFrame:CGRectMake(0,0,kScreenSize.width, rowH)];
section0headerBackView.backgroundColor =RGB(50, 176, 239);
UIView *section0header =[[UIView alloc] initWithFrame:CGRectMake(0,0,kScreenSize.width, rowH)];
section0header.backgroundColor = [UIColor whiteColor];
CGRect backRect= CGRectMake(0,0,kScreenSize.width,rowH);
UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:backRect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
CAShapeLayer *maskLayer =[[CAShapeLayer alloc] init];
maskLayer.frame = backRect;
maskLayer.path = maskPath.CGPath;
section0header.layer.mask = maskLayer;
[section0headerBackView addSubview:section0header];
CGFloat Space =kScreenSize.width*0.028;
CGFloat hotW =kScreenSize.width*0.045;
CGFloat ImgY= rowH - 10 -hotW;
UIImageView *headImg =[[UIImageView alloc] initWithFrame:CGRectMake(Space, ImgY , hotW, hotW)];
headImg.image = [UIImage imageNamed:@"home_iocnmydevice"];
[section0header addSubview:headImg];
UILabel *mineLabel = [[UILabel alloc] init];
mineLabel.frame = CGRectMake(CGRectGetMaxX(headImg.frame) + Space,ImgY,100, hotW);
mineLabel.text = @"我的设备";
mineLabel.textAlignment = NSTextAlignmentLeft;
mineLabel.font = [UIFont systemFontOfSize:16];
//mineLabel.backgroundColor = [UIColor redColor];
[section0header addSubview:mineLabel];
UIButton *shuiMingBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//shuiMingBtn.backgroundColor = [UIColor blueColor];
CGFloat btnW =200*KWidth_Scale;
shuiMingBtn.frame = CGRectMake(kScreenSize.width -15 - btnW,0, btnW, rowH -10);
[shuiMingBtn setTitleColor:RGB(0, 185.0, 239.0) forState:UIControlStateNormal];
shuiMingBtn.titleLabel.font = [UIFont systemFontOfSize:13];
UIImage *btnImg = [UIImage imageNamed:@"home_iocn_explorefastforward"];
[shuiMingBtn setImage:btnImg forState:UIControlStateNormal];
NSString *tilte = @"查看说明书";
CGSize size = [tilte sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0]}];
[shuiMingBtn setImageEdgeInsets:UIEdgeInsetsMake(-2,size.width,2,-size.width)];
[shuiMingBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,-btnImg.size.width -4, 0, btnImg.size.width+4)];
[shuiMingBtn setTitle:tilte forState:UIControlStateNormal];
[shuiMingBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
[shuiMingBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
[shuiMingBtn addTarget:self action:@selector(shuiMingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[section0header addSubview:shuiMingBtn];
[section0header bringSubviewToFront:shuiMingBtn];
UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(section0headerBackView.frame) -1, kScreenSize.width, 1)];
lineview.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1];
[section0headerBackView addSubview:lineview];
[section0headerBackView bringSubviewToFront:lineview];
return section0headerBackView;
}else if (section == 2){
//CGFloat seprwH=TabContentHeaght*0.011;
CGFloat remaiLabelH= TabContentHeaght * 0.074;
//UIView*header1view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width,seprwH + remaiLabelH)];
UIView*header1view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width, remaiLabelH)];
header1view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
CGFloat Space =kScreenSize.width*0.028;
CGFloat hotW =kScreenSize.width*0.045;
UIImageView *hotImgView=[[UIImageView alloc] init];
hotImgView.frame = CGRectMake(Space,remaiLabelH/2 - hotW/2 , hotW, hotW);
hotImgView.image = [UIImage imageNamed:@"home_iocn_hotsell"];
CGFloat remaiLabelW = 70;
UILabel *remaiLabel = [[UILabel alloc] init];
remaiLabel.frame = CGRectMake(CGRectGetMaxX(hotImgView.frame) + Space,0, remaiLabelW, remaiLabelH);
remaiLabel.text = @"行业资讯";
remaiLabel.font = [UIFont systemFontOfSize:16];
remaiLabel.textAlignment = NSTextAlignmentLeft;
UIView*backview=[[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width,remaiLabelH)];
backview.backgroundColor = [UIColor whiteColor];
UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(backview.frame) -1, kScreenSize.width, 1)];
lineview.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1];
[backview addSubview:lineview];
[backview addSubview:hotImgView];
[backview addSubview: remaiLabel];
// [backview addSubview: yanxuanDetail];
[backview bringSubviewToFront:lineview];
[header1view addSubview:backview];
return header1view;
}else if (section == 1){
UIView*view=[[UIView alloc] init];
view.backgroundColor = [UIColor whiteColor];
UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width, 1)];
lineview.backgroundColor = RGB(242, 242, 242);
[view addSubview:lineview];
return view;
}
return nil;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if (section == 0) {
//添加设备view
CGFloat rowH=TabContentHeaght*0.068;
UIView*view=[[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width, rowH)];
view.userInteractionEnabled = YES;
view.backgroundColor = [UIColor whiteColor];
CGFloat Space =kScreenSize.width*0.063;
CGFloat ImgW =kScreenSize.width*0.056;
UIImageView *headImg =[[UIImageView alloc] initWithFrame:CGRectMake(Space,rowH/2 -ImgW/2 , ImgW, ImgW)];
headImg.image = [UIImage imageNamed:@"home_iocn_add"];
[view addSubview:headImg];
UIButton *addbtn =[UIButton buttonWithType:UIButtonTypeCustom];
CGFloat Space2 =kScreenSize.width*0.031;
addbtn.frame = CGRectMake(CGRectGetMaxX(headImg.frame) + Space2 -3,1,200,rowH -2);
[addbtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
[addbtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
[addbtn setTitle:@"添加设备" forState:UIControlStateNormal];
addbtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[addbtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:addbtn];
return view;
}else if (section == 1){
UIView *view = [[UIView alloc] init];
view.backgroundColor = RGB(242, 242, 242);
return view;
}else if (section ==2){
}
return nil;
}
#pragma mark- 添加设备
-(void)addBtnAction:(UIButton *)sender{
[self pushWiFiConnectVC];
}
#pragma mark - qianDaoBtnAction
-(void)qianDaoBtnAction{
QianDaoViewController *qiandaoVC= [[QianDaoViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:qiandaoVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0) {
if (self.totalArr.count==0) {
return;
}
FormatTankAddCamera *model =self.totalArr[indexPath.row];
self.curDeviceIdx=indexPath.row;
if (!model) {
return;
}
if ([model.type isEqualToString:@"tank"]) {
//切换时主动 断开 soket
[[Socketsingleton sharedInstance] cutOffSocket];
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:model.device addWithdissMisVc:nil];
}
else if ([model.type isEqualToString:@"pets"])
{
// PetStoresViewController*store=[[PetStoresViewController alloc]init];
// store.store=model;
[[DataCenter defaultDtacenter] setValue:model forKey:@"currentStore"];
DeviceModel*pushDevice=nil;
NSString*macid=[[DataCenter defaultDtacenter].cache stringForKey:@"currentPetDevice"];
if (macid.length)
{
BOOL find=NO;
for (DeviceModel*de in model.list) {
if ([macid isEqualToString:de.macAddress])
{
find=YES;
pushDevice=de;
break;
}
}
if (find)
{
}
else
{
pushDevice=model.list.firstObject;
}
}
else
{
pushDevice=model.list.firstObject;
}
[[DataCenter defaultDtacenter].cache setString:pushDevice.macAddress forKey:@"currentPetDevice"];
[[Socketsingleton sharedInstance] cutOffSocket];
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:pushDevice addWithdissMisVc:nil];
}
else if ([model.type isEqualToString:@"camera"]){
//切换时主动 断开 soket
[[Socketsingleton sharedInstance] cutOffSocket];
//进入摄像头页面
IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init];
p2pVC.contact = model.camera;
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:p2pVC];
UIApplication*app=[UIApplication sharedApplication];
AppDelegate*app1=(AppDelegate*)app.delegate;
app1.window.rootViewController=nav;
}
}else if (indexPath.section == 2){//点击资讯
//每日打开资讯链接 加金币
[[IfishUserObsever sharedInstance] addGoldWith:READINFORMATION addType:IFISHADDGOLDTYPE0];
_isPush = YES;
PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
webVC.pushtitle = @"资讯详情";
IfishInformations *model =self.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];
self.hidesBottomBarWhenPushed = NO;
}else if (indexPath.section == 1)
{
}
}
#pragma mark - 设备使用说明
-(void)shuiMingBtnAction:(UIButton *)btn{
[self pushshuoMingView];
}
-(void)pushshuoMingView{
// self.hidesBottomBarWhenPushed = YES;
// PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
// webVC.pushlink =IFISH_DEVCEITROURL;
// //webVC.pushlink =@"http://q.eqxiu.com/s/KmmVl87l";
// webVC.pushtitle = NSLocalizedString(@"ifish_deviceuse", nil);
// [self.navigationController pushViewController:webVC animated:YES];
// self.hidesBottomBarWhenPushed = NO;
self.hidesBottomBarWhenPushed = YES;
InfoByImageViewController*info=[[InfoByImageViewController alloc]init];
info.title=@"产品说明书";
info.type=@"instruction";
info.image=[UIImage imageNamed:@"instruction"];
[self.navigationController pushViewController:info animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.view hideToastActivity];
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar cnReset];
}
#pragma mark 未绑定设备或添加设备 跳转
-(void)pushWiFiConnectVC{
IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:connectVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
#pragma mark - 长按删除
-(void)removeDeviceAt:(NSIndexPath*)indexPath;
{
FormatTankAddCamera *deviceListModel =self.totalArr[indexPath.row];
if ([deviceListModel.type isEqualToString:@"tank"]) {
[self delectTankWith:deviceListModel AtIndexPath:indexPath];
}
else if ([deviceListModel.type isEqualToString:@"pets"]) {
[self delectTankWith:deviceListModel AtIndexPath:indexPath];
}
else{
//camera
[self delectCamerWith:deviceListModel AtIndexPath:(NSIndexPath *)indexPath];
}
}
#pragma mark - 删除摄像头
-(void)delectCamerWith:(FormatTankAddCamera*)deviceListModel AtIndexPath:(NSIndexPath *)indexPath
{
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
NSMutableDictionary * para = [NSMutableDictionary dictionary];
// NSMutableArray*deviceIdArr=[[NSMutableArray alloc]init];
UserModel*model=[dataContorl getUserInfo];
IfishCameraModel *contact = deviceListModel.camera;
NSString *cameraId=contact.cameraId;
;
NSNumber *userId=model.userId;
[para setValue:cameraId forKey:@"cameraId"];
[para setValue:userId forKey:@"userId"];
__weak typeof (self)weakSelf=self;
[mannager POST:IfishdeleteCameraUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (responseObject) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
/**
* 删除摄像头 前判断是否有 设备与其绑定关系 有解除关系 从关系数组中删除
*/
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
for (DeviceCameraModel *model in guanxiiArr) {
if (contact.cameraId == model.cameraId ) {
[guanxiiArr removeObject:model];
//保存新关系数组
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
}
}
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
//重置数据库
for (IfishCameraModel *model in deviceArry) {
if ([model.cameraId isEqual:contact.cameraId]) {
[newArr removeObject:model];
}
}
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"cameraArr"];
[weakSelf.totalArr removeObjectAtIndex:indexPath.row];
[weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView reloadData];
//[self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:0] withRowAnimation: UITableViewRowAnimationFade];
});
[weakSelf.view makeToast:@"删除成功"];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
[weakSelf.view makeToast:@"删除失败"];
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
[weakSelf.view makeToast:@"请求验证失败,请重新登陆"];
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
[weakSelf.view makeToast:@"请求被舍弃,未执行"];
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[weakSelf.view makeToast:@"请求异常"];
}];
}
#pragma mark - 删除设备
-(void)delectTankWith:(FormatTankAddCamera*)deviceListModel AtIndexPath:(NSIndexPath *)indexPath
{
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
NSMutableDictionary * para = [NSMutableDictionary dictionary];
NSString*string=[NSString stringWithFormat:@"%@/api/user/deleteDeviceUser.do",JIEKOUPORT];
if ([deviceListModel.type isEqualToString:@"pets"]) {
string=[NSString stringWithFormat:@"%@/api/user/deletePetDeviceUser.do",JIEKOUPORT];
DeviceModel*model=[deviceListModel.list firstObject];
NSString *priId=model.deviceId;
;
NSString*userId=model.userId;
para[@"userId"]=userId;
para[@"deviceId"]=priId;
}
else
{
NSString *priId=deviceListModel.device.deviceId;
;
NSString*userId=deviceListModel.device.userId;
[para setValue:priId forKey:@"priId.deviceId"];
[para setValue:userId forKey:@"priId.userId"];
}
__weak typeof (self)weakSelf=self;
[mannager POST:string parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (responseObject) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
for (DeviceCameraModel *model in guanxiiArr) {
if (deviceListModel.device.deviceId == model.deviceId ) {
[guanxiiArr removeObject:model];
//保存新关系数组
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
}
}
//重置数据
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
for (DeviceModel *model in deviceArry) {
if ([model.deviceId isEqual:deviceListModel.device.deviceId]) {
[newArr removeObject:model];
}
}
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"];
[weakSelf.totalArr removeObjectAtIndex:indexPath.row];
[weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
//GCD中的dispatch_after 实现单次的延时调用 dispatch_time的单位是纳秒为防止用户使用时候的出现换算上的错误Xcode在开发者打dispatch_after的时候会自动补全下面一整段代码
//dispatch_after是延迟提交不是延迟运行
//NSEC纳秒。
//USEC微妙。
//SEC
//PER
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.tableView reloadData];
});
[weakSelf addDataRequestQueue];
/*
而如果有循环的调用的话可以用dispatch_source_set_timer来实现 用到GCD的事件源和事件监听的机制
int interval = 2;
int leeway = 0;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
if (timer) {
dispatch_source_set_timer(timer, dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * interval), interval * NSEC_PER_SEC, leeway);
dispatch_source_set_event_handler(timer, ^{
[self someMethod];
});
dispatch_resume(timer);
}
*/
[weakSelf.view makeToast:@"删除成功"];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
[weakSelf.view makeToast:@"删除失败"];
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
[weakSelf.view makeToast:@"请求验证失败,请重新登陆"];
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
[weakSelf.view makeToast:@"请求被舍弃,未执行"];
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[weakSelf.view makeToast:@"请求异常"];
}];
}
#pragma mark---删除当前缓存设备
-(void)deleteCurDevice{
FormatTankAddCamera *deviceListModel =self.totalArr[self.curDeviceIdx];
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
for (DeviceCameraModel *model in guanxiiArr) {
if (deviceListModel.device.deviceId == model.deviceId ) {
[guanxiiArr removeObject:model];
//保存新关系数组
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
}
}
//重置数据
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
for (DeviceModel *model in deviceArry) {
if ([model.deviceId isEqual:deviceListModel.device.deviceId]) {
[newArr removeObject:model];
}
}
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"];
[self.totalArr removeObjectAtIndex:self.curDeviceIdx];
NSIndexPath*indexPath=[NSIndexPath indexPathForRow:self.curDeviceIdx inSection:0];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
//GCD中的dispatch_after 实现单次的延时调用 dispatch_time的单位是纳秒为防止用户使用时候的出现换算上的错误Xcode在开发者打dispatch_after的时候会自动补全下面一整段代码
//dispatch_after是延迟提交不是延迟运行
//NSEC纳秒。
//USEC微妙。
//SEC
//PER
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
#pragma mark - 商品列表加载
-(void)loadGoodsData{
__weak typeof (self)weskSelf=self;
[AFHttpTool getIfishGoodsListWith:IfishGoodsTypeShouYE success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]){
NSLog(@"商品列表加载100");
NSArray*goodsArr=reDic[@"data"];
for (NSDictionary *goodsDic in goodsArr) {
IfishGoodsData *goodsData=[[IfishGoodsData alloc] initWithDict:goodsDic];
[weskSelf.goodsArr addObject:goodsData];
}
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:2];
[weskSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationAutomatic];
}
[weskSelf.progressHud hide:YES];
} failure:^(NSError *err) {
[weskSelf.progressHud hide:YES];
NSLog(@"%@errrrrr",err);
}];
}
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UIColor *color = [UIColor colorWithRed:53/255.0 green:53/255.0 blue:53/255.0 alpha:1];
CGFloat offsetY = scrollView.contentOffset.y;
//NSLog(@"offsetY:%f",offsetY);
if (offsetY > 0) {
CGFloat alpha = MIN(1, (offsetY)/_scrollHeight);
[self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:alpha]];
self.tableView.backgroundColor = [UIColor whiteColor];
} else {
//下拉
[self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:0]];
//CGRect rect = self.tabDowloadHoldView.frame;
////我们只需要改变图片的y值和高度即可
//rect.size.height = - offsetY;
//self.tabDowloadHoldView.frame = rect;
}
}
#pragma mark - 我的等级
-(void)levelBtnAction{
IifshMineDJViewController *mineLevelVC = [[IifshMineDJViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:mineLevelVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
#pragma mark - 我的金币
-(void)goldBtnAction:(UIButton*)btn{
IfishMineGoldViewController *GoldViewVC = [[IfishMineGoldViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:GoldViewVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
#pragma mark - 广告点击事件
-(void)tapAdWithLink:(NSString *)pushLink
{
if (![pushLink isKindOfClass:[NSNull class]] &&pushLink &&![pushLink isEqualToString:@""]){
//字条串是否包含有某字符串
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];
self.hidesBottomBarWhenPushed = NO;
} else {
[self openAliBCWithLink:pushLink];
}
}
}
#pragma mark - 商品列表点击事件
// 宝贝详情页面
-(void)tapTtemListAt:(NSString *)goodslink
{
[self openAliBCWithLink:goodslink];
}
-(void)openAliBCWithLink:(NSString *)linkUrl{
//查看商品 加金币
[[IfishUserObsever sharedInstance] addGoldWith:OPENGOODSLINK addType:IFISHADDGOLDTYPE0];
//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;
}
}
#pragma mark - 导航栏消息,跳转进入消息列表
-(void)navMeaasageBtnAction{
self.messageCount = 0;
[self setRedViewData];//刷新消息显示
// UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:sessionList];
// [nav.navigationBar resetBackgroundImage];
// nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// [self presentViewController:nav animated:YES completion:nil];
IfishMessageViewController *message = [[IfishMessageViewController alloc]init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:message animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
@end