handle dynamic snooze picker
This commit is contained in:
parent
241f527412
commit
244a137e5b
|
@ -2,9 +2,32 @@ package com.simplemobiletools.clock.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.dbHelper
|
||||
import com.simplemobiletools.clock.extensions.hideNotification
|
||||
import com.simplemobiletools.clock.extensions.setupAlarmClock
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
import com.simplemobiletools.commons.extensions.showPickIntervalDialog
|
||||
|
||||
class SnoozeReminderActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val id = intent.getIntExtra(ALARM_ID, -1)
|
||||
val alarm = dbHelper.getAlarmWithId(id) ?: return
|
||||
hideNotification(id)
|
||||
showPickIntervalDialog(config.snoozeTime, true, cancelCallback = { dialogCancelled() }) {
|
||||
config.snoozeTime = it
|
||||
setupAlarmClock(alarm, it * 60)
|
||||
finishActivity()
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogCancelled() {
|
||||
finishActivity()
|
||||
}
|
||||
|
||||
private fun finishActivity() {
|
||||
finish()
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.clock.extensions
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlarmManager
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -133,3 +134,8 @@ fun Context.cancelAlarmClock(alarm: Alarm) {
|
|||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
alarmManager.cancel(getPendingIntent(alarm))
|
||||
}
|
||||
|
||||
fun Context.hideNotification(id: Int) {
|
||||
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.cancel(id)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ class AlarmReceiver : BroadcastReceiver() {
|
|||
val notification = getNotification(context, pendingIntent, alarm)
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(alarm.id, notification)
|
||||
|
||||
context.scheduleNextAlarm(alarm, false)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package com.simplemobiletools.clock.services
|
||||
|
||||
import android.app.IntentService
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.dbHelper
|
||||
import com.simplemobiletools.clock.extensions.hideNotification
|
||||
import com.simplemobiletools.clock.extensions.setupAlarmClock
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
|
||||
|
@ -13,9 +12,7 @@ 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)
|
||||
|
||||
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.cancel(alarm.id)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue