Skip to content

Commit

Permalink
feat(themes): splash 화면 생성 및 버전 체크
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Apr 7, 2024
1 parent 68a1a1e commit a2609ab
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 8 deletions.
4 changes: 2 additions & 2 deletions android/festago/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/Theme.Festago"
android:theme="@style/Base.Theme.Festago"
android:usesCleartextTraffic="true"
tools:targetApi="31">
tools:targetApi="34">
</application>

</manifest>
18 changes: 12 additions & 6 deletions android/festago/presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

<application>
<activity
android:name=".ui.notificationlist.NotificationListActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.home.HomeActivity"
android:name=".ui.splash.SplashActivity"
android:exported="true"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:theme="@style/Base.Theme.Festago">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.notificationlist.NotificationListActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.home.HomeActivity"
android:exported="false"
android:screenOrientation="portrait" />
</application>

</manifest>
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"
}
}
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>
12 changes: 12 additions & 0 deletions android/festago/presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@
<string name="search_tv_no_result">앗! 검색 결과가 없네요</string>
<string name="search_tv_no_result_guide">찾으시는 정보가 없다면 저희에게 알려주세요</string>
<string name="search_tv_request_add">추가 요청하러 가기</string>

<!-- String related to splash -->
<string name="splash_app_update_request_dialog_title">업데이트 알림</string>
<string name="splash_app_update_request_dialog_message">새로운 페스타고를 사용하기 위해 업데이트 해주세요!</string>
<string name="splash_app_update_denied">업데이트 후 정상 사용가능합니다.</string>
<string name="splash_app_default_error_message">페스타고 실행 중 문제가 발생했습니다. 페스타고로 문의해주세요.</string>

<!-- Strings related to ok dialog -->
<string name="ok_dialog_btn_ok">확인</string>
<string name="ok_dialog_btn_update">업데이트</string>
<string name="ok_dialog_btn_cancel">취소</string>

</resources>

0 comments on commit a2609ab

Please sign in to comment.