properly schedule the next alarm at cancelling one

This commit is contained in:
tibbi
2020-05-28 19:26:26 +02:00
parent 1d45ae9b48
commit afc1f7823e
2 changed files with 37 additions and 35 deletions

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.clock.activities package com.simplemobiletools.clock.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.NotificationManager
import android.content.Intent import android.content.Intent
import android.media.AudioManager import android.media.AudioManager
import android.media.MediaPlayer import android.media.MediaPlayer
@ -126,7 +125,7 @@ class ReminderActivity : SimpleActivity() {
} }
if (isOreoPlus()) { if (isOreoPlus()) {
getSystemService(NotificationManager::class.java).cancelAll() notificationManager.cancelAll()
} }
} else if (reminder_draggable.x <= minDragX + 50f) { } else if (reminder_draggable.x <= minDragX + 50f) {
if (!didVibrate) { if (!didVibrate) {
@ -136,7 +135,7 @@ class ReminderActivity : SimpleActivity() {
} }
if (isOreoPlus()) { if (isOreoPlus()) {
getSystemService(NotificationManager::class.java).cancelAll() notificationManager.cancelAll()
} }
} }
} }
@ -222,6 +221,10 @@ class ReminderActivity : SimpleActivity() {
} }
private fun finishActivity() { private fun finishActivity() {
if (alarm != null) {
scheduleNextAlarm(alarm!!, false)
}
destroyPlayer() destroyPlayer()
finish() finish()
overridePendingTransition(0, 0) overridePendingTransition(0, 0)

View File

@ -10,7 +10,6 @@ import android.media.AudioAttributes
import android.media.AudioManager import android.media.AudioManager
import android.media.AudioManager.STREAM_ALARM import android.media.AudioManager.STREAM_ALARM
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.PowerManager import android.os.PowerManager
import android.text.SpannableString import android.text.SpannableString
import android.text.style.RelativeSizeSpan import android.text.style.RelativeSizeSpan
@ -249,10 +248,10 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
} }
val audioAttributes = AudioAttributes.Builder() val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM) .setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(STREAM_ALARM) .setLegacyStreamType(STREAM_ALARM)
.build() .build()
val name = getString(R.string.timer) val name = getString(R.string.timer)
val importance = NotificationManager.IMPORTANCE_HIGH val importance = NotificationManager.IMPORTANCE_HIGH
@ -273,17 +272,17 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
val reminderActivityIntent = getReminderActivityIntent() val reminderActivityIntent = getReminderActivityIntent()
val builder = NotificationCompat.Builder(this) val builder = NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.timer)) .setContentTitle(getString(R.string.timer))
.setContentText(getString(R.string.time_expired)) .setContentText(getString(R.string.time_expired))
.setSmallIcon(R.drawable.ic_timer) .setSmallIcon(R.drawable.ic_timer)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
.setDefaults(Notification.DEFAULT_LIGHTS) .setDefaults(Notification.DEFAULT_LIGHTS)
.setCategory(Notification.CATEGORY_EVENT) .setCategory(Notification.CATEGORY_EVENT)
.setAutoCancel(true) .setAutoCancel(true)
.setSound(Uri.parse(soundUri), AudioManager.STREAM_ALARM) .setSound(Uri.parse(soundUri), AudioManager.STREAM_ALARM)
.setChannelId(channelId) .setChannelId(channelId)
.addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent()) .addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getHideTimerPendingIntent())
if (addDeleteIntent) { if (addDeleteIntent) {
builder.setDeleteIntent(reminderActivityIntent) builder.setDeleteIntent(reminderActivityIntent)
@ -325,11 +324,11 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
val label = if (alarm.label.isNotEmpty()) alarm.label else getString(R.string.alarm) val label = if (alarm.label.isNotEmpty()) alarm.label else getString(R.string.alarm)
if (isOreoPlus()) { if (isOreoPlus()) {
val audioAttributes = AudioAttributes.Builder() val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM) .setUsage(AudioAttributes.USAGE_ALARM)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(AudioManager.STREAM_ALARM) .setLegacyStreamType(AudioManager.STREAM_ALARM)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.build() .build()
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val importance = NotificationManager.IMPORTANCE_HIGH val importance = NotificationManager.IMPORTANCE_HIGH
@ -344,17 +343,17 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
} }
val builder = NotificationCompat.Builder(this) val builder = NotificationCompat.Builder(this)
.setContentTitle(label) .setContentTitle(label)
.setContentText(getFormattedTime(getPassedSeconds(), false, false)) .setContentText(getFormattedTime(getPassedSeconds(), false, false))
.setSmallIcon(R.drawable.ic_alarm_vector) .setSmallIcon(R.drawable.ic_alarm_vector)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_LIGHTS) .setDefaults(Notification.DEFAULT_LIGHTS)
.setAutoCancel(true) .setAutoCancel(true)
.setSound(Uri.parse(soundUri), AudioManager.STREAM_ALARM) .setSound(Uri.parse(soundUri), AudioManager.STREAM_ALARM)
.setChannelId(channelId) .setChannelId(channelId)
.addAction(R.drawable.ic_snooze_vector, getString(R.string.snooze), getSnoozePendingIntent(alarm)) .addAction(R.drawable.ic_snooze_vector, getString(R.string.snooze), getSnoozePendingIntent(alarm))
.addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), getHideAlarmPendingIntent(alarm)) .addAction(R.drawable.ic_cross_vector, getString(R.string.dismiss), getHideAlarmPendingIntent(alarm))
builder.setVisibility(Notification.VISIBILITY_PUBLIC) builder.setVisibility(Notification.VISIBILITY_PUBLIC)