Skip to content

Commit fd3eb98

Browse files
committed
标记已读-代码整理
1 parent ed430d0 commit fd3eb98

7 files changed

Lines changed: 21 additions & 139 deletions

File tree

Coding_iOS/Controllers/RootControllers/Message_RootViewController.m

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,24 @@ - (instancetype)init
4747
{
4848
self = [super init];
4949
if (self) {
50-
[[UnReadManager shareManager] addObserver:self forKeyPath:kUnReadKey_messages options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
51-
[[UnReadManager shareManager] addObserver:self forKeyPath:kUnReadKey_notifications options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
50+
RAC(self, rdv_tabBarItem.badgeValue) = [RACSignal combineLatest:@[RACObserve([UnReadManager shareManager], messages),
51+
RACObserve([UnReadManager shareManager], notifications)]
52+
reduce:^id(NSNumber *messages, NSNumber *notifications){
53+
NSString *badgeTip = @"";
54+
NSNumber *unreadCount = [NSNumber numberWithInteger:messages.integerValue +notifications.integerValue];
55+
if (unreadCount.integerValue > 0) {
56+
if (unreadCount.integerValue > 99) {
57+
badgeTip = @"99+";
58+
}else{
59+
badgeTip = unreadCount.stringValue;
60+
}
61+
}
62+
return badgeTip;
63+
}];
5264
}
5365
return self;
5466
}
67+
5568
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
5669
{
5770
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -97,7 +110,6 @@ - (void)viewDidLoad
97110
[weakSelf refreshMore];
98111
}];
99112

100-
[self refreshBadgeTip];
101113
[self.refreshControl beginRefreshing];
102114
[self.myTableView setContentOffset:CGPointMake(0, -44)];
103115
[self refresh];
@@ -119,13 +131,8 @@ - (void)didReceiveMemoryWarning
119131
// Dispose of any resources that can be recreated.
120132
}
121133
- (void)dealloc{
122-
123-
[[UnReadManager shareManager] removeObserver:self forKeyPath:kUnReadKey_messages];
124-
[[UnReadManager shareManager] removeObserver:self forKeyPath:kUnReadKey_notifications];
125-
126134
_myTableView.delegate = nil;
127135
_myTableView.dataSource = nil;
128-
129136
}
130137

131138
- (void)sendMsgBtnClicked:(id)sender{
@@ -223,7 +230,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
223230
if (indexPath.row < 3) {
224231
TipsViewController *vc = [[TipsViewController alloc] init];
225232
vc.myCodingTips = [CodingTips codingTipsWithType:indexPath.row];
226-
vc.notificationDict = _notificationDict;
227233
[self.navigationController pushViewController:vc animated:YES];
228234
}else{
229235
PrivateMessage *curMsg = [_myPriMsgs.list objectAtIndex:indexPath.row-3];
@@ -265,27 +271,4 @@ - (void)removeConversation:(PrivateMessage *)curMsg inTableView:(UITableView *)t
265271
}
266272
}];
267273
}
268-
269-
270-
#pragma mark KVO_UnRead
271-
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
272-
if([keyPath isEqualToString:kUnReadKey_messages] || [keyPath isEqualToString:kUnReadKey_notifications]){
273-
[self refreshBadgeTip];
274-
}
275-
}
276-
277-
- (void)refreshBadgeTip{
278-
NSString *badgeTip = @"";
279-
NSNumber *unreadCount = [NSNumber numberWithInteger:([UnReadManager shareManager].messages.integerValue +[UnReadManager shareManager].notifications.integerValue)];
280-
if (unreadCount.integerValue > 0) {
281-
if (unreadCount.integerValue > 99) {
282-
badgeTip = @"99+";
283-
}else{
284-
badgeTip = unreadCount.stringValue;
285-
}
286-
}
287-
[self.rdv_tabBarItem setBadgeValue:badgeTip];
288-
}
289-
290-
291274
@end

Coding_iOS/Controllers/RootControllers/Project_RootViewController.m

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ - (instancetype)init
3737
{
3838
self = [super init];
3939
if (self) {
40-
[[UnReadManager shareManager] addObserver:self forKeyPath:kUnReadKey_project_update_count options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
40+
RAC(self, rdv_tabBarItem.badgeValue) = [RACSignal combineLatest:@[RACObserve([UnReadManager shareManager], project_update_count)]
41+
reduce:^id(NSNumber *project_update_count){
42+
return project_update_count.integerValue > 0? kBadgeTipStr : @"";
43+
}];
4144
}
4245
return self;
4346
}
@@ -88,7 +91,6 @@ - (void)viewDidLoad
8891
[self.view addSubview:_mySegmentControl];
8992

9093
_oldSelectedIndex = 0;
91-
[self refreshBadgeTip];
9294
}
9395

9496
- (void)viewWillAppear:(BOOL)animated{
@@ -111,10 +113,6 @@ - (void)didReceiveMemoryWarning
111113
// Dispose of any resources that can be recreated.
112114
}
113115

114-
- (void)dealloc{
115-
[[UnReadManager shareManager] removeObserver:self forKeyPath:kUnReadKey_project_update_count];
116-
}
117-
118116
#pragma mark iCarousel M
119117
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
120118
return 3;
@@ -170,25 +168,4 @@ - (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel
170168
}
171169
}
172170

173-
#pragma mark KVO_UnRead
174-
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
175-
if([keyPath isEqualToString:kUnReadKey_project_update_count]){
176-
[self refreshBadgeTip];
177-
}
178-
}
179-
180-
- (void)refreshBadgeTip{
181-
NSString *badgeTip = @"";
182-
NSNumber *project_update_count = [UnReadManager shareManager].project_update_count;
183-
if (project_update_count.integerValue > 0) {
184-
badgeTip = kBadgeTipStr;
185-
// if (project_update_count.integerValue > 99) {
186-
// badgeTip = @"99+";
187-
// }else{
188-
// badgeTip = project_update_count.stringValue;
189-
// }
190-
}
191-
[self.rdv_tabBarItem setBadgeValue:badgeTip];
192-
}
193-
194171
@end

Coding_iOS/Controllers/TipsViewController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
@interface TipsViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate>
1414
@property (strong, nonatomic) CodingTips *myCodingTips;
15-
@property (strong, nonatomic) NSMutableDictionary *notificationDict;
1615

1716
@end

Coding_iOS/Controllers/TipsViewController.m

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,13 @@ - (void)sendRequest{
115115
if (data) {
116116
[weakSelf.myCodingTips configWithObj:data];
117117
[weakSelf.myTableView reloadData];
118-
[weakSelf resetUnreadCount];
119118
weakSelf.myTableView.showsInfiniteScrolling = weakSelf.myCodingTips.canLoadMore;
120119
}
121120
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.myCodingTips.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
122121
[weakSelf refresh];
123122
}];
124123
}];
125124
}
126-
- (void)resetUnreadCount{
127-
switch (self.myCodingTips.type) {
128-
case 0:
129-
[_notificationDict setObject:[NSNumber numberWithInteger:0] forKey:kUnReadKey_notification_AT];
130-
break;
131-
case 1:
132-
[_notificationDict setObject:[NSNumber numberWithInteger:0] forKey:kUnReadKey_notification_Comment];
133-
break;
134-
default:
135-
[_notificationDict setObject:[NSNumber numberWithInteger:0] forKey:kUnReadKey_notification_System];
136-
break;
137-
}
138-
}
139125

140126
#pragma mark Table M
141127
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

Coding_iOS/Models/CodingTips.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,5 @@ - (NSDictionary *)toMarkReadParams{
7979
return @{@"id" : unReadArray};
8080
}
8181
return nil;
82-
83-
// NSDictionary *params;
84-
// if (_type == 0) {
85-
// params = @{@"type" : [NSNumber numberWithInteger:0],
86-
// @"all" : [NSNumber numberWithInteger:1]};
87-
// }else if (_type == 1){
88-
// params = @{@"type" : [NSArray arrayWithObjects:[NSNumber numberWithInteger:1], [NSNumber numberWithInteger:2], nil],
89-
// @"all" : [NSNumber numberWithInteger:1]};
90-
// }else if (_type == 2){
91-
// params = @{@"type" : [NSNumber numberWithInteger:4],
92-
// @"all" : [NSNumber numberWithInteger:1]};
93-
// }
94-
// return params;
9582
}
9683
@end

Coding_iOS/Util/Manager/UnReadManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
@interface UnReadManager : NSObject
1212
@property (strong, nonatomic) NSNumber *messages, *notifications, *project_update_count;
13-
@property (strong, nonatomic) NSNumber *notification_at, *notification_comment, *notification_system;
1413

1514
+ (instancetype)shareManager;
1615
- (void)updateUnRead;
17-
- (void)updateUnReadOfNotification;
1816
@end

Coding_iOS/Util/Manager/UnReadManager.m

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ + (instancetype)shareManager{
1919
return shared_manager;
2020
}
2121

22-
- (instancetype)init{
23-
self = [super init];
24-
if (self) {
25-
_messages = [NSNumber numberWithInteger:0];
26-
_notifications = [NSNumber numberWithInteger:0];
27-
_project_update_count = [NSNumber numberWithInteger:0];
28-
}
29-
return self;
30-
}
3122
- (void)updateUnRead{
3223
[[Coding_NetAPIManager sharedManager] request_UnReadCountWithBlock:^(id data, NSError *error) {
3324
if (data && [data isKindOfClass:[NSDictionary class]]) {
@@ -38,49 +29,10 @@ - (void)updateUnRead{
3829
//更新应用角标
3930
NSInteger unreadCount = self.messages.integerValue
4031
+self.notifications.integerValue;
41-
// +self.project_update_count.integerValue;
4232
[UIApplication sharedApplication].applicationIconBadgeNumber = unreadCount;
4333
}
4434
}];
4535
}
46-
- (void)updateUnReadOfNotification{
47-
[[Coding_NetAPIManager sharedManager] request_UnReadNotificationsWithBlock:^(id data, NSError *error) {
48-
if (data && [data isKindOfClass:[NSDictionary class]]) {
49-
NSDictionary *dataDict = (NSDictionary *)data;
50-
self.notification_at = [dataDict objectForKey:kUnReadKey_notification_AT];
51-
self.notification_comment = [dataDict objectForKey:kUnReadKey_notification_Comment];
52-
self.notification_system = [dataDict objectForKey:kUnReadKey_notification_System];
53-
}
54-
}];
55-
}
56-
- (void)setMessages:(NSNumber *)messages{
57-
if (_messages.integerValue != messages.integerValue) {
58-
_messages = messages;
59-
}
60-
}
61-
- (void)setNotifications:(NSNumber *)notifications{
62-
if (_notifications.integerValue != notifications.integerValue) {
63-
_notifications = notifications;
64-
}
65-
}
66-
- (void)setProject_update_count:(NSNumber *)project_update_count{
67-
if (_project_update_count.integerValue != project_update_count.integerValue) {
68-
_project_update_count = project_update_count;
69-
}
70-
}
71-
- (void)setNotification_at:(NSNumber *)notification_at{
72-
if (_notification_at.integerValue != notification_at.integerValue) {
73-
_notification_at = notification_at;
74-
}
75-
}
76-
- (void)setNotification_system:(NSNumber *)notification_system{
77-
if (_notification_system.integerValue != notification_system.integerValue) {
78-
_notification_system = notification_system;
79-
}
80-
}
81-
- (void)setNotification_comment:(NSNumber *)notification_comment{
82-
if (_notification_comment.integerValue != notification_comment.integerValue) {
83-
_notification_comment = notification_comment;
84-
}
85-
}
36+
37+
8638
@end

0 commit comments

Comments
 (0)