change the theme to go fullscreen.

This commit is contained in:
Thomas Andres Gomez 2022-04-21 10:23:08 +02:00
parent 2a69b75d9d
commit af5521f6bb
8 changed files with 112 additions and 12 deletions

View file

@ -7,17 +7,17 @@
<application <application
android:name=".BibLibApplication" android:name=".BibLibApplication"
android:allowBackup="false" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"> android:theme="@style/Theme.BibLib.NoActionBar">
<activity <activity
android:name=".ui.MainActivity" android:name=".ui.MainActivity"
android:exported="true" android:exported="true"
android:label="@string/app_name"> android:theme="@style/Theme.BibLib.Starting">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />

View file

@ -3,8 +3,14 @@ package com.pixelized.biblib.ui
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.activity.viewModels
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface import androidx.compose.material.Surface
import androidx.compose.runtime.getValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import com.google.accompanist.insets.ProvideWindowInsets
import com.pixelized.biblib.ui.launch.LauncherViewModel
import com.pixelized.biblib.ui.navigation.FullScreenNavHost import com.pixelized.biblib.ui.navigation.FullScreenNavHost
import com.pixelized.biblib.ui.navigation.Screen import com.pixelized.biblib.ui.navigation.Screen
import com.pixelized.biblib.ui.theme.BibLibTheme import com.pixelized.biblib.ui.theme.BibLibTheme
@ -14,17 +20,33 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
private val launcherViewModel: LauncherViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// Disable system inset consuming.
WindowCompat.setDecorFitsSystemWindows(window, false)
// splashscreen management
installSplashScreen().apply {
setKeepOnScreenCondition {
launcherViewModel.isLoading.value
}
}
// Compose
setContent { setContent {
BibLibTheme { BibLibTheme {
Surface( ProvideWindowInsets {
color = MaterialTheme.colors.background, Surface(color = MaterialTheme.colors.background) {
) { val loading by launcherViewModel.isLoading
FullScreenNavHost( if (loading.not()) {
startDestination = Screen.Authentication FullScreenNavHost(
) startDestination = Screen.Authentication
)
}
}
} }
} }
} }

View file

@ -12,7 +12,6 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.sharp.Visibility import androidx.compose.material.icons.sharp.Visibility
import androidx.compose.material.icons.sharp.VisibilityOff import androidx.compose.material.icons.sharp.VisibilityOff
import androidx.compose.runtime.* import androidx.compose.runtime.*
@ -30,9 +29,13 @@ import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import com.google.accompanist.insets.systemBarsPadding
import com.pixelized.biblib.R import com.pixelized.biblib.R
import com.pixelized.biblib.network.client.IBibLibClient import com.pixelized.biblib.network.client.IBibLibClient
import com.pixelized.biblib.ui.composable.* import com.pixelized.biblib.ui.composable.AnimatedDelayer
import com.pixelized.biblib.ui.composable.AnimatedOffset
import com.pixelized.biblib.ui.composable.StateUio
import com.pixelized.biblib.ui.composable.StateUioHandler
import com.pixelized.biblib.ui.navigation.LocalFullScreenNavHostController import com.pixelized.biblib.ui.navigation.LocalFullScreenNavHostController
import com.pixelized.biblib.ui.navigation.Screen import com.pixelized.biblib.ui.navigation.Screen
import com.pixelized.biblib.ui.theme.BibLibTheme import com.pixelized.biblib.ui.theme.BibLibTheme
@ -99,6 +102,7 @@ private fun AuthenticationScreenContent(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.verticalScroll(scrollState) .verticalScroll(scrollState)
.systemBarsPadding()
) { ) {
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
@ -358,6 +362,8 @@ fun googleStringResource(): AnnotatedString = buildAnnotatedString {
} }
} }
// endregion
@Composable @Composable
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)

View file

@ -11,5 +11,5 @@ fun AnimatedDelayer(
} }
class AnimatedDelayerScope( class AnimatedDelayerScope(
var delay : Delay = Delay() var delay: Delay = Delay()
) )

View file

@ -0,0 +1,24 @@
package com.pixelized.biblib.ui.composable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import com.google.accompanist.systemuicontroller.SystemUiController
@Composable
fun SystemThemeColor(
systemUiController: SystemUiController,
color: Color = Color.Transparent,
statusDarkIcons: Boolean,
navigationDarkIcons: Boolean,
) = SideEffect {
systemUiController.setStatusBarColor(
color = color,
darkIcons = statusDarkIcons,
)
systemUiController.setNavigationBarColor(
color = color,
darkIcons = navigationDarkIcons,
navigationBarContrastEnforced = false,
)
}

View file

@ -0,0 +1,25 @@
package com.pixelized.biblib.ui.launch
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class LauncherViewModel @Inject constructor() : ViewModel() {
private val _isLoading = mutableStateOf(true)
val isLoading: State<Boolean> get() = _isLoading
init {
viewModelScope.launch(Dispatchers.IO) {
delay(3000)
_isLoading.value = false
}
}
}

View file

@ -1,5 +1,6 @@
package com.pixelized.biblib.ui.navigation package com.pixelized.biblib.ui.navigation
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.compositionLocalOf
@ -7,7 +8,10 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.SystemUiController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.pixelized.biblib.ui.authentication.AuthenticationScreen import com.pixelized.biblib.ui.authentication.AuthenticationScreen
import com.pixelized.biblib.ui.composable.SystemThemeColor
val LocalFullScreenNavHostController = compositionLocalOf<NavHostController> { val LocalFullScreenNavHostController = compositionLocalOf<NavHostController> {
error("LocalFullScreenNavHostController is not ready yet.") error("LocalFullScreenNavHostController is not ready yet.")
@ -18,12 +22,19 @@ fun FullScreenNavHost(
navHostController: NavHostController = rememberNavController(), navHostController: NavHostController = rememberNavController(),
startDestination: Screen = Screen.Authentication startDestination: Screen = Screen.Authentication
) { ) {
val systemUiController: SystemUiController = rememberSystemUiController()
CompositionLocalProvider(LocalFullScreenNavHostController provides navHostController) { CompositionLocalProvider(LocalFullScreenNavHostController provides navHostController) {
NavHost( NavHost(
navController = navHostController, navController = navHostController,
startDestination = startDestination.route, startDestination = startDestination.route,
) { ) {
composable(Screen.Authentication.route) { composable(Screen.Authentication.route) {
SystemThemeColor(
systemUiController = systemUiController,
statusDarkIcons = isSystemInDarkTheme().not(),
navigationDarkIcons = isSystemInDarkTheme().not(),
)
AuthenticationScreen() AuthenticationScreen()
} }
composable(Screen.Home.route) { composable(Screen.Home.route) {

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.BibLib.Starting" parent="Theme.SplashScreen">
<item name="postSplashScreenTheme">@style/Theme.BibLib.NoActionBar</item>
</style>
<style name="Theme.BibLib.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>