Browse Source

[修复] 某些情况下,发现没有数据的问题

HapeLee 11 months ago
parent
commit
3720847ebb
1 changed files with 10 additions and 5 deletions
  1. 10 5
      app/src/main/java/io/legado/app/data/repository/ExploreRepository.kt

+ 10 - 5
app/src/main/java/io/legado/app/data/repository/ExploreRepository.kt

@@ -5,8 +5,10 @@ import io.legado.app.data.entities.BookSource
 import io.legado.app.data.entities.SearchBook
 import io.legado.app.help.book.isNotShelf
 import io.legado.app.model.webBook.WebBook
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.withContext
 
 interface ExploreRepository {
     fun getBookshelfItems(): Flow<List<SearchBook>>
@@ -31,11 +33,14 @@ class ExploreRepositoryImpl(
     }
 
     override suspend fun exploreBook(source: BookSource, url: String, page: Int): Result<List<SearchBook>> {
-        return try {
-            val books = WebBook.exploreBookSuspend(source, url, page)
-            Result.success(books)
-        } catch (e: Exception) {
-            Result.failure(e)
+        return withContext(Dispatchers.IO) {
+            try {
+                val books = WebBook.exploreBookSuspend(source, url, page)
+                Result.success(books)
+            } catch (e: Exception) {
+                e.printStackTrace()
+                Result.failure(e)
+            }
         }
     }