FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/UserTweetsViewController.m at master · mskobe/Coding-iOS · GitHub
mskobe
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
UserTweetsViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
381 lines (332 loc) · 14 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
UserTweetsViewController.m
Copy path
File metadata and controls
executable file
·
381 lines (332 loc) · 14 KB
Raw
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
//
//
UserTweetsViewController.m
//
Coding_iOS
//
//
Created by 王 原闯 on 14-9-4.
//
Copyright (c) 2014年 Coding. All rights reserved.
//
#
define
kCommentIndexNotFound
-
1
#
import
"
UserTweetsViewController.h
"
#
import
"
TweetCell.h
"
#
import
"
ODRefreshControl.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
UserInfoViewController.h
"
#
import
"
LikersViewController.h
"
#
import
"
TweetDetailViewController.h
"
#
import
"
SVPullToRefresh.h
"
#
import
"
WebViewController.h
"
@interface
UserTweetsViewController
()
@property
(
nonatomic
,
strong
) UITableView *myTableView;
@property
(
nonatomic
,
strong
) ODRefreshControl *refreshControl;
//
评论
@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
(
strong
,
nonatomic
) Tweet *deleteTweet;
@property
(
nonatomic
,
assign
)
NSInteger
deleteTweetsIndex;
@end
@implementation
UserTweetsViewController
- (
id
)
initWithNibName
:
(
NSString
*)
nibNameOrNil
bundle
:
(
NSBundle
*)
nibBundleOrNil
{
self = [
super
initWithNibName:
nibNameOrNil
bundle:
nibBundleOrNil];
if
(self) {
//
Custom initialization
}
return
self;
}
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
//
Do any additional setup after loading the view.
self.
title
= _curTweets.
curUser
.
name
;
//
添加myTableView
_myTableView = ({
UITableView *tableView = [[UITableView
alloc
]
initWithFrame:
self
.view.bounds
style:
UITableViewStylePlain];
tableView.
backgroundColor
= [UIColor
clearColor
];
tableView.
dataSource
= self;
tableView.
delegate
= self;
tableView.
separatorStyle
= UITableViewCellSeparatorStyleNone;
Class
tweetCellClass = [TweetCell
class
];
[tableView
registerClass:
tweetCellClass
forCellReuseIdentifier:
kCellIdentifier_Tweet
];
[
self
.view
addSubview:
tableView];
[tableView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self.
view
);
}];
tableView;
});
_refreshControl = [[ODRefreshControl
alloc
]
initInScrollView:
self
.myTableView];
[_refreshControl
addTarget:
self
action:
@selector
(
refresh
)
forControlEvents:
UIControlEventValueChanged];
//
评论
__weak
typeof
(self) weakSelf = self;
_myMsgInputView = [UIMessageInputView
messageInputViewWithType:
UIMessageInputViewContentTypeTweet];
_myMsgInputView.
delegate
= self;
[_myTableView
addInfiniteScrollingWithActionHandler:
^{
[weakSelf
refreshMore
];
}];
[
self
refresh
];
}
- (
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
[
super
viewWillDisappear:
animated];
if
(_myMsgInputView) {
[_myMsgInputView
prepareToDismiss
];
}
}
- (
void
)
viewDidAppear
:
(
BOOL
)
animated
{
[
super
viewDidAppear:
animated];
//
键盘
if
(_myMsgInputView) {
[_myMsgInputView
prepareToShow
];
}
[
self
.myTableView
reloadData
];
}
- (
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
//
Dispose of any resources that can be recreated.
}
#
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
];
}
#
pragma mark
M
- (
void
)
deleteTweet
:
(Tweet *)
curTweet
outTweetsIndex
:
(
NSInteger
)
outTweetsIndex
{
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
];
}];
}
}];
}
- (
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
];
}
}];
}
#
pragma mark
Refresh M
- (
void
)
refresh
{
if
(_curTweets.
isLoading
) {
return
;
}
_curTweets.
willLoadMore
=
NO
;
[
self
sendRequest
];
}
- (
void
)
refreshMore
{
if
(_curTweets.
isLoading
|| !_curTweets.
canLoadMore
) {
return
;
}
_curTweets.
willLoadMore
=
YES
;
[
self
sendRequest
];
}
- (
void
)
sendRequest
{
if
(_curTweets.
list
.
count
<=
0
) {
[
self
.view
beginLoading
];
}
__weak
typeof
(self) weakSelf = self;
if
(_curTweets.
curUser
.
name
.
length
<=
0
) {
[
self
refreshCurUser
];
return
;
}
[[Coding_NetAPIManager
sharedManager
]
request_Tweets_WithObj:
_curTweets
andBlock:
^(
id
data,
NSError
*error) {
[weakSelf.refreshControl
endRefreshing
];
[weakSelf.view
endLoading
];
[weakSelf.myTableView.infiniteScrollingView
stopAnimating
];
if
(data) {
[weakSelf.curTweets
configWithTweets:
data];
[weakSelf.myTableView
reloadData
];
weakSelf.
myTableView
.
showsInfiniteScrolling
= weakSelf.
curTweets
.
canLoadMore
;
}
[weakSelf.view
configBlankPage:
([[Login
curLoginUser
]
isSameToUser:
self
.curTweets.curUser]?
EaseBlankPageTypeTweet:
EaseBlankPageTypeTweetOther)
hasData:
(weakSelf.curTweets.list.count >
0
)
hasError:
(error !=
nil
)
reloadButtonBlock:
^(
id
sender) {
[weakSelf
sendRequest
];
}];
}];
}
- (
void
)
refreshCurUser
{
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_UserInfo_WithObj:
_curTweets.curUser
andBlock:
^(
id
data,
NSError
*error) {
if
(data) {
weakSelf.
curTweets
.
curUser
= data;
weakSelf.
title
= weakSelf.
curTweets
.
curUser
.
name
;
[weakSelf
sendRequest
];
}
else
{
[weakSelf.view
endLoading
];
[weakSelf.view
configBlankPage:
([[Login
curLoginUser
]
isSameToUser:
self
.curTweets.curUser]?
EaseBlankPageTypeTweet:
EaseBlankPageTypeTweetOther)
hasData:
(weakSelf.curTweets.list.count >
0
)
hasError:
YES
reloadButtonBlock:
^(
id
sender) {
[weakSelf
sendRequest
];
}];
}
}];
}
#
pragma mark
TableM
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
if
(_curTweets && _curTweets.
list
) {
return
[_curTweets.list
count
];
}
else
{
return
0
;
}
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
TweetCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_Tweet
forIndexPath:
indexPath];
[cell
setTweet:
[_curTweets.list
objectAtIndex:
indexPath.row]
needTopView:
(indexPath.row !=
0
)];
__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]) {
UIActionSheet *actionSheet = [UIActionSheet
bk_actionSheetCustomWithTitle:
@"
删除此评论
"
buttonTitles:
nil
destructiveTitle:
@"
确认删除
"
cancelTitle:
@"
取消
"
andDidDismissBlock:
^(UIActionSheet *sheet,
NSInteger
index) {
if
(index ==
0
&& weakSelf.
commentIndex
>=
0
) {
Comment *comment = [weakSelf.commentTweet.comment_list
objectAtIndex:
weakSelf.commentIndex];
[weakSelf
deleteComment:
comment
ofTweet:
weakSelf.commentTweet];
}
}];
[actionSheet
showInView:
self
.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;
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
};
cell.
moreLikersBtnClickedBlock
= ^(Tweet *curTweet){
LikersViewController *vc = [[LikersViewController
alloc
]
init
];
vc.
curTweet
= curTweet;
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
};
cell.
deleteClickedBlock
= ^(Tweet *curTweet,
NSInteger
outTweetsIndex){
if
([
self
.myMsgInputView
isAndResignFirstResponder
]) {
return
;
}
self.
deleteTweet
= curTweet;
self.
deleteTweetsIndex
= outTweetsIndex;
UIActionSheet *actionSheet = [UIActionSheet
bk_actionSheetCustomWithTitle:
@"
删除此冒泡
"
buttonTitles:
nil
destructiveTitle:
@"
确认删除
"
cancelTitle:
@"
取消
"
andDidDismissBlock:
^(UIActionSheet *sheet,
NSInteger
index) {
if
(index ==
0
) {
[weakSelf
deleteTweet:
weakSelf.deleteTweet
outTweetsIndex:
weakSelf.deleteTweetsIndex];
}
}];
[actionSheet
showInView:
self
.view];
};
cell.
goToDetailTweetBlock
= ^(Tweet *curTweet){
[
self
goToDetailWithTweet:
curTweet];
};
cell.
refreshSingleCCellBlock
= ^(){
[weakSelf.myTableView
reloadData
];
};
cell.
mediaItemClickedBlock
= ^(HtmlMediaItem *curItem){
[weakSelf
analyseLinkStr:
curItem.href];
};
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
0
];
return
cell;
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
return
[TweetCell
cellHeightWithObj:
[_curTweets.list
objectAtIndex:
indexPath.row]
needTopView:
(indexPath.row !=
0
)];
}
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
Tweet *toTweet = [_curTweets.list
objectAtIndex:
indexPath.row];
[
self
goToDetailWithTweet:
toTweet];
}
- (
void
)
goToDetailWithTweet
:
(Tweet *)
curTweet
{
TweetDetailViewController *vc = [[TweetDetailViewController
alloc
]
init
];
vc.
curTweet
= curTweet;
__weak
typeof
(self) weakSelf = self;
vc.
deleteTweetBlock
= ^(Tweet *toDeleteTweet){
[weakSelf.curTweets.list
removeObject:
toDeleteTweet];
[weakSelf.myTableView
reloadData
];
[weakSelf.view
configBlankPage:
([[Login
curLoginUser
]
isSameToUser:
self
.curTweets.curUser]?
EaseBlankPageTypeTweet:
EaseBlankPageTypeTweetOther)
hasData:
(weakSelf.curTweets.list.count >
0
)
hasError:
NO
reloadButtonBlock:
^(
id
sender) {
[weakSelf
sendRequest
];
}];
};
[
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
];
}
}
- (
void
)
scrollViewWillBeginDragging
:
(UIScrollView *)
scrollView
{
if
(scrollView == _myTableView) {
[
self
.myMsgInputView
isAndResignFirstResponder
];
}
}
#
pragma mark
Comment To Tweet
- (
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
;
}
@end
Back
|
FazBrowse Home
|
New Git URL