Skip to content

Commit

Permalink
BIT-147: Improve splash screen handling for all OS levels (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-livefront authored and vvolkgang committed Jun 20, 2024
1 parent a223e2f commit 5fc78af
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 31 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ The following is a list of all third-party dependencies included as part of the
- Purpose: Supplementary Android Compose features.
- License: Apache 2.0
- **Core SplashScreen**
- https://developer.android.com/jetpack/androidx/releases/core
- Purpose: Backwards compatible SplashScreen API implementation.
- License: Apache 2.0
- **Dagger Hilt**
- https://github.com/google/dagger
- Purpose: Dependency injection framework.
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
ksp(libs.androidx.room.compiler)
implementation(libs.androidx.room.ktx)
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.splashscreen)
implementation(platform(libs.google.firebase.bom))
implementation(libs.bitwarden.sdk)
implementation(libs.bumptech.glide)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/x8bit/bitwarden/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.x8bit.bitwarden
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.x8bit.bitwarden.ui.platform.feature.rootnav.RootNavScreen
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -13,10 +14,14 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
var shouldShowSplashScreen = true
installSplashScreen().setKeepOnScreenCondition { shouldShowSplashScreen }
super.onCreate(savedInstanceState)
setContent {
BitwardenTheme {
RootNavScreen()
RootNavScreen(
onSplashScreenRemoved = { shouldShowSplashScreen = false },
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
Expand Down Expand Up @@ -42,6 +43,7 @@ fun LoginScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.padding(horizontal = 16.dp, vertical = 32.dp),
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.x8bit.bitwarden.ui.platform.feature.rootnav

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand All @@ -23,9 +24,15 @@ import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.vaultUnlockedDestin
fun RootNavScreen(
viewModel: RootNavViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(),
onSplashScreenRemoved: () -> Unit = {},
) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle()

val isNotSplashScreen = state != RootNavState.Splash
LaunchedEffect(isNotSplashScreen) {
if (isNotSplashScreen) onSplashScreenRemoved()
}

NavHost(
navController = navController,
startDestination = SPLASH_ROUTE,
Expand Down
Binary file removed app/src/main/res/drawable-hdpi/logo_legacy.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-hdpi/logo_white_legacy.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-xhdpi/logo_legacy.png
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/drawable-xxhdpi/logo_legacy.png
Binary file not shown.
Binary file not shown.
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/splash_screen.xml

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/res/drawable/splash_screen_dark.xml

This file was deleted.

8 changes: 4 additions & 4 deletions app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<item name="android:textCursorDrawable">@null</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
</style>

Expand All @@ -20,10 +21,9 @@
</style>

<!-- Launch theme (for auto dark/light based on system) -->
<style name="LaunchTheme" parent="BaseTheme">
<item name="android:windowBackground">@drawable/splash_screen_dark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:ignore="NewApi">
<style name="LaunchTheme" parent="Theme.SplashScreen">
<item name="postSplashScreenTheme">@style/BaseTheme</item>
<item name="windowSplashScreenAnimatedIcon">
@drawable/splash_screen_round
</item>
</style>
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<item name="android:popupTheme">@android:style/ThemeOverlay.Material.Light</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionModeOverlay">true</item>
</style>
Expand All @@ -21,13 +22,12 @@
</style>

<!-- Launch theme (for auto dark/light based on system) -->
<style name="LaunchTheme" parent="BaseTheme">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:ignore="NewApi">
<style name="LaunchTheme" parent="Theme.SplashScreen">
<item name="postSplashScreenTheme">@style/BaseTheme</item>
<item name="windowSplashScreenAnimatedIcon">
@drawable/splash_screen_round
</item>
<item name="android:windowSplashScreenBackground" tools:ignore="NewApi">
<item name="windowSplashScreenBackground">
@color/ic_launcher_background
</item>
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import io.mockk.mockk
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class RootNavScreenTest : BaseComposeTest() {
Expand Down Expand Up @@ -47,15 +49,18 @@ class RootNavScreenTest : BaseComposeTest() {
every { eventFlow } returns emptyFlow()
every { stateFlow } returns rootNavStateFlow
}
var isSplashScreenRemoved = false
composeTestRule.setContent {
RootNavScreen(
viewModel = viewModel,
navController = fakeNavHostController,
onSplashScreenRemoved = { isSplashScreenRemoved = true },
)
}
composeTestRule.runOnIdle {
fakeNavHostController.assertCurrentRoute("splash")
}
assertFalse(isSplashScreenRemoved)

// Make sure navigating to Auth works as expected:
rootNavStateFlow.value = RootNavState.Auth
Expand All @@ -65,6 +70,7 @@ class RootNavScreenTest : BaseComposeTest() {
navOptions = expectedNavOptions,
)
}
assertTrue(isSplashScreenRemoved)

// Make sure navigating to vault unlocked works as expected:
rootNavStateFlow.value = RootNavState.VaultUnlocked
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ androidxHiltNavigationCompose = "1.0.0"
androidxLifecycle = "2.6.1"
androidxNavigation = "2.7.2"
androidxRoom = "2.5.2"
androidxSplash = "1.1.0-alpha02"
# Once the app and SDK reach a critical point of completeness we should begin fixing the version
# here (BIT-311).
bitwardenSdk = "0.3.0-SNAPSHOT"
Expand Down Expand Up @@ -60,6 +61,7 @@ androidx-navigation-compose = { module = "androidx.navigation:navigation-compose
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidxRoom" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidxRoom" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidxRoom" }
androidx-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "androidxSplash" }
bitwarden-sdk = { module = "com.bitwarden:sdk-android", version.ref = "bitwardenSdk" }
bumptech-glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
detekt-detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
Expand Down

0 comments on commit 5fc78af

Please sign in to comment.