|
@@ -19,8 +19,8 @@ object SourceVerificationHelp {
|
|
|
|
|
|
|
|
private val waitTime = 1.minutes.inWholeNanoseconds
|
|
private val waitTime = 1.minutes.inWholeNanoseconds
|
|
|
|
|
|
|
|
- private fun getKey(source: BaseSource) = getKey(source.getKey())
|
|
|
|
|
- fun getKey(sourceKey: String) = "${sourceKey}_verificationResult"
|
|
|
|
|
|
|
+ private fun getVerificationResultKey(source: BaseSource) = getVerificationResultKey(source.getKey())
|
|
|
|
|
+ private fun getVerificationResultKey(sourceKey: String) = "${sourceKey}_verificationResult"
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取书源验证结果
|
|
* 获取书源验证结果
|
|
@@ -30,27 +30,27 @@ object SourceVerificationHelp {
|
|
|
source: BaseSource?,
|
|
source: BaseSource?,
|
|
|
url: String,
|
|
url: String,
|
|
|
title: String,
|
|
title: String,
|
|
|
- useBrowser: Boolean
|
|
|
|
|
|
|
+ useBrowser: Boolean,
|
|
|
|
|
+ refetchAfterSuccess: Boolean = true
|
|
|
): String {
|
|
): String {
|
|
|
source
|
|
source
|
|
|
?: throw NoStackTraceException("getVerificationResult parameter source cannot be null")
|
|
?: throw NoStackTraceException("getVerificationResult parameter source cannot be null")
|
|
|
|
|
|
|
|
- val key = getKey(source)
|
|
|
|
|
- CacheManager.delete(key)
|
|
|
|
|
|
|
+ clearResult(source.getKey())
|
|
|
|
|
|
|
|
if (!useBrowser) {
|
|
if (!useBrowser) {
|
|
|
appCtx.startActivity<VerificationCodeActivity> {
|
|
appCtx.startActivity<VerificationCodeActivity> {
|
|
|
putExtra("imageUrl", url)
|
|
putExtra("imageUrl", url)
|
|
|
putExtra("sourceOrigin", source.getKey())
|
|
putExtra("sourceOrigin", source.getKey())
|
|
|
putExtra("sourceName", source.getTag())
|
|
putExtra("sourceName", source.getTag())
|
|
|
- IntentData.put(key, Thread.currentThread())
|
|
|
|
|
|
|
+ IntentData.put(getVerificationResultKey(source), Thread.currentThread())
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- startBrowser(source, url, title, true)
|
|
|
|
|
|
|
+ startBrowser(source, url, title, true, refetchAfterSuccess)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var waitUserInput = false
|
|
var waitUserInput = false
|
|
|
- while (CacheManager.get(key) == null) {
|
|
|
|
|
|
|
+ while (getResult(source.getKey()) == null) {
|
|
|
if (!waitUserInput) {
|
|
if (!waitUserInput) {
|
|
|
AppLog.putDebug("等待返回验证结果...")
|
|
AppLog.putDebug("等待返回验证结果...")
|
|
|
waitUserInput = true
|
|
waitUserInput = true
|
|
@@ -58,7 +58,7 @@ object SourceVerificationHelp {
|
|
|
LockSupport.parkNanos(this, waitTime)
|
|
LockSupport.parkNanos(this, waitTime)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return CacheManager.get(key)!!.let {
|
|
|
|
|
|
|
+ return getResult(source.getKey())!!.let {
|
|
|
it.ifBlank {
|
|
it.ifBlank {
|
|
|
throw NoStackTraceException("验证结果为空")
|
|
throw NoStackTraceException("验证结果为空")
|
|
|
}
|
|
}
|
|
@@ -73,25 +73,38 @@ object SourceVerificationHelp {
|
|
|
source: BaseSource?,
|
|
source: BaseSource?,
|
|
|
url: String,
|
|
url: String,
|
|
|
title: String,
|
|
title: String,
|
|
|
- saveResult: Boolean? = false
|
|
|
|
|
|
|
+ saveResult: Boolean? = false,
|
|
|
|
|
+ refetchAfterSuccess: Boolean? = true
|
|
|
) {
|
|
) {
|
|
|
source ?: throw NoStackTraceException("startBrowser parameter source cannot be null")
|
|
source ?: throw NoStackTraceException("startBrowser parameter source cannot be null")
|
|
|
- val key = getKey(source)
|
|
|
|
|
appCtx.startActivity<WebViewActivity> {
|
|
appCtx.startActivity<WebViewActivity> {
|
|
|
putExtra("title", title)
|
|
putExtra("title", title)
|
|
|
putExtra("url", url)
|
|
putExtra("url", url)
|
|
|
putExtra("sourceOrigin", source.getKey())
|
|
putExtra("sourceOrigin", source.getKey())
|
|
|
putExtra("sourceName", source.getTag())
|
|
putExtra("sourceName", source.getTag())
|
|
|
putExtra("sourceVerificationEnable", saveResult)
|
|
putExtra("sourceVerificationEnable", saveResult)
|
|
|
|
|
+ putExtra("refetchAfterSuccess", refetchAfterSuccess)
|
|
|
IntentData.put(url, source.getHeaderMap(true))
|
|
IntentData.put(url, source.getHeaderMap(true))
|
|
|
- IntentData.put(key, Thread.currentThread())
|
|
|
|
|
|
|
+ IntentData.put(getVerificationResultKey(source), Thread.currentThread())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- fun checkResult(key: String) {
|
|
|
|
|
- CacheManager.get(key) ?: CacheManager.putMemory(key, "")
|
|
|
|
|
- val thread = IntentData.get<Thread>(key)
|
|
|
|
|
|
|
+ fun checkResult(sourceKey: String) {
|
|
|
|
|
+ getResult(sourceKey) ?: setResult(sourceKey, "")
|
|
|
|
|
+ val thread = IntentData.get<Thread>(getVerificationResultKey(sourceKey))
|
|
|
LockSupport.unpark(thread)
|
|
LockSupport.unpark(thread)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ fun setResult(sourceKey: String, result: String?) {
|
|
|
|
|
+ CacheManager.putMemory(getVerificationResultKey(sourceKey), result ?: "")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun getResult(sourceKey: String): String? {
|
|
|
|
|
+ return CacheManager.get(getVerificationResultKey(sourceKey))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun clearResult(sourceKey: String) {
|
|
|
|
|
+ CacheManager.delete(getVerificationResultKey(sourceKey))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|