YMChatNotificationViewController.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // YMChatNotificationViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMChatNotificationViewController.h"
  9. #import "YMChatNotificationViewModel.h"
  10. #import "YMChatNotificationSectionHeaderView.h"
  11. #import "YMChatNotificationSectionFooterView.h"
  12. #import "YMChatNotificationCell.h"
  13. @interface YMChatNotificationViewController()<UITableViewDataSource, UITableViewDelegate>
  14. /// 消息通知VM
  15. @property (nonatomic, strong) YMChatNotificationViewModel *viewModel;
  16. /// 内容列表
  17. @property (nonatomic, strong) UITableView *contentTableView;
  18. @end
  19. @implementation YMChatNotificationViewController
  20. @dynamic viewModel;
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. }
  24. - (void)ym_setupViews{
  25. [self.view addSubview:self.contentTableView];
  26. [self.view setNeedsUpdateConstraints];
  27. [self.view updateConstraintsIfNeeded];
  28. }
  29. - (void)updateViewConstraints{
  30. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.equalTo(self.view).offset(kYMNavHeight);
  32. make.left.equalTo(self.view);
  33. make.right.equalTo(self.view);
  34. make.bottom.equalTo(self.view);
  35. }];
  36. [super updateViewConstraints];
  37. }
  38. - (void)ym_bindViewModel{
  39. [self.viewModel getChatNotificationListData];
  40. [self.viewModel getPredestinedAffinityInfo];
  41. [self.viewModel getLikesNotificationInfo];
  42. @weakify(self)
  43. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  44. @strongify(self)
  45. [self.contentTableView reloadData];
  46. }];
  47. }
  48. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  49. return self.viewModel.sectionDataArray.count;
  50. }
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  52. return self.viewModel.sectionDataArray[section].rowDataArray.count;
  53. }
  54. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  55. YMChatNotificationCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMChatNotificationCell class])];
  56. if (!cell) {
  57. cell = [[YMChatNotificationCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMChatNotificationCell class])];
  58. }
  59. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  60. [cell ym_bindViewModel:self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.row]];
  61. YMChatNotificationCellViewModel *cellVM = self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.row];
  62. @weakify(self)
  63. cellVM.switchNotificationBlock = ^{
  64. @strongify(self)
  65. [self.viewModel.chatNotificationFunctionsOperationSubject sendNext:@(self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.item].chatNotificationFunctionsType)];
  66. };
  67. [cell ym_bindViewModel:cellVM];
  68. return cell;
  69. }
  70. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  71. return adapt(50);
  72. }
  73. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  74. if (self.viewModel.sectionDataArray[section].isHideSectionHeader) {
  75. return nil;
  76. } else {
  77. YMChatNotificationSectionHeaderView *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])];
  78. if(!sectionHeaderView){
  79. sectionHeaderView = [[YMChatNotificationSectionHeaderView alloc] initWithReuseIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])];
  80. }
  81. [sectionHeaderView ym_bindViewModel:self.viewModel.sectionDataArray[section]];
  82. return sectionHeaderView;
  83. }
  84. }
  85. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  86. if (self.viewModel.sectionDataArray[section].isHideSectionHeader) {
  87. return CGFLOAT_MIN;
  88. } else {
  89. return adapt(45);
  90. }
  91. }
  92. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  93. if (self.viewModel.sectionDataArray[section].isHideSectionFooter) {
  94. return nil;
  95. } else {
  96. YMChatNotificationSectionFooterView *sectionFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])];
  97. if(!sectionFooterView){
  98. sectionFooterView = [[YMChatNotificationSectionFooterView alloc] initWithReuseIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])];
  99. }
  100. [sectionFooterView ym_bindViewModel:self.viewModel.sectionDataArray[section]];
  101. return sectionFooterView;
  102. }
  103. }
  104. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  105. if (self.viewModel.sectionDataArray[section].isHideSectionFooter) {
  106. return CGFLOAT_MIN;
  107. } else {
  108. return adapt(45);
  109. }
  110. }
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  112. }
  113. - (UITableView *)contentTableView{
  114. if (!_contentTableView) {
  115. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  116. _contentTableView.delegate = self;
  117. _contentTableView.dataSource = self;
  118. _contentTableView.estimatedRowHeight = 0;
  119. _contentTableView.estimatedSectionHeaderHeight = 0;
  120. _contentTableView.estimatedSectionFooterHeight = 0;
  121. _contentTableView.showsVerticalScrollIndicator = NO;
  122. _contentTableView.showsHorizontalScrollIndicator = NO;
  123. _contentTableView.separatorColor = UIColor.clearColor;
  124. _contentTableView.backgroundColor = HexColorFromRGB(0xF6F6F6);
  125. [_contentTableView registerClass:[YMChatNotificationSectionHeaderView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])];
  126. [_contentTableView registerClass:[YMChatNotificationSectionFooterView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])];
  127. [_contentTableView registerClass:[YMChatNotificationCell class] forCellReuseIdentifier:NSStringFromClass([YMChatNotificationCell class])];
  128. }
  129. return _contentTableView;
  130. }
  131. @end