DiscoverViewController.m 9.0 KB

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