优化
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.help.source
|
package io.legado.app.help.source
|
||||||
|
|
||||||
|
import com.script.rhino.runScriptWithContext
|
||||||
import io.legado.app.constant.BookSourceType
|
import io.legado.app.constant.BookSourceType
|
||||||
import io.legado.app.constant.BookType
|
import io.legado.app.constant.BookType
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
@@ -11,7 +12,6 @@ import io.legado.app.utils.MD5Utils
|
|||||||
import io.legado.app.utils.fromJsonArray
|
import io.legado.app.utils.fromJsonArray
|
||||||
import io.legado.app.utils.isJsonArray
|
import io.legado.app.utils.isJsonArray
|
||||||
import io.legado.app.utils.printOnDebug
|
import io.legado.app.utils.printOnDebug
|
||||||
import com.script.rhino.runScriptWithContext
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
@@ -96,6 +96,14 @@ suspend fun BookSourcePart.clearExploreKindsCache() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun BookSource.clearExploreKindsCache() {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val exploreKindsKey = getExploreKindsKey()
|
||||||
|
aCache.remove(exploreKindsKey)
|
||||||
|
exploreKindsMap.remove(exploreKindsKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun BookSource.getBookType(): Int {
|
fun BookSource.getBookType(): Int {
|
||||||
return when (bookSourceType) {
|
return when (bookSourceType) {
|
||||||
BookSourceType.file -> BookType.text or BookType.webFile
|
BookSourceType.file -> BookType.text or BookType.webFile
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.model
|
package io.legado.app.model
|
||||||
|
|
||||||
|
import androidx.collection.LruCache
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.script.ScriptBindings
|
import com.script.ScriptBindings
|
||||||
import com.script.rhino.RhinoScriptEngine
|
import com.script.rhino.RhinoScriptEngine
|
||||||
@@ -24,7 +25,7 @@ object SharedJsScope {
|
|||||||
private val cacheFolder = File(appCtx.cacheDir, "shareJs")
|
private val cacheFolder = File(appCtx.cacheDir, "shareJs")
|
||||||
private val aCache = ACache.get(cacheFolder)
|
private val aCache = ACache.get(cacheFolder)
|
||||||
|
|
||||||
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
|
private val scopeMap = LruCache<String, WeakReference<Scriptable>>(16)
|
||||||
|
|
||||||
fun getScope(jsLib: String?, coroutineContext: CoroutineContext?): Scriptable? {
|
fun getScope(jsLib: String?, coroutineContext: CoroutineContext?): Scriptable? {
|
||||||
if (jsLib.isNullOrBlank()) {
|
if (jsLib.isNullOrBlank()) {
|
||||||
@@ -70,7 +71,7 @@ object SharedJsScope {
|
|||||||
if (scope is ScriptableObject) {
|
if (scope is ScriptableObject) {
|
||||||
scope.sealObject()
|
scope.sealObject()
|
||||||
}
|
}
|
||||||
scopeMap[key] = WeakReference(scope)
|
scopeMap.put(key, WeakReference(scope))
|
||||||
}
|
}
|
||||||
return scope
|
return scope
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
import io.legado.app.databinding.ActivitySourceDebugBinding
|
import io.legado.app.databinding.ActivitySourceDebugBinding
|
||||||
|
import io.legado.app.help.source.clearExploreKindsCache
|
||||||
import io.legado.app.help.source.exploreKinds
|
import io.legado.app.help.source.exploreKinds
|
||||||
import io.legado.app.lib.dialogs.selector
|
import io.legado.app.lib.dialogs.selector
|
||||||
import io.legado.app.lib.theme.accentColor
|
import io.legado.app.lib.theme.accentColor
|
||||||
@@ -117,6 +118,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
|
|||||||
binding.textContent.onClick {
|
binding.textContent.onClick {
|
||||||
prefixAutoComplete("--")
|
prefixAutoComplete("--")
|
||||||
}
|
}
|
||||||
|
initExploreKinds()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initExploreKinds() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val exploreKinds = viewModel.bookSource?.exploreKinds()?.filter {
|
val exploreKinds = viewModel.bookSource?.exploreKinds()?.filter {
|
||||||
!it.url.isNullOrBlank()
|
!it.url.isNullOrBlank()
|
||||||
@@ -188,6 +193,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
|
|||||||
R.id.menu_book_src -> showDialogFragment(TextDialog("html", viewModel.bookSrc))
|
R.id.menu_book_src -> showDialogFragment(TextDialog("html", viewModel.bookSrc))
|
||||||
R.id.menu_toc_src -> showDialogFragment(TextDialog("html", viewModel.tocSrc))
|
R.id.menu_toc_src -> showDialogFragment(TextDialog("html", viewModel.tocSrc))
|
||||||
R.id.menu_content_src -> showDialogFragment(TextDialog("html", viewModel.contentSrc))
|
R.id.menu_content_src -> showDialogFragment(TextDialog("html", viewModel.contentSrc))
|
||||||
|
R.id.menu_refresh_explore -> lifecycleScope.launch {
|
||||||
|
viewModel.bookSource?.clearExploreKindsCache()
|
||||||
|
initExploreKinds()
|
||||||
|
}
|
||||||
R.id.menu_help -> showHelp("debugHelp")
|
R.id.menu_help -> showHelp("debugHelp")
|
||||||
}
|
}
|
||||||
return super.onCompatOptionsItemSelected(item)
|
return super.onCompatOptionsItemSelected(item)
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class BookSourceEditActivity :
|
|||||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_save -> viewModel.save(getSource()) {
|
R.id.menu_save -> viewModel.save(getSource()) {
|
||||||
setResult(Activity.RESULT_OK, Intent().putExtra("origin", it.bookSourceUrl))
|
setResult(RESULT_OK, Intent().putExtra("origin", it.bookSourceUrl))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,18 @@ import io.legado.app.help.config.SourceConfig
|
|||||||
import io.legado.app.help.http.CookieStore
|
import io.legado.app.help.http.CookieStore
|
||||||
import io.legado.app.help.http.newCallStrResponse
|
import io.legado.app.help.http.newCallStrResponse
|
||||||
import io.legado.app.help.http.okHttpClient
|
import io.legado.app.help.http.okHttpClient
|
||||||
|
import io.legado.app.help.source.clearExploreKindsCache
|
||||||
import io.legado.app.help.storage.ImportOldData
|
import io.legado.app.help.storage.ImportOldData
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.GSON
|
||||||
|
import io.legado.app.utils.fromJsonArray
|
||||||
|
import io.legado.app.utils.fromJsonObject
|
||||||
|
import io.legado.app.utils.getClipText
|
||||||
|
import io.legado.app.utils.isAbsUrl
|
||||||
|
import io.legado.app.utils.isJsonArray
|
||||||
|
import io.legado.app.utils.isJsonObject
|
||||||
|
import io.legado.app.utils.jsonPath
|
||||||
|
import io.legado.app.utils.printOnDebug
|
||||||
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
|
||||||
@@ -41,8 +51,12 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
|
|||||||
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) {
|
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) {
|
||||||
throw NoStackTraceException(context.getString(R.string.non_null_name_url))
|
throw NoStackTraceException(context.getString(R.string.non_null_name_url))
|
||||||
}
|
}
|
||||||
if (!source.equal(bookSource ?: BookSource())) {
|
val oldSource = bookSource ?: BookSource()
|
||||||
|
if (!source.equal(oldSource)) {
|
||||||
source.lastUpdateTime = System.currentTimeMillis()
|
source.lastUpdateTime = System.currentTimeMillis()
|
||||||
|
if (oldSource.exploreUrl != source.exploreUrl) {
|
||||||
|
oldSource.clearExploreKindsCache()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bookSource?.let {
|
bookSource?.let {
|
||||||
appDb.bookSourceDao.delete(it)
|
appDb.bookSourceDao.delete(it)
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
android:title="@string/content_src"
|
android:title="@string/content_src"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_refresh_explore"
|
||||||
|
android:title="@string/refresh_explore"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_help"
|
android:id="@+id/menu_help"
|
||||||
android:title="@string/help"
|
android:title="@string/help"
|
||||||
|
|||||||
@@ -1209,4 +1209,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1212,4 +1212,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1212,4 +1212,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1208,4 +1208,5 @@ Còn </string>
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1209,4 +1209,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1211,4 +1211,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1211,4 +1211,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1212,4 +1212,5 @@
|
|||||||
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
<string name="enable_manga_horizontal_scroll">水平滚动</string>
|
||||||
<string name="manga_color_filter">滤镜</string>
|
<string name="manga_color_filter">滤镜</string>
|
||||||
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
<string name="hide_manga_title">隐藏漫画列表标题</string>
|
||||||
|
<string name="refresh_explore">刷新发现</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user