123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //
- // 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()<UITableViewDataSource, UITableViewDelegate>
- /// 消息通知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
|