Merge branch 'master' into master
This commit is contained in:
@@ -9,6 +9,9 @@ import io.legado.app.data.entities.Cache
|
||||
@Dao
|
||||
interface CacheDao {
|
||||
|
||||
@Query("select * from caches where `key` = :key")
|
||||
fun get(key: String): Cache?
|
||||
|
||||
@Query("select value from caches where `key` = :key and (deadline = 0 or deadline > :now)")
|
||||
fun get(key: String, now: Long): String?
|
||||
|
||||
|
||||
@@ -41,15 +41,23 @@ object CacheManager {
|
||||
}
|
||||
|
||||
fun get(key: String): String? {
|
||||
return getFromMemory(key) ?: appDb.cacheDao.get(key, System.currentTimeMillis())
|
||||
getFromMemory(key)?.let {
|
||||
return it
|
||||
}
|
||||
val cache = appDb.cacheDao.get(key)
|
||||
if (cache != null && (cache.deadline == 0L || cache.deadline > System.currentTimeMillis())) {
|
||||
memoryLruCache.put(key, cache)
|
||||
return cache.value
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
//从内存中获取数据 使用lrucache 支持过期功能
|
||||
//从内存中获取数据 使用lruCache 支持过期功能
|
||||
private fun getFromMemory(key: String): String? {
|
||||
val cache = memoryLruCache.get(key) ?: return null
|
||||
val deadline = cache!!.deadline
|
||||
val deadline = cache.deadline
|
||||
return if (deadline == 0L || deadline > System.currentTimeMillis()) {
|
||||
cache!!.value
|
||||
cache.value
|
||||
} else {
|
||||
memoryLruCache.remove(key)
|
||||
null
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package io.legado.app.help
|
||||
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.ui.browser.WebViewActivity
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.ui.association.VerificationCodeActivity
|
||||
import splitties.init.appCtx
|
||||
import io.legado.app.ui.browser.WebViewActivity
|
||||
import io.legado.app.utils.startActivity
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import splitties.init.appCtx
|
||||
|
||||
|
||||
object SourceVerificationHelp {
|
||||
@@ -19,13 +19,13 @@ object SourceVerificationHelp {
|
||||
fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String {
|
||||
source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null")
|
||||
return runBlocking {
|
||||
val key = "${source?.getKey() ?: ""}_verificationResult"
|
||||
val key = "${source.getKey()}_verificationResult"
|
||||
CacheManager.delete(key)
|
||||
|
||||
if (!useBrowser) {
|
||||
appCtx.startActivity<VerificationCodeActivity> {
|
||||
putExtra("imageUrl", url)
|
||||
putExtra("sourceOrigin", source?.getKey())
|
||||
putExtra("sourceOrigin", source.getKey())
|
||||
}
|
||||
} else {
|
||||
startBrowser(source, url, title, true)
|
||||
@@ -39,10 +39,8 @@ object SourceVerificationHelp {
|
||||
}
|
||||
}
|
||||
CacheManager.get(key)!!.let {
|
||||
if (it.isBlank()) {
|
||||
it.ifBlank {
|
||||
throw NoStackTraceException("验证结果为空")
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,9 +55,9 @@ object SourceVerificationHelp {
|
||||
appCtx.startActivity<WebViewActivity> {
|
||||
putExtra("title", title)
|
||||
putExtra("url", url)
|
||||
putExtra("sourceOrigin", source?.getKey())
|
||||
putExtra("sourceOrigin", source.getKey())
|
||||
putExtra("sourceVerificationEnable", saveResult)
|
||||
IntentData.put(url, source?.getHeaderMap(true))
|
||||
IntentData.put(url, source.getHeaderMap(true))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package io.legado.app.ui.association
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.net.Uri
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
@@ -39,11 +39,12 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
|
||||
setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.run {
|
||||
toolBar.setBackgroundColor(primaryColor)
|
||||
val sourceOrigin = arguments?.getString("sourceOrigin")
|
||||
val key = "${sourceOrigin ?: ""}_verificationResult"
|
||||
val key = "${sourceOrigin}_verificationResult"
|
||||
arguments?.getString("imageUrl")?.let { imageUrl ->
|
||||
ImageLoader.load(requireContext(), imageUrl).apply {
|
||||
sourceOrigin?.let {
|
||||
|
||||
Reference in New Issue
Block a user