-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from hyeeyoung/dev-feat-version-check
[feat] 버전 정보 불러오기 API 연동
- Loading branch information
Showing
13 changed files
with
187 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/hyeeyoung/wishboard/data/model/system/AppVersionDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hyeeyoung.wishboard.data.model.system | ||
|
||
import com.hyeeyoung.wishboard.domain.model.system.AppVersion | ||
|
||
data class AppVersionDto( | ||
val platform: String, | ||
val minVersion: String, | ||
val recommendedVersion: String, | ||
) { | ||
fun toDomain(): AppVersion = AppVersion( | ||
minVersionCode = minVersion.toIntOrNull() ?: 0, | ||
latestVersionCode = recommendedVersion.toIntOrNull() ?: 0 | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/hyeeyoung/wishboard/data/repositories/SystemRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hyeeyoung.wishboard.data.repositories | ||
|
||
import com.hyeeyoung.wishboard.data.services.retrofit.SystemService | ||
import com.hyeeyoung.wishboard.domain.model.system.AppVersion | ||
import com.hyeeyoung.wishboard.domain.repositories.SystemRepository | ||
import javax.inject.Inject | ||
|
||
class SystemRepositoryImpl @Inject constructor(private val systemService: SystemService) : | ||
SystemRepository { | ||
override suspend fun fetchAppVersion(): Result<AppVersion?> = runCatching { | ||
systemService.fetchAppVersion().body()?.data?.toDomain() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/hyeeyoung/wishboard/data/services/retrofit/SystemService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hyeeyoung.wishboard.data.services.retrofit | ||
|
||
import com.hyeeyoung.wishboard.data.model.base.BaseResponseResult | ||
import com.hyeeyoung.wishboard.data.model.system.AppVersionDto | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface SystemService { | ||
@GET("version/check") | ||
suspend fun fetchAppVersion( | ||
@Query("osType") osType: String = "AOS" | ||
): Response<BaseResponseResult<AppVersionDto>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/hyeeyoung/wishboard/domain/model/system/AppVersionDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.hyeeyoung.wishboard.domain.model.system | ||
|
||
data class AppVersion( | ||
val minVersionCode: Int, | ||
val latestVersionCode: Int, | ||
) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/hyeeyoung/wishboard/domain/repositories/SystemRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hyeeyoung.wishboard.domain.repositories | ||
|
||
import com.hyeeyoung.wishboard.domain.model.system.AppVersion | ||
|
||
interface SystemRepository { | ||
suspend fun fetchAppVersion(): Result<AppVersion?> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/hyeeyoung/wishboard/presentation/splash/SplashViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
package com.hyeeyoung.wishboard.presentation.splash | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.hyeeyoung.wishboard.BuildConfig | ||
import com.hyeeyoung.wishboard.data.local.WishBoardPreference | ||
import com.hyeeyoung.wishboard.domain.repositories.SystemRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val localStorage: WishBoardPreference, | ||
private val systemRepository: SystemRepository, | ||
) : ViewModel() { | ||
fun isLogin() = localStorage.isLogin | ||
|
||
fun checkForAppUpdate( | ||
playStoreVersionCode: Int, | ||
moveToNext: () -> Unit, | ||
showUpdateDialog: (isForceUpdate: Boolean) -> Unit | ||
) { | ||
viewModelScope.launch { | ||
systemRepository.fetchAppVersion().onSuccess { remoteVersion -> | ||
if (remoteVersion == null) { | ||
moveToNext() | ||
return@launch | ||
} | ||
|
||
when { | ||
BuildConfig.VERSION_CODE < playStoreVersionCode -> { | ||
showUpdateDialog(BuildConfig.VERSION_CODE < remoteVersion.minVersionCode) | ||
} | ||
|
||
else -> { | ||
moveToNext() | ||
} | ||
} | ||
}.onFailure { | ||
moveToNext() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters