Skip to content

Commit

Permalink
feat: 스플래시 화면 구현 및 업데이트 확인 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Oct 11, 2023
1 parent 23fb2d0 commit ebeb98b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 11 deletions.
21 changes: 12 additions & 9 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,8 +73,7 @@
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>

</service>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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.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?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
splashScreen.setKeepOnScreenCondition { true }
checkAppUpdate(splashScreen)
setContentView(binding.root)
}

private fun checkAppUpdate(splashScreen: SplashScreen) {
val appUpdateManager = AppUpdateManagerFactory.create(this)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
splashScreen.setKeepOnScreenCondition { false }
requestUpdate()
} else {
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 handleOkUpdate() {
navigateToAppStore()
finish()
}

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

private fun navigateToAppStore() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")))
finish()
}
}
16 changes: 16 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,16 @@
<?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"
android:background="@color/black"
tools:context=".presentation.ui.splash.SplashActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2 changes: 1 addition & 1 deletion android/festago/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<item name="windowSplashScreenBackground">@color/black</item>

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

<item name="postSplashScreenTheme">@style/Base.Theme.Festago</item>
</style>
Expand Down
2 changes: 1 addition & 1 deletion android/festago/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<item name="windowSplashScreenBackground">@color/white</item>

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

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

0 comments on commit ebeb98b

Please sign in to comment.