DiscoverViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // DiscoverViewController.m
  3. // Wildfire Chat
  4. //
  5. // Created by WF Chat on 2017/10/28.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "DiscoverViewController.h"
  9. #import "ChatroomListViewController.h"
  10. #import "DeviceTableViewController.h"
  11. #import <WFChatUIKit/WFChatUIKit.h>
  12. #import <WFChatClient/WFCCIMService.h>
  13. #import "DiscoverMomentsTableViewCell.h"
  14. #ifdef WFC_MOMENTS
  15. #import <WFMomentClient/WFMomentClient.h>
  16. #import <WFMomentUIKit/WFMomentUIKit.h>
  17. #endif
  18. #import "UIFont+YH.h"
  19. #import "UIColor+YH.h"
  20. @interface DiscoverViewController () <UITableViewDataSource, UITableViewDelegate>
  21. @property (nonatomic, strong)UITableView *tableView;
  22. @property (nonatomic, assign)BOOL hasMoments;
  23. @property (nonatomic, strong)NSMutableArray *dataSource;
  24. @end
  25. @implementation DiscoverViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.dataSource = [NSMutableArray arrayWithArray:@[@{@"title":LocalizedString(@"Chatroom"),@"image":@"discover_chatroom",@"des":@"chatroom"},
  29. @{@"title":LocalizedString(@"Rebot"),@"image":@"rebot",@"des":@"rebot"},
  30. @{@"title":LocalizedString(@"Channel"),
  31. @"image":@"chat_channel",@"des":@"channel"},
  32. @{@"title":LocalizedString(@"DevDocs"),
  33. @"image":@"dev_docs",@"des":@"Dev"},@{@"title":@"Things",
  34. @"image":@"discover_things",@"des":@"Things"},@{@"title":@"Conference",
  35. @"image":@"discover_things",@"des":@"Conference"}]];
  36. if(NSClassFromString(@"SDTimeLineTableViewController")) {
  37. [self.dataSource insertObject:@{@"title":LocalizedString(@"Moments"),@"image":@"AlbumReflashIcon",@"des":@"moment"} atIndex:0];
  38. self.hasMoments = YES;
  39. } else {
  40. self.hasMoments = NO;
  41. }
  42. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  43. self.tableView.delegate = self;
  44. self.tableView.dataSource = self;
  45. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.01)];
  46. [self.tableView reloadData];
  47. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  48. [self.view addSubview:self.tableView];
  49. #ifdef WFC_MOMENTS
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveComments:) name:kReceiveComments object:nil];
  51. #endif
  52. }
  53. - (void)onReceiveComments:(NSNotification *)notification {
  54. [self.tableView reloadData];
  55. }
  56. - (void)didReceiveMemoryWarning {
  57. [super didReceiveMemoryWarning];
  58. // Dispose of any resources that can be recreated.
  59. }
  60. - (void)viewWillAppear:(BOOL)animated {
  61. [super viewWillAppear:animated];
  62. [self updateUnreadStatus];
  63. }
  64. - (void)updateUnreadStatus {
  65. [self.tableView reloadData];
  66. #ifdef WFC_MOMENTS
  67. [self.tabBarController.tabBar showBadgeOnItemIndex:2 badgeValue:[[WFMomentService sharedService] getUnreadCount]];
  68. #endif
  69. }
  70. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  71. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 9)];
  72. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  73. return view;
  74. }
  75. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  76. return 9;
  77. }
  78. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. return 53;
  80. }
  81. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  82. NSString *des = self.dataSource[indexPath.section][@"des"];
  83. if ([des isEqualToString:@"moment"]) {
  84. UIViewController *vc = [[NSClassFromString(@"SDTimeLineTableViewController") alloc] init];
  85. vc.hidesBottomBarWhenPushed = YES;
  86. [self.navigationController pushViewController:vc animated:YES];
  87. }
  88. if ([des isEqualToString:@"chatroom"]) {
  89. ChatroomListViewController *vc = [[ChatroomListViewController alloc] init];
  90. vc.hidesBottomBarWhenPushed = YES;
  91. [self.navigationController pushViewController:vc animated:YES];
  92. }
  93. if ([des isEqualToString:@"channel"]) {
  94. WFCUFavChannelTableViewController *channelVC = [[WFCUFavChannelTableViewController alloc] init];;
  95. channelVC.hidesBottomBarWhenPushed = YES;
  96. [self.navigationController pushViewController:channelVC animated:YES];
  97. }
  98. if ([des isEqualToString:@"rebot"]) {
  99. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  100. mvc.conversation = [[WFCCConversation alloc] init];
  101. mvc.conversation.type = Single_Type;
  102. mvc.conversation.target = @"FireRobot";
  103. mvc.conversation.line = 0;
  104. mvc.hidesBottomBarWhenPushed = YES;
  105. [self.navigationController pushViewController:mvc animated:YES];
  106. }
  107. if ([des isEqualToString:@"Dev"]) {
  108. WFCUBrowserViewController *vc = [[WFCUBrowserViewController alloc] init];
  109. vc.hidesBottomBarWhenPushed = YES;
  110. vc.url = @"http://docs.wildfirechat.cn";
  111. [self.navigationController pushViewController:vc animated:YES];
  112. }
  113. if ([des isEqualToString:@"Things"]) {
  114. DeviceTableViewController *vc = [[DeviceTableViewController alloc] init];
  115. vc.hidesBottomBarWhenPushed = YES;
  116. [self.navigationController pushViewController:vc animated:YES];
  117. }
  118. if ([des isEqualToString:@"Conference"]) {
  119. WFCUCreateConferenceViewController *vc = [[WFCUCreateConferenceViewController alloc] init];
  120. vc.hidesBottomBarWhenPushed = YES;
  121. [self.navigationController pushViewController:vc animated:YES];
  122. }
  123. }
  124. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  125. return self.dataSource.count;
  126. }
  127. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  128. return 1;
  129. }
  130. - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
  131. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  132. }
  133. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  134. UITableViewCell *cell;
  135. if (indexPath.section == 0 && self.hasMoments) {
  136. cell = [tableView dequeueReusableCellWithIdentifier:@"momentsCell"];
  137. if (cell == nil) {
  138. cell = [[DiscoverMomentsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"momentsCell"];
  139. }
  140. } else {
  141. cell = [tableView dequeueReusableCellWithIdentifier:@"defaultCell"];
  142. if (cell == nil) {
  143. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"defaultCell"];
  144. }
  145. }
  146. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  147. cell.accessoryView = nil;
  148. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  149. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  150. cell.textLabel.text = self.dataSource[indexPath.section][@"title"];
  151. cell.imageView.image = [UIImage imageNamed:self.dataSource[indexPath.section][@"image"]];
  152. if (indexPath.section == 0 && self.hasMoments) {
  153. DiscoverMomentsTableViewCell *momentsCell = (DiscoverMomentsTableViewCell *)cell;
  154. __weak typeof(self)ws = self;
  155. #ifdef WFC_MOMENTS
  156. int unread = [[WFMomentService sharedService] getUnreadCount];
  157. if (unread) {
  158. momentsCell.bubbleView.hidden = NO;
  159. [momentsCell.bubbleView setBubbleTipNumber:unread];
  160. } else {
  161. momentsCell.bubbleView.hidden = YES;
  162. }
  163. NSMutableArray<WFMFeed *> *feeds = [[WFMomentService sharedService] restoreCache:nil];
  164. if (feeds.count > 0) {
  165. momentsCell.lastFeed = [feeds objectAtIndex:0];
  166. } else {
  167. [[WFMomentService sharedService] getFeeds:0 count:10 fromUser:nil success:^(NSArray<WFMFeed *> * _Nonnull feeds) {
  168. if (feeds.count) {
  169. [[WFMomentService sharedService] storeCache:feeds forUser:nil];
  170. [ws.tableView reloadData];
  171. }
  172. } error:^(int error_code) {
  173. }];
  174. }
  175. #endif
  176. }
  177. return cell;
  178. }
  179. @end