Skip to content

Commit

Permalink
[AN/USER] feat: 인앱 업데이트 적용 및 스플래시 화면 구현 (#525) (#528)
Browse files Browse the repository at this point in the history
* feat: 인앱 업데이트 및 스플래시 의존성 추가

* feat: 스플래시 themes 추가

* feat: 업데이트 메세지 상수화

* feat: 스플래시 화면 구현 및 업데이트 확인 적용

* feat: 배경 화면을 하얀색으로 변경

* fix: 플레이스토어 문제 해결

* refactor: splashScreen 코드 리팩터링

* refactor: splash 코드 리팩터링
  • Loading branch information
SeongHoonC authored Oct 12, 2023
1 parent a5193e5 commit 45fb77c
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 10 deletions.
10 changes: 8 additions & 2 deletions android/festago/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ plugins {

android {
namespace = "com.festago.festago"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "com.festago.festago"
minSdk = 28
targetSdk = 33
targetSdk = 34
versionCode = 3
versionName = "1.0.1"

Expand Down Expand Up @@ -152,6 +152,12 @@ dependencies {

// turbine
testImplementation("app.cash.turbine:turbine:1.0.0")

// inApp Update
implementation("com.google.android.play:app-update-ktx:2.1.0")

// splash
implementation("androidx.core:core-splashscreen:1.1.0-alpha02")
}

fun getSecretKey(propertyKey: String): String {
Expand Down
19 changes: 11 additions & 8 deletions android/festago/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
android:theme="@style/Theme.Festago"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.ui.splash.SplashActivity"
android:exported="true"
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".presentation.ui.selectschool.SelectSchoolActivity"
android:exported="false" />
Expand All @@ -31,13 +41,7 @@
android:exported="false" />
<activity
android:name=".presentation.ui.home.HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:exported="false" />
<activity
android:name=".presentation.ui.ticketreserve.TicketReserveActivity"
android:exported="false" />
Expand Down Expand Up @@ -69,7 +73,6 @@
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>

</service>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.festago.festago.presentation.ui.splash

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AlertDialog
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.festago.festago.R
import com.festago.festago.databinding.ActivitySplashBinding
import com.festago.festago.presentation.ui.home.HomeActivity
import com.google.android.play.core.appupdate.AppUpdateInfo
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.hilt.android.AndroidEntryPoint

@SuppressLint("CustomSplashScreen")
@AndroidEntryPoint
class SplashActivity : ComponentActivity() {

val binding by lazy {
ActivitySplashBinding.inflate(layoutInflater)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val splashScreen = installSplashScreen()
splashScreen.setKeepOnScreenCondition { true }
checkAppUpdate(splashScreen)
setContentView(binding.root)
}

private fun checkAppUpdate(splashScreen: SplashScreen) {
val appUpdateManager = AppUpdateManagerFactory.create(this)
appUpdateManager.appUpdateInfo
.addOnSuccessListener { appUpdateInfo ->
handleOnSuccess(appUpdateInfo, splashScreen)
}.addOnFailureListener {
showHome()
}
}

private fun handleOnSuccess(appUpdateInfo: AppUpdateInfo, splashScreen: SplashScreen) {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
splashScreen.setKeepOnScreenCondition { false }
requestUpdate()
} else {
showHome()
}
}

private fun showHome() {
startActivity(HomeActivity.getIntent(this))
finish()
}

private fun requestUpdate() {
AlertDialog.Builder(this).apply {
setTitle(getString(R.string.splash_app_update_request_dialog_title))
setMessage(getString(R.string.splash_app_update_request_dialog_message))
setNegativeButton(R.string.ok_dialog_btn_cancel) { _, _ ->
handleCancelUpdate()
}
setPositiveButton(R.string.ok_dialog_btn_ok) { _, _ ->
handleOkUpdate()
}
setCancelable(false)
}.show()
}

private fun handleCancelUpdate() {
Toast.makeText(
this@SplashActivity,
getString(R.string.splash_app_update_denied),
Toast.LENGTH_SHORT,
).show()
finish()
}

private fun handleOkUpdate() {
navigateToAppStore()
finish()
}

private fun navigateToAppStore() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")))
finish()
}
}
15 changes: 15 additions & 0 deletions android/festago/app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.ui.splash.SplashActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
9 changes: 9 additions & 0 deletions android/festago/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
<item name="colorOnSurfaceVariant">@color/md_theme_dark_onSurfaceVariant</item>
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
</style>

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/black</item>

<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_festago_logo</item>
<item name="windowSplashScreenAnimationDuration">1000</item>

<item name="postSplashScreenTheme">@style/Base.Theme.Festago</item>
</style>
</resources>
7 changes: 7 additions & 0 deletions android/festago/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<string name="all_ticket_type_visitor">방문객용</string>
<string name="all_ticket_type_other">기타</string>

<!-- 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 main -->
<string name="main_btn_ticket_disable_time">HH:mm 티켓 활성화</string>
<string name="main_btn_ticket_enable_time">티켓 제시</string>
Expand Down Expand Up @@ -70,6 +76,7 @@

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

<!-- Strings related to mypage -->
<string name="mypage_btn_kakao">카카오로 로그인</string>
Expand Down
11 changes: 11 additions & 0 deletions android/festago/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@
</style>

<style name="Theme.Festago" parent="Base.Theme.Festago" />

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/white</item>

<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_festago_logo</item>
<item name="windowSplashScreenAnimationDuration">1000</item>

<item name="postSplashScreenTheme">@style/Base.Theme.Festago</item>
</style>
</resources>


0 comments on commit 45fb77c

Please sign in to comment.