|
@@ -41,12 +41,29 @@ LVKBNewHomeTableViewHeaderDelegate
|
41
|
41
|
|
42
|
42
|
}
|
43
|
43
|
|
|
44
|
+
|
|
45
|
+-(void)viewWillAppear:(BOOL)animated{
|
|
46
|
+ [super viewWillAppear:animated];
|
|
47
|
+ NSArray *arr=[[YDFMDB sharedInstance]selectDataByConditionString:nil withSelectStringArray:@[@"notiStr",@"day",@"hour",@"min",@"isOpen"] withTableName:@"notiTable" limit:-1 descID:YES];
|
|
48
|
+ [self.dataArray removeAllObjects];
|
|
49
|
+ for (NSDictionary *dic in arr) {
|
|
50
|
+ LVKBNewHomeModel *model=[[LVKBNewHomeModel alloc]init];
|
|
51
|
+ model.title=dic[@"notiStr"];
|
|
52
|
+ model.day=[dic[@"day"] integerValue];
|
|
53
|
+ model.hour=[dic[@"hour"] integerValue];
|
|
54
|
+ model.min=[dic[@"min"] integerValue];
|
|
55
|
+ model.isOpen=[dic[@"isOpen"] integerValue];
|
|
56
|
+ [self.dataArray addObject:model];
|
|
57
|
+ }
|
|
58
|
+ [self.tableView reloadData];
|
|
59
|
+}
|
|
60
|
+
|
44
|
61
|
-(void)initUI{
|
45
|
62
|
[self.view addSubview:self.topImageView];
|
46
|
63
|
[self.view addSubview:self.tableView];
|
47
|
64
|
[self.view addSubview:self.centerView];
|
48
|
65
|
[self.view addSubview:self.signInBtn];
|
49
|
|
- [[UIApplication sharedApplication].keyWindow addSubview:self.siginInView];
|
|
66
|
+ [self.view addSubview:self.siginInView];
|
50
|
67
|
[self.view addSubview:self.alarmView];
|
51
|
68
|
}
|
52
|
69
|
|
|
@@ -94,6 +111,7 @@ LVKBNewHomeTableViewHeaderDelegate
|
94
|
111
|
LVKBNewHomeModel *model=self.dataArray[indexPath.row];
|
95
|
112
|
model.index=indexPath.row;
|
96
|
113
|
[cell setModel:model];
|
|
114
|
+ cell.delegate=self;
|
97
|
115
|
cell.layer.cornerRadius=5;
|
98
|
116
|
cell.layer.masksToBounds=YES;
|
99
|
117
|
return cell;
|
|
@@ -104,9 +122,20 @@ LVKBNewHomeTableViewHeaderDelegate
|
104
|
122
|
}
|
105
|
123
|
|
106
|
124
|
-(void)switchActionByIndex:(NSInteger)index status:(BOOL)status{
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
107
|
128
|
LVKBNewHomeModel *model=self.dataArray[index];
|
|
129
|
+
|
108
|
130
|
model.isOpen=status;
|
109
|
131
|
|
|
132
|
+ if (status) {
|
|
133
|
+ [self creatNotTitle:model.title day:model.day hour:model.hour min:model.min];
|
|
134
|
+ }else{
|
|
135
|
+ [self deleteNotTitle:model.title day:model.day hour:model.hour min:model.min];
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ [[YDFMDB sharedInstance] changeDataByEqualConditionStringDictionary:@{@"notiStr":model.title,@"day":@(model.day),@"hour":@(model.hour),@"min":@(model.min)} withNewStringDictionary:@{@"isOpen":@(model.isOpen)} withTableName:@"notiTable"];
|
110
|
139
|
}
|
111
|
140
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
112
|
141
|
return YES;
|
|
@@ -124,6 +153,9 @@ LVKBNewHomeTableViewHeaderDelegate
|
124
|
153
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
125
|
154
|
//在这里实现删除操作
|
126
|
155
|
//删除数据,和删除动画
|
|
156
|
+ LVKBNewHomeModel *model=self.dataArray[indexPath.row];
|
|
157
|
+ [self deleteNotTitle:model.title day:model.day hour:model.hour min:model.min];
|
|
158
|
+ [[YDFMDB sharedInstance] deleteDataByEqualConditionStringDictionary:@{@"notiStr":model.title,@"day":@(model.day),@"hour":@(model.hour),@"min":@(model.min),@"isOpen":@(model.isOpen)} withTableName:@"notiTable"];
|
127
|
159
|
[self.dataArray removeObjectAtIndex:indexPath.row];
|
128
|
160
|
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
|
129
|
161
|
}
|
|
@@ -135,15 +167,14 @@ LVKBNewHomeTableViewHeaderDelegate
|
135
|
167
|
|
136
|
168
|
-(void)didSelectItemByIndex:(NSInteger)index{
|
137
|
169
|
NSLog(@"didSelectItemByIndex--%@",@(index));
|
|
170
|
+
|
138
|
171
|
switch (index) {
|
139
|
172
|
case 0:
|
140
|
|
- {
|
141
|
|
-
|
142
|
|
- }
|
143
|
|
- break;
|
144
|
173
|
case 1:
|
145
|
174
|
{
|
146
|
|
-
|
|
175
|
+ if (self.delegate &&[self.delegate respondsToSelector:@selector(resetTabByIndex:)]) {
|
|
176
|
+ [self.delegate resetTabByIndex:index];
|
|
177
|
+ }
|
147
|
178
|
}
|
148
|
179
|
break;
|
149
|
180
|
case 2:
|
|
@@ -158,8 +189,6 @@ LVKBNewHomeTableViewHeaderDelegate
|
158
|
189
|
}
|
159
|
190
|
}
|
160
|
191
|
-(void)didSelectBtn{
|
161
|
|
- NSLog(@"didSelectBtn");
|
162
|
|
-
|
163
|
192
|
[UIView animateWithDuration:0.5f animations:^{
|
164
|
193
|
self.alarmView.y=0;
|
165
|
194
|
}];
|
|
@@ -204,7 +233,17 @@ LVKBNewHomeTableViewHeaderDelegate
|
204
|
233
|
UILabel *label=[[UILabel alloc]init];
|
205
|
234
|
label.font=[UIFont systemFontOfSize:20];
|
206
|
235
|
label.textColor=[UIColor CHColorWithHex:0x333333];
|
207
|
|
- label.text=@"距离主卡还款日还有 10 天";
|
|
236
|
+ NSString *day=[[NSUserDefaults standardUserDefaults] objectForKey:@"zhuka_huankuan"];
|
|
237
|
+ NSInteger currentDay=[NSDate getCurrentDay];
|
|
238
|
+ if (day) {
|
|
239
|
+ if ([day integerValue]>=currentDay) {
|
|
240
|
+ label.text=[NSString stringWithFormat:@"距离主卡还款日还有 %li 天",[day integerValue]-currentDay];
|
|
241
|
+ }else{
|
|
242
|
+ label.text=[NSString stringWithFormat:@"距离主卡还款日还有 %li 天",30-currentDay+[day integerValue]];
|
|
243
|
+ }
|
|
244
|
+ }else{
|
|
245
|
+ label.text=@"距离主卡还款日还有 -- 天";
|
|
246
|
+ }
|
208
|
247
|
label.tag=1001;
|
209
|
248
|
[_centerView addSubview:label];
|
210
|
249
|
}
|
|
@@ -231,6 +270,21 @@ LVKBNewHomeTableViewHeaderDelegate
|
231
|
270
|
_signInBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
232
|
271
|
[_signInBtn setImage:[UIImage imageNamed:@"gs_signIn"] forState:UIControlStateNormal];
|
233
|
272
|
[[_signInBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
|
|
273
|
+ NSInteger day=[NSDate getCurrentDay];
|
|
274
|
+ NSNumber *num=[[NSUserDefaults standardUserDefaults]objectForKey:@"gs_day"];
|
|
275
|
+ NSNumber *numCount=[[NSUserDefaults standardUserDefaults]objectForKey:@"gs_daycount"];
|
|
276
|
+ if (day==[num integerValue]) {
|
|
277
|
+
|
|
278
|
+ }else if ((day-[num integerValue]%30)==1) {
|
|
279
|
+ //签到一天
|
|
280
|
+ numCount=@([numCount integerValue]+1);
|
|
281
|
+ }else{
|
|
282
|
+ numCount=@(1);
|
|
283
|
+ }
|
|
284
|
+ self.siginInView.dayCountLabel.text=[numCount stringValue];
|
|
285
|
+ [[NSUserDefaults standardUserDefaults]setObject:@(day) forKey:@"gs_day"];
|
|
286
|
+ [[NSUserDefaults standardUserDefaults]setObject:numCount forKey:@"gs_daycount"];
|
|
287
|
+
|
234
|
288
|
[UIView animateWithDuration:0.5f animations:^{
|
235
|
289
|
self.siginInView.y=0;
|
236
|
290
|
}];
|
|
@@ -266,6 +320,17 @@ LVKBNewHomeTableViewHeaderDelegate
|
266
|
320
|
model.hour=hour;
|
267
|
321
|
model.min=min;
|
268
|
322
|
model.isOpen=1;
|
|
323
|
+ [[YDFMDB sharedInstance]addSingleDataStringDictionary:
|
|
324
|
+ @{@"notiStr":dic[@"notiStr"],
|
|
325
|
+ @"day":@(day),
|
|
326
|
+ @"hour":@(hour),
|
|
327
|
+ @"min":@(min),
|
|
328
|
+ @"isOpen":@(1)
|
|
329
|
+ } withTableName:@"notiTable"];
|
|
330
|
+ if (weakSelf.dataArray.count==0) {
|
|
331
|
+ [[NSUserDefaults standardUserDefaults]setObject:@(day) forKey:@"zhuka_huankuan"];
|
|
332
|
+ }
|
|
333
|
+ [weakSelf creatNotTitle:dic[@"notiStr"] day:day hour:hour min:min];
|
269
|
334
|
[weakSelf.dataArray addObject:model];
|
270
|
335
|
[weakSelf.tableView reloadData];
|
271
|
336
|
};
|
|
@@ -274,4 +339,70 @@ LVKBNewHomeTableViewHeaderDelegate
|
274
|
339
|
return _alarmView;
|
275
|
340
|
}
|
276
|
341
|
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+-(void)creatNotTitle:(NSString *)title day:(NSInteger )day hour:(NSInteger )hour min:(NSInteger) min{
|
|
346
|
+ UILocalNotification *localNotification = [[UILocalNotification alloc] init];
|
|
347
|
+ if (localNotification == nil) {
|
|
348
|
+ return;
|
|
349
|
+ }
|
|
350
|
+ //设置本地通知的触发时间(如果要立即触发,无需设置),这里设置为20妙后
|
|
351
|
+ NSString *date=[NSDate getCurrentYearMonth];
|
|
352
|
+ date=[NSString stringWithFormat:@"%@-%2li %2li-%2li",date,day,hour,min];
|
|
353
|
+
|
|
354
|
+ NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init];
|
|
355
|
+ [formatter1 setDateFormat:@"yyyy-MM-dd HH-mm"];
|
|
356
|
+ NSDate *resDate = [formatter1 dateFromString:date];
|
|
357
|
+
|
|
358
|
+ localNotification.fireDate = resDate;
|
|
359
|
+ //设置本地通知的时区
|
|
360
|
+ localNotification.timeZone = [NSTimeZone defaultTimeZone];
|
|
361
|
+ //设置通知的内容
|
|
362
|
+ localNotification.alertBody = title;
|
|
363
|
+ //设置通知动作按钮的标题
|
|
364
|
+ localNotification.alertAction = @"查看";
|
|
365
|
+ //设置提醒的声音,可以自己添加声音文件,这里设置为默认提示声
|
|
366
|
+ localNotification.soundName = UILocalNotificationDefaultSoundName;
|
|
367
|
+ //设置通知的相关信息,这个很重要,可以添加一些标记性内容,方便以后区分和获取通知的信息
|
|
368
|
+ NSDictionary *dict =@{@"sign":[NSString stringWithFormat:@"%@%li%li%li",title,day,hour,min]};
|
|
369
|
+ [localNotification setUserInfo:dict];
|
|
370
|
+
|
|
371
|
+ // ios8后,需要添加这个注册,才能得到授权
|
|
372
|
+ if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
|
|
373
|
+ UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
|
|
374
|
+ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type
|
|
375
|
+ categories:nil];
|
|
376
|
+ [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
|
|
377
|
+ // 通知重复提示的单位,可以是天、周、月
|
|
378
|
+ localNotification.repeatInterval = NSCalendarUnitMonth;
|
|
379
|
+ }
|
|
380
|
+
|
|
381
|
+ //在规定的日期触发通知
|
|
382
|
+ [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
|
|
383
|
+}
|
|
384
|
+
|
|
385
|
+-(void)deleteNotTitle:(NSString *)title day:(NSInteger )day hour:(NSInteger )hour min:(NSInteger) min{
|
|
386
|
+ NSDictionary *dict =@{@"sign":[NSString stringWithFormat:@"%@%li%li%li",title,day,hour,min]};
|
|
387
|
+ NSArray *narry=[[UIApplication sharedApplication] scheduledLocalNotifications];
|
|
388
|
+ NSUInteger acount=[narry count];
|
|
389
|
+ if (acount>0)
|
|
390
|
+ {
|
|
391
|
+ // 遍历找到对应nfkey和notificationtag的通知
|
|
392
|
+ for (int i=0; i<acount; i++)
|
|
393
|
+ {
|
|
394
|
+ UILocalNotification *myUILocalNotification = [narry objectAtIndex:i];
|
|
395
|
+ NSDictionary *userInfo = myUILocalNotification.userInfo;
|
|
396
|
+ NSString *obj = [userInfo objectForKey:@"sign"];
|
|
397
|
+ if (obj==dict[@"sign"])
|
|
398
|
+ {
|
|
399
|
+ // 删除本地通知
|
|
400
|
+ [[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification];
|
|
401
|
+ break;
|
|
402
|
+ }
|
|
403
|
+ }
|
|
404
|
+ }
|
|
405
|
+
|
|
406
|
+}
|
|
407
|
+
|
277
|
408
|
@end
|