ifish/Ifish/controllers/IfishTabControllers/我的/mineControllers/IfishMeViewController.m

656 lines
22 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.

//
// IfishMeViewController.m
// ifishTabTest
//
// Created by imac on 16/7/25.
// Copyright © 2016年 xiang. All rights reserved.
//
#import "IfishMeViewController.h"
#import "LeftCellmodel.h"
#import "leftCell.h"
#import "UIImageView+WebCache.h"
#import "InfoViewController.h"
#import "ScanViewController.h"
#import "AboutUsViewController.h"
#import "SaySomethingViewController.h"
#import "UIImage+ImageEffects.h"
#import "LeftViewController.h"
#import "CenterViewController.h"
#import "RightViewController.h"
#import "SonNuoCenterViewController.h"
#import "YooseeCenterViewController.h"
#import "TwoControlCenterController.h"
#import "ThreeControlCenterViewController.h"
#import "FourControlViewController.h"
#import "NoneControlCenterViewController.h"
#import "XuToCenterViewController.h"
#import "PuasiphysicalSkinViewController.h"
#import "IfishBlackListCenterViewController.h"
#import "KeLiAiCenterViewController.h"
#import "FourControlNormalCenterController.h"
#import "SonNuoCenterViewController.h"
#import "ICSDrawerController.h"
#import "UIView+ZYDraggable.h"
#import "UIAlertView+NTESBlock.h"
#import "PushMasssageWebViewController.h"
#import "IfishUserDefaultHelper.h"
#import "UINavigationBar+Background.h"
#import "MineKanHuViewController.h"
#import "MinekanHuNotSelectShopController.h"
#import "IfishSessionViewController.h"
#import "IfishUserObsever.h"
#import "QianDaoGiftView.h"
#import "IfishGoldAndExpTostView.h"
#import "MineHeaderNewItemsCell.h"
#import "IfishMineGoldViewController.h"
#import "IifshMineDJViewController.h"
#import "WoDeRenWuViewController.h"
#import "UITabBar+addRedPointBadge.h"
#import "WodeUserAssetCell.h"
#import "IfishInformations.h"
#import "IfishDatabaseManager.h"
#import <UMSocialCore/UMSocialCore.h>
#import "IfishSetViewController.h"
@interface IfishMeViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,MineHeaderItemsDelegate>
@property(nonatomic,strong)UITableView *tableView;
@end
@implementation IfishMeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = item;
[self getTableData];
[self creatTab];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
[[NSNotificationCenter defaultCenter] addObserverForName:IFISHTASK_HAVEDONEALL object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[self.tabBarController.tabBar hideBadgeOnItemIndex:3];
}];
}
-(void)viewDidLayoutSubviews{
}
-(void)getTableData{
self.tileArr=@[@[@"扫二维码",@"我的看护"],@[@"关于我们",@"设置"],@[@"分享爱鱼奇",@"产品说明书",@"联系爱鱼奇"]];
self.headimgeArr = @[@[@"personal_iocn_scan",@"personal_iocn_care"],@[@"personal_iocn_about",@"personal_iocn_set"],@[@"personal_iocn_share",@"personal_iocn_instructions",@"personal_iocn_feedback"]];
}
-(void)creatTab{
self.automaticallyAdjustsScrollViewInsets = NO;
if (self.tableView==nil) {
[self.tableView registerNib:[UINib nibWithNibName:@"WodeUserAssetCell" bundle:nil] forCellReuseIdentifier:@"WodeUserAssetCell"];
UITableView*table=[[UITableView alloc]initWithFrame:CGRectMake(0,0, kScreenSize.width, kScreenSize.height) style:UITableViewStyleGrouped];
table.dataSource=self;
table.delegate=self;
table.separatorStyle=UITableViewCellSeparatorStyleNone;
self.tableView=table;
self.tableView.showsVerticalScrollIndicator=NO;
self.tableView.backgroundColor = TABLE_HEADER_COLOR;
[self.view addSubview:self.tableView];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0,50, 0,0)];
[self.tableView setSeparatorColor:TABLE_SEPRETLINE_COLOR];
}
[self setbackImg];
[self setuserImg];
[self setUserName];
[self setTitlabel];
}
}
-(UILabel*)setTitlabel{
if (!_Tlabel) {
_Tlabel=[[UILabel alloc] initWithFrame:CGRectMake(kScreenSize.width/2-50,20, 100, 44)];
_Tlabel.text = @"我的";
_Tlabel.textColor = [UIColor whiteColor];
_Tlabel.textAlignment = NSTextAlignmentCenter;
_Tlabel.font = [UIFont systemFontOfSize:19];
[self.backImg addSubview:_Tlabel];
}
return _Tlabel;
}
//tab头视图
-(UIImageView*)setbackImg{
if (!_backImg) {
_backImg = [[UIImageView alloc] init];
_backImg.backgroundColor = RGB(12, 118, 217);
self.backImg.frame = CGRectMake(0, 0, kScreenSize.width, kScreenSize.width * 0.44);
self.backImg.userInteractionEnabled = YES;
self.tableView.tableHeaderView = self.backImg;
}
return _backImg;
}
-(UIImageView *)setuserImg{
if (!_userImg) {
self.userImg = [[UIImageView alloc] init];
UITapGestureRecognizer*tapGestrueRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappushInfo)];
self.userImg.userInteractionEnabled=YES;
[self.userImg addGestureRecognizer:tapGestrueRecognizer];
[self.backImg addSubview:self.userImg];
}
return _userImg;
}
-(UIButton *)setUserName{
if (!_userNamebtn) {
_userNamebtn=[UIButton buttonWithType:UIButtonTypeCustom];
[_userNamebtn addTarget:self action:@selector(tappushInfo) forControlEvents:UIControlEventTouchUpInside];
[self.backImg addSubview:_userNamebtn];
}
return _userNamebtn;
}
-(void)tappushInfo{
//push时隐藏tabbar
self.hidesBottomBarWhenPushed = YES;
InfoViewController*infovc=[[InfoViewController alloc]init];
[self.navigationController pushViewController:infovc animated:YES];
//设置返回时显示
self.hidesBottomBarWhenPushed = NO;
}
#pragma -mark -functions
//获取字符串的宽度
-(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型lineBreakMode可根据自己的实际情况进行设置
return sizeToFit.width;
}
//获得字符串的高度
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型lineBreakMode可根据自己的实际情况进行设置
return sizeToFit.height;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
[self initImageView];
});
self.navigationController.navigationBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.navigationBar.hidden = NO;
}
-(void)initImageView{
UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
NSString*fullpath=[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"avatar.png"];
UIImage*saveImage=[[UIImage alloc]initWithContentsOfFile:fullpath];
if (saveImage==nil) {
// 这里注意 <null>
if ([userModel.userImg isKindOfClass:[NSNull class]]) {
//int i = (arc4random()%7) + 1;// 设置随机头像
int i = 1;
[self.userImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
}else{
if ([userModel.userImg isEqualToString:@""]) {
UIImage*User=[UIImage imageNamed:@"userIcon1"];
[self.userImg setImage:User];
}else{
// int i = 1;
// [_iconImageButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]] forState:UIControlStateNormal];
NSString*str=[NSString stringWithFormat:@"%@%@",kGetIconUrl,userModel.userImg];
[self.userImg sd_setImageWithURL:[NSURL URLWithString:str]];
}
}
}else{
NSString*str=[NSString stringWithFormat:@"%@%@",kGetIconUrl,userModel.userImg];
if ([str isEqualToString:kGetIconUrl]) {
//int i = (arc4random()%7) + 1;// 设置随机头像
int i = 1;
[self.userImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[self.userImg sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@""]];
});
}
}
NSString *title =nil;
if (userModel.nickName) {
title = userModel.nickName;
}else{
title =@"爱鱼奇用户";
}
[self.userNamebtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:title];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:8];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [title length])];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,title.length)];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0,title.length)];
[self.userNamebtn setAttributedTitle:attributedString forState:UIControlStateNormal];
[self.userNamebtn sizeToFit];
self.userNamebtn.titleLabel.textAlignment = NSTextAlignmentCenter;
CGFloat btnTitleW =[self widthForString:self.userNamebtn.titleLabel.text fontSize:20 andHeight:10];
CGFloat btnTitleH = [self heightForString:self.userNamebtn.titleLabel.text fontSize:20 andWidth:btnTitleW];
CGFloat ImgW = kScreenSize.width*0.16;
CGFloat ImgTopY = kScreenSize.width*0.18;
self.userImg.frame=CGRectMake(kScreenSize.width/2-ImgW/2,ImgTopY,ImgW, ImgW);
self.userImg.layer.masksToBounds = YES;
self.userImg.layer.cornerRadius = ImgW * 0.5;
self.userImg.layer.borderWidth = 2;
self.userImg.layer.borderColor = RGB(162,210, 255).CGColor;
self.userNamebtn.frame =CGRectMake(self.backImg.frame.size.width/2 -btnTitleW/2,CGRectGetMaxY(self.userImg.frame) + 5, btnTitleW, btnTitleH);
//等级 金币 任务
NSIndexSet *Asset = [NSIndexSet indexSetWithIndex:0];
[self.tableView reloadSections:Asset withRowAnimation:UITableViewRowAnimationNone];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 1;
}else if (section == 1){
return 2;
}else if (section == 3){
return 3;
}
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section ==0) {
WodeUserAssetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WodeUserAssetCell"];
if(cell==nil){
cell = [[WodeUserAssetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WodeUserAssetCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
cell.backgroundColor = RGB(10, 107, 197);
[cell loadCellData];
cell.itemsDelegate = self;
return cell;
}
leftCell*cell=[tableView dequeueReusableCellWithIdentifier:@"leftCell"];
if (cell==nil) {
cell= [[[NSBundle mainBundle]loadNibNamed:@"leftCell" owner:self options:nil]lastObject];
}
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font=[UIFont systemFontOfSize:20.0f];
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
LeftCellmodel*lModel=[[LeftCellmodel alloc]init];
lModel.headig=self.headimgeArr[indexPath.section -1][indexPath.row];
lModel.funTitle=self.tileArr[indexPath.section -1][indexPath.row];
[cell.headimag setImage:[UIImage imageNamed:lModel.headig]];
cell.titleLabel.text=lModel.funTitle;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
return 60.0f;
}
return 55.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//设置group tableview 有默认高度header
if (section ==0) {
return 0.01f;
}else if (section ==1){
return 5.0f;
}
return 10.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//设置一定高度tabviewfooter
if (section ==3) {
return 100.0f;
}
return 0.01f;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if (section ==0) {
UIView *Footerback=[[UIView alloc] init];
Footerback.backgroundColor = RGB(10, 107, 197);
return Footerback;
}
UIView *Footerback=[[UIView alloc] init];
Footerback.backgroundColor = TABLE_HEADER_COLOR;
return Footerback;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section==0) {
UIView *Headerback=[[UIView alloc] init];
Headerback.backgroundColor = RGB(10, 107, 197);
return Headerback;
}
UIView *Headerback=[[UIView alloc] init];
Headerback.backgroundColor = TABLE_HEADER_COLOR;
return Headerback;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section ==0) {
return;
}
if (indexPath.section == 1 && indexPath.row == 0) {
ScanViewController*scanVC=[[ScanViewController alloc]init];
UINavigationController * nVC = [[UINavigationController alloc]initWithRootViewController:scanVC];
[self presentViewController: nVC animated:YES completion:^{
}];
}
else if (indexPath.section == 1 && indexPath.row == 1){
UserModel *mode=[dataContorl getUserInfo];
if (mode.userType) {
//用户为商家 看护服务
if ([mode.userType isEqualToString:@"1"]) {
[self.view makeToast:@"您是商家,请在「我是商家」中查看「看护管理」"];
return ;
}
}
CertificationShopModel *ShopsInfo2= [[DataCenter defaultDtacenter] valueForKey:@"ShopsInfo2"];
if (ShopsInfo2.shopsId) {
MineKanHuViewController *wodeKanHu=[[MineKanHuViewController alloc] init];
wodeKanHu.xinXiModel = ShopsInfo2;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:wodeKanHu animated:YES];
self.hidesBottomBarWhenPushed = NO;
}else{
MinekanHuNotSelectShopController *notselct = [[MinekanHuNotSelectShopController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:notselct animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
}else if (indexPath.section == 2 && indexPath.row == 0){
self.hidesBottomBarWhenPushed = YES;
AboutUsViewController*usVC=[[AboutUsViewController alloc]init];
[self.navigationController pushViewController:usVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}else if (indexPath.section == 2 && indexPath.row == 1){
//设置
self.hidesBottomBarWhenPushed = YES;
IfishSetViewController *setvc =[[IfishSetViewController alloc] init];
[self.navigationController pushViewController:setvc animated:YES];
self.hidesBottomBarWhenPushed = NO;
}else if (indexPath.section == 3 && indexPath.row == 1){
// self.hidesBottomBarWhenPushed = YES;
// PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
// webVC.pushlink =IFISH_DEVCEITROURL;
// webVC.pushtitle = NSLocalizedString(@"ifish_deviceuse", nil);
// [self.navigationController pushViewController:webVC animated:YES];
// self.hidesBottomBarWhenPushed = NO;
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:IFISH_DEVCEITROURL]];
}else if (indexPath.section == 3 && indexPath.row == 2){
//联系爱鱼奇
[self connectIfish];
//app 自用问题反馈接口已弃用, 使用云信IM
//self.hidesBottomBarWhenPushed = YES;
//SaySomethingViewController*sayVc=[[SaySomethingViewController alloc]init];
//[self.navigationController pushViewController:sayVc animated:YES];
//self.hidesBottomBarWhenPushed = NO;
}else if (indexPath.section == 3 && indexPath.row == 0){
//分享爱鱼奇
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
shareObject.title = @"爱鱼奇";
UIImage *shareImg = [UIImage imageNamed:@"ifish_sharaApp.jpg"];
shareObject.shareImage = shareImg;
//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
[[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatTimeLine messageObject:messageObject currentViewController:self completion:^(id result, NSError *error) {
if (error) {
[self.view makeToast:@"暂时无法打开微信"];
//NSLog(@"************Share fail with error %@*********",error);
}else{
[[IfishUserObsever sharedInstance] addGoldWith:SHAREIFISHAPP addType:IFISHADDGOLDTYPE0];
NSLog(@"response data is %@",result);
}
}];
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
// NSLog(@"offsetY:%f",offsetY);
if (offsetY < 0) {
// CGRect rect = self.tableView.tableHeaderView.frame;
//CGFloat tabH =kScreenSize.width * 0.44;
////我们只需要改变图片的y值和高度即可
//rect.origin.y = - offsetY;
// rect.size.height = offsetY - tabH;
//self.tableView.tableHeaderView.frame = rect;
//_tableView.bounces = NO;
_tableView.backgroundColor = RGB(12, 118, 217);
}
else
{
//_tableView.bounces = YES;
_tableView.backgroundColor = TABLE_HEADER_COLOR;
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
// _tableView.bounces = YES;
}
#pragma mark - 联系爱鱼奇
-(void)connectIfish{
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
NSString *myAcount = [NSString stringWithFormat:@"%@",model.userId];
NSString *tarGetAcount = @"1";
__weak typeof(self) weakself = self;
[[NIMSDK sharedSDK].loginManager login:myAcount token:model.neteaseToken completion:^(NSError *error) {
if (!error) {
NSLog(@"登录成功");
//创建session
NIMSession *session = [NIMSession session:tarGetAcount type:NIMSessionTypeP2P];
//创建聊天页,这个页面继承自 NIMKit 中的组件 NIMSessionViewController
weakself.hidesBottomBarWhenPushed = YES;
IfishSessionViewController *vc = [[IfishSessionViewController alloc] initWithSession:session];
vc.targetChatname = @"爱鱼奇官方";
[weakself.navigationController pushViewController:vc animated:YES];
weakself.hidesBottomBarWhenPushed = NO;
}else{
NSLog(@"登录失败");
}
}];
}
#pragma mark - mineHeaderItemsDelegate
//等级
-(void)tapDengjiAction{
NSLog(@"等级");
IifshMineDJViewController *minegDJ =[[IifshMineDJViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:minegDJ animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
//金币
-(void)tapGoldAction{
NSLog(@"金币");
IfishMineGoldViewController *minegold =[[IfishMineGoldViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:minegold animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
//任务
-(void)tapRenWuAction{
NSLog(@"任务");
WoDeRenWuViewController *mineDeRen =[[WoDeRenWuViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:mineDeRen animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
@end