From 329cdac77489eb1a5cf726d658234331047b7f09 Mon Sep 17 00:00:00 2001 From: HapeLee <1321903405@qq.com> Date: Fri, 11 Jul 2025 02:36:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/google-services.json | 15 +- .../kazusa/help/update/AppReleaseInfo.kt | 2 +- .../kazusa/help/update/AppUpdateGitHub.kt | 33 ++-- .../java/io/legato/kazusa/model/Download.kt | 1 - .../legato/kazusa/ui/about/AboutFragment.kt | 41 +++-- .../io/legato/kazusa/ui/about/UpdateDialog.kt | 53 ++++--- app/src/main/res/layout/dialog_update.xml | 149 ++++++++++++++++-- 7 files changed, 212 insertions(+), 82 deletions(-) diff --git a/app/google-services.json b/app/google-services.json index 8ae52c9c9..13e6fb2ca 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -23,19 +23,10 @@ "other_platform_oauth_client": [] } } - } - ], - "configuration_version": "1", - - "project_info": { - "project_number": "735500663982", - "project_id": "kazesa-debug", - "storage_bucket": "kazesa-debug.firebasestorage.app" - }, - "client": [ + }, { "client_info": { - "mobilesdk_app_id": "1:735500663982:android:68276b2e9a0c230069013f", + "mobilesdk_app_id": "1:499897677610:android:f3b742fbea52bbfec09053", "android_client_info": { "package_name": "io.legato.kazusa.debug" } @@ -43,7 +34,7 @@ "oauth_client": [], "api_key": [ { - "current_key": "AIzaSyDt65UOURbutB8DnTOEGuDf6Vhw56T9nq4" + "current_key": "AIzaSyAaA79qTqF3S67JUVnUK7pdWx3Y3-sbOZI" } ], "services": { diff --git a/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt b/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt index 999b045da..57aa940d3 100644 --- a/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt +++ b/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt @@ -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) ?: "" diff --git a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt index 9a71f9272..6712e07c2 100644 --- a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt +++ b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt @@ -48,22 +48,27 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface { .sortedByDescending { it.createdAt } } - override fun check( - scope: CoroutineScope, - ): Coroutine { + override fun check(scope: CoroutineScope): Coroutine { 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) } + } diff --git a/app/src/main/java/io/legato/kazusa/model/Download.kt b/app/src/main/java/io/legato/kazusa/model/Download.kt index 8e07b3c30..3d67c8a98 100644 --- a/app/src/main/java/io/legato/kazusa/model/Download.kt +++ b/app/src/main/java/io/legato/kazusa/model/Download.kt @@ -7,7 +7,6 @@ import io.legato.kazusa.utils.startService object Download { - fun start(context: Context, url: String, fileName: String) { context.startService { action = IntentAction.start diff --git a/app/src/main/java/io/legato/kazusa/ui/about/AboutFragment.kt b/app/src/main/java/io/legato/kazusa/ui/about/AboutFragment.kt index dc7a8d6bc..e96624dfd 100644 --- a/app/src/main/java/io/legato/kazusa/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legato/kazusa/ui/about/AboutFragment.kt @@ -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 { diff --git a/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt b/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt index 5a4160b50..97ea0daa9 100644 --- a/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt +++ b/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt @@ -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") } + } } diff --git a/app/src/main/res/layout/dialog_update.xml b/app/src/main/res/layout/dialog_update.xml index a84d89922..bd2b23ee2 100644 --- a/app/src/main/res/layout/dialog_update.xml +++ b/app/src/main/res/layout/dialog_update.xml @@ -3,21 +3,148 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical"> + android:orientation="vertical" + android:paddingHorizontal="16dp"> - + android:orientation="vertical" + android:gravity="center" + android:paddingVertical="16dp"> - + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:orientation="horizontal" + android:layout_marginVertical="8dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file