FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/TipsViewController.m at master · garydai/Coding-iOS · GitHub
garydai
/
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
/
TipsViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
241 lines (215 loc) · 8.21 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
TipsViewController.m
Copy path
File metadata and controls
executable file
·
241 lines (215 loc) · 8.21 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
//
//
TipsViewController.m
//
Coding_iOS
//
//
Created by 王 原闯 on 14-9-2.
//
Copyright (c) 2014年 Coding. All rights reserved.
//
#
import
"
TipsViewController.h
"
#
import
"
ODRefreshControl.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
CodingTipCell.h
"
#
import
"
RegexKitLite.h
"
#
import
"
UserInfoViewController.h
"
#
import
"
TopicDetailViewController.h
"
#
import
"
TweetDetailViewController.h
"
#
import
"
ProjectViewController.h
"
#
import
"
SVPullToRefresh.h
"
#
import
"
EditTaskViewController.h
"
#
import
"
WebViewController.h
"
#
import
"
KxMenu.h
"
@interface
TipsViewController
()
@property
(
nonatomic
,
strong
) UITableView *myTableView;
@property
(
nonatomic
,
strong
) ODRefreshControl *refreshControl;
@end
@implementation
TipsViewController
- (
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.
NSString
*titleStr;
switch
(self.
myCodingTips
.
type
) {
case
0
:
titleStr =
@"
@我的
"
;
break
;
case
1
:
titleStr =
@"
评论
"
;
break
;
case
2
:
titleStr =
@"
系统通知
"
;
break
;
default
:
break
;
}
self.
title
= titleStr;
[
self
.navigationItem
setRightBarButtonItem:
[[UIBarButtonItem
alloc
]
initWithImage:
[UIImage
imageNamed:
@"
moreBtn_Nav
"
]
style:
UIBarButtonItemStylePlain
target:
self
action:
@selector
(
rightNavBtnClicked
)]
animated:
NO
];
//
添加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;
[tableView
registerClass:
[CodingTipCell
class
]
forCellReuseIdentifier:
kCellIdentifier_CodingTip
];
[
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;
[_myTableView
addInfiniteScrollingWithActionHandler:
^{
[weakSelf
refreshMore
];
}];
[
self
refresh
];
}
- (
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
//
Dispose of any resources that can be recreated.
}
- (
void
)
refresh
{
_myCodingTips.
willLoadMore
=
NO
;
[
self
sendRequest
];
}
- (
void
)
refreshMore
{
if
(!_myCodingTips.
canLoadMore
) {
[_myTableView.infiniteScrollingView
stopAnimating
];
return
;
}
_myCodingTips.
willLoadMore
=
YES
;
[
self
sendRequest
];
}
- (
void
)
sendRequest
{
if
(_myCodingTips.
list
.
count
<=
0
) {
[
self
.view
beginLoading
];
}
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_CodingTips:
_myCodingTips
andBlock:
^(
id
data,
NSError
*error) {
[weakSelf.refreshControl
endRefreshing
];
[weakSelf.view
endLoading
];
[weakSelf.myTableView.infiniteScrollingView
stopAnimating
];
if
(data) {
[weakSelf.myCodingTips
configWithObj:
data];
[weakSelf.myTableView
reloadData
];
weakSelf.
myTableView
.
showsInfiniteScrolling
= weakSelf.
myCodingTips
.
canLoadMore
;
}
[weakSelf.view
configBlankPage:
EaseBlankPageTypeViewTips
hasData:
(weakSelf.myCodingTips.list.count >
0
)
hasError:
(error !=
nil
)
reloadButtonBlock:
^(
id
sender) {
[weakSelf
refresh
];
}];
}];
}
#
pragma mark
Table M
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
NSInteger
row =
0
;
if
(_myCodingTips.
list
) {
row += [_myCodingTips.list
count
];
}
return
row;
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
CodingTipCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_CodingTip
forIndexPath:
indexPath];
CodingTip *tip = [_myCodingTips.list
objectAtIndex:
indexPath.row];
cell.
curTip
= tip;
__weak
typeof
(self) weakSelf = self;
cell.
linkClickedBlock
= ^(HtmlMediaItem *item, CodingTip *tip){
[weakSelf
analyseHtmlMediaItem:
item
andTip:
tip];
};
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
2
*
kPaddingLeftWidth
];
return
cell;
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
return
[CodingTipCell
cellHeightWithObj:
[_myCodingTips.list
objectAtIndex:
indexPath.row]];
}
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
[tableView
deselectRowAtIndexPath:
indexPath
animated:
YES
];
CodingTip *tip = [_myCodingTips.list
objectAtIndex:
indexPath.row];
[
self
p_markReadTip:
tip];
}
- (
void
)
p_markReadTip
:
(CodingTip *)
tip
{
if
(tip.
status
.
boolValue
) {
//
已读
return
;
}
@
weakify
(self);
[[Coding_NetAPIManager
sharedManager
]
request_markReadWithCodingTipIdStr:
tip.
id
andBlock:
^(
id
data,
NSError
*error) {
@
strongify
(self);
DebugLog
(
@"
%@
:
%@
"
, data, error);
if
(data) {
tip.
status
= @(
YES
);
[
self
.myTableView
reloadData
];
}
}];
}
- (
void
)
rightNavBtnClicked
{
if
([KxMenu
isShowingInView:
self
.view]) {
[KxMenu
dismissMenu:
YES
];
}
else
{
[KxMenu
setTitleFont:
[UIFont
systemFontOfSize:
14
]];
[KxMenu
setTintColor:
[UIColor
whiteColor
]];
[KxMenu
setLineColor:
[UIColor
colorWithHexString:
@"
0xdddddd
"
]];
NSArray
*menuItems = @[
[KxMenuItem
menuItem:
_myCodingTips.onlyUnread?
@"
查看全部
"
:
@"
查看未读
"
image:
[UIImage
imageNamed:
@"
tips_menu_icon_status
"
]
target:
self
action:
@selector
(
p_changeTipStatus
)],
[KxMenuItem
menuItem:
@"
全部标注已读
"
image:
[UIImage
imageNamed:
@"
tips_menu_icon_mkread
"
]
target:
self
action:
@selector
(
p_markReadAll
)],
];
[menuItems
setValue:
[UIColor
colorWithHexString:
@"
0x222222
"
]
forKey:
@"
foreColor
"
];
CGRect senderFrame =
CGRectMake
(
kScreen_Width
- (
kDevice_Is_iPhone6Plus
?
30
:
26
),
0
,
0
,
0
);
[KxMenu
showMenuInView:
self
.view
fromRect:
senderFrame
menuItems:
menuItems];
}
//
@weakify(self);
//
[[UIActionSheet bk_actionSheetCustomWithTitle:@"将本页的未读通知全部标记为已读?" buttonTitles:@[@"全部标为已读"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
//
if (index == 0) {
//
@strongify(self);
//
[self p_markReadAll];
//
}
//
}] showInView:self.view];
}
- (
void
)
p_markReadAll
{
@
weakify
(self);
[[Coding_NetAPIManager
sharedManager
]
request_markReadWithCodingTips:
_myCodingTips
andBlock:
^(
id
data,
NSError
*error) {
@
strongify
(self);
DebugLog
(
@"
%@
:
%@
"
, data, error);
if
(data) {
//
[self refresh];
for
(CodingTip *tempTip in self.
myCodingTips
.
list
) {
tempTip.
status
= @(
YES
);
}
[
self
.myTableView
reloadData
];
}
}];
}
- (
void
)
p_changeTipStatus
{
_myCodingTips.
onlyUnread
= !_myCodingTips.
onlyUnread
;
[_myTableView
reloadData
];
[
self
refresh
];
}
#
pragma mark
analyseHtmlMediaItem
- (
void
)
analyseHtmlMediaItem
:
(HtmlMediaItem *)
item
andTip
:
(CodingTip *)
tip
{
[
self
p_markReadTip:
tip];
NSString
*linkStr = item.
href
;
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
)
dealloc
{
_myTableView.
delegate
=
nil
;
_myTableView.
dataSource
=
nil
;
}
@end
Back
|
FazBrowse Home
|
New Git URL