优化
This commit is contained in:
@@ -145,6 +145,7 @@ object PreferKey {
|
||||
const val mouseWheelPage = "mouseWheelPage"
|
||||
const val recordHeapDump = "recordHeapDump"
|
||||
const val optimizeRender = "optimizeRender"
|
||||
const val updateToBeta = "updateToBeta"
|
||||
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val cAccent = "colorAccent"
|
||||
|
||||
@@ -23,6 +23,8 @@ object AppUpdate {
|
||||
|
||||
fun check(scope: CoroutineScope): Coroutine<UpdateInfo>
|
||||
|
||||
fun checkBeta(scope: CoroutineScope): Coroutine<UpdateInfo>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,5 +47,37 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
|
||||
}.timeout(10000)
|
||||
}
|
||||
|
||||
override fun checkBeta(scope: CoroutineScope): Coroutine<AppUpdate.UpdateInfo> {
|
||||
return Coroutine.async(scope) {
|
||||
val preReleaseUrl = "https://api.github.com/repos/gedoor/legado/releases/tags/beta"
|
||||
val body = okHttpClient.newCallStrResponse {
|
||||
url(preReleaseUrl)
|
||||
}.body
|
||||
if (body.isNullOrBlank()) {
|
||||
throw NoStackTraceException("获取新版本出错")
|
||||
}
|
||||
val rootDoc = jsonPath.parse(body)
|
||||
val path = "\$.assets[?(@.name =~ /legado_${appCtx.channel}_.*?apk\$/)]"
|
||||
val assetsMap = rootDoc.read<List<Any>>(path)
|
||||
.firstOrNull()
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
val assets = jsonPath.parse(assetsMap)
|
||||
val name = assets.readString("$.name")
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
val tagName = name.replace("legado_${appCtx.channel}_|\\.apk".toRegex(), "")
|
||||
if (tagName > AppConst.appInfo.versionName) {
|
||||
val updateBody = rootDoc.readString("$.body")
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
val downloadUrl = assets.readString("$.browser_download_url")
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
val fileName = assets.readString("$.name")
|
||||
?: throw NoStackTraceException("获取新版本出错")
|
||||
return@async AppUpdate.UpdateInfo(tagName, updateBody, downloadUrl, fileName)
|
||||
} else {
|
||||
throw NoStackTraceException("已是最新版本")
|
||||
}
|
||||
}.timeout(10000)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -471,6 +471,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
val defaultHomePage get() = appCtx.getPrefString(PreferKey.defaultHomePage, "bookshelf")
|
||||
|
||||
val updateToBeta get() = appCtx.getPrefBoolean(PreferKey.updateToBeta, false)
|
||||
|
||||
val doublePageHorizontal: String?
|
||||
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
|
||||
|
||||
|
||||
@@ -88,16 +88,20 @@ class AboutFragment : PreferenceFragmentCompat() {
|
||||
private fun checkUpdate() {
|
||||
waitDialog.show()
|
||||
AppUpdate.gitHubUpdate?.run {
|
||||
check(lifecycleScope)
|
||||
.onSuccess {
|
||||
showDialogFragment(
|
||||
UpdateDialog(it)
|
||||
)
|
||||
}.onError {
|
||||
appCtx.toastOnUi("${getString(R.string.check_update)}\n${it.localizedMessage}")
|
||||
}.onFinally {
|
||||
waitDialog.dismiss()
|
||||
}
|
||||
val job = if (AppConfig.updateToBeta) {
|
||||
checkBeta(lifecycleScope)
|
||||
} else {
|
||||
check(lifecycleScope)
|
||||
}
|
||||
job.onSuccess {
|
||||
showDialogFragment(
|
||||
UpdateDialog(it)
|
||||
)
|
||||
}.onError {
|
||||
appCtx.toastOnUi("${getString(R.string.check_update)}\n${it.localizedMessage}")
|
||||
}.onFinally {
|
||||
waitDialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1153,4 +1153,6 @@
|
||||
<string name="start_from">Comenzar</string>
|
||||
<string name="daily_chapters">Cap. al día</string>
|
||||
<string name="start_chapter">Cap. inicio</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1156,4 +1156,6 @@
|
||||
<string name="start_from">開始日</string>
|
||||
<string name="daily_chapters">日更の章数</string>
|
||||
<string name="start_chapter">開始の章</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1156,4 +1156,6 @@
|
||||
<string name="start_from">Começar</string>
|
||||
<string name="daily_chapters">Cap. por dia</string>
|
||||
<string name="start_chapter">Início</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1152,4 +1152,6 @@ Còn </string>
|
||||
<string name="start_from">Bắt đầu</string>
|
||||
<string name="daily_chapters">Chương/ngày</string>
|
||||
<string name="start_chapter">Chương đầu</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1153,4 +1153,6 @@
|
||||
<string name="start_from">起始日期</string>
|
||||
<string name="daily_chapters">日更章數</string>
|
||||
<string name="start_chapter">開始篇章</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1155,4 +1155,6 @@
|
||||
<string name="start_from">起始日期</string>
|
||||
<string name="daily_chapters">日更章數</string>
|
||||
<string name="start_chapter">開始篇章</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1155,4 +1155,6 @@
|
||||
<string name="start_from">开始日期</string>
|
||||
<string name="daily_chapters">日更章数</string>
|
||||
<string name="start_chapter">起始章节</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -1156,4 +1156,6 @@
|
||||
<string name="start_from">Start from</string>
|
||||
<string name="daily_chapters">Daily Chapters</string>
|
||||
<string name="start_chapter">Start Chapter</string>
|
||||
<string name="update_to_bata_title">更新至测试版</string>
|
||||
<string name="update_to_bata_summary">检查更新时查找最新的测试版本</string>
|
||||
</resources>
|
||||
|
||||
@@ -146,6 +146,12 @@
|
||||
android:summary="@string/show_add_to_shelf_alert_summary"
|
||||
android:title="@string/show_add_to_shelf_alert_title" />
|
||||
|
||||
<io.legado.app.lib.prefs.SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="updateToBeta"
|
||||
android:summary="@string/update_to_bata_summary"
|
||||
android:title="@string/update_to_bata_title" />
|
||||
|
||||
<io.legado.app.lib.prefs.Preference
|
||||
android:key="webPort"
|
||||
android:title="@string/web_port_title"
|
||||
|
||||
Reference in New Issue
Block a user