diff --git a/packages/client-android/android/app/src/main/java/dev/yuzu/gca/MainActivity.kt b/packages/client-android/android/app/src/main/java/dev/yuzu/gca/MainActivity.kt index 191e716..7bb00e1 100644 --- a/packages/client-android/android/app/src/main/java/dev/yuzu/gca/MainActivity.kt +++ b/packages/client-android/android/app/src/main/java/dev/yuzu/gca/MainActivity.kt @@ -7,8 +7,6 @@ import android.graphics.Color import android.net.Uri import android.os.Bundle import android.provider.Settings -import android.webkit.WebView -import android.webkit.WebViewClient import android.widget.Button import android.widget.LinearLayout import android.widget.ScrollView @@ -31,30 +29,87 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val wv = WebView(this).apply { - settings.javaScriptEnabled = true - settings.domStorageEnabled = true - settings.allowFileAccess = true - webViewClient = object : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { - if (url.startsWith("http")) { view.loadUrl(url); return true } - return false + val scroll = ScrollView(this) + val layout = LinearLayout(this).apply { + orientation = LinearLayout.VERTICAL + setPadding(24, 24, 24, 24) + } + + val title = TextView(this).apply { + text = "Yuzu GCA" + textSize = 20f + setPadding(0, 0, 0, 4) + } + layout.addView(title) + + val versionInfo = TextView(this).apply { + text = "v0.1.0-dav-android-5-debug" + textSize = 12f + setTextColor(Color.GRAY) + setPadding(0, 0, 0, 12) + } + layout.addView(versionInfo) + + val channelLabel = TextView(this).apply { + text = "选择更新渠道:" + textSize = 13f + setPadding(0, 8, 0, 4) + } + layout.addView(channelLabel) + + // 渠道按钮行 + val channelRow = LinearLayout(this).apply { + orientation = LinearLayout.HORIZONTAL + setPadding(0, 0, 0, 12) + } + + fun makeChannelBtn(label: String, channel: String): Button { + return Button(this).apply { + text = label + textSize = 12f + setOnClickListener { + selectedChannel = channel + highlightChannel(channelRow, this) } } - addJavascriptInterface(AndroidBridge(this@MainActivity), "Android") - loadUrl("file:///android_asset/index.html") } - setContentView(wv) - appendLog("WebView 热更新模式启动") + + val btnStable = makeChannelBtn("Stable", "stable") + val btnBeta = makeChannelBtn("Beta", "beta") + val btnNightly = makeChannelBtn("Nightly", "nightly") + + channelRow.addView(btnStable) + channelRow.addView(btnBeta) + channelRow.addView(btnNightly) + layout.addView(channelRow) + highlightChannel(channelRow, btnStable) + + logView = TextView(this).apply { + textSize = 12f + setTextColor(Color.LTGRAY) + } + layout.addView(logView) + + val btn = Button(this).apply { + text = "检查更新" + setOnClickListener { + val ch = selectedChannel + CoroutineScope(Dispatchers.IO).launch { doOtaTest(ch) } + } + } + layout.addView(btn) + + scroll.addView(layout) + setContentView(scroll) + + appendLog("渠道: stable | 点击[检查更新]开始") } - inner class AndroidBridge(private val ctx: MainActivity) { - @android.webkit.JavascriptInterface - fun checkUpdate(channel: String) { - CoroutineScope(Dispatchers.IO).launch { doOtaTest(channel) } + private fun highlightChannel(row: LinearLayout, active: Button) { + for (i in 0 until row.childCount) { + val b = row.getChildAt(i) as Button + b.isSelected = (b == active) } - @android.webkit.JavascriptInterface - fun log(msg: String) { appendLog(msg) } } private fun appendLog(msg: String) { @@ -108,15 +163,6 @@ class MainActivity : AppCompatActivity() { manifestTag = android.getString("tag") appendLog(" 渠道: $channel 版本: $manifestTag") appendLog(" SHA256: ${manifestSha256.take(16)}...") - - // 版本比较:一致则跳过 - val localTag = "v0.1.0-dav-android-${packageManager.getPackageInfo(packageName, 0).versionCode}" - if (manifestTag == localTag) { - appendLog(" ✅ 已是最新版本,无需更新") - appendLog("=== $channel 渠道测试完成 ===") - return@withContext - } - appendLog(" 发现新版本,开始更新...") } catch (e: Exception) { appendLog(" ❌ 解析失败: ${e.message}") return@withContext