-
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
23fb2d0
commit ebeb98b
Showing
5 changed files
with
111 additions
and
11 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
81 changes: 81 additions & 0 deletions
81
...id/festago/app/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,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
16
android/festago/app/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,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> |
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