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
No related branches found
No related tags found
Loading
......@@ -73,6 +73,8 @@ dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.splashscreen)
implementation(libs.androidx.compose.animation)
implementation(libs.androidx.compose.compiler)
implementation(libs.androidx.compose.foundation)
......
......@@ -9,12 +9,11 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/application_name"
android:supportsRtl="true"
android:theme="@style/Theme.Meteroid"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Meteroid">
android:theme="@style/Theme.Meteroid.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
......
......@@ -27,18 +27,29 @@ package de.chaosdorf.meteroid
import android.os.Bundle
import androidx.activity.ComponentActivity
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 de.chaosdorf.meteroid.ui.AppRouter
import de.chaosdorf.meteroid.ui.AppViewModel
import de.chaosdorf.meteroid.ui.theme.MeteroidTheme
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val viewModelProvider = ViewModelProvider(this)
val viewModel = viewModelProvider.get<AppViewModel>()
installSplashScreen().setKeepOnScreenCondition {
viewModel.initState.value == AppViewModel.InitState.LOADING
}
setContent {
MeteroidTheme {
AppRouter()
AppRouter(viewModel)
}
}
}
......
......@@ -58,18 +58,13 @@ import de.chaosdorf.meteroid.ui.wrapped.WrappedViewModel
import kotlinx.coroutines.launch
@Composable
fun AppRouter(viewModel: AppViewModel = viewModel()) {
fun AppRouter(viewModel: AppViewModel) {
val scope = rememberCoroutineScope()
val navController = rememberNavController()
val initState by viewModel.initState.collectAsState()
LaunchedEffect(initState) {
when (initState) {
AppViewModel.InitState.LOADING -> navController.navigate(
Routes.Init,
NavOptions.Builder().setPopUpTo(Routes.Init, true).build()
)
AppViewModel.InitState.CREATE_SERVER -> navController.navigate(
Routes.Servers.Add,
NavOptions.Builder().setPopUpTo(Routes.Servers.Add, true).build()
......@@ -89,19 +84,11 @@ fun AppRouter(viewModel: AppViewModel = viewModel()) {
Routes.Home.Root,
NavOptions.Builder().setPopUpTo(Routes.Home.Root, true).build()
)
else -> Unit
}
}
NavHost(navController, startDestination = Routes.Init) {
composable(route = Routes.Init) { _ ->
Box(Modifier.fillMaxSize()) {
Column(Modifier.align(Alignment.Center)) {
CircularProgressIndicator()
Text("Loading")
}
}
}
NavHost(navController, startDestination = Routes.Servers.Root) {
navigation(route = Routes.Servers.Root, startDestination = Routes.Servers.List) {
composable(Routes.Servers.List) { _ ->
ServerListScreen(
......
......@@ -15,4 +15,10 @@
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
</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>
......@@ -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-foundation = { group = "androidx.compose.foundation", name = "foundation" }
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-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class", version.ref = "androidx-compose-material3" }
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
......@@ -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-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-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.
Finish editing this message first!
Please register or to comment