// // YMChatNotificationViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/21. // Copyright © 2024 MS. All rights reserved. // #import "YMChatNotificationViewController.h" #import "YMChatNotificationViewModel.h" #import "YMChatNotificationSectionHeaderView.h" #import "YMChatNotificationSectionFooterView.h" #import "YMChatNotificationCell.h" @interface YMChatNotificationViewController() /// 消息通知VM @property (nonatomic, strong) YMChatNotificationViewModel *viewModel; /// 内容列表 @property (nonatomic, strong) UITableView *contentTableView; @end @implementation YMChatNotificationViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; } - (void)ym_setupViews{ [self.view addSubview:self.contentTableView]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(kYMNavHeight); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ [self.viewModel getChatNotificationListData]; [self.viewModel getPredestinedAffinityInfo]; [self.viewModel getLikesNotificationInfo]; @weakify(self) [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) { @strongify(self) [self.contentTableView reloadData]; }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.viewModel.sectionDataArray.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.viewModel.sectionDataArray[section].rowDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YMChatNotificationCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMChatNotificationCell class])]; if (!cell) { cell = [[YMChatNotificationCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMChatNotificationCell class])]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell ym_bindViewModel:self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.row]]; YMChatNotificationCellViewModel *cellVM = self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.row]; @weakify(self) cellVM.switchNotificationBlock = ^{ @strongify(self) [self.viewModel.chatNotificationFunctionsOperationSubject sendNext:@(self.viewModel.sectionDataArray[indexPath.section].rowDataArray[indexPath.item].chatNotificationFunctionsType)]; }; [cell ym_bindViewModel:cellVM]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return adapt(50); } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (self.viewModel.sectionDataArray[section].isHideSectionHeader) { return nil; } else { YMChatNotificationSectionHeaderView *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])]; if(!sectionHeaderView){ sectionHeaderView = [[YMChatNotificationSectionHeaderView alloc] initWithReuseIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])]; } [sectionHeaderView ym_bindViewModel:self.viewModel.sectionDataArray[section]]; return sectionHeaderView; } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (self.viewModel.sectionDataArray[section].isHideSectionHeader) { return CGFLOAT_MIN; } else { return adapt(45); } } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if (self.viewModel.sectionDataArray[section].isHideSectionFooter) { return nil; } else { YMChatNotificationSectionFooterView *sectionFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])]; if(!sectionFooterView){ sectionFooterView = [[YMChatNotificationSectionFooterView alloc] initWithReuseIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])]; } [sectionFooterView ym_bindViewModel:self.viewModel.sectionDataArray[section]]; return sectionFooterView; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (self.viewModel.sectionDataArray[section].isHideSectionFooter) { return CGFLOAT_MIN; } else { return adapt(45); } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (UITableView *)contentTableView{ if (!_contentTableView) { _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _contentTableView.delegate = self; _contentTableView.dataSource = self; _contentTableView.estimatedRowHeight = 0; _contentTableView.estimatedSectionHeaderHeight = 0; _contentTableView.estimatedSectionFooterHeight = 0; _contentTableView.showsVerticalScrollIndicator = NO; _contentTableView.showsHorizontalScrollIndicator = NO; _contentTableView.separatorColor = UIColor.clearColor; _contentTableView.backgroundColor = HexColorFromRGB(0xF6F6F6); [_contentTableView registerClass:[YMChatNotificationSectionHeaderView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([YMChatNotificationSectionHeaderView class])]; [_contentTableView registerClass:[YMChatNotificationSectionFooterView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([YMChatNotificationSectionFooterView class])]; [_contentTableView registerClass:[YMChatNotificationCell class] forCellReuseIdentifier:NSStringFromClass([YMChatNotificationCell class])]; } return _contentTableView; } @end