123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- //
- // MinePageMienBodyView.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/30.
- //
- #import "MinePageMienBodyView.h"
- #import "MineIntroduceCell.h"
- #import "MineVideoCell.h"
- #import "MineFansGroupCell.h"
- #import "StyleVideoModel.h"
- #import "WMPlayer.h"
- #import "MinePageGroupModel.h"
- #import "KSGroupConversationController.h"
- #import "MineEmptyGroupCell.h"
- #import "MineEmptyIntroduceCell.h"
- #import "MineEmptyVideoCell.h"
- #import "MyStyleViewController.h"
- #import "CreateFansGroupViewController.h"
- @interface MinePageMienBodyView ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
- {
- WMPlayer *_wmPlayer;
- CGRect _playerFrame;
- }
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, assign) BOOL isRatation;
- @property (nonatomic, strong) NSMutableArray *fansGroupArray;
- @property (nonatomic, strong) NSString *content;
- @property (nonatomic, strong) NSMutableArray *videoArray;
- @end
- @implementation MinePageMienBodyView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = HexRGB(0xf6f8f9);
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStyleGrouped];
- self.tableView.backgroundColor = HexRGB(0xf6f8f9);
- self.tableView.showsVerticalScrollIndicator = NO;
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 200.0f;
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self addSubview:self.tableView];
-
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = HexRGB(0xf6f8f9);
- self.tableView.tableFooterView = bottomView;
-
- [self.tableView registerNib:[UINib nibWithNibName:@"MineIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineIntroduceCell"];
- [self.tableView registerNib:[UINib nibWithNibName:@"MineVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineVideoCell"];
- [self.tableView registerNib:[UINib nibWithNibName:@"MineFansGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineFansGroupCell"];
-
- [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyIntroduceCell"];
- [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyVideoCell"];
- [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyGroupCell"];
-
- MJWeakSelf;
- self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- [weakSelf requestTeacherGroup];
- }];
- }
- return self;
- }
- - (void)requestData {
- [KSNetworkingManager queryTeacherStyleRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- [self endRefresh];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- self.content = [result ks_stringValueForKey:@"introduction"];
- NSArray *videoList = [result ks_arrayValueForKey:@"styleVideo"];
- [self.videoArray removeAllObjects];
- for (NSDictionary *parm in videoList) {
- StyleVideoModel *model = [[StyleVideoModel alloc] initWithDictionary:parm];
- [self.videoArray addObject:model];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- } faliure:^(NSError * _Nonnull error) {
- [self endRefresh];
- }];
- }
- - (void)requestTeacherGroup {
- [KSNetworkingManager queryTeacherGroupRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- NSMutableArray *groupArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- MinePageGroupModel *model = [[MinePageGroupModel alloc] initWithDictionary:parm];
- [groupArray addObject:model];
- }
- self.fansGroupArray = [NSMutableArray arrayWithArray:groupArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)endRefresh {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.tableView.mj_header endRefreshing];
- });
- }
- - (void)beginRefreshImmediately {
- [self.tableView.mj_header beginRefreshing];
- }
- - (void)beginFirstRefresh {
- if (!self.isHeaderRefreshed) {
- [self beginRefreshImmediately];
- }
- }
- - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
-
- if (self.lastSelectedIndexPath == indexPath) {
- return;
- }
- if (self.lastSelectedIndexPath != nil) {
- UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
- [cell setSelected:NO animated:NO];
- }
- UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
- [cell setSelected:YES animated:NO];
- self.lastSelectedIndexPath = indexPath;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- self.tableView.frame = self.bounds;
- }
- #pragma mark --- table data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 2) {
- if (self.fansGroupArray.count == 0) {
- return 1;
- }
- return self.fansGroupArray.count;
- }
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- if ([NSString isEmptyString:self.content]) {
- MineEmptyIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyIntroduceCell"];
- MJWeakSelf;
- [cell emptyIntroduceCallback:^{
- [weakSelf createStyleAction];
- }];
- return cell;
- }
- else {
- MineIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineIntroduceCell"];
- [cell configIntroduce:self.content];
- return cell;
- }
-
- }
- else if (indexPath.section == 1) {
- if (self.videoArray.count > 0) {
- MineVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineVideoCell"];
- MJWeakSelf;
- [cell configWithSource:self.videoArray];
- [cell opreationCallback:^(UIView * _Nullable containerView) {
- NSInteger index = containerView.tag - 1000;
- if (weakSelf.videoArray.count > index) {
- StyleVideoModel *model = weakSelf.videoArray[index];
- [weakSelf playVideoWithUrl:model.videoUrl];
- }
- }];
- return cell;
- }
- else {
- MineEmptyVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyVideoCell"];
- MJWeakSelf;
- [cell emptyVideoCallback:^{
- [weakSelf createStyleAction];
- }];
- return cell;
- }
-
- }
- else {
- if (self.fansGroupArray.count == 0) {
- MineEmptyGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyGroupCell"];
- MJWeakSelf;
- [cell emptyGroupCallback:^{
- [weakSelf createGroup];
- }];
- return cell;
- }
- else {
- MinePageGroupModel *model = self.fansGroupArray[indexPath.row];
- MineFansGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineFansGroupCell"];
- MJWeakSelf;
- [cell configWithSource:model chatAction:^(NSString *groupName, NSString *groupId) {
- [weakSelf chatAction:groupId groupName:groupName];
- }];
- return cell;
- }
-
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 2 && self.fansGroupArray.count != 0) {
- MinePageGroupModel *model = self.fansGroupArray[indexPath.row];
- [self chatAction:model.internalBaseClassIdentifier groupName:model.name];
- }
- }
- - (void)createStyleAction {
- MyStyleViewController *style = [[MyStyleViewController alloc] init];
- [self.naviController pushViewController:style animated:YES];
- }
- - (void)createGroup {
- CreateFansGroupViewController *ctrl = [[CreateFansGroupViewController alloc] init];
- [self.naviController pushViewController:ctrl animated:YES];
- }
- - (void)chatAction:(NSString *)groupId groupName:(NSString *)groupName {
- TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
- model.groupID = groupId;
- KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
- ctrl.conversation = model;
- [self.naviController pushViewController:ctrl animated:YES];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (section == 2) {
-
- UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 43.0f)];
- headView.backgroundColor = [UIColor clearColor];
- CGRect frame = CGRectMake(14, 0, kScreenWidth - 28, 43.0f);
- UIView *displayView = [[UIView alloc] initWithFrame:frame];
- displayView.backgroundColor = [UIColor whiteColor];
- [headView addSubview:displayView];
- if (@available(iOS 11.0, *)) {
- displayView.layer.cornerRadius = 10;
- displayView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; // 左上圆角
- }
- else {
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:displayView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = frame;
- maskLayer.path = path.CGPath;
- displayView.layer.mask = maskLayer;
- }
- UILabel *tipsLable = [[UILabel alloc] init];
- tipsLable.text = @"粉丝群";
- tipsLable.font = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
- tipsLable.textColor = HexRGB(0x333333);
- [displayView addSubview:tipsLable];
- [tipsLable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(displayView.mas_left).offset(14);
- make.top.mas_equalTo(displayView.mas_top).offset(11);
- make.height.mas_equalTo(30);
- make.width.mas_equalTo(100);
- }];
- return headView;
- }
- return [UIView new];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- if (section == 2) {
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15.0f)];
- bottomView.backgroundColor = [UIColor clearColor];
- CGRect frame = CGRectMake(14, 0, kScreenWidth - 28, 15);
- UIView *displayView = [[UIView alloc] initWithFrame:frame];
- displayView.backgroundColor = [UIColor whiteColor];
- [bottomView addSubview:displayView];
- if (@available(iOS 11.0, *)) {
- displayView.layer.cornerRadius = 10;
- displayView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
- }
- else {
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:displayView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = frame;
- maskLayer.path = path.CGPath;
- displayView.layer.mask = maskLayer;
- }
- return bottomView;
- }
- return [UIView new];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 2) {
- return 43.0f;
- }
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- if (section == 2) {
- return 15.0f;
- }
- return CGFLOAT_MIN;
- }
- - (NSMutableArray *)videoArray {
- if (!_videoArray) {
- _videoArray = [NSMutableArray array];
- }
- return _videoArray;
- }
- #pragma mark ------ WMPlayer
- - (void)playVideoWithUrl:(NSString *)fileUrl {
- fileUrl = [fileUrl getUrlEndcodeString];
- _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
- WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
- playModel.videoURL = [NSURL URLWithString:fileUrl];
- _wmPlayer.playerModel = playModel;
- _wmPlayer.delegate = self;
- _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- _bgView.backgroundColor = [UIColor blackColor];
- [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
- [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
-
- [_wmPlayer play];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
- [wmplayer removePlayer];
- [_bgView removeFromSuperview];
- [self.naviController setNeedsStatusBarAppearanceUpdate];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
- self.isRatation = !self.isRatation;
-
- if (self.isRatation) {
- [wmplayer removeFromSuperview];
- [UIView animateWithDuration:1.0f animations:^{
- wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- else {
- [wmplayer removeFromSuperview];
-
- [UIView animateWithDuration:1.0f animations:^{
- // 复原
- wmplayer.transform = CGAffineTransformIdentity;
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|