pull/2314/head
kunfei 3 years ago
parent 53b536e4f8
commit 294f23ee70
  1. 23
      app/src/main/java/io/legado/app/help/AppUpdate.kt
  2. 23
      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.help.http.okHttpClient
import io.legado.app.utils.jsonPath import io.legado.app.utils.jsonPath
import io.legado.app.utils.readString import io.legado.app.utils.readString
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import splitties.init.appCtx import splitties.init.appCtx
@ -16,10 +15,8 @@ object AppUpdate {
fun checkFromGitHub( fun checkFromGitHub(
scope: CoroutineScope, scope: CoroutineScope,
showErrorMsg: Boolean = true, ): Coroutine<UpdateInfo> {
callback: (newVersion: String, updateBody: String, url: String, fileName: String) -> Unit return Coroutine.async(scope) {
) {
Coroutine.async(scope) {
val lastReleaseUrl = appCtx.getString(R.string.latest_release_api) val lastReleaseUrl = appCtx.getString(R.string.latest_release_api)
val body = okHttpClient.newCallStrResponse { val body = okHttpClient.newCallStrResponse {
url(lastReleaseUrl) url(lastReleaseUrl)
@ -37,18 +34,18 @@ object AppUpdate {
?: throw NoStackTraceException("获取新版本出错") ?: throw NoStackTraceException("获取新版本出错")
val fileName = rootDoc.readString("$.assets[0].name") val fileName = rootDoc.readString("$.assets[0].name")
?: throw NoStackTraceException("获取新版本出错") ?: throw NoStackTraceException("获取新版本出错")
return@async arrayOf(tagName, updateBody, downloadUrl, fileName) return@async UpdateInfo(tagName, updateBody, downloadUrl, fileName)
} else { } else {
throw NoStackTraceException("已是最新版本") throw NoStackTraceException("已是最新版本")
} }
}.timeout(10000) }.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.lib.dialogs.selector
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.init.appCtx
class AboutFragment : PreferenceFragmentCompat() { class AboutFragment : PreferenceFragmentCompat() {
@ -80,14 +81,23 @@ class AboutFragment : PreferenceFragmentCompat() {
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD)) showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
} }
/**
* 检测更新
*/
private fun checkUpdate() { private fun checkUpdate() {
AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name -> AppUpdate.checkFromGitHub(lifecycleScope)
showDialogFragment( .onSuccess {
UpdateDialog(newVersion, updateBody, url, name) showDialogFragment(
) UpdateDialog(it)
} )
}.onError {
appCtx.toastOnUi("${getString(R.string.check_update)}\n${it.localizedMessage}")
}
} }
/**
* 显示qq群
*/
private fun showQqGroups() { private fun showQqGroups() {
alert(titleResource = R.string.join_qq_group) { alert(titleResource = R.string.join_qq_group) {
val names = arrayListOf<String>() val names = arrayListOf<String>()
@ -104,6 +114,9 @@ class AboutFragment : PreferenceFragmentCompat() {
} }
} }
/**
* 加入qq群
*/
private fun joinQQGroup(key: String): Boolean { private fun joinQQGroup(key: String): Boolean {
val intent = Intent() val intent = Intent()
intent.data = intent.data =

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

Loading…
Cancel
Save