Better log alarms
This commit is contained in:
parent
0273ba7bf0
commit
024a902316
5 changed files with 18 additions and 18 deletions
|
@ -249,7 +249,7 @@ class MainApp : DaggerApplication() {
|
|||
override fun onTerminate() {
|
||||
aapsLogger.debug(LTag.CORE, "onTerminate")
|
||||
unregisterActivityLifecycleCallbacks(activityMonitor)
|
||||
alarmSoundServiceHelper.stopService(this)
|
||||
alarmSoundServiceHelper.stopService(this, "onTerminate")
|
||||
super.onTerminate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ import info.nightscout.androidaps.databinding.OverviewNotificationItemBinding
|
|||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.IconsProvider
|
||||
import info.nightscout.androidaps.interfaces.NotificationHolder
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewNotification
|
||||
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -68,7 +68,7 @@ class NotificationStore @Inject constructor(
|
|||
store.add(n)
|
||||
if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction)
|
||||
raiseSystemNotification(n)
|
||||
if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId!!)
|
||||
if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId!!, n.text)
|
||||
Collections.sort(store, NotificationComparator())
|
||||
return true
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class NotificationStore @Inject constructor(
|
|||
fun remove(id: Int): Boolean {
|
||||
for (i in store.indices) {
|
||||
if (store[i].id == id) {
|
||||
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context)
|
||||
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context, "Removed " + store[i].text)
|
||||
aapsLogger.debug(LTag.NOTIFICATION, "Notification removed: " + store[i].text)
|
||||
store.removeAt(i)
|
||||
return true
|
||||
|
@ -92,7 +92,7 @@ class NotificationStore @Inject constructor(
|
|||
while (i < store.size) {
|
||||
val n = store[i]
|
||||
if (n.validTo != 0L && n.validTo < System.currentTimeMillis()) {
|
||||
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context)
|
||||
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context, "Expired " + store[i].text)
|
||||
aapsLogger.debug(LTag.NOTIFICATION, "Notification expired: " + store[i].text)
|
||||
store.removeAt(i)
|
||||
i--
|
||||
|
|
|
@ -74,11 +74,11 @@ class ErrorDialog : DaggerDialogFragment() {
|
|||
}
|
||||
binding.mute.setOnClickListener {
|
||||
uel.log(Action.ERROR_DIALOG_MUTE, Sources.Unknown)
|
||||
stopAlarm()
|
||||
stopAlarm("Mute")
|
||||
}
|
||||
binding.mute5min.setOnClickListener {
|
||||
uel.log(Action.ERROR_DIALOG_MUTE_5MIN, Sources.Unknown)
|
||||
stopAlarm()
|
||||
stopAlarm("Mute 5 min")
|
||||
handler.postDelayed(this::startAlarm, T.mins(5).msecs())
|
||||
}
|
||||
startAlarm()
|
||||
|
@ -110,14 +110,14 @@ class ErrorDialog : DaggerDialogFragment() {
|
|||
super.dismissAllowingStateLoss()
|
||||
helperActivity?.finish()
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
stopAlarm()
|
||||
stopAlarm("Dismiss")
|
||||
}
|
||||
|
||||
private fun startAlarm() {
|
||||
if (sound != 0)
|
||||
alarmSoundServiceHelper.startAlarm(ctx, sound)
|
||||
alarmSoundServiceHelper.startAlarm(ctx, sound, "$title:$status")
|
||||
}
|
||||
|
||||
private fun stopAlarm() =
|
||||
alarmSoundServiceHelper.stopService(ctx)
|
||||
private fun stopAlarm(reason: String) =
|
||||
alarmSoundServiceHelper.stopService(ctx, reason)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ open class Notification {
|
|||
|
||||
var id = 0
|
||||
var date: Long = 0
|
||||
var text: String? = null
|
||||
var text: String = ""
|
||||
var level = 0
|
||||
var validTo: Long = 0
|
||||
@RawRes var soundId: Int? = null
|
||||
|
|
|
@ -28,8 +28,8 @@ class AlarmSoundServiceHelper @Inject constructor(
|
|||
private val notificationHolder: NotificationHolder
|
||||
) {
|
||||
|
||||
fun startAlarm(context: Context, sound: Int) {
|
||||
aapsLogger.debug(LTag.CORE, "Starting alarm")
|
||||
fun startAlarm(context: Context, sound: Int, reason: String) {
|
||||
aapsLogger.debug(LTag.CORE, "Starting alarm from $reason")
|
||||
val connection = object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||
// The binder of the service that returns the instance that is created.
|
||||
|
@ -62,8 +62,8 @@ class AlarmSoundServiceHelper @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun stopService(context: Context) {
|
||||
aapsLogger.debug(LTag.CORE, "Stopping alarm")
|
||||
fun stopService(context: Context, reason: String) {
|
||||
aapsLogger.debug(LTag.CORE, "Stopping alarm from $reason")
|
||||
val alarm = Intent(context, AlarmSoundService::class.java)
|
||||
context.stopService(alarm)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue