Merge branch 'devel' into feature/nextgen

# Conflicts:
#	app/build.gradle
This commit is contained in:
Zakhar Timoshenko
2022-07-14 23:07:12 +03:00
2 changed files with 28 additions and 35 deletions

View File

@@ -89,26 +89,25 @@ class MultiSearchViewModel(
}
}
private suspend fun searchImpl(q: String) {
private suspend fun searchImpl(q: String) = coroutineScope {
val sources = settings.getMangaSources(includeHidden = false)
val dispatcher = Dispatchers.Default.limitedParallelism(MAX_PARALLELISM)
val deferredList = coroutineScope {
sources.map { source ->
async(dispatcher) {
runCatching {
val list = MangaRepository(source).getList(offset = 0, query = q)
.toUi(ListMode.GRID)
if (list.isNotEmpty()) {
MultiSearchListModel(source, list.size > MIN_HAS_MORE_ITEMS, list)
} else {
null
}
}.onFailure {
it.printStackTraceDebug()
val deferredList = sources.map { source ->
async(dispatcher) {
runCatching {
val list = MangaRepository(source).getList(offset = 0, query = q)
.toUi(ListMode.GRID)
if (list.isNotEmpty()) {
MultiSearchListModel(source, list.size > MIN_HAS_MORE_ITEMS, list)
} else {
null
}
}.onFailure {
it.printStackTraceDebug()
}
}
}
val errors = ArrayList<Throwable>()
for (deferred in deferredList) {
deferred.await()
@@ -120,13 +119,12 @@ class MultiSearchViewModel(
errors.add(it)
}
}
if (listData.value.isNotEmpty()) {
return
}
when (errors.size) {
0 -> Unit
1 -> throw errors[0]
else -> throw CompositeException(errors)
if (listData.value.isEmpty()) {
when (errors.size) {
0 -> Unit
1 -> throw errors[0]
else -> throw CompositeException(errors)
}
}
}
}