Update to new Splash Screen API
This commit is contained in:
parent
1e3788c670
commit
15d935abc8
5 changed files with 30 additions and 15 deletions
|
@ -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"
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
tools:ignore="GoogleAppIndexingWarning"
|
||||
tools:targetApi="n">
|
||||
<activity
|
||||
android:name=".ui.SplashActivity"
|
||||
android:theme="@style/SplashTheme"
|
||||
android:name=".ui.AuthActivity"
|
||||
android:theme="@style/Theme.App.Starting"
|
||||
android:resizeableActivity="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true">
|
||||
|
|
|
@ -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 -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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" />
|
|
@ -32,17 +32,14 @@
|
|||
|
||||
<style name="AppTheme" parent="BaseTheme" />
|
||||
|
||||
<style name="DateTimePickerDialogTheme" parent="BaseDateTimePickerDialogTheme" />
|
||||
|
||||
<style name="SplashTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<!-- <item name="android:windowBackground">@drawable/bg_splash</item>-->
|
||||
<item name="android:windowTranslucentNavigation">true</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
|
||||
<item name="windowSplashScreenBackground">@color/colorBackgroundPrimary</item>
|
||||
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_twigs_color</item>
|
||||
<item name="postSplashScreenTheme">@style/AppTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="DateTimePickerDialogTheme" parent="BaseDateTimePickerDialogTheme" />
|
||||
|
||||
<style name="AppTheme.EditText">
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
|
|
Loading…
Reference in a new issue