| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- //
- // MOWatchHistoryVC.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/24.
- //
- //一页的size
- #define kPageSize 15
- #import "MOWatchHistoryVC.h"
- #import "MOHistoryListCell.h"
- #import "NSDate+K1Util.h"
- #import "MOUserHomePageVC.h"
- #import "MOShowLivePagesVC.h"
- @interface MOWatchHistoryVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- /** 没有更多的数据视图 */
- @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
- @property (nonatomic, copy) NSString *next;
- @end
- @implementation MOWatchHistoryVC
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:animated];
-
- [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- self.navigationItem.title = NSLocalString(@"mimo_explore_watch_history");
- // [self setNavLeftItemWithImage:[UIImage imageNamed:@"icon_nav_back"]];
- // [self setNavRightItemWithImage:[UIImage imageNamed:@"icon_history_delete"]];
-
- [self setupUI];
-
- [self getFirstPageData];
- }
- //清除历史记录
- - (void)RightBarItemClick:(UIButton*)sender{
- WEAKSELF
- MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
- alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
- alertView.subTitleLabel.text = NSLocalString(@"mimo_explore_watch_history_delete");
- [alertView.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
- [alertView.confirmBtn setTitle:NSLocalString(@"mimo_TipConfirm") forState:UIControlStateNormal];
- alertView.confirmBlock = ^{
- [weakSelf toDeleleAllHistoryData];
- };
- [alertView show];
- }
- - (void)toDeleleAllHistoryData{
- NSDictionary *dict = @{};
- WEAKSELF
- [kHttpManager toDeleteTheLiveHistoryWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
-
- [weakSelf.dataArr removeAllObjects];
- [weakSelf.tableView reloadData];
- }
- else{
- MOLogV(@"toDeleleAllHistoryData 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- - (void)getFirstPageData{
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"page":basePage};
-
- [self getHistoryListHttpDataWith:baseDict];
- }
- - (void)getHistoryListHttpDataWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetTheLiveHistoryListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
-
- [self.tableView.mj_footer endRefreshing];
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOHistoryBaseData *baseModel = [MOHistoryBaseData modelObjectWithDictionary:data[@"data"]];
- if(baseModel.next == nil || baseModel.next.length == 0){
- self.next = @"";
-
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- self.next = baseModel.next;
- }
-
- [self theDataParsingWith:baseModel.historyList];
-
- self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
- self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)theDataParsingWith:(NSArray *)modelList{
- for (MOHistoryList *object in modelList) {
- NSString *dataStr = [NSDate getTimeWithLong:object.time formatter:@"YYYY-MM-dd"];
-
- MOHistoryBaseData *dayData;
- BOOL isHave = NO;
- for (MOHistoryBaseData *dayObject in self.dataArr) {
- if([dayObject.dayStr isEqualToString:dataStr]){
- dayData = dayObject;
- isHave = YES;
- break;
- }
- }
-
- if(isHave){
- NSMutableArray *tempArr = [dayData.historyList mutableCopy];
- [tempArr addObject:object];
- dayData.historyList = [tempArr copy];
- }
- else{
- MOHistoryBaseData *dayModel = [[MOHistoryBaseData alloc] init];
- NSMutableArray *tempArr = [NSMutableArray array];
- [tempArr addObject:object];
- dayModel.historyList = [tempArr copy];
- dayModel.dayStr = dataStr;
- [self.dataArr addObject:dayModel];
- }
- }
-
- [self.tableView reloadData];
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return self.dataArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- MOHistoryBaseData *model = self.dataArr[section];
- return model.historyList.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- WEAKSELF
- MOHistoryBaseData *sectionModel = self.dataArr[indexPath.section];
- MOHistoryList *model = sectionModel.historyList[indexPath.row];
- MOHistoryListCell *cell = [tableView dequeueReusableCellWithIdentifier:MOHistoryListCell_ID];
- if (cell == nil){
- cell = [[MOHistoryListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MOHistoryListCell_ID];
- }
- cell.cellModel = model.userBase;
- cell.followBtnBlock = ^(MOUserBase * _Nonnull cellModel, NSIndexPath * _Nonnull cellIndexPath) {
- cellModel.follow = YES;
-
- MOHistoryBaseData *sectionModel = weakSelf.dataArr[indexPath.section];
-
- for (MOHistoryList *tempModel in sectionModel.historyList) {
- if([tempModel.userBase.userProfile.id isEqualToString:cellModel.userProfile.id]){
- tempModel.userBase.follow = YES;
- break;
- }
- }
-
- NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:cellIndexPath.section];
- [weakSelf.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
- };
-
- cell.headBtnClickBlock = ^(MOUserBase * _Nonnull cellModel) {
- if(cellModel.liveRoomId.length > 0){
- //去直播间
- [weakSelf toShowTheLiveRoomWith:cellModel.liveRoomId];
- }
- else{
- //去主页
- if(cellModel.userProfile.id.length > 0){
- [weakSelf toShowTheUserHomePageWith:cellModel.userProfile.id];
- }
- }
- };
-
- return cell;
-
- }
- - (void)toShowTheLiveRoomWith:(NSString *)roomId{
-
- [MOShowAgoraKitManager shareManager].isFirstShow = YES;
- [MOShowAgoraKitManager shareManager].isCreatLive = NO;
-
- MOLiveList *model = [[MOLiveList alloc] init];
- model.id = roomId;
- MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
- vc.userType = MOShowLiveAudienceType;
- vc.roomList = @[model].mutableCopy;
- vc.focusIndex = 0;
-
- // UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:vc];
- // newNav.modalPresentationStyle = UIModalPresentationFullScreen;
- // [self.navigationController presentViewController:newNav animated:YES completion:nil];
-
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)toShowTheUserHomePageWith:(NSString *)userId{
- MOUserHomePageVC *vc = [[MOUserHomePageVC alloc] init];
- vc.userId = userId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- MOHistoryBaseData *sectionModel = self.dataArr[indexPath.section];
- MOHistoryList *model = sectionModel.historyList[indexPath.row];
-
- //去主页
- if(model.userBase.userProfile.id.length > 0){
- [self toShowTheUserHomePageWith:model.userBase.userProfile.id];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
-
- return 36.0;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- MOHistoryBaseData *sectionModel = self.dataArr[section];
- UIView *view = [[UIView alloc] init];
- view.backgroundColor = [UIColor clearColor];
-
- UIImage *image = [MOTools createImageWithColor:[MOTools colorWithHexString:@"#FFFFFF"]];
- UIImageView *bgImgView = [[UIImageView alloc] init];
- bgImgView.contentMode = UIViewContentModeScaleToFill;
- [bgImgView setImage:image];
- [view addSubview:bgImgView];
- [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(view);
- make.right.equalTo(view);
- make.top.bottom.equalTo(view);
- }];
-
- UILabel *titleLab = [[UILabel alloc] init];
- titleLab.font = [MOTextTools regularFont:13];
- titleLab.textColor = kBaseTextColor_2;
- titleLab.textAlignment = NSTextAlignmentLeft;
-
- titleLab.text = sectionModel.dayStr;
- [view addSubview:titleLab];
- [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(view).offset(26.0);
- make.centerY.equalTo(view);
- make.right.equalTo(view).offset(-15.0);
- }];
-
- return view;
- }
- #pragma mark - set UI
- - (void)setupUI{
-
- NSArray *colorArr = @[[MOTools colorWithHexString:@"#EEF2FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT)) Colors:colorArr GradientType:1];
- [self.bgImgView setImage:image];
-
- self.next = @"";
-
- self.tableView.estimatedRowHeight = 0;
- self.tableView.estimatedSectionHeaderHeight = 0;
- self.tableView.estimatedSectionFooterHeight = 0;
- self.tableView.rowHeight = 64.0;
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- self.tableView.sectionHeaderTopPadding = 0;
- }
- [self.tableView registerClass:[MOHistoryListCell class] forCellReuseIdentifier:MOHistoryListCell_ID];
-
- WEAKSELF
- self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
-
- if(weakSelf.next.length == 0){
- return;
- }
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
- NSDictionary *baseDict = @{@"page":basePage};
-
- [weakSelf getHistoryListHttpDataWith:baseDict];
- }];
-
- self.tableView.mj_footer.hidden = YES;
- self.tableView.backgroundView = self.noMoreDataView;
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
-
- return _dataArr;
- }
- - (MONoMoreDataView *)noMoreDataView{
- if(!_noMoreDataView){
- _noMoreDataView = [MONoMoreDataView new];
- }
- return _noMoreDataView;
- }
- @end
|