1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//
// ForumItemListViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/12/8.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "ForumItemListViewController.h"
#import "ForumItemTableViewCell.h"
#import "ReleasePostViewController.h"
#import "ForumItemDetailViewController.h"
#import "MWPhotoBrowser.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "CommentTagTableViewCell.h"
#import "UIButton+Title_Image.h"
static NSString *CELL_IDENTIFIER = @"ForumItemTableViewCell";
static NSString *TAGCELL_IDENTIFIER = @"CommentTagTableViewCell";
@interface ForumItemListViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate,TapClickImageViewDelegate,MWPhotoBrowserDelegate>
@property (nonatomic,strong) ForumTopicCondition *condition;
@property (nonatomic,strong) NSMutableArray *datasArray;
/**
图片数组
*/
@property (nonatomic,strong) NSMutableArray *selecteImageArray;
@end
@implementation ForumItemListViewController
#pragma mark - lazy
- (ForumTopicCondition *)condition
{
if (!_condition) {
_condition = [[ForumTopicCondition alloc] init];
DataPage *page = [[DataPage alloc] init];
page.page = ZERO;
page.rows = KROWS;
_condition.categoryEquals = self.category.fid;
_condition.page = page;
}
return _condition;
}
- (NSMutableArray *)datasArray
{
if (!_datasArray) {
_datasArray = [NSMutableArray array];
}
return _datasArray;
}
- (NSMutableArray *)selecteImageArray
{
if (!_selecteImageArray) {
_selecteImageArray = [NSMutableArray array];
}
return _selecteImageArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpRefreshAction];
[self uiConfigAction];
}
#pragma mark - 设置刷新
- (void)setUpRefreshAction
{
WS(weakSelf);
MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
weakSelf.condition.page.page = ONE;
[weakSelf.classificationListTableView.mj_footer resetNoMoreData];
[weakSelf getClassificationList:weakSelf.condition isRemoveArray:YES];
}];
headerRefresh.stateLabel.hidden = YES;
headerRefresh.lastUpdatedTimeLabel.hidden = YES;
self.classificationListTableView.mj_header =headerRefresh;
[self.classificationListTableView.mj_header beginRefreshing];
self.classificationListTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
if (++ weakSelf.condition.page.page > weakSelf.condition.page.total) {
[weakSelf.classificationListTableView.mj_footer endRefreshingWithNoMoreData];
}else
{
[weakSelf getClassificationList:weakSelf.condition isRemoveArray:NO];
}
}];
self.classificationListTableView.mj_footer.automaticallyHidden = YES;
}
#pragma mark - UI
- (void)uiConfigAction
{
self.classificationListTableView.backgroundColor = RGB(237, 238, 239, 1);
[self.postingButton horizontalCenterImageAndTitle:5];
self.classifyTitleLabel.text = self.category.name;
[self.classifyImageView sd_setImageWithURL:[NSURL URLWithString:self.category.attachmentBg.fileUrl] placeholderImage:REPLACEIMAGE];
[self.classIconImageView sd_setImageWithURL:[NSURL URLWithString:self.category.attachment.fileUrl] placeholderImage:REPLACEIMAGE];
if (self.isPosting) {
[self.postingButton setTitle:(self.isPosting == 1)?@"我要发帖":@"我要提问" forState:UIControlStateNormal];
}else {
self.postingButton.hidden = YES;
}
}
#pragma mark - 获取分类帖子列表
- (void)getClassificationList:(ForumTopicCondition *)condtion isRemoveArray:(BOOL)remove
{
[XBLoadingView showHUDViewWithDefault];
WS(weakSelf);
[HTTP networkRequestWithURL:SERVERREQUESTURL(QUERTFORUMLIST) withRequestType:ZERO withParameter:condtion withReturnValueBlock:^(id returnValue) {
[XBLoadingView hideHUDViewWithDefault];
[weakSelf endRefreshingForTableView:weakSelf.classificationListTableView];
weakSelf.classificationListTableView.emptyDataSetSource = weakSelf;
weakSelf.classificationListTableView.emptyDataSetDelegate = weakSelf;
if (RESULT(returnValue)) {
if (remove) {
[weakSelf.datasArray removeAllObjects];
}
ForumTopicResponse *result = [[ForumTopicResponse alloc] initWithDictionary:RESPONSE(returnValue) error:nil];
[weakSelf.datasArray addObjectsFromArray:result.forumTopicEntity];
weakSelf.classifyListCountLabel.text = [NSString stringWithFormat:@"%ld",result.total];
}else {
[XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
}
[weakSelf.classificationListTableView reloadData];
} withFailureBlock:^(NSError *error) {
[XBLoadingView showHUDViewWithText:error.localizedDescription];
}];
}
#pragma mark - 发帖
- (IBAction)releaseButtonClickAction:(UIButton *)sender {
ReleasePostViewController *releaseVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"ReleasePostViewController"];
releaseVc.category = self.category;
WS(weakSelf);
[releaseVc setFinishBlock:^{
[weakSelf.classificationListTableView.mj_header beginRefreshing];
}];
[self.navigationController pushViewController:releaseVc animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTOForumTopicEntity *entity = self.datasArray[indexPath.row];
if (entity.backEnd ||
entity.bestTopic ||
![[self class] isBlankString:entity.top]) {
CommentTagTableViewCell *tagCell = [tableView dequeueReusableCellWithIdentifier:TAGCELL_IDENTIFIER forIndexPath:indexPath];
[self configTagCellAction:tagCell withIndexPath:indexPath];
return tagCell;
}
ForumItemTableViewCell *commonCell = [tableView dequeueReusableCellWithIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
[self configCommonCellAction:commonCell withIndexPath:indexPath];
return commonCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.datasArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTOForumTopicEntity *entity = self.datasArray[indexPath.row];
if (entity.backEnd || entity.bestTopic || ![[self class] isBlankString:entity.top]) {
return 60;
}
//10 表示控件间隙、60 表示content Y 150 表示图片背景框高度
CGFloat height = entity.contentHeight + entity.titleHeight + 80 + 10;
if (entity.attachments.count) {
height += 150+10;
}
return height;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ForumItemDetailViewController *postDetail = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"ForumItemDetailViewController"];
CustomTOForumTopicEntity *entity = self.datasArray[indexPath.row];
postDetail.topicDetail = entity;
postDetail.category = self.category;
postDetail.indexPath = indexPath;
entity.isRead = YES;
[self.classificationListTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
WS(weakSelf);
//更新点赞数、评论数
[postDetail setRefreshBlock:^(NSInteger count,COMMENT_PRAISE type,NSIndexPath *indexPath){
switch (type) {
case Comment:
{
entity.replyCount += count;
}
break;
case Praise:
{
entity.likeCount += count;
entity.canLike = (count == 1)?NO:YES;
}
break;
default:
break;
}
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
//删除帖子
[postDetail setDelectBlock:^(NSString *topicId) {
for (int i=0; i<weakSelf.datasArray.count; i++) {
CustomTOForumTopicEntity *entity = self.datasArray[i];
if ([entity.fid isEqualToString:topicId]) {
[weakSelf.classificationListTableView.mj_header beginRefreshing];
}
}
}];
[self.navigationController pushViewController:postDetail animated:YES];
}
#pragma mark -设置普通帖子
- (void)configCommonCellAction:(ForumItemTableViewCell *)cell withIndexPath:(NSIndexPath *)indexPath
{
[cell refreshCell:indexPath withTopicEntity:self.datasArray[indexPath.row] withDelegate:self];
}
#pragma mark 设置带标签的帖子
- (void)configTagCellAction:(CommentTagTableViewCell *)cell withIndexPath:(NSIndexPath *)indexPath
{
cell.topicModel = self.datasArray[indexPath.item];
}
#pragma mark - 单击查看大图<TapClickImageViewDelegate>
- (void)tapImageViewWithIndex:(NSInteger)index withCellIndex:(NSIndexPath *)indexPath
{
[self.selecteImageArray removeAllObjects];
CustomTOForumTopicEntity *topicEntity = self.datasArray[indexPath.row];
for (TOAttachmentEntity *entity in topicEntity.attachments) {
MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:entity.fileUrl]];
[self.selecteImageArray addObject:photo];
}
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
[browser setCurrentPhotoIndex:index];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:browser];
[self.navigationController presentViewController:nav animated:YES completion:nil];
}
#pragma mark - <MWPhotoBrowserDelegate>
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
return self.selecteImageArray.count;
}
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
if (index < self.selecteImageArray.count)
return [self.selecteImageArray objectAtIndex:index];
return nil;
}
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return kNoDataImage;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
return YES;
}
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}
@end