Added post delay for vibration & deleting notification channels after their dismissal
This commit is contained in:
parent
9a23aa8e57
commit
028e9e7a80
3 changed files with 22 additions and 6 deletions
|
@ -176,10 +176,10 @@ class ReminderActivity : SimpleActivity() {
|
|||
val doVibrate = alarm?.vibrate ?: config.timerVibrate
|
||||
if (doVibrate && isOreoPlus()) {
|
||||
val pattern = LongArray(2) { 500 }
|
||||
vibrationHandler.post {
|
||||
vibrationHandler.postDelayed({
|
||||
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
vibrator?.vibrate(VibrationEffect.createWaveform(pattern, 0))
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
val soundUri = if (alarm != null) {
|
||||
|
|
|
@ -184,6 +184,15 @@ fun Context.hideNotification(id: Int) {
|
|||
manager.cancel(id)
|
||||
}
|
||||
|
||||
fun Context.deleteNotificationChannel(channelId: String) {
|
||||
if (isOreoPlus()) {
|
||||
try {
|
||||
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.deleteNotificationChannel(channelId)
|
||||
} catch (_: Throwable) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.hideTimerNotification(timerId: Int) = hideNotification(timerId)
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
|
@ -373,9 +382,11 @@ fun Context.getHideTimerPendingIntent(timerId: Int): PendingIntent {
|
|||
return PendingIntent.getBroadcast(this, timerId, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
fun Context.getHideAlarmPendingIntent(alarm: Alarm): PendingIntent {
|
||||
val intent = Intent(this, HideAlarmReceiver::class.java)
|
||||
intent.putExtra(ALARM_ID, alarm.id)
|
||||
fun Context.getHideAlarmPendingIntent(alarm: Alarm, channelId: String): PendingIntent {
|
||||
val intent = Intent(this, HideAlarmReceiver::class.java).apply {
|
||||
putExtra(ALARM_ID, alarm.id)
|
||||
putExtra(ALARM_NOTIFICATION_CHANNEL_ID, channelId)
|
||||
}
|
||||
return PendingIntent.getBroadcast(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
|
@ -397,6 +408,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
|
|||
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
|
||||
.build()
|
||||
|
||||
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||
NotificationChannel(channelId, label, importance).apply {
|
||||
|
@ -409,7 +421,7 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No
|
|||
}
|
||||
}
|
||||
|
||||
val dismissIntent = getHideAlarmPendingIntent(alarm)
|
||||
val dismissIntent = getHideAlarmPendingIntent(alarm, channelId)
|
||||
val builder = NotificationCompat.Builder(this)
|
||||
.setContentTitle(label)
|
||||
.setContentText(getFormattedTime(getPassedSeconds(), false, false))
|
||||
|
|
|
@ -4,14 +4,18 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.dbHelper
|
||||
import com.simplemobiletools.clock.extensions.deleteNotificationChannel
|
||||
import com.simplemobiletools.clock.extensions.hideNotification
|
||||
import com.simplemobiletools.clock.extensions.updateWidgets
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
import com.simplemobiletools.clock.helpers.ALARM_NOTIFICATION_CHANNEL_ID
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class HideAlarmReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val id = intent.getIntExtra(ALARM_ID, -1)
|
||||
val channelId = intent.getStringExtra(ALARM_NOTIFICATION_CHANNEL_ID)
|
||||
channelId?.let { context.deleteNotificationChannel(channelId) }
|
||||
context.hideNotification(id)
|
||||
|
||||
ensureBackgroundThread {
|
||||
|
|
Loading…
Reference in a new issue