|
|
|
@ -17,8 +17,6 @@
|
|
|
|
|
package com.google.samples.apps.nowinandroid.sync.status
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.lifecycle.asFlow
|
|
|
|
|
import androidx.lifecycle.map
|
|
|
|
|
import androidx.work.ExistingWorkPolicy
|
|
|
|
|
import androidx.work.WorkInfo
|
|
|
|
|
import androidx.work.WorkInfo.State
|
|
|
|
@ -29,6 +27,7 @@ import com.google.samples.apps.nowinandroid.sync.workers.SyncWorker
|
|
|
|
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
|
import kotlinx.coroutines.flow.conflate
|
|
|
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -38,9 +37,8 @@ class WorkManagerSyncManager @Inject constructor(
|
|
|
|
|
@ApplicationContext private val context: Context,
|
|
|
|
|
) : SyncManager {
|
|
|
|
|
override val isSyncing: Flow<Boolean> =
|
|
|
|
|
WorkManager.getInstance(context).getWorkInfosForUniqueWorkLiveData(SyncWorkName)
|
|
|
|
|
.map(MutableList<WorkInfo>::anyRunning)
|
|
|
|
|
.asFlow()
|
|
|
|
|
WorkManager.getInstance(context).getWorkInfosForUniqueWorkFlow(SyncWorkName)
|
|
|
|
|
.map(List<WorkInfo>::anyRunning)
|
|
|
|
|
.conflate()
|
|
|
|
|
|
|
|
|
|
override fun requestSync() {
|
|
|
|
@ -54,4 +52,4 @@ class WorkManagerSyncManager @Inject constructor(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val List<WorkInfo>.anyRunning get() = any { it.state == State.RUNNING }
|
|
|
|
|
private fun List<WorkInfo>.anyRunning() = any { it.state == State.RUNNING }
|
|
|
|
|