Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. #import "MMHomeViewController.h"
  2. #import "MMCoinTableViewCell.h"
  3. #import "MMWatchListProtocol.h"
  4. #import "MMCoinModel.h"
  5. #import "MMConstants.h"
  6. #import <VPSocketIO/VPSocketIO.h>
  7.  
  8. @interface MMHomeViewController ()<MMWatchListProtocol> {
  9. VPSocketIOClient *socket;
  10. }
  11.  
  12. @property (weak, nonatomic) IBOutlet UIButton *allButton;
  13. @property (weak, nonatomic) IBOutlet UIButton *watchlistButton;
  14. @property (weak, nonatomic) IBOutlet UIButton *moversButton;
  15. @property (weak, nonatomic) IBOutlet UIButton *losersButton;
  16.  
  17. @property (weak, nonatomic) IBOutlet UITableView *coinTable;
  18. @property (strong, nonatomic) NSMutableArray *coinArrayTest;
  19.  
  20. @end
  21.  
  22. @implementation MMHomeViewController
  23.  
  24. - (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  25. {
  26. self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
  27. if(self)
  28. {
  29. self.title = mCryptos;
  30. self.tabBarItem.image = [UIImage imageNamed: @"CryptosLogo"];
  31. self.tabBarItem.selectedImage = [UIImage imageNamed: @"CryptosLogo"];
  32. }
  33.  
  34. return self;
  35. }
  36.  
  37. - (IBAction)allButtonAction:(UIButton *)sender
  38. {
  39. [self.allButton setEnabled: NO];
  40. [self.watchlistButton setEnabled: YES];
  41. [self.moversButton setEnabled: YES];
  42. [self.losersButton setEnabled: YES];
  43. }
  44.  
  45. - (IBAction)watchlistButtonAction:(UIButton *)sender
  46. {
  47. [self.allButton setEnabled: YES];
  48. [self.watchlistButton setEnabled: NO];
  49. [self.moversButton setEnabled: YES];
  50. [self.losersButton setEnabled: YES];
  51. }
  52.  
  53. - (IBAction)moversButtonAction:(UIButton *)sender
  54. {
  55. [self.allButton setEnabled: YES];
  56. [self.watchlistButton setEnabled: YES];
  57. [self.moversButton setEnabled: NO];
  58. [self.losersButton setEnabled: YES];
  59. }
  60.  
  61. - (IBAction)losersButtonAction:(UIButton *)sender
  62. {
  63. [self.allButton setEnabled: YES];
  64. [self.watchlistButton setEnabled: YES];
  65. [self.moversButton setEnabled: YES];
  66. [self.losersButton setEnabled: NO];
  67. }
  68.  
  69. - (void)viewDidLoad
  70. {
  71. [super viewDidLoad];
  72. //[self createDummyData];
  73. VPSocketLogger*logger = [VPSocketLogger new];
  74. NSString *urlString = @"https://mcafeemarketcap.com:443";
  75. NSDictionary *connectParams = @{@"EIO":@"3"};
  76. self->socket = [[VPSocketIOClient alloc] init:[NSURL URLWithString:urlString]
  77. withConfig:@{@"log": @YES,
  78. @"forcePolling": @YES,
  79. @"secure": @YES,
  80. @"forceNew":@YES,
  81. @"forceWebsockets":@NO,
  82. @"selfSigned":@YES,
  83. @"reconnectWait":@1000,
  84. //@"nsp":@"/socket.io",
  85. @"connectParams":connectParams,
  86. @"logger":logger
  87. }];
  88.  
  89.  
  90. [socket on:kSocketEventConnect callback:^(NSArray *array, VPSocketAckEmitter *emitter) {
  91. NSLog(@"!!!!socket connected");
  92. }];
  93.  
  94. [socket on:@"coins prices update" callback:^(NSArray *data, VPSocketAckEmitter *emitter) {
  95. if(data.count > 0)
  96. {
  97. }
  98. }];
  99.  
  100. [socket connect];
  101. }
  102.  
  103. - (MMCoinTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. MMCoinTableViewCell *cell = (MMCoinTableViewCell *)[tableView dequeueReusableCellWithIdentifier: mCoinCellIdentifier];
  106.  
  107. if (cell == nil)
  108. {
  109. cell = [[[NSBundle mainBundle] loadNibNamed: mCoinTableCell
  110. owner: self
  111. options: nil] objectAtIndex: 0];
  112. }
  113.  
  114. MMCoinModel *currentCoin = [self.coinArrayTest objectAtIndex: indexPath.row];
  115. cell.coinIcon = currentCoin.coinImage;
  116. cell.coinName.text = currentCoin.coinName;
  117. cell.coinPrice.text = currentCoin.coinPrice;
  118. cell.percentageChange.text = currentCoin.percentageChange;
  119. cell.indexPath = indexPath;
  120. cell.favoritesButton.watchListDelegate = self;
  121.  
  122. return cell;
  123. }
  124.  
  125. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  126. {
  127. return 10;
  128. }
  129.  
  130. - (void)addToWatchList:(NSIndexPath *)indexPath
  131. {
  132. NSLog(@"WatchList!");
  133. }
  134.  
  135. - (void)createDummyData
  136. {
  137. self.coinArrayTest = [NSMutableArray new];
  138. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"BTC" coinPrice: @"12,244.43" percentChange: @"12.7%"]];
  139. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"ETH" coinPrice: @"600.13" percentChange: @"0.7%"]];
  140. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"LTC" coinPrice: @"125.12" percentChange: @"1.7%"]];
  141. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"ADA" coinPrice: @"0.37" percentChange: @"2.0%"]];
  142. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"XLM" coinPrice: @"0.44" percentChange: @"14.2%"]];
  143. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"ETC" coinPrice: @"14.23" percentChange: @"3.3%"]];
  144. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"SUB" coinPrice: @"0.51" percentChange: @"6.9%"]];
  145. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"DGX" coinPrice: @"122.12" percentChange: @"4.2%"]];
  146. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"DOGE" coinPrice: @"0.0001" percentChange: @"1.1%"]];
  147. [self.coinArrayTest addObject: [[MMCoinModel alloc] initWithImage: nil name: @"ETN" coinPrice: @"0.27" percentChange: @"17.7%"]];
  148. }
  149.  
  150. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement