diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index be36da1c6..0ca68c027 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -122,6 +122,8 @@
android:name=".services.WidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS"/>
+
+
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt
index 1336d29a6..617caca1e 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt
@@ -50,7 +50,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
mDialogTheme = getAppropriateTheme()
val eventId = intent.getIntExtra(EVENT_ID, 0)
- val event = dbHelper.getEvent(eventId)
+ val event = dbHelper.getEventWithId(eventId)
if (eventId != 0 && event == null) {
finish()
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt
index e890c7d6a..793c1ceba 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt
@@ -12,11 +12,13 @@ import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Build
+import android.support.v7.app.NotificationCompat
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.receivers.NotificationReceiver
+import com.simplemobiletools.calendar.services.SnoozeService
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.commons.extensions.isKitkatPlus
import com.simplemobiletools.commons.extensions.isLollipopPlus
@@ -154,16 +156,16 @@ fun Context.notifyEvent(event: Event) {
val pendingIntent = getPendingIntent(this, event)
val startTime = Formatter.getTimeFromTS(this, event.startTS)
val endTime = Formatter.getTimeFromTS(this, event.endTS)
- val notification = getNotification(this, pendingIntent, event.title, "${getFormattedEventTime(startTime, endTime)} ${event.description}")
+ val notification = getNotification(this, pendingIntent, event, "${getFormattedEventTime(startTime, endTime)} ${event.description}")
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id, notification)
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
-private fun getNotification(context: Context, pendingIntent: PendingIntent, title: String, content: String): Notification {
+private fun getNotification(context: Context, pendingIntent: PendingIntent, event: Event, content: String): Notification {
val soundUri = Uri.parse(context.config.reminderSound)
- val builder = Notification.Builder(context)
- .setContentTitle(title)
+ val builder = NotificationCompat.Builder(context)
+ .setContentTitle(event.title)
.setContentText(content)
.setSmallIcon(R.drawable.ic_calendar)
.setContentIntent(pendingIntent)
@@ -171,6 +173,7 @@ private fun getNotification(context: Context, pendingIntent: PendingIntent, titl
.setDefaults(Notification.DEFAULT_LIGHTS)
.setAutoCancel(true)
.setSound(soundUri)
+ .addAction(R.drawable.ic_snooze, context.getString(R.string.snooze), getSnoozePendingIntent(context, event))
if (context.isLollipopPlus())
builder.setVisibility(Notification.VISIBILITY_PUBLIC)
@@ -189,6 +192,12 @@ private fun getPendingIntent(context: Context, event: Event): PendingIntent {
return PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
+private fun getSnoozePendingIntent(context: Context, event: Event): PendingIntent {
+ val intent = Intent(context, SnoozeService::class.java).setAction("snooze")
+ intent.putExtra(EVENT_ID, event.id)
+ return PendingIntent.getService(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+}
+
fun Context.launchNewEventIntent(startNewTask: Boolean = false, today: Boolean = false) {
val code = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()).plusDays(if (today) 0 else 1))
Intent(applicationContext, EventActivity::class.java).apply {
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt
index dde13aa9a..b24c67d9c 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt
@@ -346,7 +346,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return ids.filter { it.trim().isNotEmpty() } as ArrayList
}
- fun getEvent(id: Int): Event? {
+ fun getEventWithId(id: Int): Event? {
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
val selectionArgs = arrayOf(id.toString())
val cursor = getEventsCursor(selection, selectionArgs)
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt
index 308d05b68..80a009ccb 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt
@@ -17,7 +17,7 @@ class NotificationReceiver : BroadcastReceiver() {
if (id == -1)
return
- val event = context.dbHelper.getEvent(id)
+ val event = context.dbHelper.getEventWithId(id)
if (event == null || event.getReminders().isEmpty())
return
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt
new file mode 100644
index 000000000..11113d5a0
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt
@@ -0,0 +1,22 @@
+package com.simplemobiletools.calendar.services
+
+import android.app.IntentService
+import android.app.NotificationManager
+import android.content.Context
+import android.content.Intent
+import com.simplemobiletools.calendar.extensions.dbHelper
+import com.simplemobiletools.calendar.extensions.scheduleEventIn
+import com.simplemobiletools.calendar.helpers.EVENT_ID
+
+class SnoozeService : IntentService("Snooze") {
+ override fun onHandleIntent(intent: Intent) {
+ val eventId = intent.getIntExtra(EVENT_ID, 0)
+ val event = dbHelper.getEventWithId(eventId)
+
+ if (eventId != 0 && event != null) {
+ applicationContext.scheduleEventIn(System.currentTimeMillis() + 600000, event)
+ val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ manager.cancel(eventId)
+ }
+ }
+}
diff --git a/app/src/main/res/drawable-hdpi/ic_snooze.png b/app/src/main/res/drawable-hdpi/ic_snooze.png
new file mode 100644
index 000000000..43e170721
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_snooze.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_snooze.png b/app/src/main/res/drawable-mdpi/ic_snooze.png
new file mode 100644
index 000000000..887718366
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_snooze.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_snooze.png b/app/src/main/res/drawable-xhdpi/ic_snooze.png
new file mode 100644
index 000000000..e27af11a0
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_snooze.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_snooze.png b/app/src/main/res/drawable-xxhdpi/ic_snooze.png
new file mode 100644
index 000000000..1761d04aa
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_snooze.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_snooze.png b/app/src/main/res/drawable-xxxhdpi/ic_snooze.png
new file mode 100644
index 000000000..c3cdb9288
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_snooze.png differ