// // JDViewController.m // kneet2 // // Created by Created by Jason Lee on 10/1/15. // Copyright (c) 2015 ntels. All rights reserved. // #import "CustomTableView.h" #import "OptionPopOverViewController.h" #import "WYPopoverController.h" #import "JDViewController.h" #import "HomeMemberViewController.h" #import "MorePopOverViewController.h" @interface JDViewController () { WYPopoverController *_poc; OptionPopOverViewController *_ovc; MorePopOverViewController *_MoreVc; } @end #pragma mark - Class Definition @implementation JDViewController @synthesize mainView = _mainView; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initUIOnSuper]; [self prepareViewDidLoadOnSuper]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self addSocketDataReceive]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self removeSocketDataReceive]; } - (void)initUIOnSuper { } - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView { tableView.dataSource = self; tableView.delegate = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.backgroundColor = [UIColor clearColor]; // tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)]; //this call table events; } - (void)prepareViewDidLoadOnSuper { } - (UIButton *)generateOptionButton { UIImage *image = [UIImage imageNamed:@"common_head_btn_more"]; UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"]; CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height); UIButton *button = [[UIButton alloc] initWithFrame:btnFrame]; button.tag = 9003; [button setImage:image forState:UIControlStateNormal]; [button setImage:imagePress forState:UIControlStateHighlighted]; [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.rightBarButtonItem = item; return button; } - (void)toggleOptionsWithArray:(id)sender btnArray:(NSArray *)btnArray { UIButton *moreBtn = (UIButton *)sender; if (!_poc){ _MoreVc = (MorePopOverViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"MorePopOverViewController" storyboardName:@"Common"]; _MoreVc.delegate = self; _poc = [[WYPopoverController alloc] initWithContentViewController:_MoreVc]; _poc.delegate = self; [_poc beginThemeUpdates]; _poc.popoverLayoutMargins = UIEdgeInsetsMake(0, 0, 0, 0); _poc.theme.arrowHeight = 0; _poc.theme.borderWidth = 0; _poc.theme.innerCornerRadius = 0.0f; _poc.theme.outerCornerRadius = 0.0f; _poc.theme.minOuterCornerRadius = 0.0f; [_poc endThemeUpdates]; _MoreVc.poc = _poc; } [_MoreVc popButtonSet:btnArray]; CGRect popRect = moreBtn.bounds; [_poc presentPopoverFromRect:popRect inView:moreBtn permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale]; } - (void)toggleOptions:(id)sender { UIButton *btn = (UIButton *)sender; if (!_poc) { _ovc = (OptionPopOverViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"OptionPopOverViewController" storyboardName:@"Common"]; _ovc.dataArray = _popooverOptionArray; _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc]; _poc.delegate = self; [_poc beginThemeUpdates]; _poc.popoverLayoutMargins = UIEdgeInsetsMake(10, 0, 0, 0); _poc.theme.arrowHeight = 0; _poc.theme.borderWidth = 0; _poc.theme.usesRoundedArrow = NO; _poc.theme.arrowBase = 15; _poc.theme.arrowHeight = 8; _poc.theme.borderWidth = 0; // _poc.theme.tintColor = [UIColor darkGrayColor]; _poc.theme.outerStrokeColor = kUILineColor2; _poc.theme.innerStrokeColor = kUILineColor2; _poc.theme.innerCornerRadius = 0.0f; _poc.theme.outerCornerRadius = 0.0f; _poc.theme.minOuterCornerRadius = 0.0f; [_poc endThemeUpdates]; // [_MoreVc popButtonSet:none secondType:none thirdType:del fourthType:reload]; _ovc.poc = _poc; } // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem; // UIView *itemView = [barButtonItem valueForKey:@"view"]; CGRect popRect = btn.bounds; // popRect.origin.y = 0.0f; // [_poc presentPopoverFromRect:popRect inView:btn // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:nil]; [_poc presentPopoverFromRect:popRect inView:btn permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale]; // [_poc presentPopoverFromRect:popRect inView:btn // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{ // [_ovc.tableView reloadData]; // }]; // [_poc presentPopoverFromRect:btn.bounds // inView:btn // permittedArrowDirections:WYPopoverArrowDirectionUp // animated:YES // options:WYPopoverAnimationOptionFadeWithScale]; } - (void)resetOptions { _ovc = nil; _poc = nil; } - (void)dismissOptionPopOver:(void (^)(void))completion { [_poc dismissPopoverAnimated:YES completion:^{ if (completion) { completion(); } }]; } - (void)sendDataToSocket:(SocketRequestModel *)data { // [[SocketServiceHandler sharedManager] sendDataWithDelegate:data delegate:self]; [self sendDataToSocket:data modelClass:nil]; } - (void)sendDataToSocket:(SocketRequestModel *)data modelClass:(Class)modelClass { // [[SocketServiceHandler sharedManager] sendDataWithDelegate:data modelClass:modelClass delegate:self]; [self sendDataToSocket:data modelClass:modelClass isLoading:NO]; } - (void)sendDataToSocket:(SocketRequestModel *)data modelClass:(Class)modelClass isLoading:(BOOL)isLoading { [[SocketServiceHandler sharedManager] sendDataWithDelegate:data modelClass:modelClass delegate:self isShowLoading:isLoading]; } - (void)sendDataToSocketWithOutDelegate:(SocketRequestModel *)data { [[SocketServiceHandler sharedManager] sendDataWihOutDelegate:data]; } - (void)closeSocket{ [[SocketServiceHandler sharedManager] close]; } - (BOOL)isSocketConnected { return [[SocketServiceHandler sharedManager] isSocketConnected]; } - (SRReadyState)getSocketStatus { return [[SocketServiceHandler sharedManager] getSocketStatus]; } // Socket BoradCasting -(void)addSocketDataReceive { [self removeSocketDataReceive]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSocketData:) name:kSocketBoradCast object:nil]; } -(void)removeSocketDataReceive { @try{ [[NSNotificationCenter defaultCenter] removeObserver:self name:kSocketBoradCast object:nil]; }@catch(id anException){ NSLog(@"%@", anException); } } -(void)receiveSocketData:(NSNotification *)notification { //NSLog(@"receiveSocketData : %@", notification.object); } #pragma mark - Main Logic #pragma mark - UITableView DataSource & Delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { // Remove seperator inset if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } // Prevent the cell from inheriting the Table View's margin settings if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) { [cell setPreservesSuperviewLayoutMargins:NO]; } // Explictly set your cell's layout margins if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } } - (void)showTransparencyModalView:(UIViewController *)vc { vc.providesPresentationContextTransitionStyle = YES; vc.definesPresentationContext = YES; [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext]; UIViewController *pvc = self.presentingViewController; [self dismissViewControllerAnimated:NO completion:^{//TODO : UI Confirm with Mr.Mo [pvc presentViewController:vc animated:YES completion:nil]; }]; } - (void)showTransparencyModalView:(UIViewController *)vc removeSelf:(BOOL)removeSelf { vc.providesPresentationContextTransitionStyle = YES; vc.definesPresentationContext = YES; [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext]; if (removeSelf) { UIViewController *pvc = self.presentingViewController; [self dismissViewControllerAnimated:NO completion:^{//TODO : UI Confirm with Mr.Mo [pvc presentViewController:vc animated:YES completion:nil]; }]; } else { [self presentViewController:vc animated:NO completion:nil]; } } #pragma mark - UI Events #pragma mark - MoreButtonDelegate Delegate #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end