Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26fb793ab9 |
@@ -20,7 +20,8 @@ android {
|
|||||||
applicationId = "com.example.shiftalarm"
|
applicationId = "com.example.shiftalarm"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 1125
|
versionCode = 1130
|
||||||
|
versionName = "1.3.0"
|
||||||
versionName = "1.2.5"
|
versionName = "1.2.5"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,14 +39,21 @@ object AppUpdateManager {
|
|||||||
reader.close()
|
reader.close()
|
||||||
|
|
||||||
val json = JSONObject(result)
|
val json = JSONObject(result)
|
||||||
|
val serverVersionCode = json.getInt("versionCode")
|
||||||
val serverVersionName = json.getString("versionName")
|
val serverVersionName = json.getString("versionName")
|
||||||
val apkUrl = json.getString("apkUrl")
|
val apkUrl = json.getString("apkUrl")
|
||||||
val changelog = json.optString("changelog", "버그 수정 및 성능 향상")
|
val changelog = json.optString("changelog", "버그 수정 및 성능 향상")
|
||||||
|
|
||||||
val pInfo = ctx.packageManager.getPackageInfo(ctx.packageName, 0)
|
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"
|
val currentVersionName = pInfo.versionName ?: "0.0.0"
|
||||||
|
|
||||||
if (isNewerVersion(serverVersionName, currentVersionName)) {
|
if (serverVersionCode > currentVersionCode) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
showUpdateDialog(activity, serverVersionName, changelog, apkUrl)
|
showUpdateDialog(activity, serverVersionName, changelog, apkUrl)
|
||||||
}
|
}
|
||||||
@@ -71,29 +78,6 @@ object AppUpdateManager {
|
|||||||
}.start()
|
}.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) {
|
private fun showUpdateDialog(activity: Activity, version: String, changelog: String, apkUrl: String) {
|
||||||
com.google.android.material.dialog.MaterialAlertDialogBuilder(activity)
|
com.google.android.material.dialog.MaterialAlertDialogBuilder(activity)
|
||||||
.setTitle("새로운 업데이트 발견 (v$version)")
|
.setTitle("새로운 업데이트 발견 (v$version)")
|
||||||
|
|||||||
@@ -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,
|
"versionCode": 1125,
|
||||||
"versionName": "1.2.5",
|
"versionName": "1.2.5",
|
||||||
"apkUrl": "https://git.webpluss.net/sanjeok77/ShiftRing/releases/download/v1.2.5/app.apk",
|
"apkUrl": "https://git.webpluss.net/sanjeok77/ShiftRing/releases/download/v1.2.5/app.apk",
|
||||||
|
|||||||
Reference in New Issue
Block a user