Instantly share code, notes, and snippets.
Created
October 6, 2014 19:48
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save pedronsouza/c6c35455860afd21d5b9 to your computer and use it in GitHub Desktop.
Classe antiga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DSMenuViewController.m | |
// DietaSaude | |
// | |
// Created by Vitor Rodrigues on 31/07/13. | |
// Copyright (c) 2013 B2U Editora Ltda (Portal Minha Vida). All rights reserved. | |
// | |
#import "DSMenuViewController.h" | |
#import "DSUsuarioModel.h" | |
#import "DSNotificationCenter.h" | |
#import "DSDiaryViewController.h" | |
#import "DSRootViewController.h" | |
#import "DSAssinaturaViewController.h" | |
#import "MinhaAvaliacaoTabBarViewController.h" | |
#import "DSBaseSlideNavigationTopViewController.h" | |
#import "PreencherMinhaAvaliacaoViewController.h" | |
#import "DSEvolucaoTabViewController.h" | |
#import "DSCacauBlogViewController.h" | |
#import "DSFerramentasReceitaViewController_ipad.h" | |
#import "DSExercicioModel.h" | |
#import "DSEvolucaoViewController.h" | |
#import "NSDate+MVUtils.h" | |
#import "DSNotificationManager.h" | |
#import "DSUpdateWeightViewController.h" | |
#import "DSCardapioViewController.h" | |
#import "DSChatViewController.h" | |
#import "DSAlertaPesagem.h" | |
#import "DSMenuTopTableViewCell.h" | |
#import "DSMenuBottomTableViewCell.h" | |
#define DFP_EVENT_NAME @"event" | |
#define DFP_EVENT_INFO @"subscription" | |
#define URL_METODOLOGIA @"http://www.dietaesaude.com.br/como-funciona/metodologiamobile?webview=true" | |
#define URL_NOSSA_EQUIPE @"http://www.dietaesaude.com.br/mobile/nossos-profissionais" | |
#define URL_FAQ @"http://faq.dietaesaude.com.br/index.php?req=%@&nome=%@&email=%@&tipoUsuario=%@&aparelho=%@&versao=%@" | |
#define URL_FAQ_NUTRICIONAL @"http://faq.dietaesaude.com.br/index.php?req=nutricional&nome=%@&email=%@&tipoUsuario=%@&aparelho=%@&versao=%@" | |
#define URL_FAQ_PERSONAL @"http://faq.dietaesaude.com.br/index.php?req=personal&nome=%@&email=%@&tipoUsuario=%@&aparelho=%@&versao=%@" | |
#define NOTIFICATION_CHANGE_TO_DIARY @"NotificationChangeToDiary" | |
@interface DSMenuViewController () | |
@property (strong, nonatomic) DSPesagemModel *pesagemModel; | |
@property (strong, nonatomic) DSRequestFailBlock userAuthErrorBlock; | |
@property (strong, nonatomic) DSAdBannerManager *bannerManager; | |
@end | |
@implementation DSMenuViewController | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | |
return YES; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMenu) name:@"AlertaPesagemPendente" object:nil]; | |
[self configAuthErrorBlock]; | |
if (!IS_WEBSERVICE_POINTING_TO_PRODUCAO) { | |
[self.nameLabel setTextColor:[UIColor redColor]]; | |
} | |
self.tableviewMenu.delegate = self; | |
self.tableviewMenu.dataSource = self; | |
if([self isUsuarioOnline]){ | |
[self baixarUltimasAtualizacoesDoUsuario]; | |
} | |
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickConfiguracoes:)]; | |
[tap setNumberOfTapsRequired:1]; | |
[tap setDelegate:self]; | |
[self.configButtonTouchArea addGestureRecognizer:tap]; | |
// [[self.configButtonTouchArea subviews][0] addGestureRecognizer:tap]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRemoteNotification) name:NOTIFICATION_ACTION_SHOW_VIEW object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTopViewToDiary) name:NOTIFICATION_CHANGE_TO_DIARY object:nil]; | |
} | |
- (void)viewDidAppear:(BOOL)animated { | |
if ([[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP]) { | |
if (IS_IPHONE) { | |
self.tableviewMenu.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64); | |
} | |
} | |
[self.tableviewMenu scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; | |
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; | |
} | |
- (void)viewDidDisappear:(BOOL)animated { | |
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; | |
} | |
-(void)viewWillAppear:(BOOL)animated { | |
[self loadBanner]; | |
if ([[[DSUsuarioModel sharedInstance] currentUser] avaliacao]) { | |
[self startView]; | |
} | |
[[DSTracker sharedInstance] trackPageView:@"gaveta/"]; | |
[self.tableviewMenu reloadData]; | |
[self highlightCurrentSectionRow]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
[self disposeResources]; | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; | |
} | |
- (void)disposeResources { | |
[self setNameLabel:nil]; | |
[self setTableviewMenu:nil]; | |
[self setHaveMoreButton:nil]; | |
[self setBannerContainer:nil]; | |
} | |
#pragma mark - UI Actions | |
- (IBAction)didClickLogin:(id)sender { | |
[self showLoginViewControllerWithEmail:nil password:nil]; | |
} | |
- (void)didClickConfiguracoes:(id)sender { | |
[[DSTracker sharedInstance] trackEventAction:@"open" category:@"configuracoes" label:@"menu"]; | |
[self changeTopViewController:[self configurationViewController]]; | |
} | |
- (void)didClickLembretes:(id)sender { | |
[[DSTracker sharedInstance] trackEventAction:@"open" category:@"lembretes" label:@"menu"]; | |
[self changeTopViewController:[self lembretesViewController]]; | |
} | |
-(void) configAuthErrorBlock { | |
if (![[DSUsuarioModel sharedInstance] isUsuarioOffline]) { | |
[DSBaseEngine setUserAuthErrorBlock:[self userAuthErrorBlock]]; | |
} else { | |
[DSBaseEngine setUserAuthErrorBlock:nil]; | |
} | |
} | |
-(DSRequestFailBlock) userAuthErrorBlock { | |
if (!_userAuthErrorBlock) { | |
__block DSMenuViewController *menuViewController = self; | |
_userAuthErrorBlock = ^(NSError *error) { | |
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops... Desconectado!" | |
message:@"Entre novamente com seu e-mail e senha." | |
delegate:nil | |
cancelButtonTitle:@"OK" | |
otherButtonTitles:nil]; | |
[alertView show]; | |
[menuViewController logout]; | |
}; | |
} | |
return _userAuthErrorBlock; | |
} | |
-(void)logout { | |
[DSBaseEngine setUserAuthErrorBlock:nil]; | |
[[[DSExercicioModel alloc]init] removeAll]; | |
[[DSUsuarioModel sharedInstance] logout]; | |
DSRootViewController *root = nil; | |
if(self.slidingViewController){ | |
root = (DSRootViewController*)self.slidingViewController; | |
} | |
else { | |
root = (DSRootViewController*)self.revealController; | |
} | |
[root checkForUserEvaluation]; | |
} | |
#pragma mark - View Configuration | |
-(void)startView { | |
Usuario *user = [[DSUsuarioModel sharedInstance] currentUser]; | |
self.nameLabel.text = user.nome; | |
} | |
-(void)reloadMenu { | |
[self.tableviewMenu reloadData]; | |
} | |
-(Usuario*)currentUser { | |
return [[DSUsuarioModel sharedInstance] currentUser]; | |
} | |
-(void)highlightCurrentSectionRow { | |
NSIndexPath *currentIndexPath = [self.tableviewMenu indexPathForSelectedRow]; | |
if(currentIndexPath){ | |
[self.tableviewMenu deselectRowAtIndexPath:currentIndexPath animated:NO]; | |
} | |
UIViewController *vc; | |
vc = [self currentFrontViewController]; | |
if([vc isKindOfClass:[UINavigationController class]]){ | |
vc = [(UINavigationController*)vc viewControllers][0]; | |
} | |
NSInteger selectedRow = -1; | |
if ([vc isKindOfClass:[DSDiaryViewController class]]) { | |
selectedRow = kTopMenuRowDiario; | |
} else if ([vc isKindOfClass:[DSEvolucaoViewController class]]) { | |
selectedRow = kTopMenuRowEvolution; | |
} else if([vc isKindOfClass:[DSCardapioViewController class]]) { | |
selectedRow = kTopMenuRowCardapio; // mudar para enum quando ir pro iPad | |
} else if([vc isKindOfClass:[DSChatViewController class]]){ | |
if (![self isUsuarioAssinantePago]) { | |
selectedRow = kTopMenuRowChat; | |
} | |
} | |
if(selectedRow >= 0){ | |
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedRow inSection:0]; | |
[self.tableviewMenu selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; | |
DSMenuTopTableViewCell *cell = (DSMenuTopTableViewCell*)[self.tableviewMenu cellForRowAtIndexPath:selectedIndexPath]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15]]; | |
} | |
} | |
#pragma mark - User methods | |
-(BOOL)isUsuarioAssinantePago{ | |
return [[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP]; | |
} | |
-(BOOL)isUsuarioEconomico{ | |
Usuario *usuarioAtual = [[DSUsuarioModel sharedInstance] currentUser]; | |
if ([[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP] && usuarioAtual.featureVip.intValue == 0) { | |
return YES; | |
} | |
return NO; | |
} | |
-(BOOL)isUsuarioOnline { | |
return [[DSUsuarioModel sharedInstance] isUsuarioOffline] == NO; | |
} | |
#pragma mark - TABLE VIEW METHODS | |
//SECTIONS | |
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return 2; | |
} | |
//ROWS IN SECTION | |
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ | |
if (section == 0) { | |
if ([self isUsuarioAssinantePago]) { | |
return 3; | |
} | |
return 4; | |
} | |
if ([self isUsuarioAssinantePago]) { | |
return 11; | |
} | |
return 7; | |
} | |
//CELL SETUP | |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
if (indexPath.section == 0) { | |
static NSString *cellID = @"topCell"; | |
DSMenuTopTableViewCell *cell = (DSMenuTopTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID]; | |
if(!cell) { | |
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSMenuTopTableViewCell" owner:nil options:nil] objectAtIndex:0]; | |
} | |
DSAlertaPesagem* alerta = [DSAlertaPesagem sharedInstance]; | |
switch (indexPath.row) { | |
case kTopMenuRowDiario: | |
cell.title.text = @"Diário"; | |
[cell.icon setImage:[self getDiaryIconImage:NO]]; | |
[cell.icon setHighlightedImage:[self getDiaryIconImage:YES]]; | |
break; | |
case kTopMenuRowEvolution: | |
cell.title.text = @"Evolução"; | |
[cell.icon setImage:[self getEvolutionIconImage:NO]]; | |
[cell.alert setImage:[alerta getAlertMenuImage]]; | |
[cell.icon setHighlightedImage:[self getEvolutionIconImage:YES]]; | |
break; | |
case kTopMenuRowCardapio: //workaround quando cardapio for pro iPad colocar o enum de volta | |
cell.title.text = @"Cardápios"; | |
[cell.icon setImage:[self getCardapioIconImage:NO]]; | |
[cell.icon setHighlightedImage:[self getCardapioIconImage:YES]]; | |
break; | |
case kTopMenuRowChat: | |
if (IS_IPHONE) { | |
cell.title.text = @"Chat com nutricionista"; | |
}else{ | |
cell.title.text = @"Chat"; | |
} | |
[cell.icon setImage:[self getChatIconImage:NO]]; | |
[cell.icon setHighlightedImage:[self getChatIconImage:YES]]; | |
break; | |
default: | |
break; | |
} | |
UIView* cellBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)]; | |
[cellBack setBackgroundColor:[UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:1.0]]; | |
[cell setSelectedBackgroundView:cellBack]; | |
return cell; | |
}else{ | |
static NSString *cellID = @"bottonCell"; | |
DSMenuBottomTableViewCell *cell = (DSMenuBottomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID]; | |
if(!cell) { | |
cell = [[[NSBundle mainBundle] loadNibNamed:@"DSMenuBottomTableViewCell" owner:nil options:nil] objectAtIndex:0]; | |
} | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:15]]; | |
int index; | |
if ([self isUsuarioAssinantePago]) { | |
index = indexPath.row; | |
if ([self isUsuarioEconomico]){ | |
if (indexPath.row == kBottomMenuRowChatComNutri || indexPath.row == kBottomMenuRowDuvidasFit) { | |
cell.userInteractionEnabled = NO; | |
cell.hidden = YES; | |
} | |
} | |
}else{ | |
index = indexPath.row + 4; | |
} | |
CGRect frame = cell.title.frame; | |
frame.origin.y +=10; | |
switch (index) { | |
case kBottomMenuTitle0: | |
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; | |
cell.title.text = @"CONTE COM A GENTE"; | |
cell.title.textColor = [UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:1.0]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]]; | |
[cell.title setFrame:frame]; | |
break; | |
case kBottomMenuRowChatComNutri: | |
cell.title.text = @"Chat com nutricionista"; | |
break; | |
case kBottomMenuRowDuvidasNutri: | |
cell.title.text = @"Dúvidas nutricionais"; | |
break; | |
case kBottomMenuRowDuvidasFit: | |
cell.title.text = @"Dúvidas de fitness"; | |
break; | |
case kBottomMenuTitle1: | |
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; | |
cell.title.text = @"SOBRE O DIETA E SAÚDE"; | |
cell.title.textColor = [UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:1.0]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]]; | |
[cell.title setFrame:frame]; | |
break; | |
case kBottomMenuRowConfiguracoes: | |
cell.title.text = @"Configurações gerais"; | |
break; | |
case kBottomMenuRowLembretes: | |
cell.title.text = @"Alertas de refeições"; | |
break; | |
case KBottomMenuTitle2: | |
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; | |
cell.title.text = @"CONFIGURAÇÕES"; | |
cell.title.textColor = [UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:1.0]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]]; | |
[cell.title setFrame:frame]; | |
break; | |
case kBottomMenuRowMetodologia: | |
cell.title.text = @"Nossa metodologia"; | |
break; | |
case kBottomMenuRowNossaEquipe: | |
cell.title.text = @"Nossa equipe"; | |
break; | |
case kBottomMenuRowFaleConosco: | |
cell.title.text = @"Tire suas dúvidas"; | |
break; | |
default: | |
break; | |
} | |
if (index == kBottomMenuTitle0 || index == kBottomMenuTitle1 || index == KBottomMenuTitle2) { | |
UIView* line; | |
if (index == kBottomMenuTitle0) { | |
line = [[UIView alloc]initWithFrame:CGRectMake(155, cell.title.frame.origin.y + cell.title.frame.size.height /2, cell.frame.size.width, 1)]; | |
}else if (index == kBottomMenuTitle1){ | |
line = [[UIView alloc]initWithFrame:CGRectMake(170, cell.title.frame.origin.y + cell.title.frame.size.height /2, cell.frame.size.width, 1)]; | |
}else{ | |
line = [[UIView alloc]initWithFrame:CGRectMake(130, cell.title.frame.origin.y + cell.title.frame.size.height /2, cell.frame.size.width, 1)]; | |
} | |
line.backgroundColor = [UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:0.5]; | |
[cell addSubview:line]; | |
} | |
UIView* cellBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)]; | |
[cellBack setBackgroundColor:[UIColor colorWithRed:28/255.0 green:134/255.0 blue:238/255.0 alpha:1.0]]; | |
[cell setSelectedBackgroundView:cellBack]; | |
return cell; | |
} | |
} | |
//CELL SELECTION | |
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
UIViewController *newController = nil; | |
if(indexPath.section == 0){ | |
DSMenuTopTableViewCell *cell = (DSMenuTopTableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; | |
int row = indexPath.row; | |
switch (row) { | |
case kTopMenuRowDiario: | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:16]]; | |
newController = [self contadorViewController]; | |
break; | |
case kTopMenuRowEvolution: | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:16]]; | |
newController = [self evolutionViewController]; | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar evolução" | |
properties:@{@"Origem": @"Menu"}]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"HideKeyboardViewFromEvolution" object:nil]; | |
break; | |
case kTopMenuRowChat: | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:16]]; | |
if ([[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP]) { | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar chat" | |
properties:@{@"Tipo": @"Nutricional"}]; | |
newController = [self chatViewController]; | |
[[DSTracker sharedInstance] trackEventAction:@"open" category:@"chat" label:@"gaveta"]; | |
} else { | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar chat" | |
properties:@{@"Tipo": @"Assinaturas"}]; | |
[DSAssinaturaViewController presentWebViewModallyWithFluxo:@"nutricional" andViewController:self]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; | |
} | |
break; | |
case kTopMenuRowCardapio: | |
[(UILabel*)[cell viewWithTag:1] setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:16]]; | |
if ([[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP]) { | |
[[SEGAnalytics sharedAnalytics] track:@"Ver cardápio" | |
properties:@{@"Tipo": @"Menu"}]; | |
newController = [self cardapioViewController]; | |
[[DSTracker sharedInstance] trackEventAction:@"open" category:@"cardapio" label:@""]; | |
} else { | |
[DSAssinaturaViewController presentWebViewModallyWithFluxo:@"cardapio" andViewController:self]; | |
[cell.title setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; | |
} | |
break; | |
default: | |
break; | |
} | |
}else { | |
NSString *url; | |
int index; | |
if ([self isUsuarioAssinantePago]) { | |
index = indexPath.row; | |
}else{ | |
index = indexPath.row + 4; | |
} | |
switch (index) { | |
case kBottomMenuRowChatComNutri: | |
if ([[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP]) { | |
newController = [self chatViewController]; | |
[[DSTracker sharedInstance] trackEventAction:@"open" category:@"chat" label:@"gaveta"]; | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar chat" | |
properties:@{@"Tipo": @"Nutricional"}]; | |
} else { | |
[DSAssinaturaViewController presentWebViewModallyWithFluxo:@"nutricional" andViewController:self]; | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar chat" | |
properties:@{@"Tipo": @"Assinaturas"}]; | |
} | |
break; | |
case kBottomMenuRowDuvidasNutri: | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar FAQ" | |
properties:@{@"Tipo": @"Nutricional"}]; | |
[self duvidasNutricionaisViewController]; | |
break; | |
case kBottomMenuRowDuvidasFit: | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar FAQ" | |
properties:@{@"Tipo": @"Fitness"}]; | |
[self duvidasFitnessViewController]; | |
break; | |
case kBottomMenuRowConfiguracoes: | |
[self didClickConfiguracoes:nil]; | |
break; | |
case kBottomMenuRowLembretes: | |
[self didClickLembretes:nil]; | |
break; | |
case kBottomMenuRowMetodologia: | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar FAQ" | |
properties:@{@"Tipo": @"Metodologia"}]; | |
url = URL_METODOLOGIA; | |
[[DSTracker sharedInstance] trackPageView:@"metodologiads"]; | |
[self showWebViewWithUrl:url]; | |
break; | |
case kBottomMenuRowNossaEquipe: | |
url = URL_NOSSA_EQUIPE; | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar FAQ" | |
properties:@{@"Tipo": @"Equipe"}]; | |
[[DSTracker sharedInstance] trackPageView:@"equipeds"]; | |
[self showWebViewWithUrl:url]; | |
break; | |
case kBottomMenuRowFaleConosco: | |
[[SEGAnalytics sharedAnalytics] track:@"Acessar FAQ" | |
properties:@{@"Tipo": @"Assinaturas"}]; | |
url = [self getContatoUrl]; | |
// Tracking | |
[[DSTracker sharedInstance] trackPageView:@"faq"]; | |
[self showWebViewWithUrl:url]; | |
break; | |
default: | |
break; | |
} | |
} | |
if (newController) { | |
[self changeTopViewController:newController]; | |
} | |
} | |
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
if (indexPath.section == 0) { | |
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
[(UILabel*)[cell viewWithTag:1] setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; | |
} | |
// if (self.tableviewBottom != tableView) { | |
// | |
// } | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ | |
if (indexPath.section == 0) { | |
return 43.0; | |
} | |
if ([self isUsuarioAssinantePago]) { | |
if ([self isUsuarioEconomico]){ | |
if (indexPath.row == kBottomMenuRowChatComNutri || indexPath.row == kBottomMenuRowDuvidasFit) { | |
return 0; | |
} | |
} | |
} | |
return 43.0; | |
} | |
-(void) changeTopViewToDiary { | |
[self presentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"contador"] animated:YES completion:nil]; | |
} | |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { | |
return [[UIView alloc] init]; | |
} | |
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { | |
// if(self.tableviewMenu == tableView) { | |
// return tableView.sectionHeaderHeight; | |
// } | |
return 0; | |
} | |
- (UIImage *)getCardapioIconImage:(BOOL)on { | |
return [UIImage imageNamed:[NSString stringWithFormat:@"icone_cardapios_%@", (on ? @"on" : @"off")]]; | |
} | |
- (UIImage *)getEvolutionIconImage:(BOOL)on { | |
return [UIImage imageNamed:[NSString stringWithFormat:@"icone_evolucao_%@.png", (on ? @"on" : @"off")]]; | |
} | |
- (UIImage *)getDiaryIconImage:(BOOL)on { | |
return [UIImage imageNamed:[NSString stringWithFormat:@"icone_diarios_%@.png", (on ? @"on" : @"off")]]; | |
} | |
- (UIImage *)getChatIconImage:(BOOL)on { | |
return [UIImage imageNamed:[NSString stringWithFormat:@"icone_chat_%@.png", (on ? @"on" : @"off")]]; | |
} | |
- (NSString *)getLinkedUrl:(NSString *)url { | |
Usuario *usuarioAtual = [[DSUsuarioModel sharedInstance] currentUser]; | |
NSString *completed = [[NSString stringWithFormat:url, | |
usuarioAtual.nome, | |
usuarioAtual.email, | |
[usuarioAtual.tipoUsuario stringValue], | |
[NSString stringWithFormat:@"%@|%@", [UIDevice currentDevice].name, [UIDevice currentDevice].systemVersion], | |
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
return completed; | |
} | |
#pragma mark - ViewController Getters | |
- (UIViewController *)currentFrontViewController { | |
UIViewController *vc = (self.slidingViewController) ? self.slidingViewController.topViewController : self.revealController.frontViewController; | |
return vc; | |
} | |
-(UIViewController*)contadorViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSDiaryViewController class]] == NO) { | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contador"]; | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController*)receitasViewController { | |
return [[DSFerramentasReceitaViewController_ipad alloc]init]; | |
} | |
-(UIViewController*)newContadorViewController { | |
return [self.storyboard instantiateViewControllerWithIdentifier:@"contador"]; | |
} | |
- (UIViewController *)findRootViewControllerFromViewController:(UIViewController *)currentViewController { | |
UIViewController *topViewController = currentViewController; | |
if([currentViewController isKindOfClass:[UINavigationController class]]){ | |
//Se for uma NavigationController, pega a rootViewController | |
topViewController = [((UINavigationController*)topViewController) viewControllers][0]; | |
} | |
return topViewController; | |
} | |
-(UIViewController*)evolutionViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSEvolucaoViewController class]] == NO) { | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"evolucao"]; | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController *)atualizarPesoViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSUpdateWeightViewController class]] == NO) { | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"atualizaPeso"]; | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController*)cacauBlogViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSCacauBlogViewController class]] == NO) { | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"cacauBlog"]; | |
} else { | |
DSCacauBlogViewController* cacauVC = (DSCacauBlogViewController*)topViewController; | |
[cacauVC reloadMainURL]; | |
} | |
return frontRootViewController;} | |
-(UIViewController*)configurationViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if([topViewController isKindOfClass:[DSConfigurationTableViewController class]] == NO){ | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"configuration"]; | |
// Tudo isso pois a view de config está embedada | |
DSConfigurationTableViewController *configurationView = [[(UINavigationController *)frontRootViewController viewControllers] firstObject]; | |
configurationView.delegate = self; | |
[frontRootViewController performSelector:@selector(setDelegate:) withObject:self]; | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController*)lembretesViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if([topViewController isKindOfClass:[DSRemindersTableViewController class]] == NO){ | |
frontRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"reminders"]; | |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
// Tudo isso pois a view de config está embedada | |
DSRemindersTableViewController *remindersView = [[(UINavigationController *)frontRootViewController viewControllers] firstObject]; | |
remindersView.delegate = self; | |
[frontRootViewController performSelector:@selector(setDelegate:) withObject:self]; | |
return frontRootViewController; | |
} else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ | |
((DSRemindersTableViewController *) frontRootViewController).delegate = self; | |
[frontRootViewController performSelector:@selector(setDelegate:) withObject:self]; | |
return [self navigationControllerWithRootViewController:frontRootViewController]; | |
} | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController*)loginViewController { | |
DSLoginViewController *topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"login"]; | |
[topViewController setDelegate:self]; | |
return topViewController; | |
} | |
-(UIViewController*)avaliacaoViewController { | |
// return [self.storyboard instantiateViewControllerWithIdentifier:@"contador"]; | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
//Se a viewcontroller não for da classe de contador, instancia de novo a classe do contador :) | |
if([topViewController isKindOfClass:[MinhaAvaliacaoTabBarViewController class]] == NO){ | |
frontRootViewController = [self navigationControllerWithRootViewController:[[MinhaAvaliacaoTabBarViewController alloc] init]]; | |
} | |
return frontRootViewController; | |
} | |
- (UIViewController *)duvidasViewController { | |
return nil; | |
} | |
- (void)duvidasNutricionaisViewController { | |
NSString *url_nutricional = [self getLinkedUrl:URL_FAQ_NUTRICIONAL]; | |
WebViewModalViewController *view = [[WebViewModalViewController alloc] initWithURLString:url_nutricional andWithButtonText:@"Fechar"]; | |
[self presentViewController:view animated:YES completion:NULL]; | |
} | |
- (void)duvidasFitnessViewController { | |
NSString *url_personal = [self getLinkedUrl:URL_FAQ_PERSONAL]; | |
WebViewModalViewController *view = [[WebViewModalViewController alloc] initWithURLString:url_personal andWithButtonText:@"Fechar"]; | |
[self presentViewController:view animated:YES completion:NULL]; | |
} | |
-(UIViewController*)chatViewController{ | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSChatViewController class]] == NO) { | |
frontRootViewController = [self navigationControllerWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"chat"]]; | |
} | |
return frontRootViewController; | |
} | |
-(UIViewController*)cardapioViewController { | |
UIViewController *frontRootViewController = [self currentFrontViewController]; | |
UIViewController *topViewController= [self findRootViewControllerFromViewController:frontRootViewController]; | |
if ([topViewController isKindOfClass:[DSCardapioViewController class]] == NO) { | |
frontRootViewController = [self navigationControllerWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"cardapio"]]; | |
} | |
return frontRootViewController; | |
} | |
#pragma mark - Signature Method | |
- (void)showAssinaturaViewController:(NSString *)sourceId { | |
//Chama o método estático que cria e já apresenta a viewController da assinatura | |
NSString* fluxo = nil; | |
NSString* afiliado = nil; | |
NSString* link = nil; | |
if ([self.params count] >= 4) { | |
if ([self.params objectAtIndex:1]) { | |
fluxo = [self.params objectAtIndex:1]; | |
} | |
if ([self.params objectAtIndex:2]) { | |
afiliado = [self.params objectAtIndex:2]; | |
} | |
if ([self.params objectAtIndex:3]) { | |
link = [self.params objectAtIndex:3]; | |
} | |
} | |
[DSAssinaturaViewController presentModallyFromViewController:self | |
animated:YES | |
sourceId:sourceId | |
fluxoName:fluxo | |
idAfiliado:afiliado | |
idLink:link | |
closeBlock:^(BOOL showLogin) { | |
BOOL animate = !showLogin; | |
[self.presentedViewController dismissViewControllerAnimated:(animate) completion:^{ | |
if(showLogin){ | |
//Open login screen logging in the user! | |
Usuario *user = [[DSUsuarioModel sharedInstance] currentUser]; | |
NSString *email = user.email; | |
NSString *passw = user.senha; | |
[self showLoginViewControllerWithEmail:email password:passw]; | |
} | |
}]; | |
}]; | |
} | |
#pragma mark - Login behaviours | |
-(void)showLoginViewControllerWithEmail:(NSString*)email password:(NSString*)password { | |
DSLoginViewController *vc = (DSLoginViewController *)[self loginViewController]; | |
[vc setDelegate:self]; | |
if(email != nil && password != nil){ | |
[vc setAutoLoginWithEmail:email password:password]; | |
} | |
[self presentViewController:vc animated:NO completion:NULL]; | |
} | |
-(void)loginAccepted { | |
//Reload na view :) | |
[self startView]; | |
//instancia uma nova viewController do diario de pontos para forçar o reload na view nova | |
[self changeTopViewController:[self newContadorViewController]]; | |
[self.tableviewMenu reloadData]; | |
[self.presentedViewController dismissViewControllerAnimated:NO completion:nil]; | |
[self baixarUltimasAtualizacoesDoUsuario]; | |
} | |
-(void)loginCancelled{} //Do Nothing :) | |
-(void)loginClosed{} //Do Nothing :) | |
#pragma mark - Update UI from User Updated Data download | |
- (void)baixarUltimasAtualizacoesDoUsuario { | |
// Indica que as informações adicionais precisam ser baixadas | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
[defaults setBool:NO forKey:DEFAULTS_INFORMACOES_ATUALIZADAS]; | |
[defaults synchronize]; | |
//Pega as ultimas atualizações do usuário e coloca nas propriedades da classe | |
[[DSUsuarioModel sharedInstance] baixarUltimasAtualizacoesWithCompletionBlock:^{ | |
MVLog(@"Atualizações do usuário baixadas com sucesso!"); | |
}]; | |
} | |
#pragma mark - Private Methods | |
- (void)loadBanner { | |
if ([self isUsuarioAssinantePago]) { | |
self.bannerContainer.hidden = YES; | |
} | |
NSLog(@"LOAD BANNER !!!"); | |
self.bannerManager = [[DSAdBannerManager alloc] initWithViewController:self failBlock:^(GADBannerView *view, GADRequestError *error) { | |
MVLog(@"DFP fail: %@", error.debugDescription); | |
} andAppEventBlock:^(GADBannerView *view, NSString *name, NSArray *info) { | |
if (info.count > 0 && [name isEqualToString:DFP_EVENT_NAME]) { | |
self.params = [NSArray arrayWithArray:info]; | |
[self showAdView]; | |
} | |
}]; | |
// Parâmetros para o DFP | |
NSDictionary *extras = [self getDFPExtraData]; | |
[self.bannerManager loadBanner:self.haveMoreButton adUnitId:kDSAdUnitIdBanner andBannerType:DSAdBannerManagerBannerTypeMenu andExtras:extras]; | |
} | |
- (NSDictionary *)getDFPExtraData { | |
// Passando o tipo do usuário para direcionar a campanha no DFP | |
Usuario *usuario = [[DSUsuarioModel sharedInstance] currentUser]; | |
NSString *diarNoPrograma = [@([[DSUsuarioModel sharedInstance] getDaysFromEvaluation]) stringValue]; | |
return @{@"tipo" : usuario.codigoRole.stringValue, @"dias_no_programa" : diarNoPrograma }; | |
} | |
- (void)showAdView { | |
if([self isUsuarioAssinantePago]){ | |
[self showLivroSellingPageViewController]; | |
} else { | |
[self showAssinaturaViewController:@"Banner"]; | |
} | |
[[DSTracker sharedInstance] trackEventAction:@"click_gaveta" category:@"Anúncio" label:@""]; | |
} | |
-(void)showLivroSellingPageViewController { | |
WebViewModalViewController *view = [[WebViewModalViewController alloc] initWithURLString:@"http://www.dietaesaude.com.br/avaliacao/redirect/Livro%20de%20Receitas/" andWithButtonText:@"Fechar"]; | |
[self presentViewController:view animated:YES completion:NULL]; | |
} | |
- (void)showWebViewWithUrl:(NSString *)url { | |
WebViewModalViewController *view = [[WebViewModalViewController alloc] initWithURLString:url andWithButtonText:@"Fechar"]; | |
[self presentViewController:view animated:YES completion:NULL]; | |
} | |
- (NSString *)getContatoUrl { | |
Usuario *usuarioAtual = [[DSUsuarioModel sharedInstance] currentUser]; | |
NSString *url = [[NSString stringWithFormat:URL_FAQ, | |
[[DSUsuarioModel sharedInstance] isUsuarioAssinanteVIP] ? @"central" : @"mobilegratuito", | |
usuarioAtual.nome, | |
usuarioAtual.email, | |
[usuarioAtual.tipoUsuario stringValue], | |
[NSString stringWithFormat:@"%@|%@", [UIDevice currentDevice].model, [UIDevice currentDevice].systemVersion], | |
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
return url; | |
} | |
- (void)configurationTableViewLogout { | |
[self logout]; | |
} | |
- (void)remindersTableViewLogout{ | |
[self logout]; | |
} | |
- (void)checkRemoteNotification { | |
enum DSNotificationManagerViewType viewType; | |
viewType = [[DSNotificationManager sharedInstance] checkViewQueue]; | |
switch (viewType) { | |
case DSNotificationManagerViewTypeDiario: | |
break; | |
case DSNotificationManagerViewTypeEvolucao: | |
[self changeTopViewController:[self evolutionViewController]]; | |
break; | |
case DSNotificationManagerViewTypePeso: | |
[self presentViewController:[self navigationControllerWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"atualizaPeso"]] animated:YES completion:nil]; | |
default: | |
break; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment