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