diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bf49ce368..20fca1ed9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -153,6 +153,8 @@
android:name=".services.WidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS"/>
+
+
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SnoozeReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SnoozeReminderActivity.kt
index fce53b522..27f4b9bbc 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SnoozeReminderActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SnoozeReminderActivity.kt
@@ -1,12 +1,10 @@
package com.simplemobiletools.calendar.activities
-import android.app.NotificationManager
-import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
-import com.simplemobiletools.calendar.extensions.scheduleEventIn
+import com.simplemobiletools.calendar.extensions.rescheduleReminder
import com.simplemobiletools.calendar.extensions.showEventReminderDialog
import com.simplemobiletools.calendar.helpers.EVENT_ID
@@ -18,12 +16,7 @@ class SnoozeReminderActivity : AppCompatActivity() {
val eventId = intent.getIntExtra(EVENT_ID, 0)
val event = dbHelper.getEventWithId(eventId)
config.snoozeDelay = it
-
- if (eventId != 0 && event != null) {
- applicationContext.scheduleEventIn(System.currentTimeMillis() + it * 60000, event)
- val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
- manager.cancel(eventId)
- }
+ rescheduleReminder(event, it)
finishActivity()
}
}
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 7e941a940..87d05551e 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt
@@ -29,6 +29,7 @@ import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.*
import com.simplemobiletools.calendar.receivers.CalDAVSyncReceiver
import com.simplemobiletools.calendar.receivers.NotificationReceiver
+import com.simplemobiletools.calendar.services.SnoozeService
import com.simplemobiletools.commons.extensions.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
@@ -238,9 +239,22 @@ private fun getPendingIntent(context: Context, event: Event): PendingIntent {
}
private fun getSnoozePendingIntent(context: Context, event: Event): PendingIntent {
- val intent = Intent(context, SnoozeReminderActivity::class.java).setAction("snooze")
+ val snoozeClass = if (context.config.useSameSnooze) SnoozeService::class.java else SnoozeReminderActivity::class.java
+ val intent = Intent(context, snoozeClass).setAction("Snoozeee")
intent.putExtra(EVENT_ID, event.id)
- return PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+ return if (context.config.useSameSnooze) {
+ PendingIntent.getService(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+ } else {
+ PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+ }
+}
+
+fun Context.rescheduleReminder(event: Event?, minutes: Int) {
+ if (event != null) {
+ applicationContext.scheduleEventIn(System.currentTimeMillis() + minutes * 60000, event)
+ val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ manager.cancel(event.id)
+ }
}
fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode(this)) {
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..32ebf1e6e
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt
@@ -0,0 +1,16 @@
+package com.simplemobiletools.calendar.services
+
+import android.app.IntentService
+import android.content.Intent
+import com.simplemobiletools.calendar.extensions.config
+import com.simplemobiletools.calendar.extensions.dbHelper
+import com.simplemobiletools.calendar.extensions.rescheduleReminder
+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)
+ rescheduleReminder(event, config.snoozeDelay)
+ }
+}