FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/Topic/CSHotTopicView.m at master · doudou2012/Coding-iOS · GitHub
doudou2012
/
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
/
Topic
/
CSHotTopicView.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
382 lines (308 loc) · 13.4 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
Topic
/
CSHotTopicView.m
Copy path
File metadata and controls
382 lines (308 loc) · 13.4 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
382
//
//
CSHotTopicVC.m
//
Coding_iOS
//
//
Created by pan Shiyu on 15/7/15.
//
Copyright (c) 2015年 Coding. All rights reserved.
//
#
import
"
CSHotTopicView.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
RDVTabBarController.h
"
#
import
"
RDVTabBarItem.h
"
#
import
"
UILabel+Common.h
"
#
import
"
Tweet.h
"
#
import
"
CSTopicDetailVC.h
"
#
import
"
HotTopicBannerView.h
"
#
define
kCellIdentifier_HotTopicTitleCell
@"
kCellIdentifier_HotTopicTitleCell
"
@interface
CSHotTopicView
()<UITableViewDataSource,UITableViewDelegate>
@property
(
nonatomic
,
strong
)UITableView *listView;
@property
(
nonatomic
,
strong
)
NSArray
*topiclist;
@property
(
nonatomic
,
strong
)
NSMutableArray
*adlist;
@property
(
nonatomic
,
strong
)HotTopicBannerView *adView;
@end
@implementation
CSHotTopicView
{
CGFloat _adHeight;
}
- (
id
)
initWithFrame
:
(CGRect)
frame
{
self = [
super
initWithFrame:
frame];
self.
backgroundColor
= [UIColor
whiteColor
];
_adHeight =
kScreen_Width
*
214
/
640
;
_listView = ({
UITableView *tableView = [[UITableView
alloc
]
initWithFrame:
self
.bounds
style:
UITableViewStylePlain];
tableView.
backgroundColor
= [UIColor
clearColor
];
tableView.
dataSource
= self;
tableView.
delegate
= self;
tableView.
separatorStyle
= UITableViewCellSeparatorStyleNone;
[tableView
registerClass:
[CSTopicCell
class
]
forCellReuseIdentifier:
kCellIdentifier_TopicCell
];
[tableView
registerClass:
[CSHotTopicTitleCell
class
]
forCellReuseIdentifier:
kCellIdentifier_HotTopicTitleCell
];
[
self
addSubview:
tableView];
[tableView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self);
}];
//
{
//
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.rdv_tabBarController.tabBar.frame), 0);
//
tableView.contentInset = insets;
//
tableView.scrollIndicatorInsets = insets;
//
}
tableView;
});
_topiclist = @[];
_adlist = [
NSMutableArray
new
];
[
self
refreshAdlist
];
[
self
refreshHotTopiclist
];
return
self;
}
- (
void
)
dealloc
{
_listView.
delegate
=
nil
;
_listView.
dataSource
=
nil
;
}
#
pragma mark
- data refresh
- (
void
)
refreshHotTopiclist
{
__weak
typeof
(self) wself = self;
[[Coding_NetAPIManager
sharedManager
]
request_HotTopiclistWithBlock:
^(
NSArray
*topiclist,
NSError
*error) {
if
(topiclist) {
wself.
topiclist
= [topiclist
copy
];
}
else
{
wself.
topiclist
= [
NSArray
array
];
}
[wself.listView
reloadData
];
}];
}
- (
void
)
refreshAdlist
{
__weak
typeof
(self) wself = self;
_adView = [HotTopicBannerView
new
];
_adView.
backgroundColor
= [UIColor
whiteColor
];
_adView.
tapActionBlock
= ^(
NSDictionary
*tapedBanner) {
CSTopicDetailVC *vc = [[CSTopicDetailVC
alloc
]
init
];
vc.
topicID
= [tapedBanner[
@"
id
"
]
intValue
];
[wself.parentVC.navigationController
pushViewController:
vc
animated:
YES
];
};
[[Coding_NetAPIManager
sharedManager
]
request_TopicAdlistWithBlock:
^(
id
data,
NSError
*error) {
//
if (data && [data isKindOfClass:[NSArray class]]) {
//
for (NSDictionary *dict in data) {
//
[wself.adlist addObject:({
//
CodingBanner *banner = [CodingBanner new];
//
banner.id = [dict objectForKey:@"id"];
//
banner.status = @1;
//
banner.name = [dict objectForKey:@"name"];
//
banner.title = [dict objectForKey:@"description"];
//
banner.image = [dict objectForKey:@"image_url"];
//
banner;
//
})];
//
}
//
}else {
//
//
wself.adlist = [NSMutableArray array];
//
}
wself.
adlist
= data;
wself.
adView
.
frame
=
CGRectMake
(
0
,
0
,
kScreen_Width
, wself.
adlist
.
count
==
0
?
0
: _adHeight);
wself.
adView
.
curBannerList
= wself.
adlist
;
wself.
listView
.
tableHeaderView
= wself.
adView
;
[wself.listView
reloadData
];
}];
}
#
pragma mark
- tableview
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
if
(_topiclist.
count
==
0
) {
return
0
;
}
return
_topiclist.
count
+
1
;
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
if
(indexPath.
row
==
0
) {
CSHotTopicTitleCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_HotTopicTitleCell
forIndexPath:
indexPath];
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
12
];
return
cell;
}
NSDictionary
*data = _topiclist[indexPath.row -
1
];
CSTopicCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_TopicCell
forIndexPath:
indexPath];
[cell
updateDisplayByTopic:
data];
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
12
];
return
cell;
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
if
(indexPath.
row
==
0
) {
return
35
;
}
NSDictionary
*data = _topiclist[indexPath.row -
1
];
return
[CSTopicCell
cellHeightWithData:
data];
}
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
[tableView
deselectRowAtIndexPath:
indexPath
animated:
YES
];
if
(indexPath.
row
==
0
) {
return
;
}
CSTopicDetailVC *vc = [[CSTopicDetailVC
alloc
]
init
];
NSDictionary
*topic = _topiclist[indexPath.row -
1
];
vc.
topicID
= [topic[
@"
id
"
]
intValue
];
[
self
.parentVC.navigationController
pushViewController:
vc
animated:
YES
];
}
//
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//
if (_adlist.count == 0) {
//
return 0;
//
}
//
return _adHeight;
//
}
//
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//
if (_adlist.count == 0) {
//
return nil;
//
}
//
//
if (!_adView) {
//
//
__weak CSHotTopicView *wself = self;
//
_adView = [CodingBannersView new];
//
_adView.tapActionBlock = ^(CodingBanner *tapedBanner) {
//
//
CSTopicDetailVC *vc = [[CSTopicDetailVC alloc] init];
//
vc.topicID = [tapedBanner.id intValue];
//
//
[wself.parentVC.navigationController pushViewController:vc animated:YES];
//
};
//
_adView.backgroundColor = [UIColor whiteColor];
//
//
}
//
//
_adView.curBannerList = self.adlist;
//
//
return _adView;
//
}
//
@end
#
pragma mark
-
@interface
CSTopicCell
()<TTTAttributedLabelDelegate>
@property
(
nonatomic
,
strong
)UILabel *nameLabel;
@property
(
nonatomic
,
strong
)UITTTAttributedLabel *contentLabel;
@property
(
nonatomic
,
strong
)UILabel *userCountLabel;
@property
(
strong
,
nonatomic
) UIImageView *detailIconView;
@property
(
nonatomic
,
strong
)
NSDictionary
*refData;
@end
@implementation
CSTopicCell
static
CGFloat
const
kHotTopicCellPaddingRight
=
15
;
- (
id
)
initWithStyle
:
(UITableViewCellStyle)
style
reuseIdentifier
:
(
NSString
*)
reuseIdentifier
{
self = [
super
initWithStyle:
style
reuseIdentifier:
reuseIdentifier];
if
(self) {
self.
selectionStyle
= UITableViewCellSelectionStyleNone;
self.
backgroundColor
= [UIColor
clearColor
];
self.
accessoryType
= UITableViewCellAccessoryDisclosureIndicator;
_nameLabel = [[UILabel
alloc
]
initWithFrame:
CGRectMake
(
kPaddingLeftWidth
,
15
,
kScreen_Width
-
kPaddingLeftWidth
-
kHotTopicCellPaddingRight
,
12
)];
_nameLabel.
font
= [UIFont
boldSystemFontOfSize:
15
];
_nameLabel.
backgroundColor
= [UIColor
clearColor
];
_nameLabel.
textColor
= [UIColor
colorWithHexString:
@"
0x222222
"
];
_nameLabel.
textAlignment
= NSTextAlignmentLeft;
[
self
.contentView
addSubview:
_nameLabel];
self.
contentLabel
= [[UITTTAttributedLabel
alloc
]
initWithFrame:
CGRectMake
(
kPaddingLeftWidth
, _nameLabel.bottom +
15
,
kScreen_Width
-
kPaddingLeftWidth
-
30
,
30
)];
self.
contentLabel
.
font
= [UIFont
systemFontOfSize:
14
];
self.
contentLabel
.
textColor
= [UIColor
colorWithHexString:
@"
0x222222
"
];
self.
contentLabel
.
numberOfLines
=
0
;
self.
contentLabel
.
linkAttributes
=
kLinkAttributes
;
self.
contentLabel
.
activeLinkAttributes
=
kLinkAttributesActive
;
self.
contentLabel
.
delegate
= self;
[
self
.contentLabel
addLongPressForCopy
];
[
self
.contentView
addSubview:
self
.contentLabel];
_userCountLabel = [[UILabel
alloc
]
initWithFrame:
CGRectMake
(
kPaddingLeftWidth
,
75
,
kScreen_Width
-
kPaddingLeftWidth
-
kHotTopicCellPaddingRight
,
12
)];
_userCountLabel.
font
= [UIFont
systemFontOfSize:
12
];
_userCountLabel.
backgroundColor
= [UIColor
clearColor
];
_userCountLabel.
textColor
= [UIColor
colorWithHexString:
@"
0x999999
"
];
_userCountLabel.
textAlignment
= NSTextAlignmentLeft;
[
self
.contentView
addSubview:
_userCountLabel];
if
(!self.
detailIconView
) {
//
self.detailIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreen_Width - kPaddingLeftWidth - 8, 0, 20, 20)];
//
self.detailIconView.image = [UIImage imageNamed:@"me_info_arrow_left"];
//
[self.contentView addSubview:self.detailIconView];
}
}
return
self;
}
- (
void
)
updateDisplayByTopic
:
(
NSDictionary
*)
data
{
_refData = data;
NSString
*peopleCount = data[
@"
speackers
"
];
if
(!peopleCount) {
peopleCount = data[
@"
speakers
"
];
}
if
(!peopleCount) {
peopleCount =
@"
0
"
;
}
_nameLabel.
text
= [
NSString
stringWithFormat:
@"
#
%@
#
"
,data[
@"
name
"
]];
Tweet *tweet = [
NSObject
objectOfClass:
@"
Tweet
"
fromJSON:
data[
@"
hot_tweet
"
]];
NSString
*contentStr = (tweet.
content
.
length
>
0
) ? tweet.
content
:
@"
[图片]
"
;
[
self
.contentLabel
setLongString:
contentStr
withFitWidth:
self
.contentLabel.width
maxHeight:
34
];
self.
contentLabel
.
centerY
= self.
height
/
2
;
for
(HtmlMediaItem *item in tweet.
htmlMedia
.
mediaItems
) {
if
(item.
displayStr
.
length
>
0
&& !(item.
type
== HtmlMediaItemType_Code ||item.
type
== HtmlMediaItemType_EmotionEmoji)) {
[
self
.contentLabel
addLinkToTransitInformation:
[
NSDictionary
dictionaryWithObject:
item
forKey:
@"
value
"
]
withRange:
item.range];
}
}
_userCountLabel.
top
= self.
contentLabel
.
bottom
+
10
;
_userCountLabel.
text
= [
NSString
stringWithFormat:
@"
%@
人参与
"
,peopleCount];
[
self
.detailIconView
setY:
([CSTopicCell
cellHeightWithData:
data] -
12
) /
2
];
}
+ (CGFloat)
contentLabelHeightWithTweet
:
(
NSDictionary
*)
data
{
Tweet *tweet = [
NSObject
objectOfClass:
@"
Tweet
"
fromJSON:
data[
@"
hot_tweet
"
]];
NSString
*content = (tweet.
content
.
length
>
0
) ? tweet.
content
:
@"
[图片]
"
;
CGFloat width =
kScreen_Width
-
kPaddingLeftWidth
-
kHotTopicCellPaddingRight
;
CGFloat realheight = [content
getHeightWithFont:
[UIFont
systemFontOfSize:
14
]
constrainedToSize:
CGSizeMake
(width,
1000
)];
return
MIN
(realheight,
34
);
}
+ (CGFloat)
cellHeightWithData
:
(
NSDictionary
*)
data
{
CGFloat height =
15
*
3
+
8
;
height +=
12
;
//
namelabel
height += [CSTopicCell
contentLabelHeightWithTweet:
data];
height +=
12
;
return
height;
}
#
pragma mark
TTTAttributedLabelDelegate
- (
void
)
attributedLabel
:
(TTTAttributedLabel *)
label
didSelectLinkWithTransitInformation
:
(
NSDictionary
*)
components
{
//
if (_mediaItemClickedBlock) {
//
_mediaItemClickedBlock([components objectForKey:@"value"]);
//
}
NSLog
(
@"
%@
"
,components[
@"
value
"
]);
}
@end
@implementation
CSHotTopicTitleCell
- (
id
)
initWithStyle
:
(UITableViewCellStyle)
style
reuseIdentifier
:
(
NSString
*)
reuseIdentifier
{
self = [
super
initWithStyle:
style
reuseIdentifier:
reuseIdentifier];
if
(self) {
//
Initialization code
self.
selectionStyle
= UITableViewCellSelectionStyleNone;
self.
backgroundColor
= [UIColor
clearColor
];
self.
textLabel
.
frame
=
CGRectMake
(
kPaddingLeftWidth
,
12
,
kScreen_Width
-
100
,
12
);
self.
textLabel
.
font
= [UIFont
systemFontOfSize:
13
];
self.
textLabel
.
textColor
= [UIColor
colorWithHexString:
@"
0x222222
"
];
self.
textLabel
.
text
=
@"
热门话题榜单
"
;
self.
textLabel
.
backgroundColor
= [UIColor
clearColor
];
}
return
self;
}
- (
void
)
layoutSubviews
{
[
super
layoutSubviews
];
self.
textLabel
.
frame
=
CGRectMake
(
kPaddingLeftWidth
,
12
,
kScreen_Width
-
100
,
12
);
}
@end
@interface
CSHotAdCell
()
@property
(
nonatomic
,
strong
)CSScrollview *adView;
@end
@implementation
CSHotAdCell
- (
id
)
initWithStyle
:
(UITableViewCellStyle)
style
reuseIdentifier
:
(
NSString
*)
reuseIdentifier
{
self = [
super
initWithStyle:
style
reuseIdentifier:
reuseIdentifier];
if
(self) {
//
Initialization code
self.
selectionStyle
= UITableViewCellSelectionStyleNone;
self.
backgroundColor
= [UIColor
clearColor
];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout
alloc
]
init
];
layout.
minimumLineSpacing
=
0
;
layout.
itemSize
=
CGSizeMake
(
kScreen_Width
,
80
);
layout.
scrollDirection
= UICollectionViewScrollDirectionHorizontal;
_adView = [[CSScrollview
alloc
]
initWithFrame:
CGRectMake
(
0
,
0
,
kScreen_Width
,
80
)
layout:
layout];
_adView.
autoScrollEnable
=
YES
;
_adView.
showPageControl
=
NO
;
_adView.
tapBlk
= ^(CSScrollItem* item) {
NSLog
(
@"
tap --
\n
%@
"
,item.
data
);
};
}
return
self;
}
@end
Back
|
FazBrowse Home
|
New Git URL