|
@@ -20,7 +20,7 @@ object SourceVerificationHelp {
|
|
|
private val waitTime = 1.minutes.inWholeNanoseconds
|
|
private val waitTime = 1.minutes.inWholeNanoseconds
|
|
|
|
|
|
|
|
private fun getKey(source: BaseSource) = getKey(source.getKey())
|
|
private fun getKey(source: BaseSource) = getKey(source.getKey())
|
|
|
- fun getKey(sourceKey: String) = "${sourceKey}_verificationResult"
|
|
|
|
|
|
|
+ private fun getKey(sourceKey: String) = "${sourceKey}_verificationResult"
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取书源验证结果
|
|
* 获取书源验证结果
|
|
@@ -35,22 +35,21 @@ object SourceVerificationHelp {
|
|
|
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(getKey(source), Thread.currentThread())
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
startBrowser(source, url, title, true)
|
|
startBrowser(source, url, title, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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 +57,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("验证结果为空")
|
|
|
}
|
|
}
|
|
@@ -89,9 +88,21 @@ object SourceVerificationHelp {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- 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>(getKey(sourceKey))
|
|
|
LockSupport.unpark(thread)
|
|
LockSupport.unpark(thread)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ fun setResult(sourceKey: String, result: String?) {
|
|
|
|
|
+ CacheManager.putMemory(getKey(sourceKey), result ?: "")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun getResult(sourceKey: String): String? {
|
|
|
|
|
+ return CacheManager.get(getKey(sourceKey))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun clearResult(sourceKey: String) {
|
|
|
|
|
+ CacheManager.delete(getKey(sourceKey))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|