File tree Expand file tree Collapse file tree
app/src/main/java/com/into/websoso/data/repository Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com.into.websoso.data.repository
22
3+ import com.into.websoso.BuildConfig
34import com.into.websoso.data.mapper.toData
45import com.into.websoso.data.model.MinimumVersionEntity
56import com.into.websoso.data.remote.api.VersionApi
@@ -8,7 +9,25 @@ import javax.inject.Inject
89class 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}
You can’t perform that action at this time.
0 commit comments