-
Notifications
You must be signed in to change notification settings - Fork 0
/
BulletinBoardManager.m
150 lines (117 loc) · 3.83 KB
/
BulletinBoardManager.m
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
//
// BulletinBoardManager.m
// Entitlements
//
// Created by Ray Zhang on 13-2-26.
// Copyright (c) 2013年 Ray Zhang. All rights reserved.
//
#import "BulletinBoardManager.h"
#import <BulletinBoard/BBServer.h>
#import <BulletinBoard/BBSectionInfo.h>
#import <BulletinBoard/BBSettingsGateway.h>
#define SECTION_INFO_IDENTIFIER_KEY @"_sectionInfoByID"
static BulletinBoardManager *manager = nil;
@implementation BulletinBoardManager
+ (id)sharedManager {
@synchronized(self) {
if (manager == nil) {
manager = [[self alloc] init];
}
}
return manager;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (manager == nil) {
manager = [super allocWithZone:zone];
return manager;
}
}
return nil;
}
- (id)init {
self = [super init];
if (self) {
}
return self;
}
- (void)dealloc {
[super dealloc];
}
- (id)retain {
return self;
}
- (oneway void)release {
return;
}
- (id)autorelease {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax;
}
#pragma mark - protocol NSCopying
- (id)copyWithZone:(NSZone *)zone {
return self;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)isWeeAppPluginOnWithSectionIdetifier:(NSString *)identifier {
BOOL retVal = NO;
BBServer *server = [[BBServer alloc] init];
[server _loadSavedSectionInfo];
NSMutableDictionary *sectionInfoByID = [server valueForKey:SECTION_INFO_IDENTIFIER_KEY];
BBSectionInfo *sectionInfo = [sectionInfoByID objectForKey:identifier];
if (sectionInfo) {
retVal = sectionInfo.showsInNotificationCenter;
}
[server release];
return retVal;
}
- (void)setWeeAppPluginOn:(BOOL)on withSectionIdetifier:(NSString *)identifier {
BBServer *server = [[BBServer alloc] init];
[server _loadSavedSectionInfo];
NSDictionary *sectionInfoByID = [server valueForKey:SECTION_INFO_IDENTIFIER_KEY];
BBSectionInfo *bsSectionInfo = [sectionInfoByID objectForKey:identifier];
if (bsSectionInfo == nil) {
[server _loadAllWeeAppSections];
bsSectionInfo = [server _sectionInfoForSectionID:identifier effective:YES];
}
if (bsSectionInfo) {
bsSectionInfo.showsInNotificationCenter = on;
BBSettingsGateway *gateway = [[BBSettingsGateway alloc] init];
[gateway setSectionInfo:bsSectionInfo forSectionID:bsSectionInfo.sectionID];
[gateway release];
}
[server release];
}
- (void)sortWeeAppToTopWithIdentifier:(NSString *)identifier {
BBServer *server = [[BBServer alloc] init];
NSMutableArray *savedSectionOrder = nil;
[server _readSavedSectionOrder:&savedSectionOrder andRule:0];
if ([savedSectionOrder containsObject:identifier]) {
[savedSectionOrder removeObject:identifier];
}
[savedSectionOrder insertObject:identifier atIndex:0];
if (savedSectionOrder) {
BBSettingsGateway *gateway = [[BBSettingsGateway alloc] init];
[gateway setOrderedSectionIDs:savedSectionOrder];
[gateway release];
}
[server release];
}
- (void)sortWeeAppToBottomWithIdentifier:(NSString *)identifier {
BBServer *server = [[BBServer alloc] init];
NSMutableArray *savedSectionOrder = nil;
[server _readSavedSectionOrder:&savedSectionOrder andRule:0];
if ([savedSectionOrder containsObject:identifier]) {
[savedSectionOrder removeObject:identifier];
}
[savedSectionOrder addObject:identifier];
if (savedSectionOrder) {
BBSettingsGateway *gateway = [[BBSettingsGateway alloc] init];
[gateway setOrderedSectionIDs:savedSectionOrder];
[gateway release];
}
[server release];
}
@end