优化
This commit is contained in:
@@ -83,14 +83,14 @@ class ContentProcessor private constructor(
|
|||||||
var mContent = content
|
var mContent = content
|
||||||
if (content != "null") {
|
if (content != "null") {
|
||||||
//去除重复标题
|
//去除重复标题
|
||||||
try {
|
// try {
|
||||||
val name = Pattern.quote(book.name)
|
// val name = Pattern.quote(book.name)
|
||||||
val title = Pattern.quote(chapter.title)
|
// val title = Pattern.quote(chapter.title)
|
||||||
val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex()
|
// val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex()
|
||||||
mContent = mContent.replace(titleRegex, "")
|
// mContent = mContent.replace(titleRegex, "")
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
|
// AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
|
||||||
}
|
// }
|
||||||
if (reSegment && book.getReSegment()) {
|
if (reSegment && book.getReSegment()) {
|
||||||
//重新分段
|
//重新分段
|
||||||
mContent = ContentHelp.reSegment(mContent, chapter.title)
|
mContent = ContentHelp.reSegment(mContent, chapter.title)
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
var ruleStr = exploreUrl
|
var ruleStr = exploreUrl
|
||||||
if (exploreUrl.startsWith("<js>", false)
|
if (exploreUrl.startsWith("<js>", true)
|
||||||
|| exploreUrl.startsWith("@js:", false)
|
|| exploreUrl.startsWith("@js:", true)
|
||||||
) {
|
) {
|
||||||
ruleStr = aCache.getAsString(exploreKindsKey)
|
ruleStr = aCache.getAsString(exploreKindsKey)
|
||||||
if (ruleStr.isNullOrBlank()) {
|
if (ruleStr.isNullOrBlank()) {
|
||||||
@@ -50,8 +50,8 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ruleStr.isJsonArray()) {
|
if (ruleStr.isJsonArray()) {
|
||||||
GSON.fromJsonArray<ExploreKind>(ruleStr).getOrThrow()?.let {
|
GSON.fromJsonArray<ExploreKind?>(ruleStr).getOrThrow()?.let {
|
||||||
kinds.addAll(it)
|
kinds.addAll(it.filterNotNull())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr ->
|
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_start_stop -> viewModel.startOrStopSearch()
|
||||||
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
|
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
|
||||||
|
R.id.menu_refresh_list -> viewModel.startRefreshList()
|
||||||
else -> if (item?.groupId == R.id.source_group) {
|
else -> if (item?.groupId == R.id.source_group) {
|
||||||
if (!item.isChecked) {
|
if (!item.isChecked) {
|
||||||
item.isChecked = true
|
item.isChecked = true
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
private var tasks = CompositeCoroutine()
|
private var tasks = CompositeCoroutine()
|
||||||
private var screenKey: String = ""
|
private var screenKey: String = ""
|
||||||
private var bookSourceList = arrayListOf<BookSource>()
|
private var bookSourceList = arrayListOf<BookSource>()
|
||||||
|
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 var searchCallback: SourceCallback? = null
|
private var searchCallback: SourceCallback? = null
|
||||||
@@ -136,6 +137,9 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索书籍
|
||||||
|
*/
|
||||||
fun startSearch() {
|
fun startSearch() {
|
||||||
execute {
|
execute {
|
||||||
stopSearch()
|
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> {
|
private fun getDbSearchBooks(): List<SearchBook> {
|
||||||
return if (screenKey.isEmpty()) {
|
return if (screenKey.isEmpty()) {
|
||||||
if (AppConfig.changeSourceCheckAuthor) {
|
if (AppConfig.changeSourceCheckAuthor) {
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
book != null -> initBook(book)
|
book != null -> initBook(book)
|
||||||
else -> ReadBook.upMsg(context.getString(R.string.no_book))
|
else -> ReadBook.upMsg(context.getString(R.string.no_book))
|
||||||
}
|
}
|
||||||
|
}.onError {
|
||||||
|
val msg = "初始化数据失败\n${it.localizedMessage}"
|
||||||
|
ReadBook.upMsg(msg)
|
||||||
|
AppLog.put(msg, it)
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
ReadBook.saveRead()
|
ReadBook.saveRead()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,28 +108,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.textToc.onClick {
|
binding.textToc.onClick {
|
||||||
val query = searchView.query
|
prefixAutoComplete("++")
|
||||||
if (query.isNullOrBlank() || query.length <= 2) {
|
|
||||||
searchView.setQuery("++", false)
|
|
||||||
} else {
|
|
||||||
if (!query.startsWith("++")) {
|
|
||||||
searchView.setQuery("++$query", true)
|
|
||||||
} else {
|
|
||||||
searchView.setQuery(query, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
binding.textContent.onClick {
|
binding.textContent.onClick {
|
||||||
val query = searchView.query
|
prefixAutoComplete("--")
|
||||||
if (query.isNullOrBlank() || query.length <= 2) {
|
|
||||||
searchView.setQuery("--", false)
|
|
||||||
} else {
|
|
||||||
if (!query.startsWith("--")) {
|
|
||||||
searchView.setQuery("--$query", true)
|
|
||||||
} else {
|
|
||||||
searchView.setQuery(query, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
val exploreKinds = viewModel.bookSource?.exploreKinds()?.filter {
|
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 {
|
init {
|
||||||
applyTint(context.accentColor)
|
if (!isInEditMode) {
|
||||||
|
applyTint(context.accentColor)
|
||||||
|
}
|
||||||
ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR)
|
ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR)
|
||||||
|
|
||||||
if (attrs != null) {
|
if (attrs != null) {
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
android:title="@string/book_source_manage"
|
android:title="@string/book_source_manage"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_refresh_list"
|
||||||
|
android:title="@string/refresh_list"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_check_author"
|
android:id="@+id/menu_check_author"
|
||||||
android:title="@string/checkAuthor"
|
android:title="@string/checkAuthor"
|
||||||
|
|||||||
@@ -1058,4 +1058,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1061,4 +1061,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1061,4 +1061,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1058,4 +1058,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1060,4 +1060,5 @@
|
|||||||
<string name="groups_or_source">多分組/書源</string>
|
<string name="groups_or_source">多分組/書源</string>
|
||||||
<string name="replace_state_change">取代(啟用/禁用)</string>
|
<string name="replace_state_change">取代(啟用/禁用)</string>
|
||||||
<string name="show_last_update_time">顯示上次更新時間</string>
|
<string name="show_last_update_time">顯示上次更新時間</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1060,4 +1060,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1061,4 +1061,5 @@
|
|||||||
<string name="groups_or_source">多分组/书源</string>
|
<string name="groups_or_source">多分组/书源</string>
|
||||||
<string name="replace_state_change">替换(启用/禁用)</string>
|
<string name="replace_state_change">替换(启用/禁用)</string>
|
||||||
<string name="show_last_update_time">显示上次更新时间</string>
|
<string name="show_last_update_time">显示上次更新时间</string>
|
||||||
|
<string name="refresh_list">刷新列表</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user