添加批量换源
This commit is contained in:
@@ -262,7 +262,7 @@ object WebBook {
|
|||||||
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
|
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
|
||||||
return bookChapter.url
|
return bookChapter.url
|
||||||
}
|
}
|
||||||
if(bookChapter.isVolume && bookChapter.url.startsWith(bookChapter.title)) {
|
if (bookChapter.isVolume && bookChapter.url.startsWith(bookChapter.title)) {
|
||||||
Debug.log(bookSource.bookSourceUrl, "⇒一级目录正文不解析规则")
|
Debug.log(bookSource.bookSourceUrl, "⇒一级目录正文不解析规则")
|
||||||
return bookChapter.tag ?: ""
|
return bookChapter.tag ?: ""
|
||||||
}
|
}
|
||||||
@@ -322,16 +322,16 @@ object WebBook {
|
|||||||
context: CoroutineContext = Dispatchers.IO,
|
context: CoroutineContext = Dispatchers.IO,
|
||||||
): Coroutine<Pair<BookSource, Book>> {
|
): Coroutine<Pair<BookSource, Book>> {
|
||||||
return Coroutine.async(scope, context) {
|
return Coroutine.async(scope, context) {
|
||||||
preciseSearchAwait(scope, bookSources, name, author)
|
preciseSearchAwait(scope, name, author, *bookSources.toTypedArray())
|
||||||
?: throw NoStackTraceException("没有搜索到<$name>$author")
|
?: throw NoStackTraceException("没有搜索到<$name>$author")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun preciseSearchAwait(
|
suspend fun preciseSearchAwait(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
bookSources: List<BookSource>,
|
|
||||||
name: String,
|
name: String,
|
||||||
author: String
|
author: String,
|
||||||
|
vararg bookSources: BookSource
|
||||||
): Pair<BookSource, Book>? {
|
): Pair<BookSource, Book>? {
|
||||||
bookSources.forEach { source ->
|
bookSources.forEach { source ->
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import io.legado.app.constant.PreferKey
|
|||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookGroup
|
import io.legado.app.data.entities.BookGroup
|
||||||
|
import io.legado.app.data.entities.BookSource
|
||||||
import io.legado.app.databinding.ActivityArrangeBookBinding
|
import io.legado.app.databinding.ActivityArrangeBookBinding
|
||||||
import io.legado.app.lib.dialogs.alert
|
import io.legado.app.lib.dialogs.alert
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
@@ -41,6 +42,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
|
|||||||
PopupMenu.OnMenuItemClickListener,
|
PopupMenu.OnMenuItemClickListener,
|
||||||
SelectActionBar.CallBack,
|
SelectActionBar.CallBack,
|
||||||
ArrangeBookAdapter.CallBack,
|
ArrangeBookAdapter.CallBack,
|
||||||
|
SourcePickerDialog.Callback,
|
||||||
GroupSelectDialog.CallBack {
|
GroupSelectDialog.CallBack {
|
||||||
|
|
||||||
override val binding by viewBinding(ActivityArrangeBookBinding::inflate)
|
override val binding by viewBinding(ActivityArrangeBookBinding::inflate)
|
||||||
@@ -229,4 +231,8 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun sourceOnClick(source: BookSource) {
|
||||||
|
viewModel.changeSource(adapter.selectedBooks(), source)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import io.legado.app.base.BaseViewModel
|
|||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
|
import io.legado.app.model.webBook.WebBook
|
||||||
|
|
||||||
|
|
||||||
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
|
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
|
||||||
@@ -30,8 +32,16 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeSource(books: List<Book>, source: BookSource) {
|
fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> {
|
||||||
|
return execute {
|
||||||
|
books.forEach { book ->
|
||||||
|
WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.onFinally {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
|
import androidx.core.view.setPadding
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
@@ -22,6 +23,7 @@ import io.legado.app.utils.setLayout
|
|||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import splitties.views.onClick
|
||||||
|
|
||||||
class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
|||||||
|
|
||||||
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
|
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
|
||||||
return ItemTextBinding.inflate(inflater, parent, false).apply {
|
return ItemTextBinding.inflate(inflater, parent, false).apply {
|
||||||
root.setPadding(16.dpToPx(), 8.dpToPx(), 16.dpToPx(), 8.dpToPx())
|
root.setPadding(16.dpToPx())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +99,22 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) {
|
override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) {
|
||||||
|
binding.root.onClick {
|
||||||
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
|
callback?.sourceOnClick(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val callback: Callback?
|
||||||
|
get() {
|
||||||
|
return (parentFragment as? Callback) ?: activity as? Callback
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
fun sourceOnClick(source: BookSource)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
if (!AppConfig.autoChangeSource) return
|
if (!AppConfig.autoChangeSource) return
|
||||||
execute {
|
execute {
|
||||||
val sources = appDb.bookSourceDao.allTextEnabled
|
val sources = appDb.bookSourceDao.allTextEnabled
|
||||||
WebBook.preciseSearchAwait(this, sources, name, author)?.let {
|
WebBook.preciseSearchAwait(this, name, author, *sources.toTypedArray())?.let {
|
||||||
it.second.upInfoFromOld(ReadBook.book)
|
it.second.upInfoFromOld(ReadBook.book)
|
||||||
changeTo(it.first, it.second)
|
changeTo(it.first, it.second)
|
||||||
} ?: throw NoStackTraceException("自动换源失败")
|
} ?: throw NoStackTraceException("自动换源失败")
|
||||||
|
|||||||
Reference in New Issue
Block a user