123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // XYMarkingFriendsSkillListViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/12/7.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMarkingFriendsSkillListViewController.h"
- #import "XYMarkingFriendsSkillListViewModel.h"
- #import "XYMarkingFriendsSkillListTableViewCell.h"
- #import "XYSkillUserModel.h"
- #import "XYSkillUserHomePageViewController.h"
- #import "XYSkillVoicePlayManager.h"
- @interface XYMarkingFriendsSkillListViewController ()<XYMarkingFriendsSkillListTableViewCellDelegate, XYSkillVoicePlayManagerDelegate>
- @property (nonatomic, strong) XYMarkingFriendsSkillListViewModel *viewModel;
- @property (nonatomic, strong) XYMarkingFriendsSkillListTableViewCell *playingCell;
- @end
- @implementation XYMarkingFriendsSkillListViewController
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [XYSkillVoicePlayManager sharedInstance].delegate = self;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [self stopPlay];
- [XYSkillVoicePlayManager sharedInstance].delegate = nil;
- }
- #pragma mark — Override
- - (void)bindViewModel {
- self.viewModel = XYMarkingFriendsSkillListViewModel.new;
- self.viewModel.skillId = [self.skillId copy];
- }
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, STATUS_HEIGHT + 48.0f + 68.0f + TABBAR_HEIGHT, 0);
- }
- - (void)requestRemoteData {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id _Nullable responseModel) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- } failure:^(ZYLNetworkError * _Nullable error) {
- [self tableViewDidFinishTriggerHeader:YES reload:NO];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- }];
- }
- - (void)tableViewDidTriggerFooterRefresh {
- [super tableViewDidTriggerFooterRefresh];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- return [XYMarkingFriendsSkillListTableViewCell cellWithTableView:tableView];
- }
- - (void)configureCell:(XYMarkingFriendsSkillListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell configureModel:object];
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
- cell.delegate = self;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 94.0f;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- XYSkillUserModel *model = self.viewModel.dataSource[indexPath.row];
- XYSkillUserHomePageViewController *controller = XYSkillUserHomePageViewController.new;
- controller.userId = [model.userId copy];
- controller.skillId = [model.skillId copy];
- [self.navigationController pushViewController:controller animated:YES];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- /// 滚动时停止播放
- [self stopPlay];
- // 滑动到顶部,不允许继续下滑
- if (scrollView.contentOffset.y < 0) {
- [self.tableView setContentOffset:CGPointMake(0, 0)];
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SKILL_LIST_SCROLL_OFFSET_Y" object:@{@"offsetY":@(scrollView.contentOffset.y)}];
- }
- #pragma mark — XYSkillUserListTableViewCellDelegate
- - (void)cell:(XYMarkingFriendsSkillListTableViewCell *)cell didClickVoicePlayActionAtIndexPath:(NSIndexPath *)indexPath {
- XYSkillUserModel *model = self.viewModel.dataSource[indexPath.row];
- if (self.playingCell) {
- self.playingCell.voicePlayView.playing = NO;
- self.playingCell.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [self.playingCell.skillModel.duration integerValue]];
- }
- self.playingCell = cell;
-
- // 播放/暂停
- [[XYSkillVoicePlayManager sharedInstance] playVoiceWithUrl:model.voice];
- }
- #pragma mark — XYSkillVoicePlayManagerDelegate
- /// 开始播放
- - (void)didStartPlayVoice {
- if (self.playingCell) {
- self.playingCell.voicePlayView.playing = YES;
- self.playingCell.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [self.playingCell.skillModel.duration integerValue]];
- }
- }
- /// 播放中的时间回调
- - (void)playVoiceCurrtentTime:(NSInteger)time {
- if (self.playingCell) {
- self.playingCell.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", time];
- }
- }
- /// 播放完成或者暂停播放
- - (void)playbackCompleteOrPausedWithUrl:(NSString *)voiceUrl {
- if (self.playingCell) {
- self.playingCell.voicePlayView.playing = NO;
- self.playingCell.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [self.playingCell.skillModel.duration integerValue]];
- }
- }
- #pragma mark — JXCategoryListContentViewDelegate
- /**
- 如果列表是VC,就返回VC.view
- 如果列表是View,就返回View自己
- @return 返回列表视图
- */
- - (UIView *)listView {
- return self.view;
- }
- - (void)stopPlay {
- XYSkillVoicePlayManager *playManager = [XYSkillVoicePlayManager sharedInstance];
- if (StringIsNotEmpty(playManager.currentVoiceUrl)) {
- [playManager resetStatus];
- }
- if (self.playingCell) {
- self.playingCell.voicePlayView.playing = NO;
- self.playingCell.voicePlayView.secondText = [NSString stringWithFormat:@"%ld''", [self.playingCell.skillModel.duration integerValue]];
- }
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|