-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a workmanager worker to be able to sync dirty tools in the backgr…
…ound
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
library/sync/src/main/kotlin/org/cru/godtools/sync/work/SyncDirtyFavoriteToolsWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.cru.godtools.sync.work | ||
|
||
import android.content.Context | ||
import androidx.hilt.work.HiltWorker | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.ExistingWorkPolicy | ||
import androidx.work.WorkManager | ||
import androidx.work.WorkerParameters | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedInject | ||
import org.cru.godtools.sync.task.UserFavoriteToolsSyncTasks | ||
|
||
private const val WORK_NAME = "SyncDirtyFavoriteTools" | ||
|
||
internal fun WorkManager.scheduleSyncDirtyFavoriteToolsWork() = enqueueUniqueWork( | ||
WORK_NAME, | ||
ExistingWorkPolicy.KEEP, | ||
SyncWorkRequestBuilder<SyncDirtyFavoriteToolsWorker>().build() | ||
) | ||
|
||
@HiltWorker | ||
internal class SyncDirtyFavoriteToolsWorker @AssistedInject constructor( | ||
@Assisted context: Context, | ||
@Assisted workerParams: WorkerParameters, | ||
private val favoriteToolsSyncTasks: UserFavoriteToolsSyncTasks | ||
) : CoroutineWorker(context, workerParams) { | ||
override suspend fun doWork() = | ||
if (favoriteToolsSyncTasks.syncDirtyFavoriteTools()) Result.success() else Result.retry() | ||
} |