| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913 |
- //
- // HomeViewController.m
- // RedAnt ERP Suite
- //
- // Created by Ray on 14-5-23.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "HomeViewController.h"
- #import "RANetwork.h"
- #import "const.h"
- #import "HomeTableViewCellBanner.h"
- #import "DetailViewController.h"
- #import "MainViewController.h"
- #import "HomeTableViewCellButtonBanner.h"
- #import "WebViewController.h"
- #import "ImageUtils.h"
- #import "HomeTableViewCellSlide.h"
- //#import "MainViewController.h"
- @interface HomeViewController ()
- @end
- @implementation HomeViewController
- -(void) dealloc
- {
- DebugLog(@"HOME VIEWCONTROLLER DEALLOC");
- }
- -(void) refresh_on_login
- {
- // do not refresh on login;
- }
- #ifndef RA_NOTIFICATION
- -(void) reload_container_getdata:(bool)update_data
- {
- [super reload_container_getdata:update_data];
- if(update_data)
- [ self LoadData];
- else
- [self.homeTable reloadData];
- }
- #endif
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- if(!CGSizeEqualToSize(self.ori_size, [[UIScreen mainScreen] bounds].size))
- {
- [self.homeTable reloadData];
- }
- // self.content = self.bak_content;
- // [self reload_container_getdata:false];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
-
- self.ori_size=[[UIScreen mainScreen] bounds].size;
- // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
- // self.bak_content = self.content;
- // self.content= nil;
- //// self.homeTable re
- // [self.homeTable reloadData];
-
- }
- -(void)manually_refresh
- {
-
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- if(self.isrefreshing)
- {
- [reF endRefreshing];
- return;
- }
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void) LoadData
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.isrefreshing)
- {
- return;
- }
- self.isrefreshing=true;
- DebugLog(@"HOMEVIEW BEGIN LOAD");
-
- self.mum.hidden = false;
- [self.mum startAnimating];
- self.mum.center = self.view.center;
- self.label_net_err.hidden=true;
-
- self.homeTable.hidden=true;
-
-
- [RANetwork request_home:0 customid:0 completionHandler:^(NSMutableDictionary *result) {
- [self.mum stopAnimating];
- NSMutableDictionary* data=result;
- self.content = data;
- [self.homeTable reloadData];
- self.homeTable.hidden=false;
- if([[data valueForKey:@"result"] intValue]==2)
- {
- DebugLog(@"HOMEVIEW JSON LOADED!");
-
- }
- else
- if([[data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- }
- else
- {
-
- [RAUtils message_box:@"Loading Home" message:[data valueForKey:@"err_msg"] completion:nil];
- }
-
- self.isrefreshing=false;
-
- ;
- }];
- return;
- });
- }
- -(void) ReloadData
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- [self LoadData];
-
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
- self.label_net_err.layer.borderWidth = 2.0;
- self.label_net_err.layer.cornerRadius=15;
- self.label_net_err.layer.masksToBounds=true;
-
-
-
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
-
-
- // [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- [self.homeTable addSubview:ref];
-
-
-
-
-
-
-
- RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.treeContainer.frame];
-
- treeView.delegate = self;
- treeView.dataSource = self;
- treeView.separatorStyle = RATreeViewCellSeparatorStyleSingleLine;
-
- [treeView reloadData];
- // [treeView expandRowForItem:phone withRowAnimation:RATreeViewRowAnimationLeft]; //expands Row
- [treeView setBackgroundColor:UIColorFromRGB(0xF7F7F7)];
-
- self.treeView = treeView;
- [self.treeContainer addSubview:treeView];
-
- // UIApplication * app = [UIApplication sharedApplication];
-
-
-
- }
- //- (void)viewWillAppear:(BOOL)animated
- //{
- // [super viewWillAppear:animated];
- //
- // CGRect rt1 = self.treeContainer.bounds;
- // CGRect rt2 = self.treeContainer.frame;
- //
- //
- //
- // self.treeView.frame = self.treeContainer.bounds;
- //}
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- // CGRect rt = self.treeContainer.bounds;
- // CGRect rt1 = self.treeContainer.frame;
- self.treeView.frame = self.treeContainer.bounds;
-
- // if([[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."][0] intValue] >= 7) {
- // CGRect statusBarViewRect = [[UIApplication sharedApplication] statusBarFrame];
- // float heightPadding = statusBarViewRect.size.height+self.navigationController.navigationBar.frame.size.height;
- // self.treeView.contentInset = UIEdgeInsetsMake(heightPadding, 0.0, 0.0, 0.0);
- // self.treeView.contentOffset = CGPointMake(0.0, -heightPadding);
- // }
-
- // self.homeTable.contentSize = self
- // self.scroll.contentSize = self.contentsize;
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!route!!!!!!!!!!!!!!!!!!!!!");
- // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
- // [self.homeTable reloadData];
- // // CGSize contentsize = self.scroll.contentSize;
- // // contentsize.height =330+2 * 230+29+20+20 +1 * 230+29+20+20 ;
- // // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
- // // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
- // // {
- // // contentsize.height+=250;
- // // }
- // //
- // // self.scroll.contentSize = contentsize;
- // // // CGRect frame = self.view.frame;
- // // // [self.carouselController.view removeFromSuperview];
- // // // wait(2000);
- // // // self.carouselController = [[FPCarouselNonXIBViewController alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 400)];
- // // // [self.view addSubview:self.carouselController.view];
- // // // int i = self.view.subviews.count;
- // // // int b = 0;
- // // // [self.carouselController updateFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- // what ever you want to prepare
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- [self.homeTable reloadData];
- }];
- }
- #pragma mark - Table view data source
- - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
- {
- if([cell isKindOfClass:[HomeTableViewCellSlide class]])
- {
- HomeTableViewCellSlide* slidecell=(HomeTableViewCellSlide*)cell;
- [slidecell.imgScroll stopTimmer];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
- // {
- // self.orientation = orientation;
- // [self.collectionview.collectionViewLayout invalidateLayout];
- // DebugLog(@"routed");
- // }
-
-
- NSDictionary* view_json = [self.content objectForKey:[NSString stringWithFormat:@"view_%ld",(long)indexPath.section ]];
-
- NSString* type = [view_json valueForKeyPath:@"type"];
- if([type isEqualToString:@"slideview"])
- {
- // if(UIInterfaceOrientationIsPortrait(orientation))
- // return 400;
- // else
- // return 533;
-
-
- // int i_width = 981;
- // int i_height = 512;
-
- int i_width = [[view_json valueForKey:@"width"]intValue];
- int i_height = [[view_json valueForKey:@"height"]intValue];
- if(i_width<=0||i_height<=0)
- {
- i_width=981;
-
- i_height=512;
- }
- int ui_height = (tableView.frame.size.width * i_height)/i_width;
- return ui_height;
-
- }
- else if([type isEqualToString:@"topicview"])
- {
- // int item_count =[[view_json valueForKey:@"item_count"] intValue];
- // if(UIInterfaceOrientationIsPortrait(orientation))
- // return item_count/4 * 230 +49;
- return 310;
- }
- else if([type isEqualToString:@"banner"])
- {
- // if(UIInterfaceOrientationIsPortrait(orientation))
- // return 327;//[[view_json valueForKey:@"height"] intValue];
-
- int i_width = 498;
- int i_height = 197;
-
- int ui_height = (tableView.frame.size.width * i_height)/i_width;
- return ui_height;
-
- }
- else if([type isEqualToString:@"button_banner"])
- {
- int i_width = [[view_json valueForKey:@"width"]intValue];
- int i_height = [[view_json valueForKey:@"height"]intValue];
- float ui_height = (tableView.frame.size.width * i_height)/(float)i_width;
- return ui_height;
- }
-
- return 44;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- //-----debug!!
- // if(self.content !=nil)
- // return 2;
- return [[self.content valueForKeyPath:@"count"]intValue];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- return 1;
-
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSDictionary* view_json = [self.content objectForKey:[NSString stringWithFormat:@"view_%ld",(long)indexPath.section ]];
-
- // NSString* type = [view_json valueForKeyPath:@"type"];
-
- NSString* action = [view_json valueForKeyPath:@"action"];
-
- if([action isEqualToString:@"itemSearch"])
- {
- NSString* covertype = [view_json valueForKeyPath:@"covertype"];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
- [main_vc switchToItemSearch:covertype];
- }
-
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- UITableViewCell *cell = nil;
-
- NSDictionary* view_json = [self.content objectForKey:[NSString stringWithFormat:@"view_%ld",(long)indexPath.section ]];
-
- NSString* type = [view_json valueForKeyPath:@"type"];
- if([type isEqualToString:@"slideview"])
- {
- NSString *CellIdentifier = @"HomeTableViewCellSlide";
- cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- HomeTableViewCellSlide* slidecell = (HomeTableViewCellSlide*)cell;
-
- [slidecell.imgScroll stopTimmer];
- [slidecell.imgScroll removeFromSuperview];
- // for(UIView* v in cell.contentView.subviews)
- // {
- // [v removeFromSuperview];
- //
- // }
-
- // int i_width = 981;
- // int i_height = 512;
- //如果模版有高度就用模版设置值,没有则用默认值。
- int i_width = [[view_json valueForKey:@"width"]intValue];
- int i_height = [[view_json valueForKey:@"height"]intValue];
- if(i_width<=0||i_height<=0)
- {
- i_width=981;
- i_height=512;
- }
-
-
- int ui_height = (tableView.frame.size.width * i_height)/i_width;
-
- // HomeTableViewCellSlide* slidecell = (HomeTableViewCellSlide*)cell;
- // imgScroll.tag = 1394;
- //
- //
- // for (UIView *v in cell.contentView.subviews) {
- // if(v.tag==1394)
- // [v removeFromSuperview];
- // }
-
-
-
- CycleScrollView *imgScroll = [[CycleScrollView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, ui_height) animationDuration:5];
-
- imgScroll.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
- int slide_item_count = [[view_json valueForKey:@"count"] intValue];
-
- //imgScroll.frame =CGRectMake(0, 5, width, 300);
- [imgScroll reset];
-
- // [imgScroll animationDuration:5];
- imgScroll.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.1];
-
- for(int i = 0;i<slide_item_count;i++)
- {
- NSDictionary * slide_itemjson =[view_json objectForKey:[NSString stringWithFormat:@"item_%d",i] ];
-
-
- SliderPage * tempview = [[SliderPage alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, ui_height)];
- tempview.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
- NSString* img_url = [slide_itemjson valueForKey:@"img"];
-
-
- tempview.contentMode = UIViewContentModeScaleToFill;
- tempview.img_url = img_url;
- // tempview.url =@"";
- // tempview.action_type = ;
- // tempview.params = ;
-
- [imgScroll addPage:tempview];
-
-
-
- }
-
-
- // return cell;
- // return cell;
- //Capturing strongly warring;
- // __block CycleScrollView *brimgScroll= imgScroll;
-
- // imgScroll.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
- //
- //
- //
- // SliderPage* page =brimgScroll.arr_Pages[pageIndex];
- // [page loadImage];
- //
- //
- //
- // return page ;
- //
- // // UIImageView * v= viewsArray[pageIndex];
- // // return viewsArray[pageIndex];
- // };
- // imgScroll.totalPagesCount = ^NSInteger(void){
- // return brimgScroll.arr_Pages.count; //viewsArray.count;
- // };
- [imgScroll setTotalPagesCount];
- imgScroll.TapActionBlock = ^(NSInteger pageIndex){
- DebugLog(@"点击了第%ld个",(long)pageIndex);
- NSDictionary * item_json =[view_json objectForKey:[NSString stringWithFormat:@"item_%ld",pageIndex] ];
- NSString* action = [item_json valueForKeyPath:@"action"];
-
- [RASingleton sharedInstance].homeClickedItemName = @"slide_view";
-
- // if([action isEqualToString:@"itemSearch"])
- // {
- // [Singleton sharedInstance].homeItemClick = YES;
- // NSString* covertype = [item_json valueForKeyPath:@"covertype"];
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- //
- // [main_vc switchToItemSearch:covertype];
- // }
- // else
- if([action isEqualToString:@"category"])
- {
- [RASingleton sharedInstance].homeItemClick = YES;
- NSString* cid = [item_json valueForKeyPath:@"category_id"];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
- [main_vc switchToCagegory:cid];
- }
-
- };
-
- //
- slidecell.imgScroll = imgScroll;
- // return cell;
- [cell.contentView addSubview:imgScroll];
-
-
-
- }
- else if([type isEqualToString:@"topicview"])
- {
-
- NSString *CellIdentifier = @"HomeTableViewCellTopic";
-
-
-
- // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
- HomeTableViewCellTopic * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.itemdelegate = self;
- cell.related_data = view_json;
- [cell.topicCollectionView reloadData];
-
-
-
-
- NSString * topictitle =[view_json valueForKey:@"title"];
- cell.label_title.text =topictitle;
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }
- else if([type isEqualToString:@"banner"])
- {
-
- NSString *CellIdentifier = @"HomeTableViewCellBanner";
- // cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- //
- // HomeTableViewCellBanner * bannercell=cell;
-
-
-
- HomeTableViewCellBanner * bannercell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];;
- NSString* img_url =[view_json valueForKeyPath:@"img"];
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[ImageUtils load_cached_img:file_name loadFrom:img_url size:bannercell.BannerImageView.frame.size allow_enlarge:false];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- bannercell.BannerImageView.image = img;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- bannercell.BannerImageView.image = img;
- }
- else
- bannercell.BannerImageView.image=[UIImage imageNamed:@"notfound_l"];
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
-
-
-
-
- }
- else if([type isEqualToString:@"button_banner"])
- {
-
-
- // CellIdentifier = @"CommonEditorCellEdit";
- // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- // cell.backgroundColor = [UIColor whiteColor];
- // return cell;
-
- int cell_width = [[view_json valueForKey:@"width"]intValue];
- int cell_height = [[view_json valueForKey:@"height"]intValue];
- float ui_height = (tableView.frame.size.width * cell_height)/(float)cell_width;
- float ui_width = tableView.frame.size.width ;
- NSString *CellIdentifier = @"HomeTableViewCellButtonBanner";
- cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- // HomeTableViewCellButtonBanner * bannercell=(HomeTableViewCellButtonBanner*)cell;
- for(UIView* v in cell.contentView.subviews)
- {
- [v removeFromSuperview];
- }
-
- int count = [[view_json valueForKey:@"count"] intValue];
-
- for(int i_item = 0;i_item<count;i_item++)
- {
- NSDictionary* item_json = [view_json objectForKey:[NSString stringWithFormat:@"item_%d",i_item]];
- int x = [[item_json valueForKey:@"x"]intValue];
- int y = [[item_json valueForKey:@"y"]intValue];
-
- int i_width = [[item_json valueForKey:@"width"]intValue];
- int i_height = [[item_json valueForKey:@"height"]intValue];
-
- float f_width = i_width/(cell_width/ui_width);
- float f_htight = i_height/(cell_height/ui_height);
-
- float fx = x/(cell_width/ui_width);
- float fy = y/(cell_height/ui_height);
- UIButton* btn_item = [[UIButton alloc] initWithFrame:CGRectMake(fx, fy, f_width, f_htight)];
- long tag = indexPath.section*1000+ indexPath.row*100+i_item;
- btn_item.tag = tag;
- [btn_item addTarget:self action:@selector(ButtonBannerClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [cell.contentView addSubview:btn_item];
- NSString* img_url =[item_json valueForKeyPath:@"img"];
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[ImageUtils load_cached_img:file_name loadFrom:img_url size:btn_item.frame.size allow_enlarge:false];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- [btn_item setBackgroundImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- [btn_item setBackgroundImage:img forState:UIControlStateNormal];
- }
- else
- [btn_item setBackgroundImage:[UIImage imageNamed:@"notfound_l"] forState:UIControlStateNormal];
-
- });
- });
-
-
- }
-
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
-
-
- }
- return cell;
-
-
- }
- -(void)ButtonBannerClick:(id)sender{
-
- //这个sender其实就是UIButton,因此通过sender.tag就可以拿到刚才的参数
- int tag = (int)[sender tag];
- int section = tag/1000;
- int row = (tag-section*1000)/100;
- int idx =(tag-section*1000 - row*100);
- NSDictionary* view_json = [self.content objectForKey:[NSString stringWithFormat:@"view_%ld",(long)section ]];
- NSDictionary* item_json = [view_json objectForKey:[NSString stringWithFormat:@"item_%d",idx]];
- NSString* action = [item_json valueForKeyPath:@"action"];
-
- [RASingleton sharedInstance].homeClickedItemName = item_json[@"description"];
-
- if([action isEqualToString:@"itemSearch"])
- {
- [RASingleton sharedInstance].homeItemClick = YES;
- NSString* covertype = [item_json valueForKeyPath:@"covertype"];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
- [main_vc switchToItemSearch:covertype];
- }
- else if([action isEqualToString:@"category"])
- {
- [RASingleton sharedInstance].homeItemClick = YES;
- NSString* cid = [item_json valueForKeyPath:@"category_id"];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
- [main_vc switchToCagegory:cid];
- }
- else if([action isEqualToString:@"webview"])
- {
- NSString* url = [item_json valueForKeyPath:@"url"];
-
-
- NSString* title = [item_json valueForKeyPath:@"title"];
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- //
- //
-
- WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
- ViewController.url = url;
- ViewController.title = title;
-
-
-
- [self.navigationController pushViewController:ViewController animated:YES];
-
- }
-
-
- }
- #pragma mark TreeView Delegate methods
- - (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
- return 47;
- }
- - (NSInteger)treeView:(RATreeView *)treeView indentationLevelForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
- return 3 * treeNodeInfo.treeDepthLevel;
- }
- - (BOOL)treeView:(RATreeView *)treeView shouldExpandItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
- return YES;
- }
- - (BOOL)treeView:(RATreeView *)treeView shouldItemBeExpandedAfterDataReload:(id)item treeDepthLevel:(NSInteger)treeDepthLevel
- {
- if ([item isEqual:self.expanded]) {
- return YES;
- }
-
- return NO;
- }
- - (void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
-
- NSDictionary *data = item;
- int count = [[data valueForKey:@"count"] intValue];
- if(count==0)
- {
- // NSString* category = [data valueForKey:@"id"];
-
- // if (self.CateMenu_delegate && [self.CateMenu_delegate respondsToSelector:@selector(SelectCategory:)]) {
- // [self.CateMenu_delegate SelectCategory:category];
- // }
- // /* MainViewController* pvc = (MainViewController*)self.rootViewController;
- // [pvc switchToCagegory:category];*/
- // [self dismissViewControllerAnimated:YES
- // completion:^{
- // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
- // AppDelegate *app = [[UIApplication sharedApplication] delegate];
- // [app.window removeGestureRecognizer:self.tapGesture];
- // }];
- }
-
- // if (item == nil) {
- // NSDictionary * ret =[self.categoryMenu objectForKey:[NSString stringWithFormat:@"category_%d",index] ];
- //
- // }
- // else
- // data=[data objectForKey:[NSString stringWithFormat:@"category_%d",index]];
- DebugLog(@"menu select %@",data);
- }
- - (void)treeView:(RATreeView *)treeView willDisplayCell:(UITableViewCell *)cell forItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
- if (treeNodeInfo.treeDepthLevel == 0) {
- cell.backgroundColor = UIColorFromRGB(0xF7F7F7);
- } else if (treeNodeInfo.treeDepthLevel == 1) {
- cell.backgroundColor = UIColorFromRGB(0xD1EEFC);
- } else if (treeNodeInfo.treeDepthLevel == 2) {
- cell.backgroundColor = UIColorFromRGB(0xE0F8D8);
- }
- }
- #pragma mark TreeView Data Source
- - (UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
- {
- // NSInteger numberOfChildren = [treeNodeInfo.children count];
-
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
- // if(numberOfChildren>0)
- // cell.detailTextLabel.text = [NSString stringWithFormat:@"Number of children %@", [@(numberOfChildren) stringValue]];
- cell.textLabel.text = [((NSDictionary *)item) valueForKey:@"title"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
- if (treeNodeInfo.treeDepthLevel == 0) {
- cell.detailTextLabel.textColor = [UIColor blackColor];
- }
-
- return cell;
- }
- - (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item
- {
- if (item == nil) {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- return [[appDelegate.categoryMenu valueForKey:@"count" ] intValue];
- // return [self.data count];
- }
-
- NSDictionary* data = item;
- return [[data valueForKey:@"count"] intValue];
- // RADataObject *data = item;
- // return [data.children count];
- }
- - (id)treeView:(RATreeView *)treeView child:(NSInteger)index ofItem:(id)item
- {
- NSDictionary *data = item;
-
- if (item == nil) {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSDictionary * ret =[appDelegate.categoryMenu objectForKey:[NSString stringWithFormat:@"category_%ld",(long)index] ];
- return ret;
- }
-
- return[data objectForKey:[NSString stringWithFormat:@"category_%ld",(long)index]];
- /*
-
- RADataObject *data = item;
- if (item == nil) {
- return [self.data objectAtIndex:index];
- }
-
- return [data.children objectAtIndex:index];
- */
- }
- #pragma mark - Topic cell delegate
- -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
- {
- DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- dvc.product_id=product_id;
- dvc.category_id=category;
- dvc.ispush=true;
- [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
- }
- //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- //
- // MainViewController* pvc = (MainViewController*)self.parentViewController;
- // // [pvc categoryMenuSelected:indexPath.row];
- //}
- - (void)reRefreshView {
- [self.homeTable reloadData];
- }
- #pragma mark - RA_NOTIFICAITON
- -(void) refresh_ui
- {
- [self.homeTable reloadData];
- }
- -(void) reload_data
- {
- [self LoadData];
- }
- @end
|