Skip to content

Commit 2add763

Browse files
committed
refactor: 버전처리 및 운영체제 값 처리
1 parent 3bb10cd commit 2add763

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.into.websoso.data.repository
22

3+
import com.into.websoso.BuildConfig
34
import com.into.websoso.data.mapper.toData
45
import com.into.websoso.data.model.MinimumVersionEntity
56
import com.into.websoso.data.remote.api.VersionApi
@@ -8,7 +9,25 @@ import javax.inject.Inject
89
class VersionRepository @Inject constructor(
910
private val versionApi: VersionApi,
1011
) {
11-
suspend fun fetchMinimumVersion(): MinimumVersionEntity {
12-
return versionApi.getMinimumVersion(os = "android").toData()
12+
suspend fun isUpdateRequired(): Boolean {
13+
val currentVersionCode = BuildConfig.VERSION_CODE
14+
val minVersionCode = parseVersionCode(fetchMinimumVersion().minimumVersion)
15+
return currentVersionCode < minVersionCode
16+
}
17+
18+
private suspend fun fetchMinimumVersion(): MinimumVersionEntity {
19+
return versionApi.getMinimumVersion(os = OS).toData()
20+
}
21+
22+
private fun parseVersionCode(version: String): Int {
23+
val parts = version.split(".").map { it.toIntOrNull() ?: 0 }
24+
val major = parts.getOrNull(0) ?: 0
25+
val minor = parts.getOrNull(1) ?: 0
26+
val patch = parts.getOrNull(2) ?: 0
27+
return major * 1000000 + minor * 1000 + patch
28+
}
29+
30+
companion object {
31+
private const val OS = "android"
1332
}
1433
}

0 commit comments

Comments
 (0)