mirror of
https://github.com/fumiama/copymanga.git
synced 2026-06-05 07:20:23 +08:00
v2.5.3
修复 1. 一些闪退
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
||||
minSdkVersion 23
|
||||
//noinspection OldTargetApi
|
||||
targetSdkVersion 34
|
||||
versionCode 73
|
||||
versionName '2.5.2'
|
||||
versionCode 74
|
||||
versionName '2.5.3'
|
||||
resourceConfigurations += ['zh', 'zh-rCN']
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -84,7 +84,7 @@ class Book(val path: String, private val getString: (Int) -> String, private val
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
MainActivity.mainWeakReference?.get()?.apply {
|
||||
Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
|
||||
runOnUiThread { Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,16 @@ class Api {
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
mHostApiUrls = mutableListOf(networkApiUrl.value)
|
||||
Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
if (mHostApiUrls.isEmpty()) {
|
||||
mHostApiUrls = mutableListOf(networkApiUrl.value)
|
||||
Log.d("MyApi", "myHostApiUrl set default ${mHostApiUrls[0]}")
|
||||
Toast.makeText(this, "无法获取API列表", Toast.LENGTH_SHORT).show()
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, "无法获取API列表", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,17 +65,17 @@ class Api {
|
||||
}
|
||||
// get throw error on non-json or non-200 or empty apis, path: /api/v3/xxx, return json string
|
||||
suspend fun get(path: String, forceApi: String? = null): String {
|
||||
val apis = if (forceApi == null) mu.read { mHostApiUrls } else mutableListOf(forceApi)
|
||||
val apis = if (forceApi == null) mu.read { mHostApiUrls.toTypedArray() } else arrayOf(forceApi)
|
||||
if (apis.isEmpty()) {
|
||||
throw NoSuchElementException("API列表为空")
|
||||
}
|
||||
var r: ReturnBase? = null
|
||||
apis.forEach { api ->
|
||||
val u = "https://$api$path"
|
||||
val ret = (apiProxy?.comancry(u) {
|
||||
DownloadTools.getApiContent(it)
|
||||
}?: DownloadTools.getApiContent(u)).decodeToString()
|
||||
try {
|
||||
val ret = (apiProxy?.comancry(u) {
|
||||
DownloadTools.getApiContent(it)
|
||||
}?: DownloadTools.getApiContent(u)).decodeToString()
|
||||
r = Gson().fromJson(ret, ReturnBase::class.java)
|
||||
if (r!!.code != 200) {
|
||||
mu.write { mHostApiUrls.remove(api) }
|
||||
@@ -82,7 +86,7 @@ class Api {
|
||||
mu.write { mHostApiUrls.remove(api) }
|
||||
}
|
||||
}
|
||||
throw IllegalStateException("错误码${r!!.code}, 信息: ${r!!.message}")
|
||||
throw IllegalStateException("错误码${r?.code?:-1}, 信息: ${r?.message?:"空"}")
|
||||
}
|
||||
// request throw error on non-json or non-200 or empty apis, path: /api/v3/xxx, return json string
|
||||
suspend fun request(path: String, body: ByteArray, method: String, contentType: String, forceApi: String? = null): String {
|
||||
|
||||
@@ -199,7 +199,8 @@ object DownloadTools {
|
||||
}
|
||||
conn.disconnect()
|
||||
Log.d("MyDT", "getHttpContent: ${ret.size} bytes")
|
||||
if (conn.getHeaderField("Content-type") != "application/json") {
|
||||
if (!u.startsWith("https://$proxyUrl") &&
|
||||
conn.getHeaderField("Content-type") != "application/json") {
|
||||
throw IllegalStateException("请求错误: ${ret.decodeToString()}")
|
||||
}
|
||||
decodeBody(ret, conn.getHeaderField("Content-Encoding")?:"")
|
||||
|
||||
Reference in New Issue
Block a user