Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 1a186f3

Browse files
committed
move broadcasting of notification refresh to TorService
1 parent d6a2390 commit 1a186f3

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

topl-service/src/main/java/io/matthewnelson/topl_service/notification/ServiceNotification.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,9 @@ class ServiceNotification internal constructor(
501501
notificationBuilder?.let {
502502
torService.startForeground(notificationID, it.build())
503503
inForeground = true
504+
return true
504505
}
505-
inForeground
506+
false
506507
} else {
507508
false
508509
}
@@ -579,11 +580,22 @@ class ServiceNotification internal constructor(
579580
)
580581
}
581582

583+
/**
584+
* Refreshes the notification Actions.
585+
*
586+
* @return `true` if actions were present to be refreshed, `false` if actions weren't
587+
* present, thus not needing a refresh
588+
* @see [TorServiceReceiver.deviceIsLocked]
589+
* */
582590
@Synchronized
583-
internal fun refreshActions(torService: BaseService) {
584-
if (!actionsPresent) return
585-
removeActions(torService)
586-
addActions(torService)
591+
internal fun refreshActions(torService: BaseService): Boolean {
592+
return if (actionsPresent) {
593+
removeActions(torService)
594+
addActions(torService)
595+
true
596+
} else {
597+
false
598+
}
587599
}
588600

589601
@Synchronized

topl-service/src/main/java/io/matthewnelson/topl_service/service/BaseService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ internal abstract class BaseService: Service() {
306306
}
307307
}
308308
}
309-
fun refreshNotificationActions() {
310-
serviceNotification.refreshActions(this)
309+
open fun refreshNotificationActions(): Boolean {
310+
return serviceNotification.refreshActions(this)
311311
}
312312
fun removeNotification() {
313313
serviceNotification.remove()

topl-service/src/main/java/io/matthewnelson/topl_service/service/TorService.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ internal class TorService: BaseService() {
161161

162162
// See BaseService
163163

164+
override fun refreshNotificationActions(): Boolean {
165+
val wasRefreshed = super.refreshNotificationActions()
166+
if (wasRefreshed) {
167+
val debugMsg = if (TorServiceReceiver.deviceIsLocked == true)
168+
"Removed Notification Actions"
169+
else
170+
"Added Notification Actions"
171+
broadcastLogger.debug(debugMsg)
172+
}
173+
return wasRefreshed
174+
}
164175
override fun startForegroundService(): Boolean {
165176
val wasStarted = super.startForegroundService()
166177
if (wasStarted)

topl-service/src/main/java/io/matthewnelson/topl_service/service/components/receiver/TorServiceReceiver.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ internal class TorServiceReceiver(private val torService: BaseService): Broadcas
165165
if (locked != deviceIsLocked) {
166166
setDeviceIsLocked(locked)
167167
broadcastLogger.debug("Device is locked: $deviceIsLocked")
168-
broadcastLogger.debug("Refreshing Notification Actions")
169168
torService.refreshNotificationActions()
170169
}
171170
}

0 commit comments

Comments
 (0)