From 15d935abc85469f7ea6d0d2bbd0aa18c7e7796ad Mon Sep 17 00:00:00 2001 From: William Brawner Date: Mon, 23 Aug 2021 15:57:25 -0600 Subject: [PATCH] Update to new Splash Screen API --- android/build.gradle | 1 + android/src/main/AndroidManifest.xml | 4 ++-- .../ui/{SplashActivity.kt => AuthActivity.kt} | 23 ++++++++++++++++--- ...{activity_splash.xml => activity_auth.xml} | 2 +- android/src/main/res/values/styles.xml | 15 +++++------- 5 files changed, 30 insertions(+), 15 deletions(-) rename android/src/main/java/com/wbrawner/budget/ui/{SplashActivity.kt => AuthActivity.kt} (67%) rename android/src/main/res/layout/{activity_splash.xml => activity_auth.xml} (91%) diff --git a/android/build.gradle b/android/build.gradle index 74f311a..ab0a361 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -64,6 +64,7 @@ dependencies { androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' + implementation 'androidx.core:core-splashscreen:1.0.0-alpha01' def navigation = '2.4.0-alpha07' implementation "androidx.navigation:navigation-fragment-ktx:$navigation" implementation "androidx.navigation:navigation-ui-ktx:$navigation" diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 80a7efd..0e3d7eb 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -15,8 +15,8 @@ tools:ignore="GoogleAppIndexingWarning" tools:targetApi="n"> diff --git a/android/src/main/java/com/wbrawner/budget/ui/SplashActivity.kt b/android/src/main/java/com/wbrawner/budget/ui/AuthActivity.kt similarity index 67% rename from android/src/main/java/com/wbrawner/budget/ui/SplashActivity.kt rename to android/src/main/java/com/wbrawner/budget/ui/AuthActivity.kt index f8260d5..4e9734c 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/SplashActivity.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/AuthActivity.kt @@ -2,8 +2,10 @@ package com.wbrawner.budget.ui import android.os.Bundle import android.view.View +import android.view.ViewTreeObserver import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity +import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.lifecycleScope import androidx.navigation.findNavController import com.wbrawner.budget.AsyncState @@ -13,12 +15,26 @@ import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @AndroidEntryPoint -class SplashActivity : AppCompatActivity() { +class AuthActivity : AppCompatActivity() { val viewModel: SplashViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_splash) + installSplashScreen() + val content: View = findViewById(android.R.id.content) + content.viewTreeObserver.addOnPreDrawListener( + object : ViewTreeObserver.OnPreDrawListener { + override fun onPreDraw(): Boolean { + return if (viewModel.state.value is AsyncState.Success) { + content.viewTreeObserver.removeOnPreDrawListener(this) + true + } else { + false + } + } + } + ) + setContentView(R.layout.activity_auth) window.decorView.apply { systemUiVisibility = ( View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION @@ -41,7 +57,8 @@ class SplashActivity : AppCompatActivity() { } } } - is AsyncState.Loading -> {} + is AsyncState.Loading -> { + } } } } diff --git a/android/src/main/res/layout/activity_splash.xml b/android/src/main/res/layout/activity_auth.xml similarity index 91% rename from android/src/main/res/layout/activity_splash.xml rename to android/src/main/res/layout/activity_auth.xml index b3b76ad..cd161b5 100644 --- a/android/src/main/res/layout/activity_splash.xml +++ b/android/src/main/res/layout/activity_auth.xml @@ -8,4 +8,4 @@ android:layout_height="match_parent" app:defaultNavHost="true" app:navGraph="@navigation/auth_graph" - tools:context=".ui.SplashActivity" /> + tools:context=".ui.AuthActivity" /> diff --git a/android/src/main/res/values/styles.xml b/android/src/main/res/values/styles.xml index 68b596c..40a593e 100644 --- a/android/src/main/res/values/styles.xml +++ b/android/src/main/res/values/styles.xml @@ -32,17 +32,14 @@ +