-
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.
Browse files
Browse the repository at this point in the history
…lf-version-update-notification #273 [feat] 앱 버전이 맞지 않을 경우, 업데이트 화면 뜨게 하기
- Loading branch information
Showing
18 changed files
with
330 additions
and
2 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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/sopt/peekabookaos/data/entity/response/VersionResponse.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,20 @@ | ||
package com.sopt.peekabookaos.data.entity.response | ||
|
||
import com.sopt.peekabookaos.domain.entity.Version | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class VersionResponse( | ||
val imageUrl: String, | ||
val iosForceVersion: String, | ||
val androidForceVersion: String, | ||
@SerialName("text") | ||
val versionText: String | ||
) { | ||
fun toVersion(): Version = Version( | ||
imageUrl = this.imageUrl, | ||
androidForceVersion = this.androidForceVersion, | ||
versionText = this.versionText | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopt/peekabookaos/data/repository/ForceUpdateRepositoryImpl.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,15 @@ | ||
package com.sopt.peekabookaos.data.repository | ||
|
||
import com.sopt.peekabookaos.data.source.remote.ForceUpdateDataSource | ||
import com.sopt.peekabookaos.domain.entity.Version | ||
import com.sopt.peekabookaos.domain.repository.ForceUpdateRepository | ||
import javax.inject.Inject | ||
|
||
class ForceUpdateRepositoryImpl @Inject constructor( | ||
private val forceUpdateDataSource: ForceUpdateDataSource | ||
) : ForceUpdateRepository { | ||
override suspend fun getVersion(): Result<Version> = | ||
kotlin.runCatching { forceUpdateDataSource.getVersion() }.map { response -> | ||
requireNotNull(response.data).toVersion() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/peekabookaos/data/service/ForceUpdateService.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,10 @@ | ||
package com.sopt.peekabookaos.data.service | ||
|
||
import com.sopt.peekabookaos.data.entity.BaseResponse | ||
import com.sopt.peekabookaos.data.entity.response.VersionResponse | ||
import retrofit2.http.GET | ||
|
||
interface ForceUpdateService { | ||
@GET("user/v1/version") | ||
suspend fun getVersion(): BaseResponse<VersionResponse> | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/sopt/peekabookaos/data/source/remote/ForceUpdateDataSource.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.sopt.peekabookaos.data.source.remote | ||
|
||
import com.sopt.peekabookaos.data.entity.BaseResponse | ||
import com.sopt.peekabookaos.data.entity.response.VersionResponse | ||
import com.sopt.peekabookaos.data.service.ForceUpdateService | ||
import javax.inject.Inject | ||
|
||
class ForceUpdateDataSource @Inject constructor( | ||
private val forceUpdateService: ForceUpdateService | ||
) { | ||
suspend fun getVersion(): BaseResponse<VersionResponse> = | ||
forceUpdateService.getVersion() | ||
} |
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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopt/peekabookaos/domain/entity/Version.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,11 @@ | ||
package com.sopt.peekabookaos.domain.entity | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class Version( | ||
val imageUrl: String = "", | ||
val androidForceVersion: String = "", | ||
val versionText: String = "" | ||
) : Parcelable |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/sopt/peekabookaos/domain/entity/VersionDetail.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.sopt.peekabookaos.domain.entity | ||
|
||
data class VersionDetail( | ||
val major: String, | ||
val minor: String | ||
) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/sopt/peekabookaos/domain/entity/VersionState.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,5 @@ | ||
package com.sopt.peekabookaos.domain.entity | ||
|
||
enum class VersionState { | ||
LATEST, OUTDATED | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/peekabookaos/domain/repository/ForceUpdateRepository.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.sopt.peekabookaos.domain.repository | ||
|
||
import com.sopt.peekabookaos.domain.entity.Version | ||
|
||
interface ForceUpdateRepository { | ||
suspend fun getVersion(): Result<Version> | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/peekabookaos/domain/usecase/GetVersionUseCase.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,10 @@ | ||
package com.sopt.peekabookaos.domain.usecase | ||
|
||
import com.sopt.peekabookaos.domain.repository.ForceUpdateRepository | ||
import javax.inject.Inject | ||
|
||
class GetVersionUseCase @Inject constructor( | ||
private val forceUpdateRepository: ForceUpdateRepository | ||
) { | ||
suspend operator fun invoke() = forceUpdateRepository.getVersion() | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/sopt/peekabookaos/presentation/forceUpdate/ForceUpdateActivity.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,40 @@ | ||
package com.sopt.peekabookaos.presentation.forceUpdate | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import com.sopt.peekabookaos.R | ||
import com.sopt.peekabookaos.databinding.ActivityForceUpdateBinding | ||
import com.sopt.peekabookaos.domain.entity.Version | ||
import com.sopt.peekabookaos.presentation.splash.SplashActivity.Companion.LATEST_VERSION | ||
import com.sopt.peekabookaos.util.binding.BindingActivity | ||
import com.sopt.peekabookaos.util.extensions.getParcelable | ||
|
||
class ForceUpdateActivity : | ||
BindingActivity<ActivityForceUpdateBinding>(R.layout.activity_force_update) { | ||
private lateinit var intentToPlayStore: Intent | ||
private val viewModel by viewModels<ForceUpdateViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding.viewModel = viewModel | ||
getLatestVersion() | ||
initUpdateBtnClickListener() | ||
} | ||
|
||
private fun initUpdateBtnClickListener() { | ||
binding.btnForceUpdate.setOnClickListener { | ||
intentToPlayStore = Intent( | ||
Intent.ACTION_VIEW, | ||
Uri.parse(getString(R.string.force_update_store_link)) | ||
) | ||
startActivity(intentToPlayStore) | ||
} | ||
} | ||
|
||
private fun getLatestVersion() { | ||
intent.getParcelable(LATEST_VERSION, Version::class.java) | ||
?.let { viewModel.getLatestVersion(it) } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopt/peekabookaos/presentation/forceUpdate/ForceUpdateViewModel.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,15 @@ | ||
package com.sopt.peekabookaos.presentation.forceUpdate | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.sopt.peekabookaos.domain.entity.Version | ||
|
||
class ForceUpdateViewModel : ViewModel() { | ||
private val _latestVersion: MutableLiveData<Version> = MutableLiveData() | ||
val latestVersion: LiveData<Version> = _latestVersion | ||
|
||
fun getLatestVersion(version: Version) { | ||
_latestVersion.value = version | ||
} | ||
} |
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
53 changes: 52 additions & 1 deletion
53
app/src/main/java/com/sopt/peekabookaos/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,14 +1,65 @@ | ||
package com.sopt.peekabookaos.presentation.splash | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.sopt.peekabookaos.BuildConfig | ||
import com.sopt.peekabookaos.domain.entity.SplashState | ||
import com.sopt.peekabookaos.domain.entity.Version | ||
import com.sopt.peekabookaos.domain.entity.VersionDetail | ||
import com.sopt.peekabookaos.domain.entity.VersionState | ||
import com.sopt.peekabookaos.domain.usecase.GetSplashStateUseCase | ||
import com.sopt.peekabookaos.domain.usecase.GetVersionUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val getSplashStateUseCase: GetSplashStateUseCase | ||
private val getSplashStateUseCase: GetSplashStateUseCase, | ||
private val getVersionUseCase: GetVersionUseCase | ||
) : ViewModel() { | ||
private val _latestVersion: MutableLiveData<Version> = MutableLiveData() | ||
val latestVersion: LiveData<Version> = _latestVersion | ||
private lateinit var latestVersionDetail: VersionDetail | ||
private lateinit var appVersionDetail: VersionDetail | ||
|
||
init { | ||
getVersion() | ||
} | ||
|
||
fun getSplashState(): SplashState = getSplashStateUseCase() | ||
|
||
fun checkUpdateVersion(): VersionState { | ||
latestVersionDetail = | ||
spiltVersionToMajorMinor(requireNotNull(latestVersion.value?.androidForceVersion) { "version is null" }) | ||
appVersionDetail = spiltVersionToMajorMinor(BuildConfig.VERSION_NAME) | ||
return if (appVersionDetail.major != latestVersionDetail.major || appVersionDetail.minor != latestVersionDetail.minor) VersionState.OUTDATED | ||
else VersionState.LATEST | ||
} | ||
|
||
private fun spiltVersionToMajorMinor(versionName: String): VersionDetail { | ||
val versionSpiltList = versionName.split(".") | ||
val major = versionSpiltList[0] | ||
val minor = versionSpiltList[1] | ||
return VersionDetail(major, minor) | ||
} | ||
|
||
private fun getVersion() { | ||
viewModelScope.launch { | ||
getVersionUseCase() | ||
.onSuccess { response -> | ||
_latestVersion.value = Version( | ||
response.imageUrl, | ||
response.androidForceVersion, | ||
response.versionText | ||
) | ||
} | ||
.onFailure { throwable -> | ||
Timber.e("$throwable") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.