Skip to content

Commit

Permalink
Merge pull request #22 from Steve-Mr/dev
Browse files Browse the repository at this point in the history
[feat] Now toggle sleep timer toggle slient mode in YABN
  • Loading branch information
Steve-Mr authored Jul 21, 2024
2 parents 883b68f + 9f6e682 commit 49a87b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49a87b3

Please sign in to comment.