|
@@ -6,9 +6,238 @@
|
|
|
//
|
|
|
|
|
|
#import "MusicRoomStudentPageView.h"
|
|
|
+#import "StateView.h"
|
|
|
+#import "Reachability.h"
|
|
|
+#import "MusicGroupStudenListCell.h"
|
|
|
+#import "GroupCourseStudentModel.h"
|
|
|
+#import "KSChatConversationViewController.h"
|
|
|
+
|
|
|
+@interface MusicRoomStudentPageView ()<UITableViewDelegate,UITableViewDataSource>
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) StateView *promptView;
|
|
|
+@property (nonatomic, strong) UIView *promptPlaceView;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
|
|
|
+
|
|
|
+@end
|
|
|
|
|
|
@implementation MusicRoomStudentPageView
|
|
|
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+ self.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
|
|
|
+ self.tableView.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView.showsVerticalScrollIndicator = NO;
|
|
|
+
|
|
|
+ self.tableView.dataSource = self;
|
|
|
+ self.tableView.delegate = self;
|
|
|
+
|
|
|
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
+ [self addSubview:self.tableView];
|
|
|
+ self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
+ [self.tableView registerNib:[UINib nibWithNibName:@"MusicGroupStudenListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicGroupStudenListCell"];
|
|
|
+
|
|
|
+// UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 12)];
|
|
|
+// headView.backgroundColor = [UIColor clearColor];
|
|
|
+// self.tableView.tableHeaderView = headView;
|
|
|
+
|
|
|
+ UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, iPhoneXSafeBottomMargin)];
|
|
|
+ bottomView.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView.tableFooterView = bottomView;
|
|
|
+
|
|
|
+ MJWeakSelf;
|
|
|
+ self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
|
|
|
+ [weakSelf resetParamenter];
|
|
|
+ [weakSelf requestData];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)refreshAndRequestData {
|
|
|
+ [self resetParamenter];
|
|
|
+ [self requestData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetParamenter {
|
|
|
+ self.dataArray = [NSMutableArray array];
|
|
|
+ [self.tableView.mj_footer resetNoMoreData];
|
|
|
+ [self setPromptString:@"暂无内容" imageName:@"empty_course" inView:self.tableView];
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)endRefresh {
|
|
|
+ @weakObj(self);
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ @strongObj(self);
|
|
|
+ [self.tableView.mj_header endRefreshing];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)requestData {
|
|
|
+ [KSNetworkingManager queryStudentByGroupIdRequest:KS_POST courseGroupId:self.courseGroupId success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self endRefresh];
|
|
|
+ if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
+ NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
|
|
|
+ for (NSDictionary *parm in sourceArray) {
|
|
|
+ GroupCourseStudentModel *model = [[GroupCourseStudentModel alloc] initWithDictionary:parm];
|
|
|
+ [self.dataArray addObject:model];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self endRefresh];
|
|
|
+ if (self.networkAvaiable == NO) {
|
|
|
+ [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
|
|
|
+ }
|
|
|
+ [self.dataArray removeAllObjects];
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (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 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.mas_equalTo(self.mas_top).offset(12);
|
|
|
+ make.left.right.bottom.mas_equalTo(self);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITableViewDataSource
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ return 64.0f;
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ GroupCourseStudentModel *model = self.dataArray[indexPath.row];
|
|
|
+
|
|
|
+ MusicGroupStudenListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicGroupStudenListCell"];
|
|
|
+ STUDENTCELL_ROW_INDEX cellIndex = STUDENTCELL_ROW_INDEX_MIDDLE;
|
|
|
+ if (self.dataArray.count == 1) {
|
|
|
+ cellIndex = STUDENTCELL_ROW_INDEX_SINGLE;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (indexPath.row == 0) {
|
|
|
+ cellIndex = STUDENTCELL_ROW_INDEX_TOP;
|
|
|
+ }
|
|
|
+ else if (indexPath.row == self.dataArray.count - 1) {
|
|
|
+ cellIndex = STUDENTCELL_ROW_INDEX_BOTTOM;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configWithRowIndex:cellIndex source:model callback:^(NSString * _Nonnull imUserId) {
|
|
|
+ [weakSelf chatStudent:imUserId];
|
|
|
+ }];
|
|
|
+
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)chatStudent:(NSString *)imUserId {
|
|
|
+ TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
|
|
|
+ model.userID = imUserId;
|
|
|
+ KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
|
|
|
+ ctrl.conversation = model;
|
|
|
+ [self.naviController pushViewController:ctrl animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ 设置没有数据时的显示
|
|
|
+
|
|
|
+ @param promptString 提示语
|
|
|
+ @param imgName 图片名称
|
|
|
+ @param view 显示在什么地方
|
|
|
+ */
|
|
|
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
|
|
|
+ if (self.promptView != nil) {
|
|
|
+ [self.promptView removeFromSuperview];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.promptView = [[StateView alloc]init];
|
|
|
+ self.promptView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - 300);
|
|
|
+ }
|
|
|
+ _promptPlaceView = view;
|
|
|
+ //当请求不到数据时 ,自定义提示view 将会出现;
|
|
|
+ self.promptView.imageName = imgName;
|
|
|
+ self.promptView.alpha = 0.0f;
|
|
|
+ [self.promptView setText:promptString];
|
|
|
+ [view addSubview:self.promptView];
|
|
|
+}
|
|
|
+
|
|
|
+// 结束刷新后调用方法
|
|
|
+- (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
|
|
|
+ NSInteger count;
|
|
|
+ if (array.count) {
|
|
|
+ count = array.count;
|
|
|
+ } else {
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.1 animations:^{
|
|
|
+ [[self promptView] setAlpha:count ? 0.0f :1.0f];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)networkAvaiable {
|
|
|
+ return [self checkNetworkAvaiable];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)checkNetworkAvaiable {
|
|
|
+ BOOL isExistenceNetwork = YES;
|
|
|
+ Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
|
|
|
+ switch ([reach currentReachabilityStatus]) {
|
|
|
+ case NotReachable:
|
|
|
+ isExistenceNetwork = NO;
|
|
|
+ //NSLog(@"notReachable");
|
|
|
+ break;
|
|
|
+ case ReachableViaWiFi:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"WIFI");
|
|
|
+ break;
|
|
|
+ case ReachableViaWWAN:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"3G");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return isExistenceNetwork;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
// An empty implementation adversely affects performance during animation.
|