Merge branch 'master' into request_2
# Conflicts: # app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt
This commit is contained in:
commit
80fef36d7f
|
@ -9,6 +9,7 @@ import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
|
import android.media.AudioManager.STREAM_ALARM
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
|
@ -235,24 +236,36 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
|
||||||
grantReadUriPermission(soundUri)
|
grantReadUriPermission(soundUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
val channelId = "simple_timer_channel_$soundUri"
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
val channelId = config.timerChannelId ?: "simple_timer_channel_${soundUri}_${System.currentTimeMillis()}"
|
||||||
|
config.timerChannelId = channelId
|
||||||
|
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
|
try {
|
||||||
|
notificationManager.deleteNotificationChannel(channelId)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
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(STREAM_ALARM)
|
||||||
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
||||||
val name = getString(R.string.timer)
|
val name = getString(R.string.timer)
|
||||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||||
NotificationChannel(channelId, name, importance).apply {
|
NotificationChannel(channelId, name, importance).apply {
|
||||||
setBypassDnd(true)
|
setBypassDnd(true)
|
||||||
enableLights(true)
|
enableLights(true)
|
||||||
lightColor = getAdjustedPrimaryColor()
|
lightColor = getAdjustedPrimaryColor()
|
||||||
enableVibration(config.timerVibrate)
|
|
||||||
setSound(Uri.parse(soundUri), audioAttributes)
|
setSound(Uri.parse(soundUri), audioAttributes)
|
||||||
|
|
||||||
|
if (!config.timerVibrate) {
|
||||||
|
vibrationPattern = longArrayOf(0L)
|
||||||
|
}
|
||||||
|
|
||||||
|
enableVibration(true)
|
||||||
notificationManager.createNotificationChannel(this)
|
notificationManager.createNotificationChannel(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,8 +276,9 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
|
||||||
.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(Notification.PRIORITY_LOW)
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
.setDefaults(Notification.DEFAULT_LIGHTS)
|
.setDefaults(Notification.DEFAULT_LIGHTS)
|
||||||
|
.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)
|
||||||
|
@ -274,7 +288,7 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent:
|
||||||
builder.setDeleteIntent(reminderActivityIntent)
|
builder.setDeleteIntent(reminderActivityIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setVisibility(Notification.VISIBILITY_PUBLIC)
|
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
|
||||||
if (config.timerVibrate) {
|
if (config.timerVibrate) {
|
||||||
val vibrateArray = LongArray(2) { 500 }
|
val vibrateArray = LongArray(2) { 500 }
|
||||||
|
|
|
@ -91,6 +91,7 @@ class TimerFragment : Fragment() {
|
||||||
timer_vibrate_holder.setOnClickListener {
|
timer_vibrate_holder.setOnClickListener {
|
||||||
timer_vibrate.toggle()
|
timer_vibrate.toggle()
|
||||||
config.timerVibrate = timer_vibrate.isChecked
|
config.timerVibrate = timer_vibrate.isChecked
|
||||||
|
config.timerChannelId = null
|
||||||
}
|
}
|
||||||
|
|
||||||
timer_sound.setOnClickListener {
|
timer_sound.setOnClickListener {
|
||||||
|
|
|
@ -74,4 +74,9 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
gson.fromJson(lastAlarm, Alarm::class.java)
|
gson.fromJson(lastAlarm, Alarm::class.java)
|
||||||
}
|
}
|
||||||
set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply()
|
set(alarm) = prefs.edit().putString(ALARM_LAST_CONFIG, gson.toJson(alarm)).apply()
|
||||||
|
|
||||||
|
var timerChannelId: String?
|
||||||
|
get() = prefs.getString(TIMER_CHANNEL_ID, null)
|
||||||
|
set(id) = prefs.edit().putString(TIMER_CHANNEL_ID, id).apply()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ const val TIMER_STATE = "timer_state"
|
||||||
const val TIMER_VIBRATE = "timer_vibrate"
|
const val TIMER_VIBRATE = "timer_vibrate"
|
||||||
const val TIMER_SOUND_URI = "timer_sound_uri"
|
const val TIMER_SOUND_URI = "timer_sound_uri"
|
||||||
const val TIMER_SOUND_TITLE = "timer_sound_title"
|
const val TIMER_SOUND_TITLE = "timer_sound_title"
|
||||||
|
const val TIMER_CHANNEL_ID = "timer_channel_id"
|
||||||
const val TIMER_LABEL = "timer_label"
|
const val TIMER_LABEL = "timer_label"
|
||||||
const val TIMER_MAX_REMINDER_SECS = "timer_max_reminder_secs"
|
const val TIMER_MAX_REMINDER_SECS = "timer_max_reminder_secs"
|
||||||
const val ALARM_MAX_REMINDER_SECS = "alarm_max_reminder_secs"
|
const val ALARM_MAX_REMINDER_SECS = "alarm_max_reminder_secs"
|
||||||
|
|
Loading…
Reference in New Issue