Улучшен запуск сервиса
This commit is contained in:
@@ -9,6 +9,9 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@@ -22,8 +25,11 @@ class TaskPipelineForegroundBootstrap @Inject constructor(
|
|||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
orchestrator.foregroundUi.collect { ui ->
|
orchestrator.foregroundUi
|
||||||
if (ui is TaskForegroundUiState.Visible) {
|
.map { it is TaskForegroundUiState.Visible }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.filter { visible -> visible }
|
||||||
|
.collect {
|
||||||
ContextCompat.startForegroundService(
|
ContextCompat.startForegroundService(
|
||||||
app,
|
app,
|
||||||
Intent(app, TaskPipelineForegroundService::class.java),
|
Intent(app, TaskPipelineForegroundService::class.java),
|
||||||
@@ -32,4 +38,3 @@ class TaskPipelineForegroundBootstrap @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user