From 26fb793ab92d244d0aaf583af4141a7935005755 Mon Sep 17 00:00:00 2001 From: sanjeok77 Date: Sat, 28 Feb 2026 18:50:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20v1.3.0=20-=20versionCode=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 버전 1.2.5 → 1.3.0 (versionCode 1130) - AppUpdateManager: versionCode로 업데이트 비교 - versionName 비교 로직 제거 - 더 정확한 업데이트 감지 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- app/build.gradle.kts | 3 +- .../example/shiftalarm/AppUpdateManager.kt | 32 +++++-------------- version.json | 6 ++++ 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 041ff75..539f961 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,7 +20,8 @@ android { applicationId = "com.example.shiftalarm" minSdk = 26 targetSdk = 35 - versionCode = 1125 + versionCode = 1130 + versionName = "1.3.0" versionName = "1.2.5" diff --git a/app/src/main/java/com/example/shiftalarm/AppUpdateManager.kt b/app/src/main/java/com/example/shiftalarm/AppUpdateManager.kt index aecc693..45ff2e8 100644 --- a/app/src/main/java/com/example/shiftalarm/AppUpdateManager.kt +++ b/app/src/main/java/com/example/shiftalarm/AppUpdateManager.kt @@ -39,14 +39,21 @@ object AppUpdateManager { reader.close() val json = JSONObject(result) + val serverVersionCode = json.getInt("versionCode") val serverVersionName = json.getString("versionName") val apkUrl = json.getString("apkUrl") val changelog = json.optString("changelog", "버그 수정 및 성능 향상") val pInfo = ctx.packageManager.getPackageInfo(ctx.packageName, 0) + val currentVersionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + pInfo.longVersionCode.toInt() + } else { + @Suppress("DEPRECATION") + pInfo.versionCode + } val currentVersionName = pInfo.versionName ?: "0.0.0" - if (isNewerVersion(serverVersionName, currentVersionName)) { + if (serverVersionCode > currentVersionCode) { activity.runOnUiThread { showUpdateDialog(activity, serverVersionName, changelog, apkUrl) } @@ -71,29 +78,6 @@ object AppUpdateManager { }.start() } - private fun isNewerVersion(server: String, current: String): Boolean { - try { - // Clean version strings (remove non-numeric suffixes if any) - val sClean = server.split("-")[0].split(" ")[0] - val cClean = current.split("-")[0].split(" ")[0] - - val sParts = sClean.split(".").map { it.filter { char -> char.isDigit() }.let { p -> if (p.isEmpty()) 0 else p.toInt() } } - val cParts = cClean.split(".").map { it.filter { char -> char.isDigit() }.let { p -> if (p.isEmpty()) 0 else p.toInt() } } - - val length = Math.max(sParts.size, cParts.size) - for (i in 0 until length) { - val s = if (i < sParts.size) sParts[i] else 0 - val c = if (i < cParts.size) cParts[i] else 0 - if (s > c) return true - if (s < c) return false - } - } catch (e: Exception) { - android.util.Log.e("AppUpdateManager", "Version comparison failed: ${e.message}") - return false - } - return false - } - private fun showUpdateDialog(activity: Activity, version: String, changelog: String, apkUrl: String) { com.google.android.material.dialog.MaterialAlertDialogBuilder(activity) .setTitle("새로운 업데이트 발견 (v$version)") diff --git a/version.json b/version.json index c0177ba..3dd9317 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,10 @@ { + "versionCode": 1130, + "versionName": "1.3.0", + "apkUrl": "https://git.webpluss.net/sanjeok77/ShiftRing/releases/download/v1.3.0/app.apk", + "changelog": "v1.3.0: versionCode 기반 업데이트 체크 개선", + "forceUpdate": false +} "versionCode": 1125, "versionName": "1.2.5", "apkUrl": "https://git.webpluss.net/sanjeok77/ShiftRing/releases/download/v1.2.5/app.apk",