mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 02:39:34 +02:00
Add showing blocking reason at blocked notifications
This commit is contained in:
parent
03977e7f68
commit
9163fd4353
3 changed files with 31 additions and 12 deletions
|
@ -56,7 +56,9 @@ class NotificationListener: NotificationListenerService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
runAsync {
|
runAsync {
|
||||||
if (shouldRemoveNotification(sbn) == NotificationHandling.Replace) {
|
val reason = shouldRemoveNotification(sbn)
|
||||||
|
|
||||||
|
if (reason != BlockingReason.None) {
|
||||||
val success = try {
|
val success = try {
|
||||||
cancelNotification(sbn.key)
|
cancelNotification(sbn.key)
|
||||||
|
|
||||||
|
@ -80,7 +82,18 @@ class NotificationListener: NotificationListenerService() {
|
||||||
else
|
else
|
||||||
getString(R.string.notification_filter_blocking_failed_title)
|
getString(R.string.notification_filter_blocking_failed_title)
|
||||||
)
|
)
|
||||||
.setContentText(queryAppTitleCache.query(sbn.packageName))
|
.setContentText(
|
||||||
|
queryAppTitleCache.query(sbn.packageName) +
|
||||||
|
" - " +
|
||||||
|
when (reason) {
|
||||||
|
BlockingReason.NotPartOfAnCategory -> getString(R.string.lock_reason_short_no_category)
|
||||||
|
BlockingReason.TemporarilyBlocked -> getString(R.string.lock_reason_short_temporarily_blocked)
|
||||||
|
BlockingReason.TimeOver -> getString(R.string.lock_reason_short_time_over)
|
||||||
|
BlockingReason.TimeOverExtraTimeCanBeUsedLater -> getString(R.string.lock_reason_short_time_over)
|
||||||
|
BlockingReason.BlockedAtThisTime -> getString(R.string.lock_reason_short_blocked_time_area)
|
||||||
|
BlockingReason.None -> throw IllegalStateException()
|
||||||
|
}
|
||||||
|
)
|
||||||
.setLocalOnly(true)
|
.setLocalOnly(true)
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.build()
|
.build()
|
||||||
|
@ -95,26 +108,26 @@ class NotificationListener: NotificationListenerService() {
|
||||||
// not interesting but required for old android versions
|
// not interesting but required for old android versions
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun shouldRemoveNotification(sbn: StatusBarNotification): NotificationHandling {
|
private suspend fun shouldRemoveNotification(sbn: StatusBarNotification): BlockingReason {
|
||||||
if (sbn.packageName == packageName || sbn.isOngoing) {
|
if (sbn.packageName == packageName || sbn.isOngoing) {
|
||||||
return NotificationHandling.Keep
|
return BlockingReason.None
|
||||||
}
|
}
|
||||||
|
|
||||||
val blockingReason = blockingReasonUtil.getBlockingReason(sbn.packageName).waitForNonNullValue()
|
val blockingReason = blockingReasonUtil.getBlockingReason(sbn.packageName).waitForNonNullValue()
|
||||||
|
|
||||||
if (blockingReason == BlockingReason.None) {
|
if (blockingReason == BlockingReason.None) {
|
||||||
return NotificationHandling.Keep
|
return BlockingReason.None
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSystemApp(sbn.packageName) && blockingReason == BlockingReason.NotPartOfAnCategory) {
|
if (isSystemApp(sbn.packageName) && blockingReason == BlockingReason.NotPartOfAnCategory) {
|
||||||
return NotificationHandling.Keep
|
return BlockingReason.None
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.d(LOG_TAG, "blocking notification of ${sbn.packageName} because $blockingReason")
|
Log.d(LOG_TAG, "blocking notification of ${sbn.packageName} because $blockingReason")
|
||||||
}
|
}
|
||||||
|
|
||||||
return NotificationHandling.Replace
|
return blockingReason
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSystemApp(packageName: String): Boolean {
|
private fun isSystemApp(packageName: String): Boolean {
|
||||||
|
@ -126,8 +139,4 @@ class NotificationListener: NotificationListenerService() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class NotificationHandling {
|
|
||||||
Replace, Keep
|
|
||||||
}
|
|
|
@ -55,4 +55,9 @@
|
||||||
Diese App ist in einer Kategorie, deren maximale Nutzungszeit erreicht wurde.
|
Diese App ist in einer Kategorie, deren maximale Nutzungszeit erreicht wurde.
|
||||||
Es gab noch Extra-Zeit, aber die maximale Nutzung der Extra-Zeit wurde erreicht.
|
Es gab noch Extra-Zeit, aber die maximale Nutzung der Extra-Zeit wurde erreicht.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="lock_reason_short_no_category">keine Kategorie</string>
|
||||||
|
<string name="lock_reason_short_temporarily_blocked">vorübergehend gesperrt</string>
|
||||||
|
<string name="lock_reason_short_time_over">Zeit verbraucht</string>
|
||||||
|
<string name="lock_reason_short_blocked_time_area">Sperrzeit</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -59,4 +59,9 @@
|
||||||
This App is part of a category whose time limit was reached.
|
This App is part of a category whose time limit was reached.
|
||||||
There is still extra time, but the usage limit for the extra time was reached, too.
|
There is still extra time, but the usage limit for the extra time was reached, too.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="lock_reason_short_no_category">no category</string>
|
||||||
|
<string name="lock_reason_short_temporarily_blocked">temporarily blocked</string>
|
||||||
|
<string name="lock_reason_short_time_over">time over</string>
|
||||||
|
<string name="lock_reason_short_blocked_time_area">blocked time area</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue