Explorar o código

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

HapeLee hai 11 meses
pai
achega
3720847ebb

+ 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.data.entities.SearchBook
 import io.legado.app.help.book.isNotShelf
 import io.legado.app.help.book.isNotShelf
 import io.legado.app.model.webBook.WebBook
 import io.legado.app.model.webBook.WebBook
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.withContext
 
 
 interface ExploreRepository {
 interface ExploreRepository {
     fun getBookshelfItems(): Flow<List<SearchBook>>
     fun getBookshelfItems(): Flow<List<SearchBook>>
@@ -31,11 +33,14 @@ class ExploreRepositoryImpl(
     }
     }
 
 
     override suspend fun exploreBook(source: BookSource, url: String, page: Int): Result<List<SearchBook>> {
     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)
+            }
         }
         }
     }
     }