@@ -16,12 +16,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers
16
16
import io.reactivex.disposables.CompositeDisposable
17
17
import io.reactivex.processors.PublishProcessor
18
18
import io.reactivex.schedulers.Schedulers
19
- import kotlinx.coroutines.CoroutineScope
20
- import kotlinx.coroutines.Dispatchers
21
- import kotlinx.coroutines.launch
19
+ import kotlinx.coroutines.runBlocking
22
20
import timber.log.Timber
23
21
import java.lang.reflect.Proxy
24
- import java.util.*
25
22
import javax.inject.Inject
26
23
import javax.inject.Named
27
24
import javax.inject.Singleton
@@ -88,7 +85,7 @@ class DepictsPresenter @Inject constructor(
88
85
var recentDepictedItemList: MutableList <DepictedItem > = ArrayList ();
89
86
// show recentDepictedItemList when queryString is empty
90
87
if (querystring.isEmpty()) {
91
- recentDepictedItemList = getRecentDepictedItems();
88
+ recentDepictedItemList = getRecentDepictedItems().toMutableList()
92
89
}
93
90
94
91
if (media == null ) {
@@ -268,17 +265,9 @@ class DepictsPresenter @Inject constructor(
268
265
/* *
269
266
* Get the depicts from DepictsRoomdataBase
270
267
*/
271
- fun getRecentDepictedItems (): MutableList <DepictedItem > {
272
- val depictedItemList: MutableList <DepictedItem > = ArrayList ()
273
- CoroutineScope (Dispatchers .IO ).launch {
274
- val depictsList = depictsDao.depictsList().await()
275
-
276
- for (i in depictsList.indices) {
277
- val depictedItem = depictsList[i].item
278
- depictedItemList.add(depictedItem)
279
- }
280
- }
281
- return depictedItemList
268
+ private fun getRecentDepictedItems (): List <DepictedItem > = runBlocking {
269
+ val depictsList = depictsDao.depictsList().await()
270
+ return @runBlocking depictsList.map { it.item }
282
271
}
283
272
}
284
273
0 commit comments