123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // YMPersonalDynamicViewController.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/3.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMPersonalDynamicViewController.h"
- #import "YMPersonalDynamicViewModel.h"
- #import "YMPersonalDynamicCell.h"
- @interface YMPersonalDynamicViewController ()<UITableViewDataSource, UITableViewDelegate>
- /// 个人动态VM
- @property (nonatomic, strong) YMPersonalDynamicViewModel *viewModel;
- /// 容器列表
- @property (nonatomic, strong) UITableView *contentTableView;
- @end
- @implementation YMPersonalDynamicViewController
- @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 headerRefreshing];
-
- @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)deleteDynamic:(YMPersonalDynamicCellViewModel*)model{
- NSMutableArray* actionArray = [NSMutableArray array];
- ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"删除" andblock:^{//删除动态
- [LCHttpHelper requestWithURLString:DynamicDelete parameters:@{@"dynamic_id": [NSString stringWithFormat:@"%ld",(long)model.dynamic_id]} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- [self headerRefreshing];
- }
- } failure:^(NSError *error) {
- }];
- }];
- [actionArray addObject:action];
-
- ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
- //modify by leo --fix bug ios13 20191009
- //alertSheet.alertWindow.rootViewController = self;
- alertSheet.alertWindow.hidden = NO;
- [alertSheet show];
-
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.listDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- WS(weakSelf);
- YMPersonalDynamicCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMPersonalDynamicCell class])];
- if (!cell) {
- cell = [[YMPersonalDynamicCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMPersonalDynamicCell class])];
-
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
- [[[cell.deleteBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf deleteDynamic: self.viewModel.listDataArray[indexPath.item]];
- }];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- }
- ///动态是否隐藏个性化推荐提示
- - (void)dynamicIsHidePersonalizedRecommendationTips{
- if ([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]) {
- self.contentTableView.hidden = NO;
- [self.view ym_hideEmptyView];
- } else {
- self.contentTableView.hidden = YES;
- [self.view ym_showEmptyView];
- }
- }
- - (void)headerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage = 1;
- [self.viewModel getPersonalDynamicListData];
- }
- - (void)footerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage++;
- [self.viewModel getPersonalDynamicListData];
- }
- - (UITableView *)contentTableView{
- if (!_contentTableView) {
- _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _contentTableView.delegate = self;
- _contentTableView.dataSource = self;
- _contentTableView.rowHeight = UITableViewAutomaticDimension;
- _contentTableView.estimatedRowHeight = adapt(44);
- _contentTableView.showsVerticalScrollIndicator = NO;
- _contentTableView.showsHorizontalScrollIndicator = NO;
- _contentTableView.separatorColor = UIColor.clearColor;
- _contentTableView.backgroundColor = HexColorFromRGB(0xF6F6F6);
- [_contentTableView registerClass:[YMPersonalDynamicCell class] forCellReuseIdentifier:NSStringFromClass([YMPersonalDynamicCell 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;
- }
- @end
|