YMBlackListViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // YMBlackListViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMBlackListViewController.h"
  9. #import "YMBlackListViewModel.h"
  10. #import "YMBlackListCell.h"
  11. @interface YMBlackListViewController()<UITableViewDataSource, UITableViewDelegate>
  12. /// 粉丝VM
  13. @property (nonatomic, strong) YMBlackListViewModel *viewModel;
  14. /// 内容列表
  15. @property (nonatomic, strong) UITableView *contentTableView;
  16. @end
  17. @implementation YMBlackListViewController
  18. @dynamic viewModel;
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. }
  22. - (void)ym_setupViews{
  23. [self.view addSubview:self.contentTableView];
  24. [self.view setNeedsUpdateConstraints];
  25. [self.view updateConstraintsIfNeeded];
  26. }
  27. - (void)updateViewConstraints{
  28. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.equalTo(self.view).offset(kYMNavHeight);
  30. make.left.equalTo(self.view);
  31. make.right.equalTo(self.view);
  32. make.bottom.equalTo(self.view);
  33. }];
  34. [super updateViewConstraints];
  35. }
  36. - (void)ym_bindViewModel{
  37. [self headerRefreshing];
  38. @weakify(self)
  39. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  40. @strongify(self)
  41. [self.contentTableView reloadData];
  42. switch ([result intValue]) {
  43. case YMHeaderRefresh_HasMoreData:
  44. case YMHeaderRefresh_HasNoMoreData:
  45. {
  46. [self.contentTableView.mj_header endRefreshing];
  47. [self.contentTableView.mj_footer endRefreshing];
  48. }
  49. break;
  50. case YMFooterRefresh_HasMoreData:
  51. {
  52. [self.contentTableView.mj_header endRefreshing];
  53. [self.contentTableView.mj_footer endRefreshing];
  54. if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
  55. self.contentTableView.mj_footer = self.loadMoreFooter;
  56. }
  57. }
  58. break;
  59. case YMFooterRefresh_HasNoMoreData:
  60. {
  61. [self.contentTableView.mj_header endRefreshing];
  62. [self.contentTableView.mj_footer endRefreshing];
  63. if (self.contentTableView.mj_footer == self.loadMoreFooter) {
  64. self.contentTableView.mj_footer = self.noLoadMoreFooter;
  65. }
  66. }
  67. break;
  68. case YMRefreshError: {
  69. [self.contentTableView.mj_header endRefreshing];
  70. [self.contentTableView.mj_footer endRefreshing];
  71. }
  72. break;
  73. default:
  74. break;
  75. }
  76. [self.contentTableView ym_endLoading];
  77. }];
  78. }
  79. - (void)headerRefreshing{
  80. [self.contentTableView ym_startLoading];
  81. self.viewModel.currentPage = 1;
  82. [self.viewModel getBlackListData];
  83. }
  84. - (void)footerRefreshing{
  85. [self.contentTableView ym_startLoading];
  86. self.viewModel.currentPage++;
  87. [self.viewModel getBlackListData];
  88. }
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. return self.viewModel.listDataArray.count;
  91. }
  92. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  93. YMBlackListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMBlackListCell class])];
  94. if (!cell) {
  95. cell = [[YMBlackListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMBlackListCell class])];
  96. }
  97. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  98. YMBlackListCellViewModel *cellVM = self.viewModel.listDataArray[indexPath.item];
  99. @weakify(self)
  100. cellVM.removeBlackBlock = ^{
  101. @strongify(self)
  102. [self.contentTableView ym_startLoading];
  103. [self.viewModel.listDataArray removeObjectAtIndex:indexPath.row];
  104. [self.contentTableView reloadData];
  105. [self.contentTableView ym_endLoading];
  106. };
  107. [cell ym_bindViewModel:cellVM];
  108. return cell;
  109. }
  110. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  111. return adapt(60);
  112. }
  113. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  114. }
  115. - (UITableView *)contentTableView{
  116. if (!_contentTableView) {
  117. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  118. _contentTableView.delegate = self;
  119. _contentTableView.dataSource = self;
  120. _contentTableView.estimatedRowHeight = 0;
  121. _contentTableView.estimatedSectionHeaderHeight = 0;
  122. _contentTableView.estimatedSectionFooterHeight = 0;
  123. _contentTableView.showsVerticalScrollIndicator = NO;
  124. _contentTableView.showsHorizontalScrollIndicator = NO;
  125. _contentTableView.separatorColor = UIColor.clearColor;
  126. _contentTableView.backgroundColor = UIColor.whiteColor;
  127. [_contentTableView registerClass:[YMBlackListCell class] forCellReuseIdentifier:NSStringFromClass([YMBlackListCell class])];
  128. _contentTableView.mj_header = self.refreshHeader;
  129. _contentTableView.mj_footer = self.noLoadMoreFooter;
  130. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
  131. empty.imageSize = kEmptyViewSize;
  132. _contentTableView.ym_emptyView = empty;
  133. _contentTableView.ym_emptyView.autoShowEmptyView = NO;
  134. }
  135. return _contentTableView;
  136. }
  137. @end