实时更新日志
This commit is contained in:
@@ -64,6 +64,23 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getReleaseByTag(tag: String): AppUpdate.UpdateInfo? {
|
||||
val url = "https://api.github.com/repos/HapeLee/legado-with-MD3/releases/tags/$tag"
|
||||
val res = okHttpClient.newCallResponse { url(url) }
|
||||
if (!res.isSuccessful) return null
|
||||
|
||||
val body = res.body.text()
|
||||
val release = GSON.fromJsonObject<GithubRelease>(body).getOrElse { return null }
|
||||
val info = release.gitReleaseToAppReleaseInfo().firstOrNull() ?: return null
|
||||
|
||||
return AppUpdate.UpdateInfo(
|
||||
tagName = info.versionName,
|
||||
updateLog = info.note,
|
||||
downloadUrl = info.downloadUrl,
|
||||
fileName = info.name
|
||||
)
|
||||
}
|
||||
|
||||
override fun check(scope: CoroutineScope): Coroutine<AppUpdate.UpdateInfo> {
|
||||
return Coroutine.async(scope) {
|
||||
val currentVersion = AppConst.appInfo.versionName
|
||||
|
||||
@@ -123,7 +123,7 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
|
||||
AppUpdate.gitHubUpdate?.run {
|
||||
check(lifecycleScope)
|
||||
.onSuccess {
|
||||
showDialogFragment(UpdateDialog(it))
|
||||
showDialogFragment(UpdateDialog(it, UpdateDialog.Mode.UPDATE))
|
||||
}.onError {
|
||||
appCtx.toastOnUi("${getString(R.string.check_update)}\n${it.localizedMessage}")
|
||||
}.onFinally {
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.update.AppUpdate
|
||||
import io.legado.app.help.update.AppVariant
|
||||
import io.legado.app.model.Download
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.noties.markwon.Markwon
|
||||
@@ -21,12 +22,15 @@ import io.noties.markwon.image.glide.GlideImagesPlugin
|
||||
|
||||
class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
|
||||
|
||||
constructor(updateInfo: AppUpdate.UpdateInfo) : this() {
|
||||
enum class Mode { UPDATE, VIEW_LOG }
|
||||
|
||||
constructor(updateInfo: AppUpdate.UpdateInfo, mode: Mode = Mode.UPDATE) : this() {
|
||||
arguments = Bundle().apply {
|
||||
putString("newVersion", updateInfo.tagName)
|
||||
putString("updateBody", updateInfo.updateLog)
|
||||
putString("url", updateInfo.downloadUrl)
|
||||
putString("name", updateInfo.fileName)
|
||||
putString("mode", mode.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,28 +42,24 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
|
||||
else -> AppConst.appInfo.appVariant
|
||||
}
|
||||
|
||||
val binding by viewBinding(DialogUpdateBinding::bind)
|
||||
private val binding by viewBinding(DialogUpdateBinding::bind)
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
}
|
||||
private val mode: Mode
|
||||
get() = Mode.valueOf(arguments?.getString("mode") ?: Mode.UPDATE.name)
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
//binding.toolBar.setBackgroundColor(primaryColor)
|
||||
|
||||
binding.tvCurrentVersion.text = BuildConfig.VERSION_NAME
|
||||
binding.tvVersion.text = arguments?.getString("newVersion")
|
||||
|
||||
binding.tvAbi.text = Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"
|
||||
binding.tvUrl.text = arguments?.getString("url")
|
||||
binding.tvVariable.text = checkVariant.toString()
|
||||
|
||||
val updateBody = arguments?.getString("updateBody")
|
||||
if (updateBody == null) {
|
||||
if (updateBody.isNullOrBlank()) {
|
||||
toastOnUi("没有数据")
|
||||
dismiss()
|
||||
return
|
||||
}
|
||||
|
||||
binding.textView.post {
|
||||
Markwon.builder(requireContext())
|
||||
.usePlugin(GlideImagesPlugin.create(requireContext()))
|
||||
@@ -69,19 +69,29 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
|
||||
.setMarkdown(binding.textView, updateBody)
|
||||
}
|
||||
|
||||
binding.btnUpdate.setOnClickListener {
|
||||
val url = arguments?.getString("url")
|
||||
val fileName = arguments?.getString("name")
|
||||
|
||||
if (url.isNullOrBlank() || fileName.isNullOrBlank()) {
|
||||
toastOnUi("下载信息不完整")
|
||||
return@setOnClickListener
|
||||
when (mode) {
|
||||
Mode.UPDATE -> {
|
||||
val url = arguments?.getString("url")
|
||||
val fileName = arguments?.getString("name")
|
||||
binding.ivAward.gone()
|
||||
binding.btnUpdate.setOnClickListener {
|
||||
if (url.isNullOrBlank() || fileName.isNullOrBlank()) {
|
||||
toastOnUi("下载信息不完整")
|
||||
return@setOnClickListener
|
||||
}
|
||||
Download.start(requireContext(), url, fileName)
|
||||
toastOnUi("开始下载: $fileName")
|
||||
}
|
||||
}
|
||||
|
||||
Download.start(requireContext(), url, fileName)
|
||||
toastOnUi("开始下载: $fileName")
|
||||
Mode.VIEW_LOG -> {
|
||||
binding.bottomSheetTitle.text = "已经更新至"
|
||||
binding.tvVersion.text = BuildConfig.VERSION_NAME
|
||||
binding.btnUpdate.gone()
|
||||
binding.llCurrent.gone()
|
||||
binding.tvCurrentVersion.gone()
|
||||
binding.tvUrl.gone()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,10 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.LocalConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.storage.Backup
|
||||
import io.legado.app.help.update.AppUpdateGitHub
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.ui.about.CrashLogsDialog
|
||||
import io.legado.app.ui.about.UpdateDialog
|
||||
import io.legado.app.ui.book.read.ReadBookActivity
|
||||
import io.legado.app.ui.book.search.SearchActivity
|
||||
import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment
|
||||
@@ -235,7 +237,7 @@ open class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
/**
|
||||
* 版本更新日志
|
||||
*/
|
||||
private suspend fun upVersion() = suspendCoroutine { block ->
|
||||
private suspend fun upVersion() = suspendCoroutine<Unit?> { block ->
|
||||
if (LocalConfig.versionCode == appInfo.versionCode) {
|
||||
block.resume(null)
|
||||
return@suspendCoroutine
|
||||
@@ -244,17 +246,32 @@ open class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
if (LocalConfig.isFirstOpenApp) {
|
||||
val help = String(assets.open("web/help/md/appHelp.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.help), help, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener {
|
||||
block.resume(null)
|
||||
}
|
||||
dialog.setOnDismissListener { block.resume(null) }
|
||||
showDialogFragment(dialog)
|
||||
} else if (!BuildConfig.DEBUG) {
|
||||
val log = String(assets.open("updateLog.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.update_log), log, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener {
|
||||
block.resume(null)
|
||||
return@suspendCoroutine
|
||||
}
|
||||
if (!BuildConfig.DEBUG) {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val info = AppUpdateGitHub.getReleaseByTag(BuildConfig.VERSION_NAME)
|
||||
if (info != null) {
|
||||
val dialog = UpdateDialog(info, UpdateDialog.Mode.VIEW_LOG)
|
||||
dialog.setOnDismissListener { block.resume(null) }
|
||||
showDialogFragment(dialog)
|
||||
} else {
|
||||
val fallback = String(assets.open("updateLog.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.update_log), fallback, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener { block.resume(null) }
|
||||
showDialogFragment(dialog)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
val fallback = String(assets.open("updateLog.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.update_log), fallback, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener { block.resume(null) }
|
||||
showDialogFragment(dialog)
|
||||
}
|
||||
}
|
||||
showDialogFragment(dialog)
|
||||
} else {
|
||||
block.resume(null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user