diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 041ff75..25498e4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,8 +20,9 @@ android { applicationId = "com.example.shiftalarm" minSdk = 26 targetSdk = 35 - versionCode = 1125 - versionName = "1.2.5" + versionCode = 1130 + versionName = "1.3.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 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",