MinePageMienBodyView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 "KSGroupConversationController.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 ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  66. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  67. self.content = [result ks_stringValueForKey:@"introduction"];
  68. NSArray *videoList = [result ks_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. [LOADING_MANAGER MBShowAUTOHidingInWindow: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 ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  86. NSArray *sourceArray = [dic ks_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. [LOADING_MANAGER MBShowAUTOHidingInWindow: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. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  218. model.groupID = groupId;
  219. KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
  220. ctrl.conversation = model;
  221. [self.naviController pushViewController:ctrl 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. UILabel *tipsLable = [[UILabel alloc] init];
  243. tipsLable.text = @"粉丝群";
  244. tipsLable.font = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium];
  245. tipsLable.textColor = HexRGB(0x333333);
  246. [displayView addSubview:tipsLable];
  247. [tipsLable mas_makeConstraints:^(MASConstraintMaker *make) {
  248. make.left.mas_equalTo(displayView.mas_left).offset(14);
  249. make.top.mas_equalTo(displayView.mas_top).offset(11);
  250. make.height.mas_equalTo(30);
  251. make.width.mas_equalTo(100);
  252. }];
  253. return headView;
  254. }
  255. return [UIView new];
  256. }
  257. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  258. {
  259. if (section == 2) {
  260. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15.0f)];
  261. bottomView.backgroundColor = [UIColor clearColor];
  262. CGRect frame = CGRectMake(14, 0, kScreenWidth - 28, 15);
  263. UIView *displayView = [[UIView alloc] initWithFrame:frame];
  264. displayView.backgroundColor = [UIColor whiteColor];
  265. [bottomView addSubview:displayView];
  266. if (@available(iOS 11.0, *)) {
  267. displayView.layer.cornerRadius = 10;
  268. displayView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
  269. }
  270. else {
  271. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:displayView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
  272. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  273. maskLayer.frame = frame;
  274. maskLayer.path = path.CGPath;
  275. displayView.layer.mask = maskLayer;
  276. }
  277. return bottomView;
  278. }
  279. return [UIView new];
  280. }
  281. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  282. if (section == 2) {
  283. return 43.0f;
  284. }
  285. return CGFLOAT_MIN;
  286. }
  287. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  288. if (section == 2) {
  289. return 15.0f;
  290. }
  291. return CGFLOAT_MIN;
  292. }
  293. - (NSMutableArray *)videoArray {
  294. if (!_videoArray) {
  295. _videoArray = [NSMutableArray array];
  296. }
  297. return _videoArray;
  298. }
  299. #pragma mark ------ WMPlayer
  300. - (void)playVideoWithUrl:(NSString *)fileUrl {
  301. fileUrl = [fileUrl getUrlEndcodeString];
  302. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  303. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  304. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  305. playModel.videoURL = [NSURL URLWithString:fileUrl];
  306. _wmPlayer.playerModel = playModel;
  307. _wmPlayer.delegate = self;
  308. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  309. _bgView.backgroundColor = [UIColor blackColor];
  310. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  311. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  312. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  313. [_wmPlayer play];
  314. }
  315. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  316. [wmplayer removePlayer];
  317. [_bgView removeFromSuperview];
  318. [self.naviController setNeedsStatusBarAppearanceUpdate];
  319. }
  320. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  321. self.isRatation = !self.isRatation;
  322. if (self.isRatation) {
  323. [wmplayer removeFromSuperview];
  324. [UIView animateWithDuration:1.0f animations:^{
  325. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  326. } completion:^(BOOL finished) {
  327. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  328. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  329. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  330. }];
  331. }
  332. else {
  333. [wmplayer removeFromSuperview];
  334. [UIView animateWithDuration:1.0f animations:^{
  335. // 复原
  336. wmplayer.transform = CGAffineTransformIdentity;
  337. } completion:^(BOOL finished) {
  338. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  339. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  340. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  341. }];
  342. }
  343. }
  344. /*
  345. // Only override drawRect: if you perform custom drawing.
  346. // An empty implementation adversely affects performance during animation.
  347. - (void)drawRect:(CGRect)rect {
  348. // Drawing code
  349. }
  350. */
  351. @end