XYMyVoiceRoomListViewController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // XYMyVoiceRoomListViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/7/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMyVoiceRoomListViewController.h"
  9. #import "XYMyVoiceRoomListViewModel.h"
  10. #import "XYMyVoiceRoomListModel.h"
  11. #import "XYMyVoiceRoomListTableViewCell.h"
  12. #import "XYVoiceRoomCreateViewController.h"
  13. @interface XYMyVoiceRoomListViewController ()
  14. @property (nonatomic, strong) XYMyVoiceRoomListViewModel *viewModel;
  15. @property (nonatomic, strong) UIButton *createRoomButton;
  16. @end
  17. @implementation XYMyVoiceRoomListViewController
  18. - (void)dealloc
  19. {
  20. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"VOICE_ROOM_CREATE_SUCCESS_NOTIFICATION" object:nil];
  21. }
  22. /// 重写init方法,配置你想要的属性
  23. - (instancetype)init
  24. {
  25. self = [super init];
  26. if (self) {
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. /// 设置
  33. [self _setup];
  34. /// 设置导航栏
  35. [self _setupNavigationItem];
  36. /// 设置子控件
  37. [self _setupSubViews];
  38. /// 布局子空间
  39. [self _makeSubViewsConstraints];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(voiceRoomCreateSuccessNotification:) name:@"VOICE_ROOM_CREATE_SUCCESS_NOTIFICATION" object:nil];
  41. }
  42. - (void)voiceRoomCreateSuccessNotification:(NSNotification *)notification {
  43. [self tableViewDidTriggerHeaderRefresh];
  44. }
  45. #pragma mark — Override
  46. - (void)bindViewModel {
  47. self.viewModel = XYMyVoiceRoomListViewModel.new;
  48. }
  49. - (void)tableViewDidTriggerHeaderRefresh {
  50. [self.viewModel loadData:^(id _Nullable responseModel) {
  51. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  52. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"你还没有属于自己的房间哦~") errorInfo:nil offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  53. self.createRoomButton.hidden = self.viewModel.dataSource.count>0;
  54. } failure:^(ZYLNetworkError * _Nullable error) {
  55. [self tableViewDidFinishTriggerHeader:YES reload:NO];
  56. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"你还没有属于自己的房间哦~") errorInfo:error.domain offsetTop:250.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  57. }];
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  60. return [XYMyVoiceRoomListTableViewCell cellWithTableView:tableView];
  61. }
  62. - (void)configureCell:(XYMyVoiceRoomListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  63. [cell configureModel:object];
  64. }
  65. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. return 64.0f;
  67. }
  68. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  69. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  70. XYMyVoiceRoomListModel *model = [self.viewModel.dataSource objectAtIndex:indexPath.row];
  71. [[XYChatRoomManager sharedInstance] showChatRoomWithRoomId:model.roomId roomCoverUrl:model.roomCover completion:^{
  72. }];
  73. }
  74. #pragma mark - 事件处理Or辅助方法
  75. - (void)createRoomButtonAction:(id)sender {
  76. [self.navigationController pushViewController:XYVoiceRoomCreateViewController.new animated:YES];
  77. }
  78. #pragma mark - 初始化
  79. - (void)_setup{
  80. self.title = kLocalizedString(@"我的语音房");
  81. }
  82. #pragma mark - 设置导航栏
  83. - (void)_setupNavigationItem{
  84. self.navigationItem.rightBarButtonItem = [UIBarButtonItem systemItemWithTitle:kLocalizedString(@"创建房间") titleColor:Color_TextFont imageName:nil target:self selector:@selector(createRoomButtonAction:) textType:YES];
  85. }
  86. #pragma mark - 设置子控件
  87. - (void)_setupSubViews{
  88. [self.view addSubview:self.createRoomButton];
  89. }
  90. #pragma mark - 布局子控件
  91. - (void)_makeSubViewsConstraints{
  92. [self.createRoomButton mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.centerX.equalTo(self.view);
  94. make.bottom.equalTo(self.view).offset(-52.0f);
  95. make.width.equalTo(@160.0f);
  96. make.height.equalTo(@42.0f);
  97. }];
  98. [self.createRoomButton addViewBorder:Color_Clear redian:21];
  99. }
  100. #pragma mark - Setter & Getter
  101. - (UIButton *)createRoomButton {
  102. if (!_createRoomButton) {
  103. _createRoomButton = [UIButton createButtonTextColor:Color_White textFont:Font_B(18)];
  104. [_createRoomButton setBackgroundImage:[UIImage commonRedGradientColorImageWithImgSize:CGSizeMake(160.0f, 42.0f)] forState:UIControlStateNormal];
  105. [_createRoomButton setTitle:@"创建房间" forState:UIControlStateNormal];
  106. [_createRoomButton addTarget:self action:@selector(createRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  107. _createRoomButton.hidden = YES;
  108. }
  109. return _createRoomButton;
  110. }
  111. @end