Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
471 lines (390 loc) · 16.3 KB

File metadata and controls

471 lines (390 loc) · 16.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
//
// CSTopicDetailVC.m
// Coding_iOS
//
// Created by pan Shiyu on 15/7/24.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "CSTopicDetailVC.h"
#import "TweetSendViewController.h"
#import "Coding_NetAPIManager.h"
#import "CSTopicHeaderView.h"
#import "TweetCell.h"
#import "Tweet.h"
#import "Tweets.h"
#import "UserInfoViewController.h"
#import "LikersViewController.h"
#import "TweetSendLocationDetailViewController.h"
#import "UIMessageInputView.h"
#import "TweetDetailViewController.h"
#import "CSTopicDetailVC.h"
#import "WebViewController.h"
#define kCommentIndexNotFound -1
@interface CSTopicDetailVC ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,UIMessageInputViewDelegate>
@property (nonatomic,strong)UITableView *myTableView;
@property (nonatomic,strong)Tweets *curTweets;
@property (nonatomic,strong)Tweet *curTopWteet;
@property (nonatomic,strong)CSTopicHeaderView *tableHeader;
//评论
@property (nonatomic, strong) UIMessageInputView *myMsgInputView;
@property (nonatomic, strong) Tweet *commentTweet;
@property (nonatomic, assign) NSInteger commentIndex;
@property (nonatomic, strong) UIView *commentSender;
@property (nonatomic, strong) User *commentToUser;
@property (nonatomic, assign) NSInteger curIndex;
@end
@implementation CSTopicDetailVC{
CGFloat _oldPanOffsetY;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupData];
[self setupUI];
_curIndex = 0;
[self.myTableView reloadData];
[self refreshheader];
[self refreshTopTweet];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^{
[self sendRequest];
});
}
- (void)sendRequest{
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_PublicTweetsWithTopic:_topicID andBlock:^(NSArray *datalist, NSError *error) {
NSMutableArray *list = [NSMutableArray array];
[datalist enumerateObjectsUsingBlock:^(Tweet* obj, NSUInteger idx, BOOL *stop) {
if (self.curTopWteet && [self.curTopWteet.id isEqualToNumber:obj.id]) {
}else{
[list addObject:obj];
}
}];
[weakSelf.curTweets configWithTweets:list];
[weakSelf.myTableView reloadData];
}];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
if (_myMsgInputView) {
[_myMsgInputView prepareToDismiss];
}
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
// 键盘
if (_myMsgInputView) {
[_myMsgInputView prepareToShow];
}
}
- (void)refreshTopTweet {
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_TopTweetWithTopicID:_topicID block:^(id data, NSError *error) {
if (data) {
weakSelf.curTopWteet = data;
[weakSelf.myTableView reloadData];
}
}];
}
- (void)refreshheader {
[[Coding_NetAPIManager sharedManager]request_TopicDetailsWithTopicID:_topicID block:^(id data, NSError *error) {
if (data) {
[self.tableHeader updateWithTopic:data];
}
}];
[[Coding_NetAPIManager sharedManager] request_Users_WithTopicID:_topicID andBlock:^(NSArray *userlist, NSError *error) {
if (userlist) {
[self.tableHeader updateWithJoinedUsers:userlist];
}
}];
}
#pragma mark - table view
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
if (_curTopWteet) {
return 2;
}else {
return 0;
}
}
if (_curTweets && _curTweets.list) {
return [_curTweets.list count];
}else{
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0 && indexPath.row ==0) {
CSTopTweetDescCell *cell0 = [tableView dequeueReusableCellWithIdentifier:@"CSTopTweetDescCell" forIndexPath:indexPath];
[cell0 updateUI];
[tableView addLineforPlainCell:cell0 forRowAtIndexPath:indexPath withLeftSpace:0];
return cell0;
}
TweetCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Tweet forIndexPath:indexPath];
if (indexPath.section == 0) {
[cell setTweet:_curTopWteet needTopView:NO];
}else{
[cell setTweet:[_curTweets.list objectAtIndex:indexPath.row] needTopView:YES];
}
cell.outTweetsIndex = _curIndex;
__weak typeof(self) weakSelf = self;
cell.commentClickedBlock = ^(Tweet *tweet, NSInteger index, id sender){
if ([self.myMsgInputView isAndResignFirstResponder]) {
return ;
}
weakSelf.commentTweet = tweet;
weakSelf.commentIndex = index;
weakSelf.commentSender = sender;
weakSelf.myMsgInputView.commentOfId = tweet.id;
if (weakSelf.commentIndex >= 0) {
weakSelf.commentToUser = ((Comment*)[weakSelf.commentTweet.comment_list objectAtIndex:weakSelf.commentIndex]).owner;
weakSelf.myMsgInputView.toUser = ((Comment*)[weakSelf.commentTweet.comment_list objectAtIndex:weakSelf.commentIndex]).owner;
if ([Login isLoginUserGlobalKey:weakSelf.commentToUser.global_key]) {
ESWeakSelf
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"删除此评论" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
ESStrongSelf
if (index == 0 && _self.commentIndex >= 0) {
Comment *comment = [_self.commentTweet.comment_list objectAtIndex:_self.commentIndex];
[_self deleteComment:comment ofTweet:_self.commentTweet];
}
}];
[actionSheet showInView:weakSelf.view];
return;
}
}else{
weakSelf.myMsgInputView.toUser = nil;
}
[_myMsgInputView notAndBecomeFirstResponder];
};
cell.likeBtnClickedBlock = ^(Tweet *tweet){
[weakSelf.myTableView reloadData];
};
cell.userBtnClickedBlock = ^(User *curUser){
UserInfoViewController *vc = [[UserInfoViewController alloc] init];
vc.curUser = curUser;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.moreLikersBtnClickedBlock = ^(Tweet *curTweet){
LikersViewController *vc = [[LikersViewController alloc] init];
vc.curTweet = curTweet;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.goToDetailTweetBlock = ^(Tweet *curTweet){
[weakSelf goToDetailWithTweet:curTweet];
};
cell.mediaItemClickedBlock = ^(HtmlMediaItem *curItem){
[weakSelf analyseLinkStr:curItem.href];
};
cell.deleteClickedBlock = ^(Tweet *curTweet, NSInteger outTweetsIndex){
if ([self.myMsgInputView isAndResignFirstResponder]) {
return ;
}
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"删除此冒泡" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
if (index == 0) {
[weakSelf deleteTweet:curTweet];
}
}];
[actionSheet showInView:self.view];
};
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:0];
return cell;
}
- (void)deleteComment:(Comment *)comment ofTweet:(Tweet *)tweet{
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_TweetComment_Delete_WithTweet:tweet andComment:comment andBlock:^(id data, NSError *error) {
if (data) {
[tweet deleteComment:comment];
[weakSelf.myTableView reloadData];
}
}];
}
- (void)goToDetailWithTweet:(Tweet *)curTweet{
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = curTweet;
vc.deleteTweetBlock = ^(Tweet *toDeleteTweet){
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)analyseLinkStr:(NSString *)linkStr{
if (linkStr.length <= 0) {
return;
}
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
if (vc) {
[self.navigationController pushViewController:vc animated:YES];
}else{
//网页
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
[self.navigationController pushViewController:webVc animated:YES];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
if (_curTopWteet && indexPath.row ==0) {
return 36;
}else if(_curTopWteet && indexPath.row == 1){
return [TweetCell cellHeightWithObj:_curTopWteet needTopView:NO];
}
else {
return 0;
}
}
return [TweetCell cellHeightWithObj:[_curTweets.list objectAtIndex:indexPath.row] needTopView:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0 && indexPath.row ==0) {
return;
}
Tweet *toTweet = nil;
if (indexPath.section == 0) {
toTweet = _curTopWteet;
}else{
toTweet = [_curTweets.list objectAtIndex:indexPath.row];
}
if (toTweet) {
[self goToDetailWithTweet:toTweet];
}
}
#pragma mark UIMessageInputViewDelegate
- (void)messageInputView:(UIMessageInputView *)inputView sendText:(NSString *)text{
[self sendCommentMessage:text];
}
- (void)messageInputView:(UIMessageInputView *)inputView heightToBottomChenged:(CGFloat)heightToBottom{
[UIView animateWithDuration:0.25 delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
UIEdgeInsets contentInsets= UIEdgeInsetsMake(0.0, 0.0, heightToBottom, 0.0);;
CGFloat msgInputY = kScreen_Height - heightToBottom - 64;
self.myTableView.contentInset = contentInsets;
self.myTableView.scrollIndicatorInsets = contentInsets;
if ([_commentSender isKindOfClass:[UIView class]] && !self.myTableView.isDragging && heightToBottom > 60) {
UIView *senderView = _commentSender;
CGFloat senderViewBottom = [_myTableView convertPoint:CGPointZero fromView:senderView].y+ CGRectGetMaxY(senderView.bounds);
CGFloat contentOffsetY = MAX(0, senderViewBottom- msgInputY);
[self.myTableView setContentOffset:CGPointMake(0, contentOffsetY) animated:YES];
}
} completion:nil];
}
- (void)sendCommentMessage:(id)obj{
if (_commentIndex >= 0) {
_commentTweet.nextCommentStr = [NSString stringWithFormat:@"@%@ %@", _commentToUser.name, obj];
}else{
_commentTweet.nextCommentStr = obj;
}
[self sendCurComment:_commentTweet];
{
_commentTweet = nil;
_commentIndex = kCommentIndexNotFound;
_commentSender = nil;
_commentToUser = nil;
}
self.myMsgInputView.toUser = nil;
[self.myMsgInputView isAndResignFirstResponder];
}
- (void)sendCurComment:(Tweet *)commentObj{
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Tweet_DoComment_WithObj:commentObj andBlock:^(id data, NSError *error) {
if (data) {
Comment *resultCommnet = (Comment *)data;
resultCommnet.owner = [Login curLoginUser];
[commentObj addNewComment:resultCommnet];
[weakSelf.myTableView reloadData];
}
}];
}
- (void)dealloc
{
_myTableView.delegate = nil;
_myTableView.dataSource = nil;
}
#pragma mark - myscrollview
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
if (scrollView == _myTableView) {
[self.myMsgInputView isAndResignFirstResponder];
}
}
#pragma mark -
- (void) setupUI {
self.navigationItem.title = @"话题";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"tweetBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(sendTweet)];
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor whiteColor];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[TweetCell class] forCellReuseIdentifier:kCellIdentifier_Tweet];
[tableView registerClass:[CSTopTweetDescCell class] forCellReuseIdentifier:@"CSTopTweetDescCell"];
[self.view addSubview:tableView];
CSTopicHeaderView *header = [[CSTopicHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 191)];
header.parentVC = self;
tableView.tableHeaderView = header;
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
_tableHeader = header;
tableView;
});
_myMsgInputView = [UIMessageInputView messageInputViewWithType:UIMessageInputViewContentTypeTweet];
_myMsgInputView.delegate = self;
}
- (void)setupData {
_curTweets = [Tweets tweetsWithType:TweetTypePublicTime];
}
- (void)sendTweet{
// __weak typeof(self) weakSelf = self;
TweetSendViewController *vc = [[TweetSendViewController alloc] init];
vc.sendNextTweet = ^(Tweet *nextTweet){
[nextTweet saveSendData];//发送前保存草稿
[[Coding_NetAPIManager sharedManager] request_Tweet_DoTweet_WithObj:nextTweet andBlock:^(id data, NSError *error) {
if (data) {
[Tweet deleteSendData];//发送成功后删除草稿
// Tweets *curTweets = [weakSelf getCurTweets];
// if (curTweets.tweetType != TweetTypePublicHot) {
// Tweet *resultTweet = (Tweet *)data;
// resultTweet.owner = [Login curLoginUser];
// if (curTweets.list && [curTweets.list count] > 0) {
// [curTweets.list insertObject:data atIndex:0];
// }else{
// curTweets.list = [NSMutableArray arrayWithObject:resultTweet];
// }
// [self.myTableView reloadData];
// }
// [weakSelf.view configBlankPage:EaseBlankPageTypeTweet hasData:(curTweets.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
// [weakSelf sendRequest];
// }];
}
}];
};
UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
[self.parentViewController presentViewController:nav animated:YES completion:nil];
}
#pragma mark Delete Tweet
- (void)deleteTweet:(Tweet *)curTweet{
ESWeakSelf;
[[Coding_NetAPIManager sharedManager] request_Tweet_Delete_WithObj:curTweet andBlock:^(id data, NSError *error) {
ESStrongSelf;
if (data) {
[_self.curTweets.list removeObject:curTweet];
[_self.myTableView reloadData];
[_self.view configBlankPage:([[Login curLoginUser] isSameToUser:_self.curTweets.curUser]? EaseBlankPageTypeTweet: EaseBlankPageTypeTweetOther) hasData:(_self.curTweets.list.count > 0) hasError:NO reloadButtonBlock:^(id sender) {
ESStrongSelf;
[_self sendRequest];
}];
}
}];
}
@end
@implementation CSTopTweetDescCell
- (void)updateUI {
self.imageView.frame = CGRectMake(12, 0, 15, 15);
self.imageView.image = [UIImage imageNamed:@"icon_topic_hotTop"];
self.imageView.centerY = 18;
self.textLabel.backgroundColor = [UIColor clearColor];
self.textLabel.frame = CGRectMake(30, 0, 100, 36);
self.textLabel.font = [UIFont systemFontOfSize:12];
self.textLabel.textColor = [UIColor colorWithHexString:@"0x666666"];
self.textLabel.text = @"置顶话题";
}
@end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.