pull/2314/head
kunfei 2 years ago
parent 53b536e4f8
commit 294f23ee70
  1. 23
      app/src/main/java/io/legado/app/help/AppUpdate.kt
  2. 17
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  3. 11
      app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt

@ -8,7 +8,6 @@ import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.jsonPath
import io.legado.app.utils.readString
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import splitties.init.appCtx
@ -16,10 +15,8 @@ object AppUpdate {
fun checkFromGitHub(
scope: CoroutineScope,
showErrorMsg: Boolean = true,
callback: (newVersion: String, updateBody: String, url: String, fileName: String) -> Unit
) {
Coroutine.async(scope) {
): Coroutine<UpdateInfo> {
return Coroutine.async(scope) {
val lastReleaseUrl = appCtx.getString(R.string.latest_release_api)
val body = okHttpClient.newCallStrResponse {
url(lastReleaseUrl)
@ -37,18 +34,18 @@ object AppUpdate {
?: throw NoStackTraceException("获取新版本出错")
val fileName = rootDoc.readString("$.assets[0].name")
?: throw NoStackTraceException("获取新版本出错")
return@async arrayOf(tagName, updateBody, downloadUrl, fileName)
return@async UpdateInfo(tagName, updateBody, downloadUrl, fileName)
} else {
throw NoStackTraceException("已是最新版本")
}
}.timeout(10000)
.onSuccess {
callback.invoke(it[0], it[1], it[2], it[3])
}.onError {
if (showErrorMsg) {
appCtx.toastOnUi("检测更新\n${it.localizedMessage}")
}
}
}
data class UpdateInfo(
val tagName: String,
val updateLog: String,
val downloadUrl: String,
val fileName: String
)
}

@ -16,6 +16,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import splitties.init.appCtx
class AboutFragment : PreferenceFragmentCompat() {
@ -80,14 +81,23 @@ class AboutFragment : PreferenceFragmentCompat() {
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
}
/**
* 检测更新
*/
private fun checkUpdate() {
AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name ->
AppUpdate.checkFromGitHub(lifecycleScope)
.onSuccess {
showDialogFragment(
UpdateDialog(newVersion, updateBody, url, name)
UpdateDialog(it)
)
}.onError {
appCtx.toastOnUi("${getString(R.string.check_update)}\n${it.localizedMessage}")
}
}
/**
* 显示qq群
*/
private fun showQqGroups() {
alert(titleResource = R.string.join_qq_group) {
val names = arrayListOf<String>()
@ -104,6 +114,9 @@ class AboutFragment : PreferenceFragmentCompat() {
}
}
/**
* 加入qq群
*/
private fun joinQQGroup(key: String): Boolean {
val intent = Intent()
intent.data =

@ -6,6 +6,7 @@ import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogUpdateBinding
import io.legado.app.help.AppUpdate
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.Download
@ -19,12 +20,12 @@ import io.noties.markwon.image.glide.GlideImagesPlugin
class UpdateDialog() : BaseDialogFragment(R.layout.dialog_update) {
constructor(newVersion: String, updateBody: String, url: String, name: String) : this() {
constructor(updateInfo: AppUpdate.UpdateInfo) : this() {
arguments = Bundle().apply {
putString("newVersion", newVersion)
putString("updateBody", updateBody)
putString("url", url)
putString("name", name)
putString("newVersion", updateInfo.tagName)
putString("updateBody", updateInfo.updateLog)
putString("url", updateInfo.downloadUrl)
putString("name", updateInfo.fileName)
}
}

Loading…
Cancel
Save