mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
1a5281320b
commit
3a69271a10
@ -83,14 +83,14 @@ class ContentProcessor private constructor(
|
||||
var mContent = content
|
||||
if (content != "null") {
|
||||
//去除重复标题
|
||||
try {
|
||||
val name = Pattern.quote(book.name)
|
||||
val title = Pattern.quote(chapter.title)
|
||||
val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex()
|
||||
mContent = mContent.replace(titleRegex, "")
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
|
||||
}
|
||||
// try {
|
||||
// val name = Pattern.quote(book.name)
|
||||
// val title = Pattern.quote(chapter.title)
|
||||
// val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex()
|
||||
// mContent = mContent.replace(titleRegex, "")
|
||||
// } catch (e: Exception) {
|
||||
// AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
|
||||
// }
|
||||
if (reSegment && book.getReSegment()) {
|
||||
//重新分段
|
||||
mContent = ContentHelp.reSegment(mContent, chapter.title)
|
||||
|
@ -35,8 +35,8 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
||||
withContext(Dispatchers.IO) {
|
||||
kotlin.runCatching {
|
||||
var ruleStr = exploreUrl
|
||||
if (exploreUrl.startsWith("<js>", false)
|
||||
|| exploreUrl.startsWith("@js:", false)
|
||||
if (exploreUrl.startsWith("<js>", true)
|
||||
|| exploreUrl.startsWith("@js:", true)
|
||||
) {
|
||||
ruleStr = aCache.getAsString(exploreKindsKey)
|
||||
if (ruleStr.isNullOrBlank()) {
|
||||
@ -50,8 +50,8 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
||||
}
|
||||
}
|
||||
if (ruleStr.isJsonArray()) {
|
||||
GSON.fromJsonArray<ExploreKind>(ruleStr).getOrThrow()?.let {
|
||||
kinds.addAll(it)
|
||||
GSON.fromJsonArray<ExploreKind?>(ruleStr).getOrThrow()?.let {
|
||||
kinds.addAll(it.filterNotNull())
|
||||
}
|
||||
} else {
|
||||
ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr ->
|
||||
|
@ -216,6 +216,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
||||
}
|
||||
R.id.menu_start_stop -> viewModel.startOrStopSearch()
|
||||
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
|
||||
R.id.menu_refresh_list -> viewModel.startRefreshList()
|
||||
else -> if (item?.groupId == R.id.source_group) {
|
||||
if (!item.isChecked) {
|
||||
item.isChecked = true
|
||||
|
@ -46,6 +46,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
private var tasks = CompositeCoroutine()
|
||||
private var screenKey: String = ""
|
||||
private var bookSourceList = arrayListOf<BookSource>()
|
||||
private var searchBookList = arrayListOf<SearchBook>()
|
||||
private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>())
|
||||
private val tocMap = ConcurrentHashMap<String, List<BookChapter>>()
|
||||
private var searchCallback: SourceCallback? = null
|
||||
@ -136,6 +137,9 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索书籍
|
||||
*/
|
||||
fun startSearch() {
|
||||
execute {
|
||||
stopSearch()
|
||||
@ -235,6 +239,58 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新列表
|
||||
*/
|
||||
fun startRefreshList() {
|
||||
execute {
|
||||
stopSearch()
|
||||
searchBookList.clear()
|
||||
searchBookList.addAll(searchBooks)
|
||||
searchBooks.clear()
|
||||
searchStateData.postValue(true)
|
||||
initSearchPool()
|
||||
for (i in 0 until threadCount) {
|
||||
refreshList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshList() {
|
||||
synchronized(this) {
|
||||
if (searchIndex >= searchBookList.lastIndex) {
|
||||
return
|
||||
}
|
||||
searchIndex++
|
||||
}
|
||||
val searchBook = searchBookList[searchIndex]
|
||||
val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) {
|
||||
val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@async
|
||||
loadBookInfo(source, searchBook.toBook())
|
||||
}.timeout(60000L)
|
||||
.onError {
|
||||
nextRefreshList()
|
||||
}
|
||||
.onSuccess {
|
||||
nextRefreshList()
|
||||
}
|
||||
tasks.add(task)
|
||||
}
|
||||
|
||||
private fun nextRefreshList() {
|
||||
synchronized(this) {
|
||||
if (searchIndex < searchBookList.lastIndex) {
|
||||
refreshList()
|
||||
} else {
|
||||
searchIndex++
|
||||
}
|
||||
if (searchIndex >= searchBookList.lastIndex + min(searchBookList.size, threadCount)) {
|
||||
searchStateData.postValue(false)
|
||||
tasks.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDbSearchBooks(): List<SearchBook> {
|
||||
return if (screenKey.isEmpty()) {
|
||||
if (AppConfig.changeSourceCheckAuthor) {
|
||||
|
@ -70,6 +70,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
book != null -> initBook(book)
|
||||
else -> ReadBook.upMsg(context.getString(R.string.no_book))
|
||||
}
|
||||
}.onError {
|
||||
val msg = "初始化数据失败\n${it.localizedMessage}"
|
||||
ReadBook.upMsg(msg)
|
||||
AppLog.put(msg, it)
|
||||
}.onFinally {
|
||||
ReadBook.saveRead()
|
||||
}
|
||||
|
@ -108,28 +108,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
|
||||
}
|
||||
}
|
||||
binding.textToc.onClick {
|
||||
val query = searchView.query
|
||||
if (query.isNullOrBlank() || query.length <= 2) {
|
||||
searchView.setQuery("++", false)
|
||||
} else {
|
||||
if (!query.startsWith("++")) {
|
||||
searchView.setQuery("++$query", true)
|
||||
} else {
|
||||
searchView.setQuery(query, true)
|
||||
}
|
||||
}
|
||||
prefixAutoComplete("++")
|
||||
}
|
||||
binding.textContent.onClick {
|
||||
val query = searchView.query
|
||||
if (query.isNullOrBlank() || query.length <= 2) {
|
||||
searchView.setQuery("--", false)
|
||||
} else {
|
||||
if (!query.startsWith("--")) {
|
||||
searchView.setQuery("--$query", true)
|
||||
} else {
|
||||
searchView.setQuery(query, true)
|
||||
}
|
||||
}
|
||||
prefixAutoComplete("--")
|
||||
}
|
||||
launch {
|
||||
val exploreKinds = viewModel.bookSource?.exploreKinds()?.filter {
|
||||
@ -156,6 +138,19 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
|
||||
}
|
||||
}
|
||||
|
||||
private fun prefixAutoComplete(prefix: String) {
|
||||
val query = searchView.query
|
||||
if (query.isNullOrBlank() || query.length <= 2) {
|
||||
searchView.setQuery(prefix, false)
|
||||
} else {
|
||||
if (!query.startsWith(prefix)) {
|
||||
searchView.setQuery("$prefix$query", true)
|
||||
} else {
|
||||
searchView.setQuery(query, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开关闭历史界面
|
||||
*/
|
||||
|
@ -56,7 +56,9 @@ class VerticalSeekBar @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
}
|
||||
|
||||
init {
|
||||
applyTint(context.accentColor)
|
||||
if (!isInEditMode) {
|
||||
applyTint(context.accentColor)
|
||||
}
|
||||
ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR)
|
||||
|
||||
if (attrs != null) {
|
||||
|
@ -23,6 +23,11 @@
|
||||
android:title="@string/book_source_manage"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_refresh_list"
|
||||
android:title="@string/refresh_list"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_check_author"
|
||||
android:title="@string/checkAuthor"
|
||||
|
@ -1058,4 +1058,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1061,4 +1061,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1061,4 +1061,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1058,4 +1058,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1060,4 +1060,5 @@
|
||||
<string name="groups_or_source">多分組/書源</string>
|
||||
<string name="replace_state_change">取代(啟用/禁用)</string>
|
||||
<string name="show_last_update_time">顯示上次更新時間</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1060,4 +1060,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
@ -1061,4 +1061,5 @@
|
||||
<string name="groups_or_source">多分组/书源</string>
|
||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||
<string name="show_last_update_time">显示上次更新时间</string>
|
||||
<string name="refresh_list">刷新列表</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user