Skip to content
Snippets Groups Projects
Verified Commit c9252d2c authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

feat: add native splash screen

parent 77f9228c
Branches
No related tags found
No related merge requests found
...@@ -73,6 +73,8 @@ dependencies { ...@@ -73,6 +73,8 @@ dependencies {
implementation(libs.androidx.activity) implementation(libs.androidx.activity)
implementation(libs.androidx.activity.compose) implementation(libs.androidx.activity.compose)
implementation(libs.androidx.splashscreen)
implementation(libs.androidx.compose.animation) implementation(libs.androidx.compose.animation)
implementation(libs.androidx.compose.compiler) implementation(libs.androidx.compose.compiler)
implementation(libs.androidx.compose.foundation) implementation(libs.androidx.compose.foundation)
......
...@@ -9,12 +9,11 @@ ...@@ -9,12 +9,11 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/application_name" android:label="@string/application_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Meteroid"
android:usesCleartextTraffic="true"> android:usesCleartextTraffic="true">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"
android:theme="@style/Theme.Meteroid"> android:theme="@style/Theme.Meteroid.SplashScreen">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
......
...@@ -27,18 +27,29 @@ package de.chaosdorf.meteroid ...@@ -27,18 +27,29 @@ package de.chaosdorf.meteroid
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import de.chaosdorf.meteroid.ui.AppRouter import de.chaosdorf.meteroid.ui.AppRouter
import de.chaosdorf.meteroid.ui.AppViewModel
import de.chaosdorf.meteroid.ui.theme.MeteroidTheme import de.chaosdorf.meteroid.ui.theme.MeteroidTheme
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val viewModelProvider = ViewModelProvider(this)
val viewModel = viewModelProvider.get<AppViewModel>()
installSplashScreen().setKeepOnScreenCondition {
viewModel.initState.value == AppViewModel.InitState.LOADING
}
setContent { setContent {
MeteroidTheme { MeteroidTheme {
AppRouter() AppRouter(viewModel)
} }
} }
} }
......
...@@ -58,18 +58,13 @@ import de.chaosdorf.meteroid.ui.wrapped.WrappedViewModel ...@@ -58,18 +58,13 @@ import de.chaosdorf.meteroid.ui.wrapped.WrappedViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
fun AppRouter(viewModel: AppViewModel = viewModel()) { fun AppRouter(viewModel: AppViewModel) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val navController = rememberNavController() val navController = rememberNavController()
val initState by viewModel.initState.collectAsState() val initState by viewModel.initState.collectAsState()
LaunchedEffect(initState) { LaunchedEffect(initState) {
when (initState) { when (initState) {
AppViewModel.InitState.LOADING -> navController.navigate(
Routes.Init,
NavOptions.Builder().setPopUpTo(Routes.Init, true).build()
)
AppViewModel.InitState.CREATE_SERVER -> navController.navigate( AppViewModel.InitState.CREATE_SERVER -> navController.navigate(
Routes.Servers.Add, Routes.Servers.Add,
NavOptions.Builder().setPopUpTo(Routes.Servers.Add, true).build() NavOptions.Builder().setPopUpTo(Routes.Servers.Add, true).build()
...@@ -89,19 +84,11 @@ fun AppRouter(viewModel: AppViewModel = viewModel()) { ...@@ -89,19 +84,11 @@ fun AppRouter(viewModel: AppViewModel = viewModel()) {
Routes.Home.Root, Routes.Home.Root,
NavOptions.Builder().setPopUpTo(Routes.Home.Root, true).build() NavOptions.Builder().setPopUpTo(Routes.Home.Root, true).build()
) )
else -> Unit
} }
} }
NavHost(navController, startDestination = Routes.Init) { NavHost(navController, startDestination = Routes.Servers.Root) {
composable(route = Routes.Init) { _ ->
Box(Modifier.fillMaxSize()) {
Column(Modifier.align(Alignment.Center)) {
CircularProgressIndicator()
Text("Loading")
}
}
}
navigation(route = Routes.Servers.Root, startDestination = Routes.Servers.List) { navigation(route = Routes.Servers.Root, startDestination = Routes.Servers.List) {
composable(Routes.Servers.List) { _ -> composable(Routes.Servers.List) { _ ->
ServerListScreen( ServerListScreen(
......
...@@ -15,4 +15,10 @@ ...@@ -15,4 +15,10 @@
<item name="android:windowMinWidthMajor">100%</item> <item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item> <item name="android:windowMinWidthMinor">100%</item>
</style> </style>
<style name="Theme.Meteroid.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#003984</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
<item name="postSplashScreenTheme">@style/Theme.Meteroid</item>
</style>
</resources> </resources>
...@@ -34,7 +34,7 @@ androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", versi ...@@ -34,7 +34,7 @@ androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", versi
androidx-compose-animation = { group = "androidx.compose.animation", name = "animation" } androidx-compose-animation = { group = "androidx.compose.animation", name = "animation" }
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" } androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" } androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }
androidx-compose-material-icons = { group = "androidx.compose.material", name = "material-icons-extended", version = "1.6.0-alpha08" } androidx-compose-material-icons = { group = "androidx.compose.material", name = "material-icons-extended", version = "1.6.0-beta01" }
androidx-compose-material = { group = "androidx.compose.material3", name = "material3", version.ref = "androidx-compose-material3" } androidx-compose-material = { group = "androidx.compose.material3", name = "material3", version.ref = "androidx-compose-material3" }
androidx-compose-material-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class", version.ref = "androidx-compose-material3" } androidx-compose-material-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class", version.ref = "androidx-compose-material3" }
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime" } androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
...@@ -46,6 +46,8 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin ...@@ -46,6 +46,8 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin
androidx-compose-ui-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidx-compose-tooling" } androidx-compose-ui-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidx-compose-tooling" }
androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" } androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" }
androidx-splashscreen = { module = "androidx.core:core-splashscreen", version = "1.0.1" }
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "androidx-datastore" } androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "androidx-datastore" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidx-room" } androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidx-room" }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment