Fix NPE in SyncPresenter (#1582)

This commit is contained in:
Michael 2021-10-14 01:44:34 +02:00 committed by GitHub
parent e3122127c0
commit ac86737050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -74,7 +74,7 @@ class SyncManager @Inject constructor(
} }
} }
fun startOneTimeSyncWorker(): Flow<WorkInfo> { fun startOneTimeSyncWorker(): Flow<WorkInfo?> {
val work = OneTimeWorkRequestBuilder<SyncWorker>() val work = OneTimeWorkRequestBuilder<SyncWorker>()
.setInputData( .setInputData(
Data.Builder() Data.Builder()

View File

@ -46,7 +46,7 @@ class SyncPresenter @Inject constructor(
fun onSyncNowClicked() { fun onSyncNowClicked() {
view?.run { view?.run {
syncManager.startOneTimeSyncWorker().onEach { workInfo -> syncManager.startOneTimeSyncWorker().onEach { workInfo ->
when (workInfo.state) { when (workInfo?.state) {
WorkInfo.State.ENQUEUED -> { WorkInfo.State.ENQUEUED -> {
setSyncInProgress(true) setSyncInProgress(true)
Timber.i("Setting sync now started") Timber.i("Setting sync now started")
@ -63,9 +63,9 @@ class SyncPresenter @Inject constructor(
) )
analytics.logEvent("sync_now", "status" to "failed") analytics.logEvent("sync_now", "status" to "failed")
} }
else -> Timber.d("Sync now state: ${workInfo.state}") else -> Timber.d("Sync now state: ${workInfo?.state}")
} }
if (workInfo.state.isFinished) { if (workInfo?.state?.isFinished == true) {
setSyncInProgress(false) setSyncInProgress(false)
setSyncDateInView() setSyncDateInView()
} }