JDViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. // JDViewController.m
  3. // kneet2
  4. //
  5. // Created by Created by Jason Lee on 10/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "CustomTableView.h"
  9. #import "OptionPopOverViewController.h"
  10. #import "WYPopoverController.h"
  11. #import "JDViewController.h"
  12. #import "HomeMemberViewController.h"
  13. #import "MorePopOverViewController.h"
  14. @interface JDViewController () <WYPopoverControllerDelegate, UITableViewDataSource, UITableViewDelegate, MoreButtonDelegate, SocketServiceDelegate> {
  15. WYPopoverController *_poc;
  16. OptionPopOverViewController *_ovc;
  17. MorePopOverViewController *_MoreVc;
  18. }
  19. @end
  20. #pragma mark - Class Definition
  21. @implementation JDViewController
  22. @synthesize mainView = _mainView;
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self initUIOnSuper];
  27. [self prepareViewDidLoadOnSuper];
  28. }
  29. - (void)initUIOnSuper {
  30. }
  31. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  32. tableView.dataSource = self;
  33. tableView.delegate = self;
  34. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. tableView.backgroundColor = [UIColor clearColor];
  36. // tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)]; //this call table events;
  37. }
  38. - (void)prepareViewDidLoadOnSuper {
  39. }
  40. - (UIButton *)generateOptionButton {
  41. UIImage *image = [UIImage imageNamed:@"common_head_btn_more"];
  42. UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"];
  43. CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height);
  44. UIButton *button = [[UIButton alloc] initWithFrame:btnFrame];
  45. button.tag = 9003;
  46. [button setImage:image forState:UIControlStateNormal];
  47. [button setImage:imagePress forState:UIControlStateHighlighted];
  48. [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside];
  49. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
  50. self.navigationItem.rightBarButtonItem = item;
  51. return button;
  52. }
  53. - (void)toggleOptionsWithArray:(id)sender btnArray:(NSArray *)btnArray
  54. {
  55. UIButton *moreBtn = (UIButton *)sender;
  56. if (!_poc){
  57. _MoreVc = (MorePopOverViewController *)[CommonUtil
  58. instantiateViewControllerWithIdentifier:@"MorePopOverViewController"
  59. storyboardName:@"Common"];
  60. _MoreVc.delegate = self;
  61. _poc = [[WYPopoverController alloc] initWithContentViewController:_MoreVc];
  62. _poc.delegate = self;
  63. [_poc beginThemeUpdates];
  64. _poc.popoverLayoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
  65. _poc.theme.arrowHeight = 0;
  66. _poc.theme.borderWidth = 0;
  67. _poc.theme.innerCornerRadius = 0.0f;
  68. _poc.theme.outerCornerRadius = 0.0f;
  69. _poc.theme.minOuterCornerRadius = 0.0f;
  70. [_poc endThemeUpdates];
  71. [_MoreVc popButtonSet:btnArray];
  72. _MoreVc.poc = _poc;
  73. }
  74. CGRect popRect = moreBtn.bounds;
  75. [_poc presentPopoverFromRect:popRect
  76. inView:moreBtn
  77. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp
  78. animated:YES
  79. options:WYPopoverAnimationOptionFadeWithScale];
  80. }
  81. - (void)toggleOptions:(id)sender {
  82. UIButton *btn = (UIButton *)sender;
  83. if (!_poc) {
  84. _ovc = (OptionPopOverViewController *)[CommonUtil
  85. instantiateViewControllerWithIdentifier:@"OptionPopOverViewController"
  86. storyboardName:@"Common"];
  87. _ovc.dataArray = _popooverOptionArray;
  88. _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc];
  89. _poc.delegate = self;
  90. [_poc beginThemeUpdates];
  91. _poc.popoverLayoutMargins = UIEdgeInsetsMake(10, 0, 0, 0);
  92. _poc.theme.arrowHeight = 0;
  93. _poc.theme.borderWidth = 0;
  94. _poc.theme.usesRoundedArrow = NO;
  95. _poc.theme.arrowBase = 15;
  96. _poc.theme.arrowHeight = 8;
  97. _poc.theme.borderWidth = 0;
  98. // _poc.theme.tintColor = [UIColor darkGrayColor];
  99. _poc.theme.outerStrokeColor = kUILineColor2;
  100. _poc.theme.innerStrokeColor = kUILineColor2;
  101. _poc.theme.innerCornerRadius = 0.0f;
  102. _poc.theme.outerCornerRadius = 0.0f;
  103. _poc.theme.minOuterCornerRadius = 0.0f;
  104. [_poc endThemeUpdates];
  105. // [_MoreVc popButtonSet:none secondType:none thirdType:del fourthType:reload];
  106. _ovc.poc = _poc;
  107. }
  108. // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem;
  109. // UIView *itemView = [barButtonItem valueForKey:@"view"];
  110. CGRect popRect = btn.bounds;
  111. // popRect.origin.y = 0.0f;
  112. // [_poc presentPopoverFromRect:popRect inView:btn
  113. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:nil];
  114. [_poc presentPopoverFromRect:popRect
  115. inView:btn
  116. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp
  117. animated:YES
  118. options:WYPopoverAnimationOptionFadeWithScale];
  119. // [_poc presentPopoverFromRect:popRect inView:btn
  120. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{
  121. // [_ovc.tableView reloadData];
  122. // }];
  123. // [_poc presentPopoverFromRect:btn.bounds
  124. // inView:btn
  125. // permittedArrowDirections:WYPopoverArrowDirectionUp
  126. // animated:YES
  127. // options:WYPopoverAnimationOptionFadeWithScale];
  128. }
  129. - (void)resetOptions {
  130. _ovc = nil;
  131. _poc = nil;
  132. }
  133. - (void)dismissOptionPopOver:(void (^)(void))completion {
  134. [_poc dismissPopoverAnimated:YES completion:^{
  135. if (completion) {
  136. completion();
  137. }
  138. }];
  139. }
  140. - (void)sendDataToSocket:(NSDictionary *)data
  141. {
  142. [[SocketServiceHandler sharedManager] sendDataWithDelegate:data delegate:self];
  143. }
  144. - (void)sendDataToSocketWithOutDelegate:(NSDictionary *)data
  145. {
  146. [[SocketServiceHandler sharedManager] sendData:data];
  147. }
  148. - (void)closeSocket{
  149. [[SocketServiceHandler sharedManager] close];
  150. }
  151. - (BOOL)isSocketConnected
  152. {
  153. return [[SocketServiceHandler sharedManager] isSocketConnected];
  154. }
  155. - (SRReadyState)getSocketStatus
  156. {
  157. return [[SocketServiceHandler sharedManager] getSocketStatus];
  158. }
  159. #pragma mark - Main Logic
  160. #pragma mark - UITableView DataSource & Delegate
  161. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  162. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  163. }
  164. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  165. // Remove seperator inset
  166. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  167. [cell setSeparatorInset:UIEdgeInsetsZero];
  168. }
  169. // Prevent the cell from inheriting the Table View's margin settings
  170. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  171. [cell setPreservesSuperviewLayoutMargins:NO];
  172. }
  173. // Explictly set your cell's layout margins
  174. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  175. [cell setLayoutMargins:UIEdgeInsetsZero];
  176. }
  177. }
  178. #pragma mark - UI Events
  179. #pragma mark - MoreButtonDelegate Delegate
  180. #pragma mark - MemoryWarning
  181. - (void)didReceiveMemoryWarning
  182. {
  183. [super didReceiveMemoryWarning];
  184. // Dispose of any resources that can be recreated.
  185. }
  186. @end