WFCUProfileTableViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //
  2. // WFCUProfileTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/22.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUProfileTableViewController.h"
  9. #import "SDWebImage.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUMessageListViewController.h"
  12. #import "MBProgressHUD.h"
  13. #import "WFCUMyPortraitViewController.h"
  14. #import "WFCUVerifyRequestViewController.h"
  15. @interface WFCUProfileTableViewController () <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>
  16. @property (strong, nonatomic)UIImageView *portraitView;
  17. @property (strong, nonatomic)UILabel *nameLabel;
  18. @property (strong, nonatomic)UILabel *displayNameLabel;
  19. @property (strong, nonatomic)UITableViewCell *headerCell;
  20. @property (strong, nonatomic)UILabel *mobileLabel;
  21. @property (strong, nonatomic)UILabel *emailLabel;
  22. @property (strong, nonatomic)UILabel *addressLabel;
  23. @property (strong, nonatomic)UILabel *companyLabel;
  24. @property (strong, nonatomic)UILabel *socialLabel;
  25. @property (strong, nonatomic)UITableViewCell *sendMessageCell;
  26. @property (strong, nonatomic)UITableViewCell *voipCallCell;
  27. @property (strong, nonatomic)UITableViewCell *addFriendCell;
  28. @property (nonatomic, strong)UITableView *tableView;
  29. @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *cells;
  30. @end
  31. @implementation WFCUProfileTableViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  35. [self.view addSubview:self.tableView];
  36. self.tableView.delegate = self;
  37. self.tableView.dataSource = self;
  38. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"..." style:UIBarButtonItemStyleDone target:self action:@selector(onRightBtn:)];
  39. [self loadData];
  40. self.tableView.tableFooterView = [[UIView alloc] init];
  41. }
  42. - (void)onRightBtn:(id)sender {
  43. NSString *title;
  44. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userInfo.userId]) {
  45. title = @"删除好友";
  46. } else {
  47. title = @"添加好友";
  48. }
  49. UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:title otherButtonTitles:nil, nil];
  50. [actionSheet showInView:self.view];
  51. }
  52. - (void)loadData {
  53. self.cells = [[NSMutableArray alloc] init];
  54. self.headerCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  55. for (UIView *subView in self.headerCell.subviews) {
  56. [subView removeFromSuperview];
  57. }
  58. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  59. self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 48, 48)];
  60. self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(64, 8, width - 64 - 8, 21)];
  61. self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(64, 33, width - 64 - 8, 21)];
  62. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewPortrait:)];
  63. [self.portraitView addGestureRecognizer:tap];
  64. self.portraitView.userInteractionEnabled = YES;
  65. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:self.userInfo.portrait] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  66. [self.nameLabel setText:self.userInfo.name];
  67. self.displayNameLabel.text = self.userInfo.displayName;
  68. [self.headerCell addSubview:self.portraitView];
  69. [self.headerCell addSubview:self.displayNameLabel];
  70. [self.headerCell addSubview:self.nameLabel];
  71. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userInfo.userId]) {
  72. if (self.userInfo.mobile.length > 0) {
  73. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  74. cell.textLabel.text = self.userInfo.mobile;
  75. [self.cells addObject:cell];
  76. }
  77. if (self.userInfo.email.length > 0) {
  78. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  79. cell.textLabel.text = self.userInfo.email;
  80. [self.cells addObject:cell];
  81. }
  82. if (self.userInfo.address.length) {
  83. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  84. cell.textLabel.text = self.userInfo.address;
  85. [self.cells addObject:cell];
  86. }
  87. if (self.userInfo.company.length) {
  88. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  89. cell.textLabel.text = self.userInfo.company;
  90. [self.cells addObject:cell];
  91. }
  92. if (self.userInfo.social.length) {
  93. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  94. cell.textLabel.text = self.userInfo.social;
  95. [self.cells addObject:cell];
  96. }
  97. }
  98. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userInfo.userId]) {
  99. self.sendMessageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  100. for (UIView *subView in self.sendMessageCell.subviews) {
  101. [subView removeFromSuperview];
  102. }
  103. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  104. [btn setTitle:@"发送消息" forState:UIControlStateNormal];
  105. [btn setBackgroundColor:[UIColor greenColor]];
  106. [btn addTarget:self action:@selector(onSendMessageBtn:) forControlEvents:UIControlEventTouchDown];
  107. btn.layer.cornerRadius = 5.f;
  108. btn.layer.masksToBounds = YES;
  109. [self.sendMessageCell addSubview:btn];
  110. self.voipCallCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  111. for (UIView *subView in self.voipCallCell.subviews) {
  112. [subView removeFromSuperview];
  113. }
  114. btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  115. [btn setTitle:@"视频聊天" forState:UIControlStateNormal];
  116. [btn setBackgroundColor:[UIColor grayColor]];
  117. [btn addTarget:self action:@selector(onVoipCallBtn:) forControlEvents:UIControlEventTouchDown];
  118. btn.layer.cornerRadius = 5.f;
  119. btn.layer.masksToBounds = YES;
  120. [self.voipCallCell addSubview:btn];
  121. } else if([[WFCCNetworkService sharedInstance].userId isEqualToString:self.userInfo.userId]) {
  122. } else {
  123. self.addFriendCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  124. for (UIView *subView in self.addFriendCell.subviews) {
  125. [subView removeFromSuperview];
  126. }
  127. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  128. [btn setTitle:@"添加好友" forState:UIControlStateNormal];
  129. [btn setBackgroundColor:[UIColor greenColor]];
  130. [btn addTarget:self action:@selector(onAddFriendBtn:) forControlEvents:UIControlEventTouchDown];
  131. btn.layer.cornerRadius = 5.f;
  132. btn.layer.masksToBounds = YES;
  133. [self.addFriendCell addSubview:btn];
  134. }
  135. [self.tableView reloadData];
  136. }
  137. - (void)onViewPortrait:(id)sender {
  138. WFCUMyPortraitViewController *pvc = [[WFCUMyPortraitViewController alloc] init];
  139. pvc.userId = self.userInfo.userId;
  140. [self.navigationController pushViewController:pvc animated:YES];
  141. }
  142. - (void)onSendMessageBtn:(id)sender {
  143. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  144. mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:self.userInfo.userId line:0];
  145. for (UIViewController *vc in self.navigationController.viewControllers) {
  146. if ([vc isKindOfClass:[WFCUMessageListViewController class]]) {
  147. [self.navigationController popToViewController:vc animated:YES];
  148. return;
  149. }
  150. }
  151. [self.navigationController pushViewController:mvc animated:YES];
  152. }
  153. - (void)onVoipCallBtn:(id)sender {
  154. }
  155. - (void)onAddFriendBtn:(id)sender {
  156. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  157. vc.userId = self.userInfo.userId;
  158. [self.navigationController pushViewController:vc animated:YES];
  159. }
  160. - (void)didReceiveMemoryWarning {
  161. [super didReceiveMemoryWarning];
  162. // Dispose of any resources that can be recreated.
  163. }
  164. #pragma mark - UITableViewDataSource<NSObject>
  165. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  166. if (section == 0) {
  167. return 1;
  168. } else if(section == 1) {
  169. return self.cells.count;
  170. } else {
  171. if (self.sendMessageCell) {
  172. return 2;
  173. } else {
  174. return 1;
  175. }
  176. }
  177. }
  178. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  179. if (indexPath.section == 0) {
  180. return self.headerCell;
  181. } else if (indexPath.section == 1) {
  182. return self.cells[indexPath.row];
  183. } else {
  184. if (self.sendMessageCell) {
  185. if (indexPath.row == 0) {
  186. return self.sendMessageCell;
  187. } else {
  188. return self.voipCallCell;
  189. }
  190. } else {
  191. return self.addFriendCell;
  192. }
  193. }
  194. }
  195. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  196. if (self.sendMessageCell || self.voipCallCell || self.addFriendCell) {
  197. return 3;
  198. } else {
  199. return 2;
  200. }
  201. }
  202. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  203. return @" ";
  204. }
  205. #pragma mark - UITableViewDelegate
  206. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  207. if (indexPath.section == 0) {
  208. return 64;
  209. } else if(indexPath.section == 1) {
  210. return 48;
  211. } else {
  212. return 56;
  213. }
  214. }
  215. #pragma mark - UIActionSheetDelegate <NSObject>
  216. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  217. if(buttonIndex == 0) {
  218. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  219. hud.label.text = @"处理中...";
  220. [hud showAnimated:YES];
  221. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userInfo.userId]) {
  222. [[WFCCIMService sharedWFCIMService] deleteFriend:self.userInfo.userId success:^{
  223. dispatch_async(dispatch_get_main_queue(), ^{
  224. [hud hideAnimated:YES];
  225. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  226. hud.mode = MBProgressHUDModeText;
  227. hud.label.text = @"处理成功";
  228. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  229. [hud hideAnimated:YES afterDelay:1.f];
  230. });
  231. } error:^(int error_code) {
  232. dispatch_async(dispatch_get_main_queue(), ^{
  233. [hud hideAnimated:YES];
  234. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  235. hud.mode = MBProgressHUDModeText;
  236. hud.label.text = @"处理失败";
  237. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  238. [hud hideAnimated:YES afterDelay:1.f];
  239. });
  240. }];
  241. } else {
  242. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  243. vc.userId = self.userInfo.userId;
  244. [self.navigationController pushViewController:vc animated:YES];
  245. }
  246. }
  247. }
  248. @end