pull/1352/head
gedoor 3 years ago
parent 51bdceb836
commit 00f4434d48
  1. 13
      app/src/main/java/io/legado/app/help/AppUpdate.kt
  2. 4
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  3. 16
      app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt

@ -1,6 +1,5 @@
package io.legado.app.help
import io.legado.app.constant.AppConst
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
@ -13,10 +12,10 @@ import splitties.init.appCtx
object AppUpdate {
fun checkUpdate(
fun checkFromGitHub(
scope: CoroutineScope,
showErrorMsg: Boolean = true,
callback: (newVersion: String, updateBody: String, url: String) -> Unit
callback: (newVersion: String, updateBody: String, url: String, fileName: String) -> Unit
) {
Coroutine.async(scope) {
val lastReleaseUrl = "https://api.github.com/repos/gedoor/legado/releases/latest"
@ -29,17 +28,19 @@ object AppUpdate {
val rootDoc = jsonPath.parse(body)
val tagName = rootDoc.readString("$.tag_name")
?: throw NoStackTraceException("获取新版本出错")
if (tagName > AppConst.appInfo.versionName) {
if (tagName > "3.20.092208") {
val updateBody = rootDoc.readString("$.body")
?: throw NoStackTraceException("获取新版本出错")
val downloadUrl = rootDoc.readString("$.assets[0].browser_download_url")
?: throw NoStackTraceException("获取新版本出错")
return@async Triple(tagName, updateBody, downloadUrl)
val fileName = rootDoc.readString("$.assets[0].name")
?: throw NoStackTraceException("获取新版本出错")
return@async arrayOf(tagName, updateBody, downloadUrl, fileName)
} else {
throw NoStackTraceException("已是最新版本")
}
}.onSuccess {
callback.invoke(it.first, it.second, it.third)
callback.invoke(it[0], it[1], it[2], it[3])
}.onError {
appCtx.toastOnUi("检测更新\n${it.localizedMessage}")
}

@ -85,9 +85,9 @@ class AboutFragment : PreferenceFragmentCompat() {
}
private fun checkUpdate() {
AppUpdate.checkUpdate(lifecycleScope) { newVersion, updateBody, url ->
AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name ->
childFragmentManager.showDialog(
UpdateDialog(newVersion, updateBody, url)
UpdateDialog(newVersion, updateBody, url, name)
)
}
}

@ -9,6 +9,7 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogUpdateBinding
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.Download
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
@ -19,11 +20,12 @@ import io.noties.markwon.image.glide.GlideImagesPlugin
class UpdateDialog() : BaseDialogFragment() {
constructor(newVersion: String, updateBody: String, url: String) : this() {
constructor(newVersion: String, updateBody: String, url: String, name: String) : this() {
arguments = Bundle().apply {
putString("newVersion", newVersion)
putString("updateBody", updateBody)
putString("url", url)
putString("name", name)
}
}
@ -65,6 +67,18 @@ class UpdateDialog() : BaseDialogFragment() {
}
if (!AppConfig.isGooglePlay) {
binding.toolBar.inflateMenu(R.menu.app_update)
binding.toolBar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_download -> {
val url = arguments?.getString("url")
val name = arguments?.getString("name")
if (url != null && name != null) {
Download.start(requireContext(), url, name)
}
}
}
return@setOnMenuItemClickListener true
}
}
}

Loading…
Cancel
Save