更新界面

This commit is contained in:
HapeLee
2025-07-11 02:36:16 +08:00
parent b007a81277
commit 329cdac774
7 changed files with 212 additions and 82 deletions
@@ -13,7 +13,7 @@ data class AppReleaseInfo(
val downloadUrl: String,
val assetUrl: String
) {
val versionName: String = Regex("""legado_app_([\d.]+)""")
val versionName: String = Regex("""legado_app_([\d.]+)\.apk""")
.find(name)
?.groupValues?.get(1)
?: ""
@@ -48,22 +48,27 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
.sortedByDescending { it.createdAt }
}
override fun check(
scope: CoroutineScope,
): Coroutine<AppUpdate.UpdateInfo> {
override fun check(scope: CoroutineScope): Coroutine<AppUpdate.UpdateInfo> {
return Coroutine.async(scope) {
getLatestRelease()
val currentVersion = AppConst.appInfo.versionName
val releases = getLatestRelease()
.filter { it.appVariant == checkVariant }
.firstOrNull { it.versionName > AppConst.appInfo.versionName }
?.let {
return@async AppUpdate.UpdateInfo(
it.versionName,
it.note,
it.downloadUrl,
it.name
)
}
?: throw NoStackTraceException("已是最新版本")
val latest = releases
.firstOrNull { it.versionName > currentVersion }
if (latest != null) {
return@async AppUpdate.UpdateInfo(
latest.versionName,
latest.note,
latest.downloadUrl,
latest.name
)
}
throw NoStackTraceException("已是最新版本")
}.timeout(10000)
}
}
@@ -7,7 +7,6 @@ import io.legato.kazusa.utils.startService
object Download {
fun start(context: Context, url: String, fileName: String) {
context.startService<DownloadService> {
action = IntentAction.start
@@ -1,7 +1,5 @@
package io.legato.kazusa.ui.about
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.annotation.StringRes
@@ -35,6 +33,7 @@ import io.legato.kazusa.utils.toastOnUi
import kotlinx.coroutines.delay
import splitties.init.appCtx
import java.io.File
import androidx.core.net.toUri
class AboutFragment : PreferenceFragmentCompat() {
@@ -103,23 +102,23 @@ class AboutFragment : PreferenceFragmentCompat() {
}
/**
* 加入qq群
*/
private fun joinQQGroup(key: String): Boolean {
val intent = Intent()
intent.data =
Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D$key")
// 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
kotlin.runCatching {
startActivity(intent)
return true
}.onFailure {
toastOnUi("添加失败,请手动添加")
}
return false
}
// /**
// * 加入qq群
// */
// private fun joinQQGroup(key: String): Boolean {
// val intent = Intent()
// intent.data =
// "mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D$key".toUri()
// // 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面
// // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// kotlin.runCatching {
// startActivity(intent)
// return true
// }.onFailure {
// toastOnUi("添加失败,请手动添加")
// }
// return false
// }
private fun saveLog() {
Coroutine.async {
@@ -131,7 +130,7 @@ class AboutFragment : PreferenceFragmentCompat() {
appCtx.toastOnUi("未开启日志记录,请去其他设置里打开记录日志")
delay(3000)
}
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
val doc = FileDoc.fromUri(backupPath.toUri(), true)
copyLogs(doc)
copyHeapDump(doc)
appCtx.toastOnUi("已保存至备份目录")
@@ -153,7 +152,7 @@ class AboutFragment : PreferenceFragmentCompat() {
appCtx.toastOnUi("开始创建堆转储")
System.gc()
CrashHandler.doHeapDump(true)
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
val doc = FileDoc.fromUri(backupPath.toUri(), true)
if (!copyHeapDump(doc)) {
appCtx.toastOnUi("未找到堆转储文件")
} else {
@@ -3,6 +3,7 @@ package io.legato.kazusa.ui.about
import android.os.Build
import android.os.Bundle
import android.view.View
import io.legato.kazusa.BuildConfig
import io.legato.kazusa.R
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
import io.legato.kazusa.databinding.DialogUpdateBinding
@@ -34,7 +35,13 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
//binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.title = arguments?.getString("newVersion")
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")
val updateBody = arguments?.getString("updateBody")
if (updateBody == null) {
toastOnUi("没有数据")
@@ -49,31 +56,33 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
.build()
.setMarkdown(binding.textView, updateBody)
}
binding.toolBar.inflateMenu(R.menu.app_update)
binding.toolBar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_download -> {
val url = arguments?.getString("url")
val baseName = arguments?.getString("name")
?.removeSuffix(".apk")
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: "universal"
val abiSuffix = when {
abi.contains("arm64") -> "arm64-v8a"
abi.contains("armeabi") -> "armeabi-v7a"
else -> "universal"
}
binding.btnUpdate.setOnClickListener {
val urlPrefix = arguments?.getString("url")
val baseName = arguments?.getString("name")?.removeSuffix(".apk")
val name = "${baseName}_$abiSuffix.apk"
if (url != null && baseName != null) {
Download.start(requireContext(), url, name)
toastOnUi(R.string.download_start)
}
}
if (urlPrefix == null || baseName == null) {
toastOnUi("下载信息不完整")
return@setOnClickListener
}
return@setOnMenuItemClickListener true
// 获取当前 ABI 后缀
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: ""
val abiSuffix = when {
abi.contains("arm64") -> "arm64-v8a"
abi.contains("armeabi") -> "armeabi-v7a"
else -> ""
}
// 拼接文件名和下载链接
val fileName = "${baseName}_$abiSuffix.apk"
val fullUrl = urlPrefix
.substringBeforeLast("/") + "/" + fileName
Download.start(requireContext(), fullUrl, fileName)
toastOnUi("开始下载: $fileName")
}
}
}