Skip to content

Commit 10f3322

Browse files
committed
refactor: rename foreground state class
1 parent 3bcc9ff commit 10f3322

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

app/src/main/java/to/bitkit/androidServices/LightningNodeService.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import to.bitkit.models.NewTransactionSheetDetails
3535
import to.bitkit.models.NotificationDetails
3636
import to.bitkit.repositories.LightningRepo
3737
import to.bitkit.repositories.WalletRepo
38-
import to.bitkit.services.NodeServiceState
38+
import to.bitkit.services.NodeServiceFgState
3939
import to.bitkit.ui.ID_NOTIFICATION_NODE
4040
import to.bitkit.ui.MainActivity
4141
import to.bitkit.ui.pushNotification
@@ -76,7 +76,7 @@ class LightningNodeService : Service() {
7676
lateinit var appWidgetRefreshScheduler: AppWidgetRefreshScheduler
7777

7878
@Inject
79-
lateinit var nodeServiceState: NodeServiceState
79+
lateinit var nodeServiceFgState: NodeServiceFgState
8080

8181
private var hasStartedNode = false
8282

@@ -195,7 +195,7 @@ class LightningNodeService : Service() {
195195
}
196196

197197
ACTION_START_SERVICE -> if (promoteToForeground(startId)) {
198-
nodeServiceState.setForegroundServiceRunning(true)
198+
nodeServiceFgState.setForegroundServiceRunning(true)
199199
setupService()
200200
}
201201
else -> stop(startId) { Logger.warn("Stopped service for unsupported action '$action'", context = TAG) }
@@ -237,7 +237,7 @@ class LightningNodeService : Service() {
237237

238238
override fun onDestroy() {
239239
Logger.debug("onDestroy", context = TAG)
240-
nodeServiceState.setForegroundServiceRunning(false)
240+
nodeServiceFgState.setForegroundServiceRunning(false)
241241
// Safe to call even if already stopped — guarded by lifecycleMutex + isStoppedOrStopping()
242242
serviceScope.launch { lightningRepo.stop() }
243243
super.onDestroy()

app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import to.bitkit.models.msatCeilOf
3737
import to.bitkit.repositories.ActivityRepo
3838
import to.bitkit.repositories.BlocktankRepo
3939
import to.bitkit.repositories.LightningRepo
40-
import to.bitkit.services.NodeServiceState
40+
import to.bitkit.services.NodeServiceFgState
4141
import to.bitkit.ui.pushNotification
4242
import to.bitkit.utils.Logger
4343
import to.bitkit.utils.measured
@@ -54,7 +54,7 @@ class WakeNodeWorker @AssistedInject constructor(
5454
private val activityRepo: ActivityRepo,
5555
private val cacheStore: CacheStore,
5656
private val receivedNotificationContent: ReceivedNotificationContent,
57-
private val nodeServiceState: NodeServiceState,
57+
private val nodeServiceFgState: NodeServiceFgState,
5858
) : CoroutineWorker(appContext, workerParams) {
5959
private var bestAttemptContent: NotificationDetails? = null
6060

@@ -269,7 +269,7 @@ class WakeNodeWorker @AssistedInject constructor(
269269
}
270270

271271
private fun isHandledInProcess(): Boolean =
272-
App.currentActivity?.value != null || nodeServiceState.isForegroundServiceRunning
272+
App.currentActivity?.value != null || nodeServiceFgState.isForegroundServiceRunning
273273

274274
private suspend fun deliver() {
275275
// Send notification first

app/src/main/java/to/bitkit/services/NodeServiceState.kt renamed to app/src/main/java/to/bitkit/services/NodeServiceFgState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import javax.inject.Singleton
1010
* instead of posting its own (duplicate) notification.
1111
*/
1212
@Singleton
13-
class NodeServiceState @Inject constructor() {
13+
class NodeServiceFgState @Inject constructor() {
1414
@Volatile
1515
var isForegroundServiceRunning = false
1616
private set

app/src/test/java/to/bitkit/fcm/WakeNodeWorkerTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import to.bitkit.repositories.ActivityRepo
4141
import to.bitkit.repositories.BlocktankRepo
4242
import to.bitkit.repositories.LightningRepo
4343
import to.bitkit.services.NodeEventHandler
44-
import to.bitkit.services.NodeServiceState
44+
import to.bitkit.services.NodeServiceFgState
4545
import to.bitkit.test.BaseUnitTest
4646
import kotlin.test.assertEquals
4747
import kotlin.test.assertNotNull
@@ -57,7 +57,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
5757
private val activityRepo = mock<ActivityRepo>()
5858
private val cacheStore = mock<CacheStore>()
5959
private val receivedNotificationContent = mock<ReceivedNotificationContent>()
60-
private val nodeServiceState = NodeServiceState()
60+
private val nodeServiceFgState = NodeServiceFgState()
6161

6262
private val channelId = "channel-1"
6363
private val receivedTitle by lazy { context.getString(R.string.notification__received__title) }
@@ -71,7 +71,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
7171
val app = context as Application
7272
Shadows.shadowOf(app).grantPermissions(Manifest.permission.POST_NOTIFICATIONS)
7373

74-
// Default: app killed (no foreground activity); nodeServiceState defaults to not-running
74+
// Default: app killed (no foreground activity); nodeServiceFgState defaults to not-running
7575
App.currentActivity = CurrentActivity()
7676
}
7777

@@ -113,7 +113,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
113113

114114
@Test
115115
fun `cjit channel ready skips notification when foreground service is running`() = test {
116-
nodeServiceState.setForegroundServiceRunning(true)
116+
nodeServiceFgState.setForegroundServiceRunning(true)
117117
val channel = cjitChannel(sats = 48_064)
118118
stubChannel(channel, cjitEntry = IcJitEntry.mock())
119119
stubStartFiring(channelReadyEvent())
@@ -178,7 +178,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
178178

179179
@Test
180180
fun `payment received skips notification when foreground service is running`() = test {
181-
nodeServiceState.setForegroundServiceRunning(true)
181+
nodeServiceFgState.setForegroundServiceRunning(true)
182182
whenever(workerParams.inputData).thenReturn(
183183
workDataOf("type" to BlocktankNotificationType.incomingHtlc.name),
184184
)
@@ -204,7 +204,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
204204
activityRepo = activityRepo,
205205
cacheStore = cacheStore,
206206
receivedNotificationContent = receivedNotificationContent,
207-
nodeServiceState = nodeServiceState,
207+
nodeServiceFgState = nodeServiceFgState,
208208
)
209209

210210
private fun channelReadyEvent() = mock<Event.ChannelReady> {

0 commit comments

Comments
 (0)