Skip to content

Commit c35fa57

Browse files
committed
Refactor: 앱 버전 관리를 app 모듈로 이전
- AndroidApplicationVersionNameProvider 삭제 (BuildConfig 직접 참조 제거) - PackageManagerVersionNameProvider 추가: PackageManager로 런타임에 버전명 조회 - AppVersionModule 추가: app BuildConfig의 버전 정수를 @nAmed로 제공 - VersionDataSourceImpl: BuildConfig 직접 참조 → @nAmed 주입 방식으로 변경 - PlayStoreUtils: BuildConfig.APPLICATION_ID → activity.packageName으로 변경 - data, presentation 모듈의 불필요한 buildConfig 블록 제거
1 parent 482e60a commit c35fa57

8 files changed

Lines changed: 60 additions & 41 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.threegap.bitnagil.di.data
2+
3+
import com.threegap.bitnagil.BuildConfig
4+
import dagger.Module
5+
import dagger.Provides
6+
import dagger.hilt.InstallIn
7+
import dagger.hilt.components.SingletonComponent
8+
import javax.inject.Named
9+
10+
@Module
11+
@InstallIn(SingletonComponent::class)
12+
object AppVersionModule {
13+
14+
@Provides
15+
@Named("versionMajor")
16+
fun provideVersionMajor(): Int = BuildConfig.VERSION_MAJOR
17+
18+
@Provides
19+
@Named("versionMinor")
20+
fun provideVersionMinor(): Int = BuildConfig.VERSION_MINOR
21+
22+
@Provides
23+
@Named("versionPatch")
24+
fun provideVersionPatch(): Int = BuildConfig.VERSION_PATCH
25+
}

app/src/main/java/com/threegap/bitnagil/di/presentation/VersionNameProviderModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.threegap.bitnagil.di.presentation
22

3-
import com.threegap.bitnagil.presentation.util.version.AndroidApplicationVersionNameProvider
43
import com.threegap.bitnagil.presentation.util.version.VersionNameProvider
4+
import com.threegap.bitnagil.util.version.PackageManagerVersionNameProvider
55
import dagger.Binds
66
import dagger.Module
77
import dagger.hilt.InstallIn
@@ -13,5 +13,5 @@ import javax.inject.Singleton
1313
abstract class VersionNameProviderModule {
1414
@Binds
1515
@Singleton
16-
abstract fun bindVersionNameProvider(androidApplicationVersionNameProvider: AndroidApplicationVersionNameProvider): VersionNameProvider
16+
abstract fun bindVersionNameProvider(impl: PackageManagerVersionNameProvider): VersionNameProvider
1717
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.threegap.bitnagil.util.version
2+
3+
import android.content.Context
4+
import com.threegap.bitnagil.presentation.util.version.VersionNameProvider
5+
import dagger.hilt.android.qualifiers.ApplicationContext
6+
import javax.inject.Inject
7+
8+
class PackageManagerVersionNameProvider @Inject constructor(
9+
@param:ApplicationContext private val context: Context,
10+
) : VersionNameProvider {
11+
override fun getVersionName(): String =
12+
context.packageManager.getPackageInfo(context.packageName, 0).versionName.orEmpty()
13+
}

data/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
plugins {
22
alias(libs.plugins.bitnagil.android.library)
33
alias(libs.plugins.bitnagil.android.hilt)
4-
alias(libs.plugins.kotlin.serialization)
4+
alias(libs.plugins.bitnagil.kotlin.serialization)
55
}
66

77
android {
8-
namespace = "com.threegap.bitnagil.data"
98
}
109

1110
dependencies {
1211
implementation(projects.core.network)
1312
implementation(projects.core.datastore)
1413
implementation(projects.domain)
1514

16-
implementation(libs.kotlinx.serialization.json)
1715
implementation(platform(libs.okhttp.bom))
1816
implementation(libs.bundles.okhttp)
1917
implementation(platform(libs.retrofit.bom))
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.threegap.bitnagil.data.version.datasourceImpl
22

3-
import com.threegap.bitnagil.data.BuildConfig
43
import com.threegap.bitnagil.data.version.datasource.VersionDataSource
54
import com.threegap.bitnagil.data.version.model.response.VersionCheckResponse
65
import com.threegap.bitnagil.data.version.service.VersionService
76
import javax.inject.Inject
7+
import javax.inject.Named
88

99
class VersionDataSourceImpl @Inject constructor(
1010
private val versionService: VersionService,
11+
@param:Named("versionMajor") private val majorVersion: Int,
12+
@param:Named("versionMinor") private val minorVersion: Int,
13+
@param:Named("versionPatch") private val patchVersion: Int,
1114
) : VersionDataSource {
1215

1316
override suspend fun checkVersion(): Result<VersionCheckResponse> =
1417
versionService.checkVersion(
15-
majorVersion = BuildConfig.VERSION_MAJOR,
16-
minorVersion = BuildConfig.VERSION_MINOR,
17-
patchVersion = BuildConfig.VERSION_PATCH,
18+
majorVersion = majorVersion,
19+
minorVersion = minorVersion,
20+
patchVersion = patchVersion,
1821
)
1922
}

presentation/build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ plugins {
22
alias(libs.plugins.bitnagil.android.library)
33
alias(libs.plugins.bitnagil.android.compose.library)
44
alias(libs.plugins.bitnagil.android.hilt)
5-
alias(libs.plugins.kotlin.parcelize)
6-
alias(libs.plugins.kotlin.serialization)
7-
}
8-
9-
android {
10-
namespace = "com.threegap.bitnagil.presentation"
5+
alias(libs.plugins.bitnagil.kotlin.parcelize)
6+
alias(libs.plugins.bitnagil.kotlin.serialization)
117
}
128

139
dependencies {
@@ -17,7 +13,6 @@ dependencies {
1713
implementation(libs.bundles.androidx.core)
1814
implementation(libs.bundles.orbit)
1915
implementation(libs.kakao.v2.user)
20-
implementation(libs.kotlinx.serialization.json)
2116
implementation(libs.lottie.compose)
2217
implementation(libs.bundles.coil)
2318
implementation(libs.accompanist.permissions)

presentation/src/main/java/com/threegap/bitnagil/presentation/util/playstore/PlayStoreUtils.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ import androidx.lifecycle.lifecycleScope
1616
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
1717
import com.google.android.play.core.install.model.AppUpdateType
1818
import com.google.android.play.core.install.model.UpdateAvailability
19-
import com.threegap.bitnagil.presentation.BuildConfig
2019
import kotlinx.coroutines.delay
2120
import kotlinx.coroutines.launch
2221
import kotlinx.coroutines.suspendCancellableCoroutine
2322
import kotlin.coroutines.resume
2423
import kotlin.system.exitProcess
2524

26-
private const val PACKAGE_NAME = BuildConfig.APPLICATION_ID
2725
private const val GOOGLE_PLAY_PACKAGE = "com.android.vending"
2826
private const val APP_EXIT_DELAY = 500L
2927

@@ -32,45 +30,46 @@ fun openAppInPlayStore(
3230
shouldFinishApp: Boolean = true,
3331
) {
3432
activity?.let {
35-
val isSuccess = tryOpenPlayStore(it) || tryOpenWebBrowser(it)
33+
val packageName = it.packageName
34+
val isSuccess = tryOpenPlayStore(it, packageName) || tryOpenWebBrowser(it, packageName)
3635

3736
if (isSuccess && shouldFinishApp) {
3837
finishAppWithDelay(it)
3938
}
4039
}
4140
}
4241

43-
private fun tryOpenPlayStore(activity: ComponentActivity): Boolean =
42+
private fun tryOpenPlayStore(activity: ComponentActivity, packageName: String): Boolean =
4443
try {
45-
val intent = createPlayStoreIntent()
44+
val intent = createPlayStoreIntent(packageName)
4645
activity.startActivity(intent)
4746
true
4847
} catch (e: ActivityNotFoundException) {
4948
false
5049
}
5150

52-
private fun tryOpenWebBrowser(activity: ComponentActivity): Boolean =
51+
private fun tryOpenWebBrowser(activity: ComponentActivity, packageName: String): Boolean =
5352
try {
54-
val intent = createWebIntent()
53+
val intent = createWebIntent(packageName)
5554
activity.startActivity(intent)
5655
true
5756
} catch (e: Exception) {
5857
false
5958
}
6059

61-
private fun createPlayStoreIntent(): Intent =
60+
private fun createPlayStoreIntent(packageName: String): Intent =
6261
Intent(
6362
Intent.ACTION_VIEW,
64-
"market://details?id=$PACKAGE_NAME".toUri(),
63+
"market://details?id=$packageName".toUri(),
6564
).apply {
6665
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
6766
setPackage(GOOGLE_PLAY_PACKAGE)
6867
}
6968

70-
private fun createWebIntent(): Intent =
69+
private fun createWebIntent(packageName: String): Intent =
7170
Intent(
7271
Intent.ACTION_VIEW,
73-
"https://play.google.com/store/apps/details?id=$PACKAGE_NAME".toUri(),
72+
"https://play.google.com/store/apps/details?id=$packageName".toUri(),
7473
).apply {
7574
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
7675
}

presentation/src/main/java/com/threegap/bitnagil/presentation/util/version/AndroidApplicationVersionNameProvider.kt

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)