This commit is contained in:
Horis
2023-10-12 15:01:33 +08:00
parent e30d2a9ca7
commit 314619e014
2 changed files with 17 additions and 9 deletions

View File

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

View File

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