-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationViewController.m
288 lines (209 loc) · 9.36 KB
/
NotificationViewController.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
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
//
// NotificationViewController.m
// Parodize
//
// Created by Apple on 29/06/17.
// Copyright © 2017 Parodize. All rights reserved.
//
#import "NotificationViewController.h"
@interface NotificationViewController (){
NSMutableArray *soundsArray;
NSMutableArray *soundsTitleArray;
NSMutableArray *notificationTypeArray;
NotificationObject *nObj;
UITableViewCell *prevCell;
NSIndexPath *selectedIndex;
UIBarButtonItem *doneButton;
NSIndexSet *indexSet;
}
@end
@implementation NotificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
soundsTitleArray = [[NSMutableArray alloc]initWithObjects:@"Calypso",@"Ladder",nil];
soundsArray = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:1322],[NSNumber numberWithInt:1326], nil];
notificationTypeArray = [[NSMutableArray alloc]initWithObjects:@"Challenge",@"Like",@"Poke",@"Response",nil];
doneButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneSettingsAction:)];
self.navigationItem.rightBarButtonItem=doneButton;
self.title=@"Notifications";
nObj = [[NotificationObject alloc]init];
nObj.challenge=_notifications.challenge;
nObj.poke=_notifications.poke;
nObj.like=_notifications.like;
nObj.response=_notifications.response;
indexSet = [NSIndexSet indexSetWithIndex:1];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section==0) {
return @"When to show";
}else{
return @"Sounds";
}
return nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) {
return notificationTypeArray.count;
}else{
return soundsTitleArray.count;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
// NSString* cellIdentifier=@"notifyCell";
//
// UITableViewCell *cell=(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//
// if (cell==nil)
// {
// //NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PendingCell" owner:self options:nil];
// cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
//
//
// }
// UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
// cell.accessoryView = switchView;
// switchView.on=YES;
// [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
// return cell;
// }else if(indexPath.section==1){
NSString* cellIdentifier=@"listCell";
UITableViewCell *cell=(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
//NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PendingCell" owner:self options:nil];
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchView;
switchView.on=NO;
[switchView addTarget:self action:@selector(listSwitchChanged:) forControlEvents:UIControlEventValueChanged];
switchView.tag=indexPath.row;
if (indexPath.row==0) {
if (_notifications.challenge==0) {
switchView.on = NO;
}else{
switchView.on = YES;
}
}else if (indexPath.row==1) {
if (_notifications.like==0) {
switchView.on = NO;
}else{
switchView.on = YES;
}
}else if (indexPath.row==2) {
if (_notifications.poke==0) {
switchView.on = NO;
}else{
switchView.on = YES;
}
}else if (indexPath.row==3) {
if (_notifications.response==0) {
switchView.on = NO;
}else{
switchView.on = YES;
}
}
cell.textLabel.text=notificationTypeArray[indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if(indexPath.section==1){
NSString* cellIdentifier=@"soundCell";
UITableViewCell *cell=(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
//NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PendingCell" owner:self options:nil];
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = soundsTitleArray[indexPath.row];
if (indexPath == selectedIndex) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==1) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
selectedIndex = nil;
}else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
selectedIndex = indexPath;
[tableView beginUpdates];
[tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
}
}
}
- (void)switchChanged:(id)sender {
UISwitch *switchControl = sender;
NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" );
}
- (void)listSwitchChanged:(id)sender {
// NotificationObject *nObj = [[NotificationObject alloc]init];
UISwitch *switchControl = sender;
NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" );
int value = switchControl.on ? 1 : 0 ;
if (switchControl.tag==0) {
_notifications.challenge=value;
}else if (switchControl.tag==1){
_notifications.like=value;
}else if (switchControl.tag==2){
_notifications.poke=value;
}else if (switchControl.tag==3){
_notifications.response=value;
}
[self updateSettings];
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
}
-(void)updateSettings{
NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseAPI,SETTINGS];
NSDictionary *notifDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:_notifications.challenge],@"challenge",[NSNumber numberWithInt:_notifications.like],@"like",[NSNumber numberWithInt:_notifications.poke],@"poke",[NSNumber numberWithInt:_notifications.response],@"response",nil];
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:_settingObj.notifSound,@"notifSound",[NSNumber numberWithInt:_settingObj.privateProfile],@"privateProfile",[NSNumber numberWithInt:_settingObj.profileVisibility],@"profileVisibility",notifDict,@"notifications",nil];
NSDictionary *userInfo = @{
@"postdata": dict
};
[[Context contextSharedManager] pgfetchDataForURL:urlStr userInfo:userInfo postTypeMethod:ePOST headerAutherization:YES withCompletionHandler:^(NSDictionary *data, NSError *error) {
if ([data objectForKey:RESPONSE_ERROR]) {
[[Context contextSharedManager] showAlertView:self withMessage:[data objectForKey:RESPONSE_ERROR] withAlertTitle:SERVER_ERROR];
}
else{
// NSDictionary *successDict=[data objectForKey:@"success"];
}
}];
}
-(void)deactiveAccount{
NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseAPI,DEACTIVATE_ACCOUNT];
[[Context contextSharedManager] pgfetchDataForURL:urlStr userInfo:nil postTypeMethod:eGET headerAutherization:YES withCompletionHandler:^(NSDictionary *data, NSError *error) {
if ([data objectForKey:RESPONSE_ERROR]) {
[[Context contextSharedManager] showAlertView:self withMessage:[data objectForKey:RESPONSE_ERROR] withAlertTitle:SERVER_ERROR];
}
else{
// NSDictionary *successDict=[data objectForKey:@"success"];
}
}];
}
-(void)doneSettingsAction:(id)sender{
}
@end