diff --git a/app/src/main/java/com/maary/liveinpeace/Constants.kt b/app/src/main/java/com/maary/liveinpeace/Constants.kt index 67c7a22..0a4b6b8 100644 --- a/app/src/main/java/com/maary/liveinpeace/Constants.kt +++ b/app/src/main/java/com/maary/liveinpeace/Constants.kt @@ -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" @@ -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" } } \ No newline at end of file diff --git a/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt b/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt index 53e2384..047cb18 100644 --- a/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt +++ b/app/src/main/java/com/maary/liveinpeace/SleepNotification.kt @@ -3,6 +3,7 @@ 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 @@ -10,16 +11,19 @@ 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 { @@ -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) diff --git a/app/src/main/java/com/maary/liveinpeace/service/ForegroundService.kt b/app/src/main/java/com/maary/liveinpeace/service/ForegroundService.kt index 464fcf2..d3bf2c2 100644 --- a/app/src/main/java/com/maary/liveinpeace/service/ForegroundService.kt +++ b/app/src/main/java/com/maary/liveinpeace/service/ForegroundService.kt @@ -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(){ diff --git a/build.gradle b/build.gradle index 147c328..8e89450 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.4.0' apply false - id 'com.android.library' version '8.4.0' apply false + id 'com.android.application' version '8.5.1' apply false + id 'com.android.library' version '8.5.1' apply false id 'org.jetbrains.kotlin.android' version '2.0.0' apply false id 'com.google.devtools.ksp' version "2.0.0-1.0.21" apply false } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 647c950..2724bc9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri May 12 10:24:55 CST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists