From d813c18ec9c037af239ac62d1b5c788582fd0482 Mon Sep 17 00:00:00 2001 From: FerdyRod Date: Fri, 22 Dec 2023 14:34:09 +0100 Subject: [PATCH] inject StockDispatcher to fix code smell --- .../dhis2/android/rtsm/coroutines/StockDispatcherProvider.kt | 3 ++- .../java/org/dhis2/android/rtsm/services/StockManagerImpl.kt | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/coroutines/StockDispatcherProvider.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/coroutines/StockDispatcherProvider.kt index b555b051adc..a517ac656ad 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/coroutines/StockDispatcherProvider.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/coroutines/StockDispatcherProvider.kt @@ -2,8 +2,9 @@ package org.dhis2.android.rtsm.coroutines import kotlinx.coroutines.Dispatchers import org.dhis2.commons.viewmodel.DispatcherProvider +import javax.inject.Inject -class StockDispatcherProvider : DispatcherProvider { +class StockDispatcherProvider @Inject constructor() : DispatcherProvider { override fun io() = Dispatchers.IO diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockManagerImpl.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockManagerImpl.kt index 28a2e1490ee..284b7b1308f 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockManagerImpl.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockManagerImpl.kt @@ -3,9 +3,9 @@ package org.dhis2.android.rtsm.services import androidx.lifecycle.liveData import io.reactivex.Single import io.reactivex.disposables.CompositeDisposable -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.lang3.math.NumberUtils +import org.dhis2.android.rtsm.coroutines.StockDispatcherProvider import org.dhis2.android.rtsm.data.AppConfig import org.dhis2.android.rtsm.data.models.IdentifiableModel import org.dhis2.android.rtsm.data.models.SearchParametersModel @@ -36,6 +36,7 @@ class StockManagerImpl @Inject constructor( private val disposable: CompositeDisposable, private val schedulerProvider: BaseSchedulerProvider, private val ruleValidationHelper: RuleValidationHelper, + private val dispatcher: StockDispatcherProvider, ) : StockManager { override suspend fun search( @@ -43,7 +44,7 @@ class StockManagerImpl @Inject constructor( ou: String?, config: AppConfig, ): SearchResult { - val list = withContext(Dispatchers.IO) { + val list = withContext(dispatcher.io()) { var teiRepository = d2.trackedEntityModule().trackedEntityInstanceQuery() if (!ou.isNullOrEmpty()) {