Skip to content

Commit

Permalink
Sleep Timer now triggers MUTE state in YABN
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mr committed Jul 21, 2024
1 parent 01f0e43 commit 9f6e682
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/maary/liveinpeace/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Constants {
const val BROADCAST_ACTION_SLEEPTIMER_DECREMENT = "com.maary.liveinpeace.action.DECREMENT"
const val BROADCAST_ACTION_SLEEPTIMER_TOGGLE = "com.maary.liveinpeace.sleeptimer.TOGGLE"
const val BROADCAST_ACTION_SLEEPTIMER_UPDATE = "com.maary.liveinpeace.sleeptimer.UPDATE"
const val BROADCAST_ACTION_YABN_MUTE = "com.maary.yetanotherbatterynotifier.receiver.SettingsReceiver.dnd"
// 前台服务状态改变广播
const val BROADCAST_ACTION_FOREGROUND = "com.maary.liveinpeace.ACTION_FOREGROUND_SERVICE_STATE"
const val BROADCAST_FOREGROUND_INTENT_EXTRA = "isForegroundServiceRunning"
Expand All @@ -67,5 +68,8 @@ class Constants {
const val ID_NOTIFICATION_GROUP_SLEEPTIMER = "LIP_notification_group_sleeptimer"
const val PATTERN_DATE_DATABASE = "yyyy-MM-dd"
const val PATTERN_DATE_BUTTON = "MM/dd"

const val YABN_PACKAGE_NAME = "com.maary.yetanotherbatterynotifier"
const val YABN_MUTE_RECEIVER = "com.maary.yetanotherbatterynotifier.receiver.SettingsReceiver"
}
}
26 changes: 20 additions & 6 deletions app/src/main/java/com/maary/liveinpeace/SleepNotification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ package com.maary.liveinpeace
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_MUTE
import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_SLEEPTIMER_CANCEL
import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_SLEEPTIMER_DECREMENT
import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_SLEEPTIMER_INCREMENT
import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
import com.maary.liveinpeace.SleepNotification.Action.CANCEL
import com.maary.liveinpeace.SleepNotification.Action.INCREMENT
import com.maary.liveinpeace.SleepNotification.Action.DECREMENT
import com.maary.liveinpeace.Constants.Companion.BROADCAST_ACTION_YABN_MUTE
import com.maary.liveinpeace.Constants.Companion.CHANNEL_ID_SLEEPTIMER
import com.maary.liveinpeace.Constants.Companion.ID_NOTIFICATION_GROUP_SLEEPTIMER
import com.maary.liveinpeace.Constants.Companion.ID_NOTIFICATION_SLEEPTIMER
import com.maary.liveinpeace.Constants.Companion.YABN_MUTE_RECEIVER
import com.maary.liveinpeace.Constants.Companion.YABN_PACKAGE_NAME
import com.maary.liveinpeace.SleepNotification.Action.CANCEL
import com.maary.liveinpeace.SleepNotification.Action.DECREMENT
import com.maary.liveinpeace.SleepNotification.Action.INCREMENT
import com.maary.liveinpeace.receiver.MuteMediaReceiver
import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit


object SleepNotification {
Expand Down Expand Up @@ -76,6 +80,16 @@ object SleepNotification {
require(timeout > 0)
val eta = System.currentTimeMillis() + timeout

val muteYABNIntent = Intent()
muteYABNIntent.setComponent(
ComponentName(
YABN_PACKAGE_NAME,
YABN_MUTE_RECEIVER
)
)
muteYABNIntent.action = BROADCAST_ACTION_YABN_MUTE
sendBroadcast(muteYABNIntent)

val muteMediaIntent = Intent(this, MuteMediaReceiver::class.java)
muteMediaIntent.action = BROADCAST_ACTION_MUTE
val pendingMuteIntent = PendingIntent.getBroadcast(this, 0, muteMediaIntent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class ForegroundService: Service() {
override fun updateNotification(context: Context) {
with(NotificationManagerCompat.from(applicationContext)){
notify(ID_NOTIFICATION_FOREGROUND, createForegroundNotification(applicationContext))
} }

}
}
}

private fun saveDataWhenStop(){
Expand Down

0 comments on commit 9f6e682

Please sign in to comment.