308 lines
14 KiB
Objective-C
308 lines
14 KiB
Objective-C
//
|
|
// DDMyInformationDynamicViewController.m
|
|
// DingDangApp
|
|
//
|
|
// Created by apple on 2023/5/29.
|
|
//
|
|
|
|
#import "DDMyInformationDynamicViewController.h"
|
|
#import "DDDynamicDataTableViewCell.h"
|
|
#import "UIScrollView+ListViewAutoplaySJAdd.h"
|
|
#import <SJVideoPlayer/SJVideoPlayer.h>
|
|
#import "DDMyInfoReportViewController.h"
|
|
|
|
@interface DDMyInformationDynamicViewController ()<SJPlayerAutoplayDelegate,UITableViewDelegate,UITableViewDataSource>
|
|
@property (nonatomic,strong) UITableView * myTableView;
|
|
@property (nonatomic, assign) NSInteger pageNum;
|
|
@property (nonatomic, strong) SJVideoPlayer * videoPlayer;
|
|
|
|
@end
|
|
|
|
@implementation DDMyInformationDynamicViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
self.pageNum = 1;
|
|
[self.view addSubview:self.myTableView];
|
|
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
|
|
}];
|
|
[self originRequest];
|
|
}
|
|
-(UITableView *)myTableView
|
|
{
|
|
if (!_myTableView) {
|
|
_myTableView = [[UITableView alloc] initWithFrame:CGRectZero
|
|
style:UITableViewStyleGrouped];
|
|
_myTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
_myTableView.estimatedSectionHeaderHeight = 0;
|
|
_myTableView.estimatedSectionFooterHeight = 0;
|
|
_myTableView.dataSource = self;
|
|
_myTableView.delegate = self;
|
|
_myTableView.estimatedRowHeight = 0;
|
|
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_myTableView.separatorColor = [UIColor clearColor];
|
|
_myTableView.backgroundColor = [UIColor jk_colorWithHexString:@"#ffffff"];
|
|
[_myTableView registerClass:DDDynamicDataTableViewCell.class forCellReuseIdentifier:@"DDDynamicDataTableViewCell"];
|
|
WeakSelf(weakSelf)
|
|
_myTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
[weakSelf originRequest];
|
|
}];
|
|
_myTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.pageNum ++ ;
|
|
[weakSelf refreshListData];
|
|
}];
|
|
}
|
|
return _myTableView;
|
|
}
|
|
|
|
-(void)originRequest
|
|
{
|
|
self.pageNum = 1;
|
|
[self refreshListData];
|
|
}
|
|
- (void)refreshListData{
|
|
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
|
|
[requestDict setObject:@(20) forKey:@"current_page"];
|
|
[requestDict setObject:@(self.pageNum) forKey:@"page_number"];
|
|
[requestDict setObject:[ToolsObject IsNullWithObject:self.user_id]?[ToolsObject getUserModel].user_id:self.user_id forKey:@"user_id"];
|
|
WeakSelf(weakSelf)
|
|
[NetworkRequest requestPOST:@"/my/dynamic/list" parameters:requestDict block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200) {
|
|
if ([ToolsObject IsNullWithObject:response.data]) {
|
|
[weakSelf.myTableView.mj_header endRefreshing];
|
|
[weakSelf.myTableView.mj_footer endRefreshing];
|
|
return;
|
|
}
|
|
if (weakSelf.pageNum == 1) {
|
|
[weakSelf.listArr removeAllObjects];
|
|
}
|
|
[weakSelf.listArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDDynamicModel.class json:response.data[@"record"]]];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView.mj_header endRefreshing];
|
|
[weakSelf.myTableView.mj_footer endRefreshing];
|
|
[weakSelf.myTableView reloadData];
|
|
});
|
|
if ([response.data[@"next"]integerValue] == 0) {
|
|
[weakSelf.myTableView.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
}
|
|
}];
|
|
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
return CGFLOAT_MIN;
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
{
|
|
return CGFLOAT_MIN;
|
|
}
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
return 1;
|
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return self.listArr.count;
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
DDDynamicModel * model = self.listArr[indexPath.row];
|
|
return model.rowHeight;
|
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
static NSString *indentifiers = @"DDDynamicDataTableViewCell";
|
|
DDDynamicDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifiers];
|
|
if (!cell) {
|
|
cell = [[DDDynamicDataTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifiers];
|
|
}
|
|
cell.rowIndexPath = indexPath;
|
|
cell.model = self.listArr[indexPath.row];
|
|
WeakSelf(weakSelf)
|
|
cell.clickSupportBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
NSMutableDictionary *parameter =[NSMutableDictionary dictionary];
|
|
[parameter setValue:dynamicModel.id forKey:@"dynamic_id"];
|
|
if (dynamicModel.is_give_like) {
|
|
[parameter setValue:@"nolike" forKey:@"scene"];
|
|
}else{
|
|
[parameter setValue:@"like" forKey:@"scene"];
|
|
}
|
|
[NetworkRequest requestPOST:@"/dynamic/set/like" parameters:parameter block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200){
|
|
dynamicModel.is_give_like = !dynamicModel.is_give_like;
|
|
if (dynamicModel.is_give_like) {
|
|
dynamicModel.support = [NSString stringWithFormat:@"%d",dynamicModel.support.intValue + 1];
|
|
}else {
|
|
if (dynamicModel.support.intValue == 0) {
|
|
dynamicModel.support = @"0";
|
|
} else {
|
|
dynamicModel.support = [NSString stringWithFormat:@"%d",dynamicModel.support.intValue - 1];
|
|
}
|
|
}
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
});
|
|
}else{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
});
|
|
}
|
|
}];
|
|
};
|
|
cell.clickPlayVoideoBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
[weakSelf sj_playerNeedPlayNewAssetAtIndexPath:index];
|
|
};
|
|
cell.clickHeaderImageBlock = ^(DDDynamicModel * _Nonnull dynamicModel) {
|
|
if (dynamicModel.in_live) {
|
|
RoomUserInfoModel *userModel = [[RoomUserInfoModel alloc]init];
|
|
userModel.user_id = dynamicModel.user_id;
|
|
[[ToolsObject shareTools] jumpToRoomVC:dynamicModel.in_live_room_id followUser:userModel];
|
|
}else{
|
|
[ToolsObject pushMyInformationViewController:dynamicModel.user_id];
|
|
}
|
|
};
|
|
cell.clickAttentionBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
if (dynamicModel.is_attention) {
|
|
[weakSelf requestcancelFollow:dynamicModel withIndexPath:index];
|
|
}else{
|
|
[weakSelf requestAddFollow:dynamicModel withIndexPath:index];
|
|
}
|
|
};
|
|
cell.clickRemoveBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
|
|
[requestDict setObject:dynamicModel.id forKey:@"dynamic_id"];
|
|
[NetworkRequest requestPOST:@"/dynamic/del/dynamic" parameters:requestDict block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200) {
|
|
[weakSelf.listArr removeObjectAtIndex:index.row];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView reloadData];
|
|
});
|
|
}
|
|
}];
|
|
};
|
|
cell.clickReportBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
DDMyInfoReportViewController * jubaoVC = [[DDMyInfoReportViewController alloc] init];
|
|
jubaoVC.juBaoType = 3;
|
|
jubaoVC.jubao_id = dynamicModel.id;
|
|
[[ToolsObject getCurrentViewController].navigationController pushViewController:jubaoVC animated:YES];
|
|
};
|
|
cell.clickCantSeeBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
[weakSelf.listArr removeObjectAtIndex:index.row];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView reloadData];
|
|
});
|
|
};
|
|
cell.clickBlackBlock = ^(DDDynamicModel * _Nonnull dynamicModel, NSIndexPath * _Nonnull index) {
|
|
[weakSelf.listArr removeObjectAtIndex:index.row];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.myTableView reloadData];
|
|
});
|
|
};
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
return cell;
|
|
}
|
|
- (void)sj_playerNeedPlayNewAssetAtIndexPath:(NSIndexPath *)indexPath {
|
|
DDDynamicModel *model = self.listArr[indexPath.row];
|
|
if (!_videoPlayer) {
|
|
_videoPlayer = [SJVideoPlayer player];
|
|
}
|
|
SJEdgeControlButtonItem *playItem = [_videoPlayer.defaultEdgeControlLayer.bottomAdapter itemForTag:SJEdgeControlLayerTopItem_Back];
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(itemDidPlay:) name:SJEdgeControlButtonItemPerformedActionNotification object:playItem];
|
|
|
|
SJEdgeControlButtonItem *playItem1 = [_videoPlayer.defaultEdgeControlLayer.bottomAdapter itemForTag:SJEdgeControlLayerBottomItem_FullBtn];
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(itemDidPlay:) name:SJEdgeControlButtonItemPerformedActionNotification object:playItem1];
|
|
_videoPlayer.playbackObserver.playbackDidFinishExeBlock = ^(__kindof SJBaseVideoPlayer * _Nonnull player) {
|
|
[player replay];
|
|
};
|
|
_videoPlayer.delayInSecondsForHiddenPlaceholderImageView = 0.3;
|
|
_videoPlayer.muted = YES;
|
|
_videoPlayer.playerVolume = 0;
|
|
_videoPlayer.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithURL:[NSURL URLWithString:model.video] playModel:[SJPlayModel playModelWithTableView:self.myTableView indexPath:indexPath]];
|
|
[self showVideoPlayer:NO];
|
|
}
|
|
- (void)showVideoPlayer:(BOOL)mute{
|
|
[self.videoPlayer pause];
|
|
if (!self.videoPlayer.isFitOnScreen) {
|
|
[self.videoPlayer setFitOnScreen:YES animated:YES];
|
|
WeakSelf(weakSelf)
|
|
self.videoPlayer.fitOnScreenObserver.fitOnScreenWillBeginExeBlock = ^(id<SJFitOnScreenManager> _Nonnull mgr) {
|
|
if (mgr.isFitOnScreen) {
|
|
[weakSelf.videoPlayer play];
|
|
if (mute) {
|
|
weakSelf.videoPlayer.playerVolume = 0;
|
|
}else{
|
|
weakSelf.videoPlayer.playerVolume = 1;
|
|
weakSelf.videoPlayer.muted = NO;
|
|
}
|
|
}
|
|
};
|
|
|
|
}else{
|
|
[self.videoPlayer setFitOnScreen:NO animated:YES];
|
|
[self.videoPlayer pause];
|
|
WeakSelf(weakSelf)
|
|
self.videoPlayer.fitOnScreenObserver.fitOnScreenWillBeginExeBlock = ^(id<SJFitOnScreenManager> _Nonnull mgr) {
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
[weakSelf.videoPlayer stop];
|
|
weakSelf.videoPlayer = nil;
|
|
});
|
|
};
|
|
}
|
|
}
|
|
-(void)itemDidPlay:(NSNotification *)notification {
|
|
SJEdgeControlButtonItem *item = notification.object;
|
|
if (item.tag == SJEdgeControlLayerTopItem_Back || item.tag == SJEdgeControlLayerBottomItem_FullBtn) {
|
|
[self.videoPlayer setFitOnScreen:NO animated:YES];
|
|
[self.videoPlayer pause];
|
|
WeakSelf(weakSelf)
|
|
self.videoPlayer.fitOnScreenObserver.fitOnScreenWillBeginExeBlock = ^(id<SJFitOnScreenManager> _Nonnull mgr) {
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
[weakSelf.videoPlayer stop];
|
|
weakSelf.videoPlayer = nil;
|
|
});
|
|
};
|
|
}
|
|
}
|
|
- (void)requestAddFollow:(DDDynamicModel *)dynamicModel withIndexPath:(NSIndexPath *)index{
|
|
|
|
if ([ToolsObject IsNullWithObject:dynamicModel.user_id]) {
|
|
[ToolsObject addPopVieToText:@"没有获取到该用户信息"];
|
|
return;
|
|
}
|
|
[ToolsObject ShowSVProgressHUD:@""];
|
|
NSMutableDictionary *parameter =@{@"followed_user_id":dynamicModel.user_id}.mutableCopy;
|
|
WeakSelf(weakSelf)
|
|
__block DDDynamicModel * tempModel = dynamicModel;
|
|
[NetworkRequest requestPOST:@"/dynamic/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200) {
|
|
[ToolsObject addPopVieToText:@"关注成功"];
|
|
tempModel.user.is_attention = !tempModel.user.is_attention;
|
|
[weakSelf.listArr replaceObjectAtIndex:index.row withObject:tempModel];
|
|
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
}];
|
|
}
|
|
- (void)requestcancelFollow:(DDDynamicModel *)dynamicModel withIndexPath:(NSIndexPath *)index{
|
|
|
|
if ([ToolsObject IsNullWithObject:dynamicModel.user_id]) {
|
|
[ToolsObject addPopVieToText:@"没有获取到该用户信息"];
|
|
return;
|
|
}
|
|
[ToolsObject ShowSVProgressHUD:@""];
|
|
NSMutableDictionary *parameter =@{@"followed_user_id":dynamicModel.user_id}.mutableCopy;
|
|
__block DDDynamicModel * tempModel = dynamicModel;
|
|
WeakSelf(weakSelf)
|
|
[NetworkRequest requestPOST:@"/dynamic/cancel/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200) {
|
|
tempModel.user.is_attention = !tempModel.user.is_attention;
|
|
[weakSelf.listArr replaceObjectAtIndex:index.row withObject:tempModel];
|
|
[weakSelf.myTableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
}];
|
|
}
|
|
|
|
@end
|