123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // YMGreetingSettingViewController.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/23.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMGreetingSettingViewController.h"
- #import "YMGreetingSettingViewModel.h"
- #import "YMGreetingSettingCell.h"
- @interface YMGreetingSettingViewController()<UITableViewDataSource, UITableViewDelegate>
- /// 打招呼设置VM
- @property (nonatomic, strong) YMGreetingSettingViewModel *viewModel;
- /// 内容列表
- @property (nonatomic, strong) UITableView *contentTableView;
- /// 新建模板按钮
- @property (nonatomic, strong) UIButton *createTemplateBtn;
- @end
- @implementation YMGreetingSettingViewController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self headerRefreshing];
- }
- - (void)viewDidDisappear:(BOOL)animated{
- [super viewDidDisappear:animated];
- [[YMAudioPlayer sharedInstance] stop];
- }
- - (void)ym_setupViews{
- [self.view addSubview:self.contentTableView];
- [self.view addSubview:self.createTemplateBtn];
- [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);
- }];
-
- [self.createTemplateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentTableView.mas_bottom).offset(adapt(10));
- make.left.equalTo(self.view).offset(adapt(30));
- make.right.equalTo(self.view).offset(adapt(-30));
- make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
- make.height.mas_equalTo(adapt(50));
- }];
-
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel{
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.contentTableView reloadData];
- switch ([result intValue]) {
- case YMHeaderRefresh_HasMoreData:
- case YMHeaderRefresh_HasNoMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- }
- break;
- case YMFooterRefresh_HasMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
- self.contentTableView.mj_footer = self.loadMoreFooter;
- }
- }
- break;
- case YMFooterRefresh_HasNoMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- if (self.contentTableView.mj_footer == self.loadMoreFooter) {
- self.contentTableView.mj_footer = self.noLoadMoreFooter;
- }
- }
- break;
- case YMRefreshError: {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- }
- break;
- default:
- break;
- }
- [self.contentTableView ym_endLoading];
- }];
- }
- - (void)headerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage = 1;
- [self.viewModel getGreetingSettingListData];
- }
- - (void)footerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage++;
- [self.viewModel getGreetingSettingListData];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.listDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- YMGreetingSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMGreetingSettingCell class])];
- if (!cell) {
- cell = [[YMGreetingSettingCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMGreetingSettingCell class])];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- YMGreetingSettingCellViewModel *cellVM = self.viewModel.listDataArray[indexPath.item];
- @weakify(self)
- cellVM.refreshGreetingSettingListBlock = ^{
- @strongify(self)
- [self headerRefreshing];
- };
- [cell ym_bindViewModel:cellVM];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- __weak typeof(self) weakSelf = self;
- CGFloat cellHeight = [tableView fd_heightForCellWithIdentifier:NSStringFromClass([YMGreetingSettingCell class]) configuration:^(id cell) {
- [cell ym_bindViewModel:weakSelf.viewModel.listDataArray[indexPath.item]];
- }];
- return cellHeight;
- }
- - (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:[YMGreetingSettingCell class] forCellReuseIdentifier:NSStringFromClass([YMGreetingSettingCell class])];
- _contentTableView.mj_header = self.refreshHeader;
- _contentTableView.mj_footer = self.noLoadMoreFooter;
- YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
- empty.imageSize = kEmptyViewSize;
- _contentTableView.ym_emptyView = empty;
- _contentTableView.ym_emptyView.autoShowEmptyView = NO;
- }
- return _contentTableView;
- }
- - (UIButton *)createTemplateBtn{
- if (!_createTemplateBtn) {
- _createTemplateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _createTemplateBtn.titleLabel.font = LCFont(15);
- [_createTemplateBtn setTitle:@"新建模板" forState:UIControlStateNormal];
- [_createTemplateBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
- [_createTemplateBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
- _createTemplateBtn.layer.cornerRadius = adapt(8);
- _createTemplateBtn.layer.masksToBounds = YES;
- WS(weakSelf)
- [[[_createTemplateBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel gotoCreateGreetingTemplate];
- }];
- }
- return _createTemplateBtn;
- }
- @end
|