decide if default snooze reminder should be used, or show a snooze picker
This commit is contained in:
parent
4482d34ab5
commit
b4c26da2ce
4 changed files with 36 additions and 11 deletions
|
@ -153,6 +153,8 @@
|
|||
android:name=".services.WidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS"/>
|
||||
|
||||
<service android:name=".services.SnoozeService"/>
|
||||
|
||||
<receiver android:name=".receivers.NotificationReceiver"/>
|
||||
|
||||
<receiver android:name=".receivers.CalDAVSyncReceiver"/>
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue