Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 버전 정보 불러오기 API 연동 #440

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId "com.hyeeyoung.wishboard"
minSdkVersion 24
targetSdkVersion 34
versionCode 39
versionName "1.2.6"
versionCode 40
versionName "1.2.7"
compileSdk 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
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
)
}
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()
}
}
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>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ abstract class RepositoryModule {

@Binds
abstract fun bindPhotoRepository(photoRepositoryImpl: PhotoRepositoryImpl): PhotoRepository

@Binds
abstract fun bindSystemRepository(systemRepositoryImpl: SystemRepositoryImpl): SystemRepository
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/hyeeyoung/wishboard/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ object ServiceModule {
@Provides
fun provideUserService(retrofit: Retrofit): UserService =
retrofit.create(UserService::class.java)

@Singleton
@Provides
fun provideSystemService(retrofit: Retrofit): SystemService =
retrofit.create(SystemService::class.java)
}
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,
)
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?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,52 @@ import android.view.View
import com.hyeeyoung.wishboard.R
import com.hyeeyoung.wishboard.databinding.DialogOneButtonBinding
import com.hyeeyoung.wishboard.presentation.base.screen.BaseDialogFragment
import com.hyeeyoung.wishboard.presentation.common.types.DialogButtonReplyType
import com.hyeeyoung.wishboard.util.DialogListener

class OneButtonDialogFragment(
private val title: String,
private val description: String?
) : BaseDialogFragment<DialogOneButtonBinding>(R.layout.dialog_one_button) {
class OneButtonDialogFragment :
BaseDialogFragment<DialogOneButtonBinding>(R.layout.dialog_one_button) {
private lateinit var listener: DialogListener

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.title.text = title
binding.description.text = description

arguments?.let {
binding.title.text = it.getString(ARG_TITLE)
binding.description.text = it.getString(ARG_DESCRIPTION)
binding.yes.text = it.getString(ARG_BUTTON_TEXT) ?: getString(R.string.confirm)
}

addListener()
}

private fun addListener() {
binding.yes.setOnClickListener {
dismiss()
listener.onButtonClicked(DialogButtonReplyType.YES.name)
}
}

fun setListener(listener: DialogListener) {
this.listener = listener
}

companion object {
private const val ARG_TITLE = "title"
private const val ARG_DESCRIPTION = "description"
private const val ARG_BUTTON_TEXT = "buttonText"

fun newInstance(
title: String,
description: String?,
buttonText: String? = null,
): OneButtonDialogFragment {
val args = Bundle().apply {
putString(ARG_TITLE, title)
putString(ARG_DESCRIPTION, description)
putString(ARG_BUTTON_TEXT, buttonText)
}

return OneButtonDialogFragment().apply { arguments = args }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.google.android.play.core.install.model.UpdateAvailability
import com.hyeeyoung.wishboard.BuildConfig
import com.hyeeyoung.wishboard.R
import com.hyeeyoung.wishboard.databinding.ActivitySplashBinding
import com.hyeeyoung.wishboard.presentation.common.screens.OneButtonDialogFragment
import com.hyeeyoung.wishboard.presentation.common.screens.TwoButtonDialogFragment
import com.hyeeyoung.wishboard.presentation.common.types.DialogButtonReplyType
import com.hyeeyoung.wishboard.presentation.main.MainActivity
Expand All @@ -28,7 +29,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

lifecycleScope.launch() {
lifecycleScope.launch {
delay(2000)
checkForNewVersionUpdate()
}
Expand All @@ -50,7 +51,17 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
&& appUpdateInfo.availableVersionCode() != BuildConfig.VERSION_CODE
) {
showUpdateDialog()
showOptionalUpdateDialog()
viewModel.checkForAppUpdate(
playStoreVersionCode = appUpdateInfo.availableVersionCode(),
moveToNext = { moveToNext() },
showUpdateDialog = { isForceUpdate ->
when (isForceUpdate) {
true -> showForceUpdateDialog()
false -> showOptionalUpdateDialog()
}
}
)
} else {
moveToNext()
}
Expand All @@ -59,7 +70,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
}
}

private fun showUpdateDialog() {
private fun showOptionalUpdateDialog() {
TwoButtonDialogFragment.newInstance(
title = getString(R.string.app_update_dialog_title),
description = getString(R.string.app_update_dialog_description),
Expand All @@ -76,6 +87,22 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
}.show(supportFragmentManager, "UpdateDialog")
}

private fun showForceUpdateDialog() {
OneButtonDialogFragment.newInstance(
title = getString(R.string.app_update_dialog_title),
description = getString(R.string.app_update_dialog_description),
buttonText = getString(R.string.app_update_dialog_yes_button_text),
).apply {
setListener(object : DialogListener {
override fun onButtonClicked(clicked: String) {
if (clicked == DialogButtonReplyType.YES.name) {
moveToPlayStore()
}
}
})
}.show(supportFragmentManager, "ForceUpdateDialog")
}

private fun moveToPlayStore() {
Intent(Intent.ACTION_VIEW).apply {
data =
Expand Down
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()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ import com.hyeeyoung.wishboard.databinding.FragmentWishBinding
import com.hyeeyoung.wishboard.designsystem.component.CustomSnackbar
import com.hyeeyoung.wishboard.domain.model.WishItemDetail
import com.hyeeyoung.wishboard.presentation.common.screens.OneButtonDialogFragment
import com.hyeeyoung.wishboard.presentation.common.types.DialogButtonReplyType
import com.hyeeyoung.wishboard.presentation.common.types.ProcessStatus
import com.hyeeyoung.wishboard.presentation.folder.screens.FolderListBottomDialogFragment
import com.hyeeyoung.wishboard.presentation.noti.screens.NotiSettingBottomDialogFragment
import com.hyeeyoung.wishboard.presentation.wishitem.WishItemStatus
import com.hyeeyoung.wishboard.presentation.wishitem.viewmodels.WishItemRegistrationViewModel
import com.hyeeyoung.wishboard.util.BaseFragment
import com.hyeeyoung.wishboard.util.DialogListener
import com.hyeeyoung.wishboard.util.FolderListDialogListener
import com.hyeeyoung.wishboard.util.extension.*
import com.hyeeyoung.wishboard.util.extension.getParcelableValue
import com.hyeeyoung.wishboard.util.extension.requestCamera
import com.hyeeyoung.wishboard.util.extension.requestSelectPicture
import com.hyeeyoung.wishboard.util.extension.showPhotoDialog
import com.hyeeyoung.wishboard.util.extension.takePicture
import com.hyeeyoung.wishboard.util.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint

Expand Down Expand Up @@ -128,6 +134,7 @@ class WishBasicFragment : BaseFragment<FragmentWishBinding>(R.layout.fragment_wi
moveToPrevious(WishItemStatus.ADDED)
}
}

else -> {}
}
}
Expand All @@ -137,10 +144,12 @@ class WishBasicFragment : BaseFragment<FragmentWishBinding>(R.layout.fragment_wi
ProcessStatus.IDLE -> {
binding.loadingLottie.visibility = View.GONE
}

ProcessStatus.IN_PROGRESS -> {
binding.loadingLottie.visibility = View.VISIBLE
binding.loadingLottie.playAnimation()
}

else -> {}
}
}
Expand All @@ -159,11 +168,18 @@ class WishBasicFragment : BaseFragment<FragmentWishBinding>(R.layout.fragment_wi
}

private fun showItemNonUpdateDialog() {
val dialog = OneButtonDialogFragment(
getString(R.string.item_non_update_dialog_title),
getString(R.string.item_non_update_dialog_description)
)
dialog.show(parentFragmentManager, "ItemNonUpdateDialog")
OneButtonDialogFragment.newInstance(
title = getString(R.string.item_non_update_dialog_title),
description = getString(R.string.item_non_update_dialog_description)
).apply {
setListener(object : DialogListener {
override fun onButtonClicked(clicked: String) {
if (clicked == DialogButtonReplyType.YES.name) {
dismiss()
}
}
})
}.show(parentFragmentManager, "ItemNonUpdateDialog")
}

private fun showFolderListDialog() {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/dialog_one_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
app:layout_constraintTop_toTopOf="parent">

<TextView
style="@style/Widget.Dialog.TextAppearance.Title"
android:id="@+id/title"
style="@style/Widget.Dialog.TextAppearance.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -48,9 +48,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/confirm"
android:textColor="@color/green_700"
app:layout_constraintTop_toBottomOf="@id/description" />
app:layout_constraintTop_toBottomOf="@id/description"
tools:text="@string/confirm" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Expand Down
Loading