-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68a1a1e
commit a2609ab
Showing
5 changed files
with
172 additions
and
8 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
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
129 changes: 129 additions & 0 deletions
129
...o/presentation/src/main/java/com/festago/festago/presentation/ui/splash/SplashActivity.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,129 @@ | ||
package com.festago.festago.presentation.ui.splash | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.AlertDialog | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.activity.ComponentActivity | ||
import androidx.core.splashscreen.SplashScreen | ||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
import com.festago.festago.presentation.BuildConfig | ||
import com.festago.festago.presentation.R | ||
import com.festago.festago.presentation.databinding.ActivitySplashBinding | ||
import com.festago.festago.presentation.ui.home.HomeActivity | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings | ||
import com.kakao.sdk.common.KakaoSdk | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@SuppressLint("CustomSplashScreen") | ||
@AndroidEntryPoint | ||
class SplashActivity : ComponentActivity() { | ||
|
||
private val binding by lazy { ActivitySplashBinding.inflate(layoutInflater) } | ||
private val firebaseRemoteConfig by lazy { FirebaseRemoteConfig.getInstance() } | ||
private lateinit var splashScreen: SplashScreen | ||
private val configSettings by lazy { | ||
FirebaseRemoteConfigSettings.Builder() | ||
.setMinimumFetchIntervalInSeconds(if (BuildConfig.DEBUG) DEBUG_REMOTE_CONFIG_FETCH_INTERVAL else RELEASE_REMOTE_CONFIG_FETCH_INTERVAL) | ||
.build() | ||
} | ||
|
||
init { | ||
firebaseRemoteConfig.setConfigSettingsAsync(configSettings) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
splashScreen = installSplashScreen() | ||
splashScreen.setKeepOnScreenCondition { true } | ||
initKakaoSdk() | ||
setContentView(binding.root) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
checkAppUpdate() | ||
} | ||
|
||
private fun initKakaoSdk() { | ||
KakaoSdk.init(this.applicationContext, BuildConfig.KAKAO_NATIVE_APP_KEY) | ||
} | ||
|
||
private fun checkAppUpdate() { | ||
firebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(this) { | ||
if (it.isSuccessful) { | ||
val isCurrentVersion = firebaseRemoteConfig.getBoolean(KEY_IS_CURRENT_VERSION) | ||
if (isCurrentVersion) { | ||
navigateToHome() | ||
return@addOnCompleteListener | ||
} | ||
splashScreen.setKeepOnScreenCondition { false } | ||
requestUpdate() | ||
} | ||
} | ||
} | ||
|
||
private fun requestUpdate() { | ||
val forceUpdate = firebaseRemoteConfig.getBoolean(KEY_FORCE_UPDATE_REQUIRED) | ||
val currentVersionDescription = | ||
firebaseRemoteConfig.getString(KEY_CURRENT_VERSION_DESCRIPTION) | ||
if (forceUpdate) { | ||
requestForceUpdate(message = currentVersionDescription) | ||
return | ||
} | ||
requestOptionalUpdate(message = currentVersionDescription) | ||
} | ||
|
||
private fun requestOptionalUpdate(message: String) { | ||
alertUpdate(update = ::handleUpdate, cancel = ::navigateToHome, message) | ||
} | ||
|
||
private fun requestForceUpdate(message: String) { | ||
alertUpdate(update = ::handleUpdate, cancel = ::handleCancelForceUpdate, message) | ||
} | ||
|
||
private fun handleUpdate() { | ||
navigateToAppStore() | ||
finish() | ||
} | ||
|
||
private fun navigateToHome() { | ||
startActivity(HomeActivity.getIntent(this)) | ||
finish() | ||
} | ||
|
||
private fun navigateToAppStore() { | ||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))) | ||
finish() | ||
} | ||
|
||
private fun alertUpdate(update: () -> Unit, cancel: () -> Unit, message: String) { | ||
AlertDialog.Builder(this).apply { | ||
setTitle(getString(R.string.splash_app_update_request_dialog_title)) | ||
setMessage(message) | ||
setPositiveButton(R.string.ok_dialog_btn_update) { _, _ -> update() } | ||
setNegativeButton(R.string.ok_dialog_btn_cancel) { _, _ -> cancel() } | ||
setCancelable(false) | ||
}.show() | ||
} | ||
|
||
private fun handleCancelForceUpdate() { | ||
Toast.makeText( | ||
this@SplashActivity, | ||
getString(R.string.splash_app_update_denied), | ||
Toast.LENGTH_SHORT, | ||
).show() | ||
finish() | ||
} | ||
|
||
companion object { | ||
private const val DEBUG_REMOTE_CONFIG_FETCH_INTERVAL = 0L | ||
private const val RELEASE_REMOTE_CONFIG_FETCH_INTERVAL = 3600L | ||
private const val KEY_FORCE_UPDATE_REQUIRED = "FORCE_UPDATE_REQUIRED" | ||
private const val KEY_IS_CURRENT_VERSION = "IS_CURRENT_VERSION" | ||
private const val KEY_CURRENT_VERSION_DESCRIPTION = "CURRENT_VERSION_DESCRIPTION" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
android/festago/presentation/src/main/res/layout/activity_splash.xml
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/background_gray_01" | ||
tools:context=".ui.splash.SplashActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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