MOWatchHistoryVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //
  2. // MOWatchHistoryVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/24.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOWatchHistoryVC.h"
  10. #import "MOHistoryListCell.h"
  11. #import "NSDate+K1Util.h"
  12. #import "MOUserHomePageVC.h"
  13. #import "MOShowLivePagesVC.h"
  14. @interface MOWatchHistoryVC ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
  16. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  17. @property (nonatomic, strong) NSMutableArray *dataArr;
  18. /** 没有更多的数据视图 */
  19. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  20. @property (nonatomic, copy) NSString *next;
  21. @end
  22. @implementation MOWatchHistoryVC
  23. - (void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:animated];
  25. [self.navigationController setNavigationBarHidden:NO animated:animated];
  26. [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view from its nib.
  31. self.navigationItem.title = NSLocalString(@"mimo_explore_watch_history");
  32. // [self setNavLeftItemWithImage:[UIImage imageNamed:@"icon_nav_back"]];
  33. // [self setNavRightItemWithImage:[UIImage imageNamed:@"icon_history_delete"]];
  34. [self setupUI];
  35. [self getFirstPageData];
  36. }
  37. //清除历史记录
  38. - (void)RightBarItemClick:(UIButton*)sender{
  39. WEAKSELF
  40. MOTitleNormalAlertView *alertView = [[MOTitleNormalAlertView alloc] init];
  41. alertView.titleLabel.text = NSLocalString(@"mimo_alert_normal_tip");
  42. alertView.subTitleLabel.text = NSLocalString(@"mimo_explore_watch_history_delete");
  43. [alertView.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
  44. [alertView.confirmBtn setTitle:NSLocalString(@"mimo_TipConfirm") forState:UIControlStateNormal];
  45. alertView.confirmBlock = ^{
  46. [weakSelf toDeleleAllHistoryData];
  47. };
  48. [alertView show];
  49. }
  50. - (void)toDeleleAllHistoryData{
  51. NSDictionary *dict = @{};
  52. WEAKSELF
  53. [kHttpManager toDeleteTheLiveHistoryWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  54. if(kCode_Success){
  55. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
  56. [weakSelf.dataArr removeAllObjects];
  57. [weakSelf.tableView reloadData];
  58. }
  59. else{
  60. MOLogV(@"toDeleleAllHistoryData 接口报错了");
  61. kShowNetError(data)
  62. }
  63. }];
  64. }
  65. - (void)getFirstPageData{
  66. self.next = @"";
  67. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  68. NSDictionary *baseDict = @{@"page":basePage};
  69. [self getHistoryListHttpDataWith:baseDict];
  70. }
  71. - (void)getHistoryListHttpDataWith:(NSDictionary *)dict{
  72. WEAKSELF
  73. [kHttpManager toGetTheLiveHistoryListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  74. __strong typeof(weakSelf) self = weakSelf;
  75. [self.tableView.mj_footer endRefreshing];
  76. if(kCode_Success){
  77. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  78. MOHistoryBaseData *baseModel = [MOHistoryBaseData modelObjectWithDictionary:data[@"data"]];
  79. if(baseModel.next == nil || baseModel.next.length == 0){
  80. self.next = @"";
  81. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  82. }
  83. else{
  84. self.next = baseModel.next;
  85. }
  86. [self theDataParsingWith:baseModel.historyList];
  87. self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  88. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  89. }
  90. else{
  91. kShowNetError(data)
  92. }
  93. }];
  94. }
  95. - (void)theDataParsingWith:(NSArray *)modelList{
  96. for (MOHistoryList *object in modelList) {
  97. NSString *dataStr = [NSDate getTimeWithLong:object.time formatter:@"YYYY-MM-dd"];
  98. MOHistoryBaseData *dayData;
  99. BOOL isHave = NO;
  100. for (MOHistoryBaseData *dayObject in self.dataArr) {
  101. if([dayObject.dayStr isEqualToString:dataStr]){
  102. dayData = dayObject;
  103. isHave = YES;
  104. break;
  105. }
  106. }
  107. if(isHave){
  108. NSMutableArray *tempArr = [dayData.historyList mutableCopy];
  109. [tempArr addObject:object];
  110. dayData.historyList = [tempArr copy];
  111. }
  112. else{
  113. MOHistoryBaseData *dayModel = [[MOHistoryBaseData alloc] init];
  114. NSMutableArray *tempArr = [NSMutableArray array];
  115. [tempArr addObject:object];
  116. dayModel.historyList = [tempArr copy];
  117. dayModel.dayStr = dataStr;
  118. [self.dataArr addObject:dayModel];
  119. }
  120. }
  121. [self.tableView reloadData];
  122. }
  123. #pragma mark - UITableViewDelegate,UITableViewDataSource
  124. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  125. return self.dataArr.count;
  126. }
  127. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  128. MOHistoryBaseData *model = self.dataArr[section];
  129. return model.historyList.count;
  130. }
  131. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  132. WEAKSELF
  133. MOHistoryBaseData *sectionModel = self.dataArr[indexPath.section];
  134. MOHistoryList *model = sectionModel.historyList[indexPath.row];
  135. MOHistoryListCell *cell = [tableView dequeueReusableCellWithIdentifier:MOHistoryListCell_ID];
  136. if (cell == nil){
  137. cell = [[MOHistoryListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MOHistoryListCell_ID];
  138. }
  139. cell.cellModel = model.userBase;
  140. cell.followBtnBlock = ^(MOUserBase * _Nonnull cellModel, NSIndexPath * _Nonnull cellIndexPath) {
  141. cellModel.follow = YES;
  142. MOHistoryBaseData *sectionModel = weakSelf.dataArr[indexPath.section];
  143. for (MOHistoryList *tempModel in sectionModel.historyList) {
  144. if([tempModel.userBase.userProfile.id isEqualToString:cellModel.userProfile.id]){
  145. tempModel.userBase.follow = YES;
  146. break;
  147. }
  148. }
  149. NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:cellIndexPath.section];
  150. [weakSelf.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
  151. };
  152. cell.headBtnClickBlock = ^(MOUserBase * _Nonnull cellModel) {
  153. if(cellModel.liveRoomId.length > 0){
  154. //去直播间
  155. [weakSelf toShowTheLiveRoomWith:cellModel.liveRoomId];
  156. }
  157. else{
  158. //去主页
  159. if(cellModel.userProfile.id.length > 0){
  160. [weakSelf toShowTheUserHomePageWith:cellModel.userProfile.id];
  161. }
  162. }
  163. };
  164. return cell;
  165. }
  166. - (void)toShowTheLiveRoomWith:(NSString *)roomId{
  167. [MOShowAgoraKitManager shareManager].isFirstShow = YES;
  168. [MOShowAgoraKitManager shareManager].isCreatLive = NO;
  169. MOLiveList *model = [[MOLiveList alloc] init];
  170. model.id = roomId;
  171. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  172. vc.userType = MOShowLiveAudienceType;
  173. vc.roomList = @[model].mutableCopy;
  174. vc.focusIndex = 0;
  175. // UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:vc];
  176. // newNav.modalPresentationStyle = UIModalPresentationFullScreen;
  177. // [self.navigationController presentViewController:newNav animated:YES completion:nil];
  178. vc.hidesBottomBarWhenPushed = YES;
  179. [self.navigationController pushViewController:vc animated:YES];
  180. }
  181. - (void)toShowTheUserHomePageWith:(NSString *)userId{
  182. MOUserHomePageVC *vc = [[MOUserHomePageVC alloc] init];
  183. vc.userId = userId;
  184. [self.navigationController pushViewController:vc animated:YES];
  185. }
  186. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  187. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  188. MOHistoryBaseData *sectionModel = self.dataArr[indexPath.section];
  189. MOHistoryList *model = sectionModel.historyList[indexPath.row];
  190. //去主页
  191. if(model.userBase.userProfile.id.length > 0){
  192. [self toShowTheUserHomePageWith:model.userBase.userProfile.id];
  193. }
  194. }
  195. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  196. return 36.0;
  197. }
  198. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  199. MOHistoryBaseData *sectionModel = self.dataArr[section];
  200. UIView *view = [[UIView alloc] init];
  201. view.backgroundColor = [UIColor clearColor];
  202. UIImage *image = [MOTools createImageWithColor:[MOTools colorWithHexString:@"#FFFFFF"]];
  203. UIImageView *bgImgView = [[UIImageView alloc] init];
  204. bgImgView.contentMode = UIViewContentModeScaleToFill;
  205. [bgImgView setImage:image];
  206. [view addSubview:bgImgView];
  207. [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.left.equalTo(view);
  209. make.right.equalTo(view);
  210. make.top.bottom.equalTo(view);
  211. }];
  212. UILabel *titleLab = [[UILabel alloc] init];
  213. titleLab.font = [MOTextTools regularFont:13];
  214. titleLab.textColor = kBaseTextColor_2;
  215. titleLab.textAlignment = NSTextAlignmentLeft;
  216. titleLab.text = sectionModel.dayStr;
  217. [view addSubview:titleLab];
  218. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  219. make.left.equalTo(view).offset(26.0);
  220. make.centerY.equalTo(view);
  221. make.right.equalTo(view).offset(-15.0);
  222. }];
  223. return view;
  224. }
  225. #pragma mark - set UI
  226. - (void)setupUI{
  227. NSArray *colorArr = @[[MOTools colorWithHexString:@"#EEF2FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
  228. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT)) Colors:colorArr GradientType:1];
  229. [self.bgImgView setImage:image];
  230. self.next = @"";
  231. self.tableView.estimatedRowHeight = 0;
  232. self.tableView.estimatedSectionHeaderHeight = 0;
  233. self.tableView.estimatedSectionFooterHeight = 0;
  234. self.tableView.rowHeight = 64.0;
  235. //iOS15适配
  236. if (@available(iOS 15.0, *))
  237. {
  238. self.tableView.sectionHeaderTopPadding = 0;
  239. }
  240. [self.tableView registerClass:[MOHistoryListCell class] forCellReuseIdentifier:MOHistoryListCell_ID];
  241. WEAKSELF
  242. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  243. if(weakSelf.next.length == 0){
  244. return;
  245. }
  246. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  247. NSDictionary *baseDict = @{@"page":basePage};
  248. [weakSelf getHistoryListHttpDataWith:baseDict];
  249. }];
  250. self.tableView.mj_footer.hidden = YES;
  251. self.tableView.backgroundView = self.noMoreDataView;
  252. }
  253. - (NSMutableArray *)dataArr{
  254. if(!_dataArr){
  255. _dataArr = [NSMutableArray array];
  256. }
  257. return _dataArr;
  258. }
  259. - (MONoMoreDataView *)noMoreDataView{
  260. if(!_noMoreDataView){
  261. _noMoreDataView = [MONoMoreDataView new];
  262. }
  263. return _noMoreDataView;
  264. }
  265. @end