From ce2b5797bcbd3c0b0eea3d4e8969ff0cec5183cf Mon Sep 17 00:00:00 2001 From: sictiru Date: Mon, 1 Apr 2024 09:25:44 -0700 Subject: [PATCH] Fix sending sync update status from feed utils --- .../src/main/java/com/newsblur/activity/NbActivity.kt | 2 +- .../main/java/com/newsblur/service/NbSyncManager.kt | 3 ++- .../app/src/main/java/com/newsblur/util/FeedUtils.kt | 10 +++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/NbActivity.kt b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/NbActivity.kt index 5f6a3587fb..7bb0152c41 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/NbActivity.kt +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/NbActivity.kt @@ -65,7 +65,7 @@ open class NbActivity : AppCompatActivity() { // Facilitates the db updates by the sync service on the UI lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.RESUMED) { + repeatOnLifecycle(Lifecycle.State.CREATED) { launch { NbSyncManager.state.collectLatest { withContext(Dispatchers.Main) { diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/service/NbSyncManager.kt b/clients/android/NewsBlur/app/src/main/java/com/newsblur/service/NbSyncManager.kt index 814d9afeea..058df95582 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/service/NbSyncManager.kt +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/service/NbSyncManager.kt @@ -1,6 +1,7 @@ package com.newsblur.service import com.newsblur.util.NBScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.launch @@ -26,7 +27,7 @@ object NbSyncManager { fun submitError(msg: String) = submit(NBSync.Error(msg)) private fun submit(nbSync: NBSync) { - NBScope.launch { + NBScope.launch(Dispatchers.IO) { _state.emit(nbSync) } } diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/FeedUtils.kt b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/FeedUtils.kt index 54d92897a9..face0a0b02 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/FeedUtils.kt +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/FeedUtils.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.text.TextUtils +import com.newsblur.NbApplication import com.newsblur.R import com.newsblur.activity.NbActivity import com.newsblur.database.BlurDatabaseHelper @@ -13,10 +14,11 @@ import com.newsblur.domain.Story import com.newsblur.fragment.ReadingActionConfirmationFragment import com.newsblur.network.APIConstants import com.newsblur.network.APIManager +import com.newsblur.service.NBSyncService +import com.newsblur.service.NbSyncManager import com.newsblur.service.NbSyncManager.UPDATE_METADATA import com.newsblur.service.NbSyncManager.UPDATE_SOCIAL import com.newsblur.service.NbSyncManager.UPDATE_STORY -import com.newsblur.service.NBSyncService import com.newsblur.service.OriginalTextService import com.newsblur.util.FeedExt.disableNotification import com.newsblur.util.FeedExt.setNotifyFocus @@ -486,8 +488,10 @@ class FeedUtils( UIUtils.handleUri(context, Uri.parse(url)) } - private fun syncUpdateStatus(updateType: Int) { - + private fun syncUpdateStatus(update: Int) { + if (NbApplication.isAppForeground) { + NbSyncManager.submitUpdate(update) + } } companion object {