Horis hace 3 años
padre
commit
1dff187c64

+ 6 - 9
app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt

@@ -51,6 +51,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
     private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>())
     private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>())
     private val tocMap = ConcurrentHashMap<String, List<BookChapter>>()
     private val tocMap = ConcurrentHashMap<String, List<BookChapter>>()
     private var searchCallback: SourceCallback? = null
     private var searchCallback: SourceCallback? = null
+    private val emptyBookSource = BookSource()
     val bookMap = ConcurrentHashMap<String, Book>()
     val bookMap = ConcurrentHashMap<String, Book>()
     val searchDataFlow = callbackFlow {
     val searchDataFlow = callbackFlow {
 
 
@@ -113,7 +114,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
     }.flowOn(IO)
     }.flowOn(IO)
 
 
     @Volatile
     @Volatile
-    private var searchIndex = -1
+    private var searchIndex = 0
 
 
     override fun onCleared() {
     override fun onCleared() {
         super.onCleared()
         super.onCleared()
@@ -137,7 +138,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
     private fun initSearchPool() {
     private fun initSearchPool() {
         searchPool = Executors
         searchPool = Executors
             .newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
             .newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher()
-        searchIndex = -1
+        searchIndex = 0
     }
     }
 
 
     fun refresh(): Boolean {
     fun refresh(): Boolean {
@@ -180,13 +181,14 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
     }
     }
 
 
     private fun search() {
     private fun search() {
-        synchronized(this) {
+        val searchIndex = synchronized(this) {
             if (searchIndex >= bookSourceList.lastIndex) {
             if (searchIndex >= bookSourceList.lastIndex) {
                 return
                 return
             }
             }
             searchIndex++
             searchIndex++
         }
         }
         val source = bookSourceList[searchIndex]
         val source = bookSourceList[searchIndex]
+        bookSourceList[searchIndex] = emptyBookSource
         val task = execute(context = searchPool!!, executeContext = searchPool!!) {
         val task = execute(context = searchPool!!, executeContext = searchPool!!) {
             val resultBooks = WebBook.searchBookAwait(source, name)
             val resultBooks = WebBook.searchBookAwait(source, name)
             resultBooks.forEach { searchBook ->
             resultBooks.forEach { searchBook ->
@@ -197,15 +199,10 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
                     return@forEach
                     return@forEach
                 }
                 }
                 when {
                 when {
-                    searchBook.latestChapterTitle.isNullOrEmpty() &&
-                            (AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc) -> {
+                    AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc || AppConfig.changeSourceLoadWordCount -> {
                         loadBookInfo(source, searchBook.toBook())
                         loadBookInfo(source, searchBook.toBook())
                     }
                     }
 
 
-                    AppConfig.changeSourceLoadWordCount -> {
-                        loadBookToc(source, searchBook.toBook())
-                    }
-
                     else -> {
                     else -> {
                         searchCallback?.searchSuccess(searchBook)
                         searchCallback?.searchSuccess(searchBook)
                     }
                     }

+ 11 - 0
app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@@ -172,6 +172,7 @@ class ReadBookActivity : BaseReadBookActivity(),
     private val prevPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.PREV) } }
     private val prevPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.PREV) } }
     private var bookChanged = false
     private var bookChanged = false
     private var pageChanged = false
     private var pageChanged = false
+    private var reloadContent = false
 
 
     //恢复跳转前进度对话框的交互结果
     //恢复跳转前进度对话框的交互结果
     private var confirmRestoreProcess: Boolean? = null
     private var confirmRestoreProcess: Boolean? = null
@@ -218,6 +219,10 @@ class ReadBookActivity : BaseReadBookActivity(),
         super.onPostCreate(savedInstanceState)
         super.onPostCreate(savedInstanceState)
         viewModel.initData(intent) {
         viewModel.initData(intent) {
             upMenu()
             upMenu()
+            if (reloadContent) {
+                reloadContent = false
+                ReadBook.loadContent(resetPageOffset = false)
+            }
         }
         }
     }
     }
 
 
@@ -225,6 +230,10 @@ class ReadBookActivity : BaseReadBookActivity(),
         super.onNewIntent(intent)
         super.onNewIntent(intent)
         viewModel.initData(intent ?: return) {
         viewModel.initData(intent ?: return) {
             upMenu()
             upMenu()
+            if (reloadContent) {
+                reloadContent = false
+                ReadBook.loadContent(resetPageOffset = false)
+            }
         }
         }
     }
     }
 
 
@@ -1428,6 +1437,8 @@ class ReadBookActivity : BaseReadBookActivity(),
             if (it) {
             if (it) {
                 if (isInitFinish) {
                 if (isInitFinish) {
                     ReadBook.loadContent(resetPageOffset = false)
                     ReadBook.loadContent(resetPageOffset = false)
+                } else {
+                    reloadContent = true
                 }
                 }
             } else {
             } else {
                 readView.upContent(resetPageOffset = false)
                 readView.upContent(resetPageOffset = false)