MinePageMienBodyView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. //
  2. // MinePageMienBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "MinePageMienBodyView.h"
  8. #import "MineIntroduceCell.h"
  9. #import "MineVideoCell.h"
  10. #import "MineFansGroupCell.h"
  11. #import "StyleVideoModel.h"
  12. #import "WMPlayer.h"
  13. #import "MinePageGroupModel.h"
  14. #import "KSChatConversationViewController.h"
  15. #import "MineEmptyGroupCell.h"
  16. #import "MineEmptyIntroduceCell.h"
  17. #import "MineEmptyVideoCell.h"
  18. #import "MyStyleViewController.h"
  19. #import "CreateFansGroupViewController.h"
  20. @interface MinePageMienBodyView ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
  21. {
  22. WMPlayer *_wmPlayer;
  23. CGRect _playerFrame;
  24. }
  25. @property (nonatomic, strong) UIView *bgView;
  26. @property (nonatomic, assign) BOOL isRatation;
  27. @property (nonatomic, strong) NSMutableArray *fansGroupArray;
  28. @property (nonatomic, strong) NSString *content;
  29. @property (nonatomic, strong) NSMutableArray *videoArray;
  30. @end
  31. @implementation MinePageMienBodyView
  32. - (instancetype)initWithFrame:(CGRect)frame {
  33. self = [super initWithFrame:frame];
  34. if (self) {
  35. self.backgroundColor = HexRGB(0xf6f8f9);
  36. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStyleGrouped];
  37. self.tableView.backgroundColor = HexRGB(0xf6f8f9);
  38. self.tableView.showsVerticalScrollIndicator = NO;
  39. self.tableView.rowHeight = UITableViewAutomaticDimension;
  40. self.tableView.estimatedRowHeight = 200.0f;
  41. self.tableView.dataSource = self;
  42. self.tableView.delegate = self;
  43. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  44. [self addSubview:self.tableView];
  45. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  46. bottomView.backgroundColor = HexRGB(0xf6f8f9);
  47. self.tableView.tableFooterView = bottomView;
  48. [self.tableView registerNib:[UINib nibWithNibName:@"MineIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineIntroduceCell"];
  49. [self.tableView registerNib:[UINib nibWithNibName:@"MineVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineVideoCell"];
  50. [self.tableView registerNib:[UINib nibWithNibName:@"MineFansGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineFansGroupCell"];
  51. [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyIntroduceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyIntroduceCell"];
  52. [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyVideoCell"];
  53. [self.tableView registerNib:[UINib nibWithNibName:@"MineEmptyGroupCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MineEmptyGroupCell"];
  54. MJWeakSelf;
  55. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  56. [weakSelf requestData];
  57. [weakSelf requestTeacherGroup];
  58. }];
  59. }
  60. return self;
  61. }
  62. - (void)requestData {
  63. [KSNetworkingManager queryTeacherStyleRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  64. [self endRefresh];
  65. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  66. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  67. self.content = [result stringValueForKey:@"introduction"];
  68. NSArray *videoList = [result arrayValueForKey:@"styleVideo"];
  69. [self.videoArray removeAllObjects];
  70. for (NSDictionary *parm in videoList) {
  71. StyleVideoModel *model = [[StyleVideoModel alloc] initWithDictionary:parm];
  72. [self.videoArray addObject:model];
  73. }
  74. }
  75. else {
  76. [self MBPShow:MESSAGEKEY];
  77. }
  78. [self.tableView reloadData];
  79. } faliure:^(NSError * _Nonnull error) {
  80. [self endRefresh];
  81. }];
  82. }
  83. - (void)requestTeacherGroup {
  84. [KSNetworkingManager queryTeacherGroupRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  85. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  86. NSArray *sourceArray = [dic arrayValueForKey:@"data"];
  87. NSMutableArray *groupArray = [NSMutableArray array];
  88. for (NSDictionary *parm in sourceArray) {
  89. MinePageGroupModel *model = [[MinePageGroupModel alloc] initWithDictionary:parm];
  90. [groupArray addObject:model];
  91. }
  92. self.fansGroupArray = [NSMutableArray arrayWithArray:groupArray];
  93. }
  94. else {
  95. [self MBPShow:MESSAGEKEY];
  96. }
  97. [self.tableView reloadData];
  98. } faliure:^(NSError * _Nonnull error) {
  99. }];
  100. }
  101. - (void)endRefresh {
  102. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  103. [self.tableView.mj_header endRefreshing];
  104. });
  105. }
  106. - (void)beginRefreshImmediately {
  107. [self.tableView.mj_header beginRefreshing];
  108. }
  109. - (void)beginFirstRefresh {
  110. if (!self.isHeaderRefreshed) {
  111. [self beginRefreshImmediately];
  112. }
  113. }
  114. - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
  115. if (self.lastSelectedIndexPath == indexPath) {
  116. return;
  117. }
  118. if (self.lastSelectedIndexPath != nil) {
  119. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
  120. [cell setSelected:NO animated:NO];
  121. }
  122. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  123. [cell setSelected:YES animated:NO];
  124. self.lastSelectedIndexPath = indexPath;
  125. }
  126. - (void)layoutSubviews {
  127. [super layoutSubviews];
  128. self.tableView.frame = self.bounds;
  129. }
  130. #pragma mark --- table data source
  131. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  132. return 3;
  133. }
  134. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  135. if (section == 2) {
  136. if (self.fansGroupArray.count == 0) {
  137. return 1;
  138. }
  139. return self.fansGroupArray.count;
  140. }
  141. return 1;
  142. }
  143. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  144. if (indexPath.section == 0) {
  145. if ([NSString isEmptyString:self.content]) {
  146. MineEmptyIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyIntroduceCell"];
  147. MJWeakSelf;
  148. [cell emptyIntroduceCallback:^{
  149. [weakSelf createStyleAction];
  150. }];
  151. return cell;
  152. }
  153. else {
  154. MineIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineIntroduceCell"];
  155. [cell configIntroduce:self.content];
  156. return cell;
  157. }
  158. }
  159. else if (indexPath.section == 1) {
  160. if (self.videoArray.count > 0) {
  161. MineVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineVideoCell"];
  162. MJWeakSelf;
  163. [cell configWithSource:self.videoArray];
  164. [cell opreationCallback:^(UIView * _Nullable containerView) {
  165. NSInteger index = containerView.tag - 1000;
  166. if (weakSelf.videoArray.count > index) {
  167. StyleVideoModel *model = weakSelf.videoArray[index];
  168. [weakSelf playVideoWithUrl:model.videoUrl];
  169. }
  170. }];
  171. return cell;
  172. }
  173. else {
  174. MineEmptyVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyVideoCell"];
  175. MJWeakSelf;
  176. [cell emptyVideoCallback:^{
  177. [weakSelf createStyleAction];
  178. }];
  179. return cell;
  180. }
  181. }
  182. else {
  183. if (self.fansGroupArray.count == 0) {
  184. MineEmptyGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineEmptyGroupCell"];
  185. MJWeakSelf;
  186. [cell emptyGroupCallback:^{
  187. [weakSelf createGroup];
  188. }];
  189. return cell;
  190. }
  191. else {
  192. MinePageGroupModel *model = self.fansGroupArray[indexPath.row];
  193. MineFansGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineFansGroupCell"];
  194. MJWeakSelf;
  195. [cell configWithSource:model chatAction:^(NSString *groupName, NSString *groupId) {
  196. [weakSelf chatAction:groupId groupName:groupName];
  197. }];
  198. return cell;
  199. }
  200. }
  201. }
  202. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  203. if (indexPath.section == 2 && self.fansGroupArray.count != 0) {
  204. MinePageGroupModel *model = self.fansGroupArray[indexPath.row];
  205. [self chatAction:model.internalBaseClassIdentifier groupName:model.name];
  206. }
  207. }
  208. - (void)createStyleAction {
  209. MyStyleViewController *style = [[MyStyleViewController alloc] init];
  210. [self.naviController pushViewController:style animated:YES];
  211. }
  212. - (void)createGroup {
  213. CreateFansGroupViewController *ctrl = [[CreateFansGroupViewController alloc] init];
  214. [self.naviController pushViewController:ctrl animated:YES];
  215. }
  216. - (void)chatAction:(NSString *)groupId groupName:(NSString *)groupName {
  217. KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
  218. conversationVC.targetId = groupId;
  219. conversationVC.title = groupName;
  220. conversationVC.conversationType = ConversationType_GROUP;
  221. [self.naviController pushViewController:conversationVC animated:YES];
  222. }
  223. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  224. if (section == 2) {
  225. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 43.0f)];
  226. headView.backgroundColor = [UIColor clearColor];
  227. CGRect frame = CGRectMake(14, 0, kScreenWidth - 28, 43.0f);
  228. UIView *displayView = [[UIView alloc] initWithFrame:frame];
  229. displayView.backgroundColor = [UIColor whiteColor];
  230. [headView addSubview:displayView];
  231. if (@available(iOS 11.0, *)) {
  232. displayView.layer.cornerRadius = 10;
  233. displayView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; // 左上圆角
  234. }
  235. else {
  236. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:displayView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
  237. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  238. maskLayer.frame = frame;
  239. maskLayer.path = path.CGPath;
  240. displayView.layer.mask = maskLayer;
  241. }
  242. UIImageView *iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_fans"]];
  243. [displayView addSubview:iconImage];
  244. [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
  245. make.left.mas_equalTo(displayView.mas_left).offset(12);
  246. make.top.mas_equalTo(displayView.mas_top).offset(17);
  247. make.width.mas_equalTo(24);
  248. make.height.mas_equalTo(24);
  249. }];
  250. UILabel *tipsLable = [[UILabel alloc] init];
  251. tipsLable.text = @"粉丝群";
  252. tipsLable.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
  253. tipsLable.textColor = HexRGB(0x333333);
  254. [displayView addSubview:tipsLable];
  255. [tipsLable mas_makeConstraints:^(MASConstraintMaker *make) {
  256. make.left.mas_equalTo(iconImage.mas_right).offset(4);
  257. make.centerY.mas_equalTo(iconImage.mas_centerY);
  258. make.height.mas_equalTo(30);
  259. make.width.mas_equalTo(100);
  260. }];
  261. return headView;
  262. }
  263. return [UIView new];
  264. }
  265. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  266. {
  267. if (section == 2) {
  268. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15.0f)];
  269. bottomView.backgroundColor = [UIColor clearColor];
  270. CGRect frame = CGRectMake(14, 0, kScreenWidth - 28, 15);
  271. UIView *displayView = [[UIView alloc] initWithFrame:frame];
  272. displayView.backgroundColor = [UIColor whiteColor];
  273. [bottomView addSubview:displayView];
  274. if (@available(iOS 11.0, *)) {
  275. displayView.layer.cornerRadius = 10;
  276. displayView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
  277. }
  278. else {
  279. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:displayView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
  280. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  281. maskLayer.frame = frame;
  282. maskLayer.path = path.CGPath;
  283. displayView.layer.mask = maskLayer;
  284. }
  285. return bottomView;
  286. }
  287. return [UIView new];
  288. }
  289. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  290. if (section == 2) {
  291. return 43.0f;
  292. }
  293. return CGFLOAT_MIN;
  294. }
  295. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  296. if (section == 2) {
  297. return 15.0f;
  298. }
  299. return CGFLOAT_MIN;
  300. }
  301. - (NSMutableArray *)videoArray {
  302. if (!_videoArray) {
  303. _videoArray = [NSMutableArray array];
  304. }
  305. return _videoArray;
  306. }
  307. #pragma mark ------ WMPlayer
  308. - (void)playVideoWithUrl:(NSString *)fileUrl {
  309. fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  310. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  311. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  312. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  313. playModel.videoURL = [NSURL URLWithString:fileUrl];
  314. _wmPlayer.playerModel = playModel;
  315. _wmPlayer.delegate = self;
  316. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  317. _bgView.backgroundColor = [UIColor blackColor];
  318. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  319. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  320. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  321. [_wmPlayer play];
  322. }
  323. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  324. [wmplayer removePlayer];
  325. [_bgView removeFromSuperview];
  326. [self.naviController setNeedsStatusBarAppearanceUpdate];
  327. }
  328. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  329. self.isRatation = !self.isRatation;
  330. if (self.isRatation) {
  331. [wmplayer removeFromSuperview];
  332. [UIView animateWithDuration:1.0f animations:^{
  333. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  334. } completion:^(BOOL finished) {
  335. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  336. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  337. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  338. }];
  339. }
  340. else {
  341. [wmplayer removeFromSuperview];
  342. [UIView animateWithDuration:1.0f animations:^{
  343. // 复原
  344. wmplayer.transform = CGAffineTransformIdentity;
  345. } completion:^(BOOL finished) {
  346. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  347. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  348. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  349. }];
  350. }
  351. }
  352. /*
  353. // Only override drawRect: if you perform custom drawing.
  354. // An empty implementation adversely affects performance during animation.
  355. - (void)drawRect:(CGRect)rect {
  356. // Drawing code
  357. }
  358. */
  359. @end