Skip to content

Commit 720ea9a

Browse files
committed
通知 - 标记已读
1 parent b413367 commit 720ea9a

10 files changed

Lines changed: 110 additions & 42 deletions

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@
224224
4E8D5D6E1B45400100B70936 /* ZXScanCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8D5D6D1B45400100B70936 /* ZXScanCodeViewController.m */; };
225225
4E8D5D731B454D5000B70936 /* OTPAuthClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8D5D721B454D5000B70936 /* OTPAuthClock.m */; };
226226
4E8D5D7D1B462ADB00B70936 /* OTPTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8D5D7C1B462ADB00B70936 /* OTPTableViewCell.m */; };
227+
4E8F92DE1B67BE3C00033D8F /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E8F92DB1B67BE3C00033D8F /* [email protected] */; };
228+
4E8F92DF1B67BE3C00033D8F /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E8F92DC1B67BE3C00033D8F /* [email protected] */; };
229+
4E8F92E01B67BE3C00033D8F /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E8F92DD1B67BE3C00033D8F /* [email protected] */; };
227230
4E90F89B1AF709C100B44F03 /* bubble.html in Resources */ = {isa = PBXBuildFile; fileRef = 4E90F8971AF709C100B44F03 /* bubble.html */; };
228231
4E90F89C1AF709C100B44F03 /* code.html in Resources */ = {isa = PBXBuildFile; fileRef = 4E90F8981AF709C100B44F03 /* code.html */; };
229232
4E90F89D1AF709C100B44F03 /* markdown.html in Resources */ = {isa = PBXBuildFile; fileRef = 4E90F8991AF709C100B44F03 /* markdown.html */; };
@@ -1116,6 +1119,9 @@
11161119
4E8D5D721B454D5000B70936 /* OTPAuthClock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPAuthClock.m; sourceTree = "<group>"; };
11171120
4E8D5D7B1B462ADB00B70936 /* OTPTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPTableViewCell.h; sourceTree = "<group>"; };
11181121
4E8D5D7C1B462ADB00B70936 /* OTPTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPTableViewCell.m; sourceTree = "<group>"; };
1122+
4E8F92DB1B67BE3C00033D8F /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
1123+
4E8F92DC1B67BE3C00033D8F /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
1124+
4E8F92DD1B67BE3C00033D8F /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
11191125
4E90F8971AF709C100B44F03 /* bubble.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = bubble.html; path = webview/app/build/bubble.html; sourceTree = "<group>"; };
11201126
4E90F8981AF709C100B44F03 /* code.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = code.html; path = webview/app/build/code.html; sourceTree = "<group>"; };
11211127
4E90F8991AF709C100B44F03 /* markdown.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = markdown.html; path = webview/app/build/markdown.html; sourceTree = "<group>"; };
@@ -3249,7 +3255,6 @@
32493255
8EA6CF6319E240C40076D59C /* [email protected] */,
32503256
8EA6CF7119E240C40076D59C /* [email protected] */,
32513257
8EA6CF7319E240C40076D59C /* [email protected] */,
3252-
8EA6CF7419E240C40076D59C /* [email protected] */,
32533258
8EA6CF7B19E240C40076D59C /* [email protected] */,
32543259
8EA6CF9619E240C40076D59C /* [email protected] */,
32553260
8EA6CF9719E240C40076D59C /* [email protected] */,
@@ -3304,6 +3309,10 @@
33043309
4E63840A1B33F9B400D98648 /* [email protected] */,
33053310
4EE1A23B1B5F3834004284F1 /* [email protected] */,
33063311
4EE1A23C1B5F3834004284F1 /* [email protected] */,
3312+
8EA6CF7419E240C40076D59C /* [email protected] */,
3313+
4E8F92DB1B67BE3C00033D8F /* [email protected] */,
3314+
4E8F92DC1B67BE3C00033D8F /* [email protected] */,
3315+
4E8F92DD1B67BE3C00033D8F /* [email protected] */,
33073316
);
33083317
path = Images;
33093318
sourceTree = "<group>";
@@ -4173,6 +4182,7 @@
41734182
4E76D4DE1A5A7B4A0094A35E /* [email protected] in Resources */,
41744183
4E96E7E41A1B537E0037C098 /* [email protected] in Resources */,
41754184
4EC461B41B39360F00D08970 /* [email protected] in Resources */,
4185+
4E8F92E01B67BE3C00033D8F /* [email protected] in Resources */,
41764186
4EA679191A14BFA0001A0324 /* [email protected] in Resources */,
41774187
4E6383D61B32665700D98648 /* [email protected] in Resources */,
41784188
4EF17ECE1B3C3112003CDD2D /* [email protected] in Resources */,
@@ -4236,6 +4246,7 @@
42364246
4EF17EE01B3C3112003CDD2D /* [email protected] in Resources */,
42374247
4E2719C71AB07ED6006AE214 /* [email protected] in Resources */,
42384248
4E6383E61B3272CF00D98648 /* [email protected] in Resources */,
4249+
4E8F92DF1B67BE3C00033D8F /* [email protected] in Resources */,
42394250
8E64ED8B19EE484A006E99DA /* README.textile in Resources */,
42404251
8E97CE9D1A0C7E26006F9AD7 /* [email protected] in Resources */,
42414252
4E0849821A918A7F00BD27F6 /* [email protected] in Resources */,
@@ -4310,6 +4321,7 @@
43104321
8E7612F41A08B1EA005BE797 /* [email protected] in Resources */,
43114322
4E94C50C1B4D334B00EB668A /* [email protected] in Resources */,
43124323
4E6383E01B32676600D98648 /* [email protected] in Resources */,
4324+
4E8F92DE1B67BE3C00033D8F /* [email protected] in Resources */,
43134325
4E76D4DC1A5A77DD0094A35E /* [email protected] in Resources */,
43144326
8E97CE521A0A3410006F9AD7 /* [email protected] in Resources */,
43154327
8EC911291A027A54009EAE99 /* [email protected] in Resources */,

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ + (void)handleNotificationInfo:(NSDictionary *)userInfo applicationState:(UIAppl
104104
//标记为已读
105105
NSString *notification_id = [userInfo objectForKey:@"notification_id"];
106106
if (notification_id) {
107-
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTip:notification_id andBlock:^(id data, NSError *error) {
108-
if (error) {
109-
DebugLog(@"request_markReadWithCodingTip: %@", error.description);
110-
}else{
111-
DebugLog(@"request_markReadWithCodingTip: %@", data);
112-
}
107+
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTipIdStr:notification_id andBlock:^(id data, NSError *error) {
113108
}];
114109
}
115110
//弹出临时会话

Coding_iOS/Controllers/TipsViewController.m

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ - (void)viewDidLoad
5454
break;
5555
}
5656
self.title = titleStr;
57+
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"moreBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(rightNavBtnClicked)] animated:NO];
5758

5859
// 添加myTableView
5960
_myTableView = ({
@@ -138,7 +139,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
138139
cell.linkClickedBlock = ^(HtmlMediaItem *item, CodingTip *tip){
139140
[weakSelf analyseHtmlMediaItem:item andTip:tip];
140141
};
141-
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
142+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:2* kPaddingLeftWidth];
142143
return cell;
143144
}
144145

@@ -148,10 +149,56 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
148149

149150
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
150151
[tableView deselectRowAtIndexPath:indexPath animated:YES];
152+
CodingTip *tip = [_myCodingTips.list objectAtIndex:indexPath.row];
153+
[self p_markReadTip:tip];
154+
}
155+
156+
- (void)p_markReadTip:(CodingTip *)tip{
157+
if (tip.status.boolValue) {//已读
158+
return;
159+
}
160+
@weakify(self);
161+
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTipIdStr:tip.id andBlock:^(id data, NSError *error) {
162+
@strongify(self);
163+
DebugLog(@"%@: %@", data, error);
164+
if (data) {
165+
tip.status = @(YES);
166+
[self.myTableView reloadData];
167+
}
168+
}];
169+
}
170+
171+
- (void)rightNavBtnClicked{
172+
@weakify(self);
173+
[[UIActionSheet bk_actionSheetCustomWithTitle:@"将本页的未读通知全部标记为已读?" buttonTitles:@[@"全部标为已读"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
174+
if (index == 0) {
175+
@strongify(self);
176+
[self p_markReadAll];
177+
}
178+
}] showInView:self.view];
179+
}
180+
181+
- (void)p_markReadAll{
182+
@weakify(self);
183+
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTips:_myCodingTips andBlock:^(id data, NSError *error) {
184+
@strongify(self);
185+
DebugLog(@"%@: %@", data, error);
186+
if (data) {
187+
// [self refresh];
188+
[self showHudTipStr:@"标记成功~"];
189+
for (CodingTip *tempTip in self.myCodingTips.list) {
190+
tempTip.status = @(YES);
191+
}
192+
[self.myTableView reloadData];
193+
}
194+
}];
151195
}
152196

153197
#pragma mark analyseHtmlMediaItem
154198
- (void)analyseHtmlMediaItem:(HtmlMediaItem *)item andTip:(CodingTip *)tip{
199+
200+
[self p_markReadTip:tip];
201+
155202
NSString *linkStr = item.href;
156203
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
157204
if (vc) {
7.46 KB
Loading
12.6 KB
Loading

Coding_iOS/Models/CodingTip.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
@interface CodingTip : NSObject
1414

15-
@property (readwrite, nonatomic, strong) NSNumber *id, *owner_id, *status, *target_id, *type;
15+
@property (readwrite, nonatomic, strong) NSNumber *status;
16+
@property (strong, nonatomic) NSString *id, *owner_id, *target_id, *type;
1617
@property (readwrite, nonatomic, strong) NSDate *created_at;
1718
@property (readwrite, nonatomic, strong) NSString *content, *target_type;
1819
@property (readwrite, nonatomic, strong) HtmlMedia *htmlMedia;

Coding_iOS/Models/CodingTips.m

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,17 @@ - (NSDictionary *)toTipsParams{
6464
}
6565

6666
- (NSDictionary *)toMarkReadParams{
67-
if (!self.list || self.list.count <= 0) {
68-
return nil;
69-
}
70-
71-
NSMutableArray *unReadArray = [[NSMutableArray alloc] init];
72-
for (CodingTip *curTip in self.list) {
73-
if (!curTip.status.boolValue) {//未读
74-
[unReadArray addObject:curTip.id];
75-
}
76-
}
77-
78-
if (unReadArray.count > 0) {
79-
return @{@"id" : unReadArray};
67+
NSDictionary *params;
68+
if (_type == 0) {
69+
params = @{@"type" : @(0),
70+
@"all" : @(1)};
71+
}else if (_type == 1){
72+
params = @{@"type" : @[@(1), @(2)],
73+
@"all" : @(1)};
74+
}else if (_type == 2){
75+
params = @{@"type" : @(4),
76+
@"all" : @(1)};
8077
}
81-
return nil;
78+
return params;
8279
}
8380
@end

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ typedef NS_ENUM(NSUInteger, VerifyType){
170170
- (void)request_SendPrivateMessage:(PrivateMessage *)nextMsg andBlock:(void (^)(id data, NSError *error))block;
171171
- (void)request_SendPrivateMessage:(PrivateMessage *)nextMsg andBlock:(void (^)(id data, NSError *error))block progerssBlock:(void (^)(CGFloat progressValue))progress;
172172
- (void)request_CodingTips:(CodingTips *)curTips andBlock:(void (^)(id data, NSError *error))block;
173-
- (void)request_markReadWithCodingTip:(NSString *)tipIdStr andBlock:(void (^)(id data, NSError *error))block;
173+
- (void)request_markReadWithCodingTips:(CodingTips *)curTips andBlock:(void (^)(id data, NSError *error))block;
174+
- (void)request_markReadWithCodingTipIdStr:(NSString *)tipIdStr andBlock:(void (^)(id data, NSError *error))block;
174175
- (void)request_DeletePrivateMessage:(PrivateMessage *)curMsg andBlock:(void (^)(id data, NSError *error))block;
175176
- (void)request_DeletePrivateMessagesWithObj:(PrivateMessage *)curObj andBlock:(void (^)(id data, NSError *error))block;
176177

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,29 +1656,38 @@ - (void)request_CodingTips:(CodingTips *)curTips andBlock:(void (^)(id data, NSE
16561656
id resultData = [data valueForKeyPath:@"data"];
16571657
CodingTips *resultA = [NSObject objectOfClass:@"CodingTips" fromJSON:resultData];
16581658
block(resultA, nil);
1659-
// 标记为已读
1660-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/notification/mark-read" withParams:[curTips toMarkReadParams] withMethodType:Post andBlock:^(id data1, NSError *error1) {
1661-
if (data1) {
1662-
[[UnReadManager shareManager] updateUnRead];
1663-
}
1664-
}];
16651659
}else{
16661660
block(nil, error);
16671661
}
16681662
}];
16691663
}
1670-
- (void)request_markReadWithCodingTip:(NSString *)tipIdStr andBlock:(void (^)(id data, NSError *error))block{
1671-
if (!tipIdStr) {
1664+
- (void)request_markReadWithCodingTips:(CodingTips *)curTips andBlock:(void (^)(id data, NSError *error))block{
1665+
[MobClick event:kUmeng_Event_Request label:@"标记某类型的消息为已读"];
1666+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/notification/mark-read" withParams:[curTips toMarkReadParams] withMethodType:Post andBlock:^(id data, NSError *error) {
1667+
if (data) {
1668+
block(data, nil);
1669+
[[UnReadManager shareManager] updateUnRead];
1670+
}else{
1671+
block(nil, error);
1672+
}
1673+
}];
1674+
}
1675+
- (void)request_markReadWithCodingTipIdStr:(NSString *)tipIdStr andBlock:(void (^)(id data, NSError *error))block{
1676+
if (tipIdStr.length <= 0) {
16721677
return;
16731678
}
16741679
[MobClick event:kUmeng_Event_Request label:@"标记某条消息为已读"];
16751680
NSDictionary *params = @{@"id" : tipIdStr};
1676-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/notification/mark-read" withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
1681+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/notification/mark-read" withParams:params withMethodType:Post autoShowError:NO andBlock:^(id data, NSError *error) {
16771682
if (data) {
1683+
block(data, nil);
16781684
[[UnReadManager shareManager] updateUnRead];
1685+
}else{
1686+
block(nil, error);
16791687
}
16801688
}];
16811689
}
1690+
16821691
- (void)request_DeletePrivateMessage:(PrivateMessage *)curMsg andBlock:(void (^)(id data, NSError *error))block{
16831692
[MobClick event:kUmeng_Event_Request label:@"删除私信"];
16841693
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[curMsg toDeletePath] withParams:nil withMethodType:Delete andBlock:^(id data, NSError *error) {

Coding_iOS/Views/Cell/CodingTipCell.m

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014年 Coding. All rights reserved.
77
//
88

9-
#define kCodingTipCell_WidthContent (kScreen_Width - 2*kPaddingLeftWidth - 35)
9+
#define kCodingTipCell_WidthContent (kScreen_Width - 2*kPaddingLeftWidth - 50)
1010
#define kCodingTipCell_FontContent [UIFont systemFontOfSize:15]
1111

1212
#import "CodingTipCell.h"
@@ -25,11 +25,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
2525
self.selectionStyle = UITableViewCellSelectionStyleNone;
2626
self.backgroundColor = [UIColor clearColor];
2727
if (!_iconView) {
28-
_iconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 10, 25, 25)];
28+
_iconView = [[UIImageView alloc] initWithFrame:CGRectMake(2* kPaddingLeftWidth, 12, 25, 25)];
2929
[self.contentView addSubview:_iconView];
3030
}
3131
if (!_contentLabel) {
32-
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth +35, 10, kCodingTipCell_WidthContent, 20)];
32+
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth +50, 12, kCodingTipCell_WidthContent, 20)];
3333
_contentLabel.font = kCodingTipCell_FontContent;
3434
_contentLabel.backgroundColor = [UIColor clearColor];
3535
_contentLabel.textColor = [UIColor colorWithHexString:@"0x222222"];
@@ -39,7 +39,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3939
[self.contentView addSubview:_contentLabel];
4040
}
4141
if (!_timeLabel) {
42-
_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
42+
_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width - kPaddingLeftWidth - 80, 0, 80, 15)];
4343
_timeLabel.font = [UIFont systemFontOfSize:12];
4444
_timeLabel.backgroundColor = [UIColor clearColor];
4545
_timeLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
@@ -61,22 +61,28 @@ - (void)layoutSubviews{
6161
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"tipIcon_%@", _curTip.target_type]];
6262
_iconView.image = image? image : [UIImage imageNamed:@"tipIcon_Other"];
6363
[_contentLabel setLongString:_curTip.content withFitWidth:kCodingTipCell_WidthContent];
64-
curBottomY += [_curTip.content getHeightWithFont:kCodingTipCell_FontContent constrainedToSize:CGSizeMake(kCodingTipCell_WidthContent, CGFLOAT_MAX)]+10;
65-
NSString *timeStr = [_curTip.created_at stringTimeDisplay];
66-
[_timeLabel setLongString:timeStr withVariableWidth:200];
67-
[_timeLabel setCenter:CGPointMake(kScreen_Width -(CGRectGetWidth(_timeLabel.frame)/2 +kPaddingLeftWidth), curBottomY+ CGRectGetHeight(_timeLabel.frame)/2)];
6864
for (HtmlMediaItem *item in _curTip.htmlMedia.mediaItems) {
6965
if (item.displayStr.length > 0) {
7066
[self.contentLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
7167
}
7268
}
69+
70+
curBottomY += [_curTip.content getHeightWithFont:kCodingTipCell_FontContent constrainedToSize:CGSizeMake(kCodingTipCell_WidthContent, CGFLOAT_MAX)] + 12;
71+
_timeLabel.text = [_curTip.created_at stringTimeDisplay];
72+
[_timeLabel setY:curBottomY];
73+
74+
// NSString *timeStr = [_curTip.created_at stringTimeDisplay];
75+
// [_timeLabel setLongString:timeStr withVariableWidth:200];
76+
// [_timeLabel setCenter:CGPointMake(kScreen_Width -(CGRectGetWidth(_timeLabel.frame)/2 +kPaddingLeftWidth), curBottomY+ CGRectGetHeight(_timeLabel.frame)/2)];
77+
78+
[self addBadgeTip:_curTip.status.boolValue? @"": kBadgeTipStr withCenterPosition:CGPointMake(kPaddingLeftWidth, _iconView.center.y)];
7379
}
7480

7581
+ (CGFloat)cellHeightWithObj:(id)obj{
7682
CGFloat cellHeight = 0;
7783
if ([obj isKindOfClass:[CodingTip class]]) {
7884
CodingTip *curTip = (CodingTip *)obj;
79-
cellHeight += 10 + [curTip.content getHeightWithFont:kCodingTipCell_FontContent constrainedToSize:CGSizeMake(kCodingTipCell_WidthContent, CGFLOAT_MAX)] +10+20;
85+
cellHeight += [curTip.content getHeightWithFont:kCodingTipCell_FontContent constrainedToSize:CGSizeMake(kCodingTipCell_WidthContent, CGFLOAT_MAX)] + 15 + 12 * 3;
8086
}
8187
return cellHeight;
8288
}

0 commit comments

Comments
 (0)