显示换源进度 (#4893)
* change source progress * format,隐藏初始状态 * resolve PR comment * resolve PR comment1 * resolve PR comment2
This commit is contained in:
@@ -48,6 +48,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,6 +236,26 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repeatOnLifecycle(STARTED) {
|
||||||
|
viewModel.finishedChangeSourceResult
|
||||||
|
.drop(1)
|
||||||
|
.collect { (count, name) ->
|
||||||
|
binding.tvDur.text =
|
||||||
|
getString(
|
||||||
|
R.string.change_source_progress,
|
||||||
|
adapter.itemCount,
|
||||||
|
count,
|
||||||
|
viewModel.totalSourceCount,
|
||||||
|
name
|
||||||
|
)
|
||||||
|
delay(500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
|
appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import io.legado.app.help.coroutine.Coroutine
|
|||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.utils.internString
|
import io.legado.app.utils.internString
|
||||||
import io.legado.app.utils.mapParallelSafe
|
import io.legado.app.utils.mapParallelSafe
|
||||||
|
import io.legado.app.utils.onEachIndexed
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
@@ -35,6 +36,8 @@ import kotlinx.coroutines.asCoroutineDispatcher
|
|||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
@@ -43,6 +46,7 @@ import kotlinx.coroutines.flow.flowOn
|
|||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
@@ -62,9 +66,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
private var oldBook: Book? = null
|
private var oldBook: Book? = null
|
||||||
private var screenKey: String = ""
|
private var screenKey: String = ""
|
||||||
private var bookSourceParts = arrayListOf<BookSourcePart>()
|
private var bookSourceParts = arrayListOf<BookSourcePart>()
|
||||||
|
val totalSourceCount:Int
|
||||||
|
get() = bookSourceParts.size
|
||||||
private var searchBookList = arrayListOf<SearchBook>()
|
private var searchBookList = arrayListOf<SearchBook>()
|
||||||
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 val _finishedChangeSourceResult = MutableStateFlow(0 to "")
|
||||||
|
val finishedChangeSourceResult= _finishedChangeSourceResult.asStateFlow()
|
||||||
private var tocMapChapterCount = 0
|
private var tocMapChapterCount = 0
|
||||||
private val contentProcessor by lazy {
|
private val contentProcessor by lazy {
|
||||||
ContentProcessor.get(oldBook!!)
|
ContentProcessor.get(oldBook!!)
|
||||||
@@ -181,6 +189,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
tocMap.clear()
|
tocMap.clear()
|
||||||
bookMap.clear()
|
bookMap.clear()
|
||||||
tocMapChapterCount = 0
|
tocMapChapterCount = 0
|
||||||
|
_finishedChangeSourceResult.value = 0 to ""
|
||||||
val searchGroup = AppConfig.searchGroup
|
val searchGroup = AppConfig.searchGroup
|
||||||
if (searchGroup.isBlank()) {
|
if (searchGroup.isBlank()) {
|
||||||
bookSourceParts.addAll(appDb.bookSourceDao.allEnabledPart)
|
bookSourceParts.addAll(appDb.bookSourceDao.allEnabledPart)
|
||||||
@@ -223,8 +232,15 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
}.onStart {
|
}.onStart {
|
||||||
searchStateData.postValue(true)
|
searchStateData.postValue(true)
|
||||||
}.mapParallelSafe(threadCount) {
|
}.mapParallelSafe(threadCount) {
|
||||||
withTimeout(60000L) {
|
runCatching {
|
||||||
search(it)
|
withTimeout(60000L) {
|
||||||
|
search(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it
|
||||||
|
}.onEachIndexed { index, value ->
|
||||||
|
_finishedChangeSourceResult.update { _ ->
|
||||||
|
index + 1 to value.bookSourceName
|
||||||
}
|
}
|
||||||
}.onCompletion {
|
}.onCompletion {
|
||||||
searchStateData.postValue(false)
|
searchStateData.postValue(false)
|
||||||
|
|||||||
@@ -1137,6 +1137,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">结果 %1$d, 当前进度 %2$d / %3$d: %4$s</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="default_home_page">默认主页</string>
|
<string name="default_home_page">默认主页</string>
|
||||||
|
|||||||
@@ -1140,6 +1140,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">結果 %1$d、現在の進行状況 %2$d / %3$d: %4$s</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="default_home_page">默认主页</string>
|
<string name="default_home_page">默认主页</string>
|
||||||
|
|||||||
@@ -1140,6 +1140,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">" Resultado %1$d, progresso atual %2$d / %3$d: %4$s"</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="default_home_page">默认主页</string>
|
<string name="default_home_page">默认主页</string>
|
||||||
|
|||||||
@@ -1136,6 +1136,7 @@ Còn </string>
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">Kết quả %1$d, tiến trình hiện tại %2$d / %3$d: %4$s</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="sync_book_progress_success">" Đồng bộ hóa tiến trình thành công"</string>
|
<string name="sync_book_progress_success">" Đồng bộ hóa tiến trình thành công"</string>
|
||||||
|
|||||||
@@ -1137,6 +1137,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">" 結果 %1$d, 當前進度 %2$d / %3$d: %4$s"</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="sync_book_progress_success">進度同步成功</string>
|
<string name="sync_book_progress_success">進度同步成功</string>
|
||||||
|
|||||||
@@ -1139,6 +1139,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">" 結果 %1$d, 當前進度 %2$d / %3$d: %4$s"</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="sync_book_progress_success">進度同步成功</string>
|
<string name="sync_book_progress_success">進度同步成功</string>
|
||||||
|
|||||||
@@ -1139,6 +1139,7 @@
|
|||||||
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
|
||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
|
<string name="change_source_progress">结果 %1$d, 当前进度 %2$d / %3$d: %4$s</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
<string name="export_wait">等待导出</string>
|
<string name="export_wait">等待导出</string>
|
||||||
<string name="sync_book_progress_success">进度同步成功</string>
|
<string name="sync_book_progress_success">进度同步成功</string>
|
||||||
|
|||||||
@@ -1142,6 +1142,7 @@
|
|||||||
<string name="export_book_notification_content">Exporting (%1$s), with %2$d to be exported.</string>
|
<string name="export_book_notification_content">Exporting (%1$s), with %2$d to be exported.</string>
|
||||||
<string name="export_md">Export(MD)</string>
|
<string name="export_md">Export(MD)</string>
|
||||||
<string name="change_source_delay">Change source delay</string>
|
<string name="change_source_delay">Change source delay</string>
|
||||||
|
<string name="change_source_progress">Result %1$d, Progress %2$d / %3$d: %4$s</string>
|
||||||
<string name="open_book_info_by_click_title">Click on the book title to open details</string>
|
<string name="open_book_info_by_click_title">Click on the book title to open details</string>
|
||||||
<string name="export_wait">Waiting for export</string>
|
<string name="export_wait">Waiting for export</string>
|
||||||
<string name="show_bookshelf_fast_scroller">Show quick scroll bar</string>
|
<string name="show_bookshelf_fast_scroller">Show quick scroll bar</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user