123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644 |
- #import "TopicesVC.h"
- #import "CommunityCell.h"
- #import "TopicVC.h"
- #import "LoginViewController.h"
- #import "PostTopicVC.h"
- #import "EXButton.h"
- #import <MJRefresh.h>
- typedef NS_ENUM(NSInteger, MyGetDataType) {
- //正常请求数据
- MyGetDataTypeNomal=0,
- //下拉刷新请求数据
- MyGetDataTypeHeaderRefresh,
- //上拉加载更多请求数据
- MyGetDataTypeFooterRefresh
- };
- @interface TopicesVC ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,CommunityCellDelegate>
- {
- /**多个topic
- */
- NSMutableArray* models;
-
- UITableView* myTableView;
-
- UILabel* lblTopicCnt,* lblStuCnt;
-
- UIView* moodV;
-
- UIButton* moodBg;
- //记录页书
- NSInteger _currentPageNum;
- //加载数据的类型
- MyGetDataType _getDataType;
- //正在加载的状态
- BOOL _IS_LOADING;
- }
- @end
- @implementation TopicesVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
-
- [self setRefreshAction];
-
- [self getModelsAsyc];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- }
- #pragma mark -
- /**注意这里是导航栏带来的Y值偏移
- */
- -(void)myInit
- {
- [self configNavigationBar];
- self.navigationController.navigationBar.translucent = NO;
- [self.view setBackgroundColor:[UIColor whiteColor]];
-
- _currentPageNum = 0;
- _getDataType = MyGetDataTypeNomal;
- _IS_LOADING = NO;
- models = [NSMutableArray array];
-
- CGFloat x,y,w,h,bd;
-
- //最好是。它们的tag值不要变。
- NSArray* arr = @[@"最新话题",@"吐槽",@"晒图",@"找驾校",@"科目一",
- @"科目二",@"科目三",@"科目四",@"下证",@"许愿",
- @"科目一学员",@"科目一考试",@"科目二学员",@"科目二考试",@"科目三学员",
- @"科目三考试",@"科目四学员",@"下证学员",@"报名学员",@"unknown",@"unknown",@"unknown"];
-
- if (1 == _type.intValue || 2 == _type.intValue)
- {
- if ([_groupId isEqualToString:@"-1"]) {
- if (_jxjc.length == 0)
- {
- if (defUser.userSchDict) {
- NSString* str = [defUser.userSchDict objectForKey:@"shortName"];
- [self setTitle:str];
- }
- }
- else
- {
- [self setTitle:_jxjc];
- }
- }else{
- [self setTitle:arr[_groupId.intValue]];
- }
- }
-
- if( 2 == [_type intValue]){
- [self setTitle:@"学车记录"];
- }
- if( 3 == [_type intValue]){
- [self setTitle:@"学车直播"];
- }
- if (4 == _type.intValue) {
- [self setTitle:@"学车问答"];
- }
-
- y = 0;
- x = 0;
- w = kSize.width;
- h = kSize.width*201/721;
- UIImageView* imgV = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [imgV setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
- [imgV setContentMode:UIViewContentModeScaleAspectFill];
-
- // h += 40;
- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [header addSubview:imgV];
-
- y = h-40;
- h = 40;
- w = kSize.width/2.0;
- x = 0;
- UILabel* label;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setFont:[UIFont scaleSize:NormalFont]];
- [label setBackgroundColor:[UIColor colorWithWhite:.2 alpha:.6]];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:[UIColor whiteColor]];
- [label setText:@"话题"];
- // [header addSubview:label];
- lblTopicCnt = label;
-
- x+=w;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setBackgroundColor:[UIColor colorWithWhite:.2 alpha:.6]];
- [label setFont:[UIFont scaleSize:NormalFont]];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:[UIColor whiteColor]];
- [label setText:@"驾友"];
- // [header addSubview:label];
- lblStuCnt = label;
-
-
- UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - 60 - kNavOffSet - kSafeAreaBottomHeight) style:UITableViewStyleGrouped];
- [self.view addSubview:tv];
- //当把table的style设为group之后。table的背景色莫名变灰
- [tv setBackgroundColor:[UIColor whiteColor]];
- myTableView = tv;
- [myTableView setDelegate:self];
- [myTableView setDataSource:self];
- [myTableView setTableHeaderView:header];
- [myTableView setTableFooterView:[UIView new]];
-
- if ([tv respondsToSelector:@selector(setSeparatorInset:)])
- {
- [tv setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([tv respondsToSelector:@selector(setLayoutMargins:)])
- {
- [tv setLayoutMargins:UIEdgeInsetsZero];
- }
-
- x = 0;
- w = kSize.width;
- h = 60;
- y = kSize.height - h - kNavOffSet - kSafeAreaBottomHeight;
- UIView* vi;
- vi = [UIView new];
- [vi setFrame:CGRectMake(x, y, w, h)];
- [vi setBackgroundColor:backGroundColor];
- [self.view addSubview:vi];
-
-
- NSInteger tag = 0;
- STButton* stBtn;
- y = 0;
- w = 80;
- x = (kSize.width - w)/2.0;
- stBtn = [STButton new];
- [stBtn setFrame:CGRectMake(x, y, w, h)];
- [vi addSubview:stBtn];
- arr = @[@"placeHolder",@"发布话题",@"我要记录",@"我要直播",@"我要提问",@"unknown"];
- [stBtn setImage:[UIImage imageNamed:@"community2.png"] withTitle:arr[_type.intValue] Font:13 forState:UIControlStateNormal];
- [stBtn setTag:tag++];
- [stBtn target:self];
- [stBtn setStyle:1];
- [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
-
- UIButton* btn;
- btn = [[UIButton alloc] initWithFrame:kFrame];
- if ( 3 == _type.intValue) {
- [[UIApplication sharedApplication].keyWindow addSubview:btn];
- }
- [btn setBackgroundColor:[UIColor colorWithWhite:.01 alpha:.5]];
- [btn setTag:tag++];
- [btn target:self];
- moodBg = btn;
- [moodBg setHidden:YES];
-
- bd = 25;
- w = kSize.width - bd*2;
- h = w / 3.0 * 2.77;
- vi = [[UIView alloc] initWithFrame:CGRectMake(bd, -h, w, h)];
- [vi borderColor:[UIColor whiteColor] width:.01 cornorRadios:13];
- [btn addSubview:vi];
- moodV = vi;
- [vi setBackgroundColor:[UIColor whiteColor]];
-
- h = w*.3*.57;//.57 + .2
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w, h)];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setText:@"你是什么心情?"];
- [label setTextColor:contentTextColor];
- [vi addSubview:label];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(w - 40,10,30,30)];
- [btn setImage:[UIImage imageNamed:@"drawer_img08.png"] forState:UIControlStateNormal];
- [vi addSubview:btn];
- [btn setTag:tag++];
- [btn target:self];
-
-
- y += h;
- w /= 3.0;
- h = w;
- NSArray *images;
- images = @[@"mood0.png",@"mood1.png",@"mood2.png",@"mood3.png",@"mood4.png",@"mood5.png"];
- for (int i=0; i<images.count; i++) {
- btn = [[UIButton alloc] initWithFrame:CGRectMake(w*(i%3),y+h*(i/3), w-1, h-1)];
- [btn setImage:[UIImage imageNamed:images[i] ] forState:UIControlStateNormal];
- [vi addSubview:btn];
- [btn setTag:tag++];
- [btn target:self];
- }
-
- [RACObserve(RQ_SHARE_FUNCTION, shieldTopicIDArr) subscribeNext:^(NSArray *arr) {
- if (arr.count > 0 && models.count >0) {
- NSMutableArray *arrs = [NSMutableArray array];
- [[models.rac_sequence.signal filter:^BOOL(NSDictionary *dic) {
- return ![arr containsObject:dic[@"ID"]];
- }] subscribeNext:^(NSDictionary *dic) {
- [arrs addObject:dic];
- } completed:^{
- models = arrs;
- dispatch_sync(dispatch_get_main_queue(), ^{
- [myTableView reloadData];
- });
- }];
- }
- }];
-
- [RACObserve(RQ_SHARE_FUNCTION, shieldPeopleIDArr) subscribeNext:^(NSArray *arr) {
- if (arr.count > 0 && models.count >0) {
- NSMutableArray *arrs = [NSMutableArray array];
- [[models.rac_sequence.signal filter:^BOOL(NSDictionary *dic) {
- return ![arr containsObject:dic[@"TI_CRUSER"]];
- }] subscribeNext:^(NSDictionary *dic) {
- [arrs addObject:dic];
- } completed:^{
- models = arrs;
- dispatch_sync(dispatch_get_main_queue(), ^{
- [myTableView reloadData];
- });
- }];
- }
- }];
- }
- -(void)btnClick:(UIButton*)sender
- {
- NSInteger tag = sender.tag;
- //NSLog(@"btnClick %d",(int)sender.tag);
-
- if (0 == tag ) {
- if (!myDelegate.isLogin) {
- [LoginViewController loginFromVC:self];
- return;
- }
- }
- if (0 == tag && 3 == _type.intValue ) {
- //show MOOD
- [moodBg setHidden:NO];
- [UIView animateWithDuration:.3 animations:^{
- moodV.center = CGPointMake(moodBg.middleX, moodBg.middleY + 39);
- } completion:^(BOOL finished) {
-
- [UIView animateWithDuration:.2 animations:^{
- moodV.center = moodBg.center;
- } completion:^(BOOL finished) {
-
- }];
- }];
- return;
- }
-
- [self hideMood];
- if ( 1 == tag || 2 == tag) {
- //阴影背景。和关闭按钮。
- return;
- }
-
- PostTopicVC* vc = [PostTopicVC new];
- [vc complete:^{
- [self headerRefresh];
- }];
- vc.type = _type;
- vc.groupId = _groupId;
- vc.childID = _childID;
- vc.mood = tag - 2;
- [self navPushHideTabbarToVC:vc];
- }
- -(void)hideMood
- {
- if (moodBg.hidden) {
- return;
- }
- [UIView animateWithDuration:.3 animations:^{
- moodBg.alpha = 0;
- } completion:^(BOOL finished) {
- [moodBg setHidden:YES];
- [moodBg setAlpha:1];
- moodV.y = -moodV.height;
- }];
- }
- -(void)gotoComment:(NSString *)comId
- {
- if (!myDelegate.isLogin) {
- LoginViewController* vc = [[LoginViewController alloc] init];
- vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:vc animated:YES completion:nil];
- }else{
- TopicVC* vc = [[TopicVC alloc] init];
- [vc setTopicId:comId];
- [vc setTextViewActive:YES];
- [self navPushHideTabbarToVC:vc];
- }
- }
- #pragma mark 表的编辑
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return communityCellHeight(models[indexPath.row] , 0);
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return models.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CommunityCell* cell = [CommunityCell cellForTableView:tableView Style:0];
- //用于通知VC跳转到评论
- [cell setDelegate:self];
- if (models.count > 0) {
- [cell setModel:models[indexPath.row]];//崩溃 index 3 beyond bounds for empty array,出现次数3次
- if ([[models[indexPath.row] objectForKey:@"TI_TYPE"] integerValue] == 4) {
- if ([[models[indexPath.row] objectForKey:@"TI_IS_FINISH"] integerValue] > 0) {
- cell.acceptLabel.text = @"已解决";
- cell.acceptLabel.textColor = defGreen;
- cell.acceptLabel.layer.borderWidth = 1;
- cell.acceptLabel.layer.borderColor = defGreen.CGColor;
- }else{
- cell.acceptLabel.text = @"未解决";
- cell.acceptLabel.textColor = [UIColor redColor];
- cell.acceptLabel.layer.borderWidth = 1;
- cell.acceptLabel.layer.borderColor = [[UIColor redColor] CGColor];
- }
- }else{
- cell.acceptLabel.hidden = YES;
- }
- }
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:NO];
- NSDictionary* dict = models[indexPath.row];
- TopicVC* vc = [[TopicVC alloc] init];
- [vc setTopicId:dict[@"ID"]];
- [self navPushHideTabbarToVC:vc];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)])
- {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([cell respondsToSelector:@selector(setLayoutMargins:)])
- {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- #pragma mark - 下拉刷新,上拉加载 -
- -(void)setRefreshAction{
-
- // 下拉刷新
- __weak typeof(self) weakSelf = self;
- MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf headerRefresh];
- }];
- myTableView.mj_header = mj_header;
-
- MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
- myTableView.mj_footer = mj_footer;
-
- }
- -(void)headerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeHeaderRefresh;
- //加载数据
- [self getModelsAsyc];
- }
- -(void)footerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeFooterRefresh;
- //加载数据
- [self getModelsAsyc];
- }
- #pragma mark cell代理
- -(void)didPoint:(NSDictionary *)dict
- {
- // NSLog(@"didPoint->%@",dict);
- [self uploadTopicCommentPoints:dict];
- }
- -(void)uploadTopicCommentPoints:(NSDictionary*)obj
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"topicId" Value:obj[@"ID"]];
- NSString* method = @"uploadTopicCommentPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsgFailed();
- return;
- }
- }];
- }
- -(void)didDePoint:(NSDictionary *)dict
- {
- // NSLog(@"didDePoint->%@",dict);
- [self deleteTopicCommentPoints:dict];
- }
- -(void)deleteTopicCommentPoints:(NSDictionary*)obj
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray* arr = [NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"topicId" Value:obj[@"ID"]];
-
- NSString* method = @"deleteTopicCommentPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsgFailed();
- return;
- }
- }];
- }
- #pragma mark -
- -(void)getModelsAsyc
- {
- if (_IS_LOADING) {
- return;
- }
- _IS_LOADING=YES;
- NSInteger needLoadPage;
- needLoadPage=_currentPageNum+1;
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- needLoadPage=1;
- }else if (_getDataType == MyGetDataTypeNomal){
- [MBProgressHUD showLoadToView:self.view];
- }
-
- //-1就是驾校。
- if ([_groupId isEqualToString:@"-1"]) {
- [self getTopicByJxbhWithPage:needLoadPage];
- }else{
- [self getTopicInfosWithPage:needLoadPage];
- }
- }
- -(void)getTopicInfosWithPage:(NSInteger)needLoadPage
- {
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"groupId" Value:_groupId];
- [arr addPro:@"type" Value:_type];
- [arr addPro:@"crUser" Value:defUser.userDict[@"id"]];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"7"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)needLoadPage]];
- if ([_type isEqualToString:@"2"])
- {
- [arr addPro:@"childGroupId" Value:_childID];
- }
- NSString* method = @"getTopicInfos";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
- _IS_LOADING = NO;
- if (_getDataType == MyGetDataTypeNomal) {
- [MBProgressHUD hideHUDForView:self.view];
- }else if (_getDataType == MyGetDataTypeFooterRefresh){
- [myTableView.mj_footer endRefreshing];
- }else{
- [myTableView.mj_header endRefreshing];
- }
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- NSArray *arr = dict[@"body"];
- if (arr.count > 0) {
- if (_getDataType == MyGetDataTypeHeaderRefresh){
- [models removeAllObjects];
- }
- [[arr.rac_sequence.signal filter:^BOOL(NSDictionary *dic) {
- return ![RQ_SHARE_FUNCTION.shieldTopicIDArr containsObject:dic[@"ID"]] && ![RQ_SHARE_FUNCTION.shieldPeopleIDArr containsObject:dic[@"TI_CRUSER"]] ;
- }] subscribeNext:^(NSDictionary *dic) {
- [models addObject:dic];
- } completed:^{
- dispatch_sync(dispatch_get_main_queue(), ^{
- [myTableView reloadData];
- _currentPageNum=needLoadPage;
- _getDataType=MyGetDataTypeNomal;
- [lblTopicCnt setText:[NSString stringWithFormat:@"话题 %d",(int)models.count]];
- });
- }];
- }else{
- ShowMsg(@"已加载全部");
- }
- }];
-
- }
- -(void)getTopicByJxbhWithPage:(NSInteger)needLoadPage
- {
-
- if ([_jxbh isEqualToString:@""])
- {
- _jxbh = defUser.userSchoolId;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"jxbh" Value: _jxbh];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)needLoadPage]];
- NSString* method = @"getTopicByJxbh";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
- _IS_LOADING = NO;
- if (_getDataType == MyGetDataTypeNomal) {
- [MBProgressHUD hideHUDForView:self.view];
- }else if (_getDataType == MyGetDataTypeFooterRefresh){
- [myTableView.mj_footer endRefreshing];
- }else{
- [myTableView.mj_header endRefreshing];
- }
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- NSArray *arr = dict[@"body"];
- if (arr.count > 0) {
- if (_getDataType==MyGetDataTypeHeaderRefresh){
- [models removeAllObjects];
- }
- [[arr.rac_sequence.signal filter:^BOOL(NSDictionary *dic) {
- return ![RQ_SHARE_FUNCTION.shieldTopicIDArr containsObject:dic[@"ID"]] && ![RQ_SHARE_FUNCTION.shieldPeopleIDArr containsObject:dic[@"TI_CRUSER"]] ;
- }] subscribeNext:^(NSDictionary *dic) {
- [models addObject:dic];
- } completed:^{
- dispatch_sync(dispatch_get_main_queue(), ^{
- [myTableView reloadData];
- _currentPageNum=needLoadPage;
- _getDataType=MyGetDataTypeNomal;
- [lblTopicCnt setText:[NSString stringWithFormat:@"话题 %d",(int)models.count]];
- });
- }];
- }else{
- ShowMsg(@"已加载全部");
- }
- }];
- }
- @end
|