From f8276455223ebb0680e3d4b87043f24a6ad1a296 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 14 Mar 2018 20:15:01 +0100 Subject: [PATCH] handle Snooze at Reminder activity --- .../clock/activities/ReminderActivity.kt | 15 +++++++++++++++ .../clock/activities/SnoozeReminderActivity.kt | 2 +- .../simplemobiletools/clock/extensions/Context.kt | 1 + .../clock/services/SnoozeService.kt | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt index b658f03f..7c5d85ea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt @@ -8,6 +8,7 @@ import com.simplemobiletools.clock.extensions.* import com.simplemobiletools.clock.helpers.ALARM_ID import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.MINUTE_SECONDS import kotlinx.android.synthetic.main.activity_reminder.* class ReminderActivity : SimpleActivity() { @@ -70,6 +71,20 @@ class ReminderActivity : SimpleActivity() { } private fun snoozeClicked() { + if (config.useSameSnooze) { + setupAlarmClock(alarm!!, config.snoozeTime * MINUTE_SECONDS) + finishActivity() + } else { + showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true, cancelCallback = { finishActivity() }) { + config.snoozeTime = it / MINUTE_SECONDS + setupAlarmClock(alarm!!, it) + finishActivity() + } + } + } + private fun finishActivity() { + finish() + overridePendingTransition(0, 0) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/SnoozeReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/SnoozeReminderActivity.kt index 6d5379ae..98b2f694 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/SnoozeReminderActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/SnoozeReminderActivity.kt @@ -19,7 +19,7 @@ class SnoozeReminderActivity : AppCompatActivity() { val alarm = dbHelper.getAlarmWithId(id) ?: return hideNotification(id) showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true, cancelCallback = { dialogCancelled() }) { - config.snoozeTime = it * 60 + config.snoozeTime = it / MINUTE_SECONDS setupAlarmClock(alarm, it) finishActivity() } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt index 6bca43a6..df5fbd54 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -305,6 +305,7 @@ fun Context.getHideTimerPendingIntent(): PendingIntent { fun Context.getHideAlarmPendingIntent(alarm: Alarm): PendingIntent { val intent = Intent(this, HideAlarmReceiver::class.java) + intent.putExtra(ALARM_ID, alarm.id) return PendingIntent.getBroadcast(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT) } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/services/SnoozeService.kt b/app/src/main/kotlin/com/simplemobiletools/clock/services/SnoozeService.kt index 54ac0ca9..4b5c51a6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/services/SnoozeService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/services/SnoozeService.kt @@ -9,13 +9,14 @@ import com.simplemobiletools.clock.extensions.hideNotification import com.simplemobiletools.clock.extensions.setupAlarmClock import com.simplemobiletools.clock.helpers.ALARM_ID import com.simplemobiletools.clock.helpers.HIDE_REMINDER_ACTIVITY +import com.simplemobiletools.commons.helpers.MINUTE_SECONDS class SnoozeService : IntentService("Snooze") { override fun onHandleIntent(intent: Intent) { val id = intent.getIntExtra(ALARM_ID, -1) val alarm = dbHelper.getAlarmWithId(id) ?: return hideNotification(id) - setupAlarmClock(alarm, config.snoozeTime * 60) + setupAlarmClock(alarm, config.snoozeTime * MINUTE_SECONDS) if (intent.getBooleanExtra(HIDE_REMINDER_ACTIVITY, false)) { Intent(this, ReminderActivity::class.java).apply {