Skip to content

Commit 287834c

Browse files
committed
Added RRULE support
1 parent 35f07c5 commit 287834c

File tree

17 files changed

+146
-66
lines changed

17 files changed

+146
-66
lines changed

.idea/caches/build_file_checksums.ser

587 Bytes
Binary file not shown.

.idea/caches/gradle_models.ser

155 KB
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 5 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ dependencies {
2222
implementation fileTree(dir: 'libs', include: ['*.jar'])
2323
implementation 'com.android.support:appcompat-v7:26.1.0'
2424
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25-
compile 'com.wdullaer:materialdatetimepicker:3.6.0'
25+
implementation 'com.wdullaer:materialdatetimepicker:3.6.0'
2626
testImplementation 'junit:junit:4.12'
2727
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2828
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29-
compile project(path: ':notifyme')
29+
implementation project(path: ':notifyme')
3030
}

app/src/main/java/com/allyants/notificationlibrary/MainActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.os.Bundle;
55
import android.support.v7.app.AppCompatActivity;
6+
import android.util.Log;
67
import android.view.View;
78
import android.widget.Button;
89
import android.widget.EditText;
@@ -30,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
3031

3132
Button btnCancel = findViewById(R.id.btnCancel);
3233

34+
3335
dpd = DatePickerDialog.newInstance(
3436
MainActivity.this,
3537
now.get(Calendar.YEAR),
@@ -84,6 +86,7 @@ public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int seco
8486
.addAction(new Intent(),"Dismiss",true,false)
8587
.addAction(intent,"Done")
8688
.large_icon(R.mipmap.ic_launcher_round)
89+
.rrule("FREQ=MINUTELY;INTERVAL=5;COUNT=2")
8790
.build();
8891
}
8992
}

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.0.1'
10+
classpath 'com.android.tools.build:gradle:3.2.1'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong
@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
google()
2121
jcenter()
22+
maven { url 'https://jitpack.io' }
2223
}
2324
}
2425

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jun 15 09:46:44 CDT 2018
1+
#Sat Dec 29 20:45:25 CST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

notifyme/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929

3030
implementation 'com.android.support:appcompat-v7:26.1.0'
3131
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
32+
implementation 'com.github.dmfs.lib-recur:lib-recur:0.11.1'
3233
testImplementation 'junit:junit:4.12'
3334
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3435
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

notifyme/src/main/java/com/allyants/notifyme/ActionReceiver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
import android.database.sqlite.SQLiteDatabase;
88
import android.util.Log;
99

10+
import java.util.Calendar;
11+
1012
import static com.allyants.notifyme.Notification.NotificationEntry.TABLE_NAME;
1113

1214
public class ActionReceiver extends BroadcastReceiver {
1315

1416
@Override
1517
public void onReceive(Context context, Intent intent) {
1618
String notificationId = intent.getStringExtra("_id");
17-
Log.e("id",notificationId);
19+
String rrule = intent.getStringExtra("rrule");
20+
long dstart = intent.getLongExtra("dstart",Calendar.getInstance().getTimeInMillis());
1821
int index = intent.getIntExtra("index",-1);
1922
String action = intent.getStringExtra("action");
2023
try {
@@ -30,10 +33,7 @@ public void onReceive(Context context, Intent intent) {
3033
}
3134

3235
if(intent.getBooleanExtra("dismiss",true)){
33-
com.allyants.notifyme.Notification.NotificationDBHelper mDbHelper = new com.allyants.notifyme.Notification.NotificationDBHelper(context);
34-
SQLiteDatabase db = mDbHelper.getWritableDatabase();
35-
db.delete(TABLE_NAME, com.allyants.notifyme.Notification.NotificationEntry._ID+" = "+notificationId,null);
36-
db.close();
36+
DeletePendingIntent.DeleteNotification(context,notificationId,rrule,dstart);
3737
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
3838
mNotificationManager.cancel(Integer.parseInt(notificationId));
3939
}
Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
package com.allyants.notifyme;
22

3+
import android.app.NotificationManager;
34
import android.content.BroadcastReceiver;
5+
import android.content.ContentValues;
46
import android.content.Context;
57
import android.content.Intent;
68
import android.database.sqlite.SQLiteDatabase;
9+
import android.util.Log;
710

11+
import org.dmfs.rfc5545.DateTime;
12+
import org.dmfs.rfc5545.recur.RecurrenceRule;
13+
import org.dmfs.rfc5545.recur.RecurrenceRuleIterator;
14+
15+
import java.util.Calendar;
16+
17+
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_TIME;
818
import static com.allyants.notifyme.Notification.NotificationEntry.TABLE_NAME;
919

1020
public class DeletePendingIntent extends BroadcastReceiver {
1121

1222
@Override
1323
public void onReceive(Context context, Intent intent) {
1424
String notificationId = intent.getStringExtra("_id");
15-
com.allyants.notifyme.Notification.NotificationDBHelper mDbHelper = new com.allyants.notifyme.Notification.NotificationDBHelper(context);
16-
SQLiteDatabase db = mDbHelper.getWritableDatabase();
17-
db.delete(TABLE_NAME, com.allyants.notifyme.Notification.NotificationEntry._ID+" = "+notificationId,null);
18-
db.close();
25+
String rrule = intent.getStringExtra("rrule");
26+
long dstart = intent.getLongExtra("dstart",Calendar.getInstance().getTimeInMillis());
27+
DeleteNotification(context,notificationId,rrule,dstart);
28+
}
29+
30+
public static void DeleteNotification(Context context,String notificationId,String rrule,long dstart){
31+
try {
32+
RecurrenceRule r = new RecurrenceRule(rrule);
33+
RecurrenceRuleIterator it = r.iterator(new DateTime(dstart));
34+
it.fastForward(DateTime.now());
35+
long next_time = it.nextMillis();
36+
Log.e("time",String.valueOf(next_time));
37+
com.allyants.notifyme.Notification.NotificationDBHelper mDbHelper = new com.allyants.notifyme.Notification.NotificationDBHelper(context);
38+
SQLiteDatabase db = mDbHelper.getWritableDatabase();
39+
ContentValues args = new ContentValues();
40+
args.put(NOTIFICATION_TIME,next_time);
41+
db.update(TABLE_NAME,args,com.allyants.notifyme.Notification.NotificationEntry._ID+" = "+notificationId,null);
42+
db.close();
43+
NotifyMe.scheduleNotification(context,notificationId,next_time);
44+
}catch (Exception e)
45+
{
46+
Log.e("error",e.getMessage());
47+
com.allyants.notifyme.Notification.NotificationDBHelper mDbHelper = new com.allyants.notifyme.Notification.NotificationDBHelper(context);
48+
SQLiteDatabase db = mDbHelper.getWritableDatabase();
49+
db.delete(TABLE_NAME, com.allyants.notifyme.Notification.NotificationEntry._ID+" = "+notificationId,null);
50+
db.close();
51+
}
52+
1953
}
2054
}

notifyme/src/main/java/com/allyants/notifyme/Notification.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public static class NotificationEntry implements BaseColumns{
1717
public static final String TABLE_NAME = "notification";
1818
public static final String NOTIFICATION_TITLE_TEXT = "title";
1919
public static final String NOTIFICATION_TIME = "time";
20+
public static final String NOTIFICATION_DSTART = "dstart";
21+
public static final String NOTIFICATION_RRULE = "rrule";
2022
public static final String NOTIFICATION_ACTIONS = "actions";
2123
public static final String NOTIFICATION_CUSTOM_ID = "custom_id";
2224
public static final String NOTIFICATION_ACTIONS_TEXT = "actions_text";
@@ -34,10 +36,12 @@ public static class NotificationEntry implements BaseColumns{
3436
NotificationEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
3537
NotificationEntry.NOTIFICATION_TITLE_TEXT + " TEXT," +
3638
NotificationEntry.NOTIFICATION_TIME + " LONG," +
39+
NotificationEntry.NOTIFICATION_DSTART + " LONG," +
3740
NotificationEntry.NOTIFICATION_ACTIONS + " TEXT," +
3841
NotificationEntry.NOTIFICATION_ACTIONS_TEXT + " TEXT," +
3942
NotificationEntry.NOTIFICATION_COLOR + " INTEGER," +
4043
NotificationEntry.NOTIFICATION_ACTIONS_DISMISS + " TEXT," +
44+
NotificationEntry.NOTIFICATION_RRULE + " TEXT," +
4145
NotificationEntry.NOTIFICATION_LED_COLOR + " INTEGER," +
4246
NotificationEntry.NOTIFICATION_CUSTOM_ID + " TEXT," +
4347
NotificationEntry.NOTIFICATION_SMALL_ICON + " TEXT," +
@@ -51,7 +55,7 @@ public static class NotificationEntry implements BaseColumns{
5155

5256
public static class NotificationDBHelper extends SQLiteOpenHelper {
5357
// If you change the database schema, you must increment the database version.
54-
public static final int DATABASE_VERSION = 1;
58+
public static final int DATABASE_VERSION = 2;
5559
public static final String DATABASE_NAME = "Notification.db";
5660

5761
public NotificationDBHelper(Context context) {

notifyme/src/main/java/com/allyants/notifyme/NotificationPublisher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_ACTIONS_TEXT;
2424
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_COLOR;
2525
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_CONTENT_TEXT;
26+
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_DSTART;
2627
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_LARGE_ICON;
2728
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_LED_COLOR;
29+
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_RRULE;
2830
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_SMALL_ICON;
2931
import static com.allyants.notifyme.Notification.NotificationEntry.NOTIFICATION_TITLE_TEXT;
3032
import static com.allyants.notifyme.Notification.NotificationEntry.TABLE_NAME;
@@ -47,6 +49,8 @@ public void onReceive(final Context context, Intent intent) {
4749
data.moveToFirst();
4850
String title = data.getString(data.getColumnIndex(NOTIFICATION_TITLE_TEXT));
4951
String content = data.getString(data.getColumnIndex(NOTIFICATION_CONTENT_TEXT));
52+
String rrule = data.getString(data.getColumnIndex(NOTIFICATION_RRULE));
53+
long dstart = data.getLong(data.getColumnIndex(NOTIFICATION_DSTART));
5054
String str_actions = data.getString(data.getColumnIndex(NOTIFICATION_ACTIONS));
5155
String str_actions_text = data.getString(data.getColumnIndex(NOTIFICATION_ACTIONS_TEXT));
5256
String str_actions_dismiss = data.getString(data.getColumnIndex(NOTIFICATION_ACTIONS_DISMISS));
@@ -81,6 +85,8 @@ public void onReceive(final Context context, Intent intent) {
8185
Intent tent = new Intent(context,ActionReceiver.class);
8286
tent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8387
tent.putExtra("_id",notificationId);
88+
tent.putExtra("rrule",rrule);
89+
tent.putExtra("dstart",dstart);
8490
tent.putExtra("index",i);
8591
tent.putExtra("action",actions[i]);
8692
tent.putExtra("collapse",Boolean.parseBoolean(actions_collapse[i]));
@@ -95,6 +101,8 @@ public void onReceive(final Context context, Intent intent) {
95101
mBuilder.setSound(uri);
96102
Intent deleteIntent = new Intent(context,DeletePendingIntent.class);
97103
deleteIntent.putExtra("_id",notificationId);
104+
deleteIntent.putExtra("rrule",rrule);
105+
deleteIntent.putExtra("dstart",dstart);
98106
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,Integer.parseInt(notificationId),deleteIntent,PendingIntent.FLAG_UPDATE_CURRENT);
99107
mBuilder.setDeleteIntent(pendingIntent);
100108
Notification notification = mBuilder.build();

0 commit comments

Comments
 (0)