JDViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. [self addSocketDataReceive];
  33. }
  34. -(void)viewWillDisappear:(BOOL)animated
  35. {
  36. [super viewWillDisappear:animated];
  37. [self removeSocketDataReceive];
  38. }
  39. - (void)initUIOnSuper {
  40. }
  41. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  42. tableView.dataSource = self;
  43. tableView.delegate = self;
  44. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  45. tableView.backgroundColor = [UIColor clearColor];
  46. // tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)]; //this call table events;
  47. }
  48. - (void)prepareViewDidLoadOnSuper {
  49. }
  50. - (UIButton *)generateOptionButton {
  51. UIImage *image = [UIImage imageNamed:@"common_head_btn_more"];
  52. UIImage *imagePress = [UIImage imageNamed:@"common_head_btn_more_press"];
  53. CGRect btnFrame = CGRectMake(0, 0, image.size.width, image.size.height);
  54. UIButton *button = [[UIButton alloc] initWithFrame:btnFrame];
  55. button.tag = 9003;
  56. [button setImage:image forState:UIControlStateNormal];
  57. [button setImage:imagePress forState:UIControlStateHighlighted];
  58. [button addTarget:self action:@selector(toggleOptions:) forControlEvents:UIControlEventTouchUpInside];
  59. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
  60. self.navigationItem.rightBarButtonItem = item;
  61. return button;
  62. }
  63. - (void)toggleOptionsWithArray:(id)sender btnArray:(NSArray *)btnArray
  64. {
  65. UIButton *moreBtn = (UIButton *)sender;
  66. if (!_poc){
  67. _MoreVc = (MorePopOverViewController *)[CommonUtil
  68. instantiateViewControllerWithIdentifier:@"MorePopOverViewController"
  69. storyboardName:@"Common"];
  70. _MoreVc.delegate = self;
  71. _poc = [[WYPopoverController alloc] initWithContentViewController:_MoreVc];
  72. _poc.delegate = self;
  73. [_poc beginThemeUpdates];
  74. _poc.popoverLayoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
  75. _poc.theme.arrowHeight = 0;
  76. _poc.theme.borderWidth = 0;
  77. _poc.theme.innerCornerRadius = 0.0f;
  78. _poc.theme.outerCornerRadius = 0.0f;
  79. _poc.theme.minOuterCornerRadius = 0.0f;
  80. [_poc endThemeUpdates];
  81. [_MoreVc popButtonSet:btnArray];
  82. _MoreVc.poc = _poc;
  83. }
  84. CGRect popRect = moreBtn.bounds;
  85. [_poc presentPopoverFromRect:popRect
  86. inView:moreBtn
  87. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp
  88. animated:YES
  89. options:WYPopoverAnimationOptionFadeWithScale];
  90. }
  91. - (void)toggleOptions:(id)sender {
  92. UIButton *btn = (UIButton *)sender;
  93. if (!_poc) {
  94. _ovc = (OptionPopOverViewController *)[CommonUtil
  95. instantiateViewControllerWithIdentifier:@"OptionPopOverViewController"
  96. storyboardName:@"Common"];
  97. _ovc.dataArray = _popooverOptionArray;
  98. _poc = [[WYPopoverController alloc] initWithContentViewController:_ovc];
  99. _poc.delegate = self;
  100. [_poc beginThemeUpdates];
  101. _poc.popoverLayoutMargins = UIEdgeInsetsMake(10, 0, 0, 0);
  102. _poc.theme.arrowHeight = 0;
  103. _poc.theme.borderWidth = 0;
  104. _poc.theme.usesRoundedArrow = NO;
  105. _poc.theme.arrowBase = 15;
  106. _poc.theme.arrowHeight = 8;
  107. _poc.theme.borderWidth = 0;
  108. // _poc.theme.tintColor = [UIColor darkGrayColor];
  109. _poc.theme.outerStrokeColor = kUILineColor2;
  110. _poc.theme.innerStrokeColor = kUILineColor2;
  111. _poc.theme.innerCornerRadius = 0.0f;
  112. _poc.theme.outerCornerRadius = 0.0f;
  113. _poc.theme.minOuterCornerRadius = 0.0f;
  114. [_poc endThemeUpdates];
  115. // [_MoreVc popButtonSet:none secondType:none thirdType:del fourthType:reload];
  116. _ovc.poc = _poc;
  117. }
  118. // UIBarButtonItem *barButtonItem = self.navigationItem.rightBarButtonItem;
  119. // UIView *itemView = [barButtonItem valueForKey:@"view"];
  120. CGRect popRect = btn.bounds;
  121. // popRect.origin.y = 0.0f;
  122. // [_poc presentPopoverFromRect:popRect inView:btn
  123. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:nil];
  124. [_poc presentPopoverFromRect:popRect
  125. inView:btn
  126. permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp
  127. animated:YES
  128. options:WYPopoverAnimationOptionFadeWithScale];
  129. // [_poc presentPopoverFromRect:popRect inView:btn
  130. // permittedArrowDirections:WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp animated:YES options:WYPopoverAnimationOptionFadeWithScale completion:^{
  131. // [_ovc.tableView reloadData];
  132. // }];
  133. // [_poc presentPopoverFromRect:btn.bounds
  134. // inView:btn
  135. // permittedArrowDirections:WYPopoverArrowDirectionUp
  136. // animated:YES
  137. // options:WYPopoverAnimationOptionFadeWithScale];
  138. }
  139. - (void)resetOptions {
  140. _ovc = nil;
  141. _poc = nil;
  142. }
  143. - (void)dismissOptionPopOver:(void (^)(void))completion {
  144. [_poc dismissPopoverAnimated:YES completion:^{
  145. if (completion) {
  146. completion();
  147. }
  148. }];
  149. }
  150. - (void)sendDataToSocket:(SocketRequestModel *)data
  151. {
  152. // [[SocketServiceHandler sharedManager] sendDataWithDelegate:data delegate:self];
  153. [self sendDataToSocket:data modelClass:nil];
  154. }
  155. - (void)sendDataToSocket:(SocketRequestModel *)data modelClass:(Class)modelClass
  156. {
  157. // [[SocketServiceHandler sharedManager] sendDataWithDelegate:data modelClass:modelClass delegate:self];
  158. [self sendDataToSocket:data modelClass:modelClass isLoading:NO];
  159. }
  160. - (void)sendDataToSocket:(SocketRequestModel *)data modelClass:(Class)modelClass isLoading:(BOOL)isLoading
  161. {
  162. [[SocketServiceHandler sharedManager] sendDataWithDelegate:data modelClass:modelClass delegate:self isShowLoading:isLoading];
  163. }
  164. - (void)sendDataToSocketWithOutDelegate:(SocketRequestModel *)data
  165. {
  166. [[SocketServiceHandler sharedManager] sendDataWihOutDelegate:data];
  167. }
  168. - (void)closeSocket{
  169. [[SocketServiceHandler sharedManager] close];
  170. }
  171. - (BOOL)isSocketConnected
  172. {
  173. return [[SocketServiceHandler sharedManager] isSocketConnected];
  174. }
  175. - (SRReadyState)getSocketStatus
  176. {
  177. return [[SocketServiceHandler sharedManager] getSocketStatus];
  178. }
  179. // Socket BoradCasting
  180. -(void)addSocketDataReceive
  181. {
  182. [self removeSocketDataReceive];
  183. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSocketData:) name:kSocketBoradCast object:nil];
  184. }
  185. -(void)removeSocketDataReceive
  186. {
  187. @try{
  188. [[NSNotificationCenter defaultCenter] removeObserver:self name:kSocketBoradCast object:nil];
  189. }@catch(id anException){
  190. NSLog(@"%@", anException);
  191. }
  192. }
  193. -(void)receiveSocketData:(NSNotification *)notification
  194. {
  195. NSLog(@"receiveSocketData : %@", notification.object);
  196. }
  197. #pragma mark - Main Logic
  198. #pragma mark - UITableView DataSource & Delegate
  199. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  200. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  201. }
  202. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  203. // Remove seperator inset
  204. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  205. [cell setSeparatorInset:UIEdgeInsetsZero];
  206. }
  207. // Prevent the cell from inheriting the Table View's margin settings
  208. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  209. [cell setPreservesSuperviewLayoutMargins:NO];
  210. }
  211. // Explictly set your cell's layout margins
  212. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  213. [cell setLayoutMargins:UIEdgeInsetsZero];
  214. }
  215. }
  216. #pragma mark - UI Events
  217. #pragma mark - MoreButtonDelegate Delegate
  218. #pragma mark - MemoryWarning
  219. - (void)didReceiveMemoryWarning
  220. {
  221. [super didReceiveMemoryWarning];
  222. // Dispose of any resources that can be recreated.
  223. }
  224. @end