TCUserInfoViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // TCUserInfoController.m
  3. // TCLVBIMDemo
  4. //
  5. // Created by jemilyzhou on 16/8/1.
  6. // Copyright © 2016年 tencent. All rights reserved.
  7. //
  8. #import "TCUserInfoViewController.h"
  9. #import "TCEditUserInfoViewController.h"
  10. #import "TCUserInfoCell.h"
  11. #import "TCUserInfoModel.h"
  12. //#import "TCLoginModel.h"
  13. #import "TCConstants.h"
  14. #import <UIKit/UIKit.h>
  15. #import <mach/mach.h>
  16. #import <Foundation/Foundation.h>
  17. #import <AVFoundation/AVFoundation.h>
  18. //#import "TCWebViewController.h"
  19. static NSString * const HomePageURL = @"https://cloud.tencent.com/product/ugsv";
  20. #define L(X) NSLocalizedString((X), nil)
  21. extern BOOL g_bNeedEnterPushSettingView;
  22. @implementation TCUserInfoViewController
  23. {
  24. UIButton *_loginBtn;
  25. }
  26. - (void)dealloc
  27. {
  28. [[NSNotificationCenter defaultCenter] removeObserver:self name:KReloadUserInfoNotification object:nil];
  29. }
  30. /**
  31. * 用于点击 退出登录 按钮后的回调,用于登录出原界面
  32. *
  33. * @param sender 无意义
  34. */
  35. - (void)logout:(id)sender
  36. {
  37. AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  38. // [[TCLoginModel sharedInstance] logout:^{
  39. // [[TCLoginParam shareInstance] clearLocal];
  40. // [app enterLoginUI];
  41. // [self.dataTable reloadData];
  42. // }];
  43. }
  44. - (void)viewDidLoad
  45. {
  46. [super viewDidLoad];
  47. // 设置通知消息,接受到通知后重绘cell,确保更改后的用户资料能同步到用户信息界面
  48. [[NSNotificationCenter defaultCenter] removeObserver:self name:KReloadUserInfoNotification object:nil];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserInfoOnController:) name:KReloadUserInfoNotification object:nil];
  50. [self initUI];
  51. return;
  52. }
  53. -(void)initUI
  54. {
  55. UIView *viewBack=[[UIView alloc] init];
  56. viewBack.frame = self.view.frame;
  57. viewBack.backgroundColor= RGB(0x18, 0x1D, 0x27);
  58. [self.view addSubview:viewBack];
  59. // 初始化需要绘制在tableview上的数据
  60. __weak typeof(self) ws = self;
  61. TCUserInfoCellItem *backFaceItem = [[TCUserInfoCellItem alloc] initWith:@"" value:@"" type:TCUserInfo_View action:^(TCUserInfoCellItem *menu, TCUserInfoTableViewCell *cell) {
  62. [ws onEditUserInfo:menu cell:cell];
  63. nil; }];
  64. // TCUserInfoCellItem *setItem = [[TCUserInfoCellItem alloc] initWith:ASLocalizedString(@"编辑个人信息")value:nil type:TCUserInfo_Edit action:^(TCUserInfoCellItem *menu, TCUserInfoTableViewCell *cell) {
  65. // [ws onEditUserInfo:menu cell:cell]; } ];
  66. TCUserInfoCellItem *aboutItem = [[TCUserInfoCellItem alloc] initWith:NSLocalizedString(@"TCUserInfoView.HintAboutApp", nil) value:nil type:TCUserInfo_About action:^(TCUserInfoCellItem *menu, TCUserInfoTableViewCell *cell) { [ws onShowAppVersion:menu cell:cell]; } ];
  67. TCUserInfoCellItem *getSupportItem = [[TCUserInfoCellItem alloc] initWith:NSLocalizedString(ASLocalizedString(@"获取技术支持服务"), nil) value:nil type:TCUserInfo_About action:^(TCUserInfoCellItem *menu, TCUserInfoTableViewCell *cell) { [ws onShowAppSupport:menu cell:cell]; } ];
  68. TCUserInfoCellItem *aboutSDKItem = [[TCUserInfoCellItem alloc] initWith:NSLocalizedString(@"TCUserInfoView.ProductIntroduction", nil) value:nil type:TCUserInfo_About action:^(TCUserInfoCellItem *menu, TCUserInfoTableViewCell *cell) { [ws onShowSDKInfo:menu cell:cell]; } ];
  69. CGFloat tableHeight = self.view.height;// 365;
  70. CGFloat quitBtnYSpace = tableHeight + 20;
  71. // _userInfoUISetArry = [NSMutableArray arrayWithArray:@[backFaceItem,setItem, aboutItem]];
  72. _userInfoUISetArry = [NSMutableArray arrayWithArray:@[backFaceItem,aboutItem,getSupportItem,aboutSDKItem]];
  73. //设置tableview属性
  74. CGRect frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, tableHeight);
  75. _dataTable = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
  76. _dataTable.backgroundColor = UIColor.clearColor;
  77. [_dataTable setDelegate:self];
  78. [_dataTable setDataSource:self];
  79. [_dataTable setScrollEnabled:NO];
  80. [_dataTable setSeparatorColor:[UIColor clearColor]];
  81. [self.view addSubview:_dataTable];
  82. //计算退出登录按钮的位置和显示
  83. _loginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  84. _loginBtn.frame = CGRectMake(0, quitBtnYSpace, self.view.frame.size.width, 45);
  85. _loginBtn.backgroundColor = [UIColor whiteColor];
  86. _loginBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  87. [_loginBtn setTitle:NSLocalizedString(@"TCLoginView.Login", nil) forState: UIControlStateNormal];
  88. [_loginBtn setTitleColor:RGB(0xFF,0x58,0x4C) forState:UIControlStateNormal];
  89. [_loginBtn setBackgroundColor:RGB(0x1F,0x25,0x31)];
  90. [_loginBtn addTarget:self action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];
  91. UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 75)];
  92. wrapper.backgroundColor = UIColor.clearColor;
  93. [wrapper addSubview:_loginBtn];
  94. _loginBtn.bottom = wrapper.height;
  95. _dataTable.tableFooterView = wrapper;
  96. }
  97. #pragma mark 与view界面相关
  98. -(void)viewWillDisappear:(BOOL)animated
  99. {
  100. [super viewWillDisappear:animated];
  101. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
  102. }
  103. -(void)viewWillAppear:(BOOL)animated
  104. {
  105. [super viewWillAppear:animated];
  106. [self.navigationController setNavigationBarHidden:YES];
  107. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
  108. // if([TCLoginParam shareInstance].isExpired){
  109. // [_loginBtn setTitle:NSLocalizedString(@"TCLoginView.Login", nil) forState: UIControlStateNormal];
  110. // }else{
  111. // [_loginBtn setTitle:NSLocalizedString(@"TCUserInfoView.Logout", nil) forState: UIControlStateNormal];
  112. // }
  113. [_dataTable reloadData];
  114. }
  115. /**
  116. * 用于接受头像下载成功后通知,因为用户可能因为网络情况下载头像很慢甚至失败数次,导致用户信息页面显示默认头像
  117. * 当用户头像下载成功后刷新tableview,使得头像信息得以更新
  118. * 另外如果用户在 编辑个人页面 修改头像或者修改昵称,也会发送通知,通知用户信息界面信息变更
  119. *
  120. * @param notification 无意义
  121. */
  122. -(void)updateUserInfoOnController:(NSNotification *)notification
  123. {
  124. [_dataTable reloadData];
  125. }
  126. #pragma mark 绘制用户信息页面上的tableview
  127. //获取需要绘制的cell数目
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  129. {
  130. return _userInfoUISetArry.count;
  131. }
  132. //获取需要绘制的cell高度
  133. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  134. {
  135. TCUserInfoCellItem *item = _userInfoUISetArry[indexPath.row];
  136. return [TCUserInfoCellItem heightOf:item];
  137. }
  138. //绘制Cell
  139. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. TCUserInfoCellItem *item = _userInfoUISetArry[indexPath.row];
  142. TCUserInfoTableViewCell *cell = (TCUserInfoTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"cell"];
  143. if(cell == nil)
  144. {
  145. cell = [[TCUserInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  146. [cell initUserinfoViewCellData:item];
  147. }
  148. [cell drawRichCell:item];
  149. return cell;
  150. }
  151. #pragma mark 点击用户信息页面上的tableview的回调
  152. /**
  153. * 用于点击tableview中的cell后的回调相应
  154. *
  155. * @param tableView tableview变量
  156. * @param indexPath cell的某行
  157. */
  158. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  159. {
  160. TCUserInfoCellItem *item = _userInfoUISetArry[indexPath.row];
  161. TCUserInfoTableViewCell *cell = [_dataTable cellForRowAtIndexPath:indexPath];
  162. if (item.action)
  163. {
  164. item.action(item, cell);
  165. }
  166. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  167. }
  168. /**
  169. * 用于显示 编辑个人信息 页面
  170. *
  171. * @param menu 无意义
  172. * @param cell 无意义
  173. */
  174. - (void)onEditUserInfo:(TCUserInfoCellItem *)menu cell:(TCUserInfoTableViewCell *)cell
  175. {
  176. //个人信息编辑的逻辑不再维护
  177. // TCEditUserInfoViewController *vc = [[TCEditUserInfoViewController alloc] init];
  178. // [self.navigationController pushViewController:vc animated:true];
  179. }
  180. /// 获取技术支持按钮事件
  181. - (void)onShowAppSupport:(id)menu cell:(id)cell
  182. {
  183. NSString *message = [@[L(ASLocalizedString(@"关注公众号“腾讯云视频”")), L(ASLocalizedString(@"给公众号发送“小视频”"))] componentsJoinedByString:@"\n"];
  184. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(ASLocalizedString(@"获取技术支持服务"), nil) message:message delegate:nil cancelButtonTitle:NSLocalizedString(@"Common.Close", nil) otherButtonTitles:nil, nil];
  185. [alert show];
  186. }
  187. /**
  188. * 用户显示小直播的版本号信息
  189. *
  190. * @param menu 无意义
  191. * @param cell 无意义
  192. */
  193. - (void)onShowAppVersion:(TCUserInfoCellItem *)menu cell:(TCUserInfoTableViewCell *)cell
  194. {
  195. NSString* rtmpSDKVersion = [NSString stringWithFormat:NSLocalizedString(@"TCUserInfoView.InfoRTMPFmt", nil),[TXLiveBase getSDKVersionStr]];
  196. NSString* appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  197. NSString *info = [NSString stringWithFormat:NSLocalizedString(@"TCUserInfoView.InfoAppFmt", nil), appVersion, rtmpSDKVersion];
  198. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TCUserInfoView.HintAboutApp", nil) message:info delegate:nil cancelButtonTitle:NSLocalizedString(@"Common.Close", nil) otherButtonTitles:nil, nil];
  199. [alert show];
  200. }
  201. /**
  202. * 用户显示SDK信息
  203. *
  204. * @param menu 无意义
  205. * @param cell 无意义
  206. */
  207. - (void)onShowSDKInfo:(TCUserInfoCellItem *)menu cell:(TCUserInfoTableViewCell *)cell
  208. {
  209. // [TCUtil report:xiaoshipin_about_sdk userName:nil code:0 msg:ASLocalizedString(@"点击关于SDK")];
  210. // TCWebViewController *next = [[TCWebViewController alloc] initWithURL:HomePageURL];
  211. // next.hidesBottomBarWhenPushed = YES;
  212. // [self.navigationController pushViewController:next animated:YES];
  213. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://cloud.tencent.com/product/UGSV"]];
  214. }
  215. @end