2023-06-06 13:13:54 -07:00
|
|
|
package com.anthonyla.paperize.ui
|
2023-05-27 10:38:50 -07:00
|
|
|
|
2023-05-30 17:40:10 -07:00
|
|
|
import android.app.Activity
|
2023-06-06 13:13:54 -07:00
|
|
|
import androidx.compose.animation.ExperimentalAnimationApi
|
2023-05-27 10:38:50 -07:00
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.material3.Scaffold
|
|
|
|
|
import androidx.compose.runtime.Composable
|
2023-05-28 23:43:42 -07:00
|
|
|
import androidx.compose.runtime.SideEffect
|
2023-06-05 11:51:12 -07:00
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
|
|
|
import androidx.compose.runtime.setValue
|
2023-05-27 10:38:50 -07:00
|
|
|
import androidx.compose.ui.Modifier
|
2023-05-28 23:43:42 -07:00
|
|
|
import androidx.compose.ui.graphics.Color
|
2023-05-30 17:40:10 -07:00
|
|
|
import androidx.compose.ui.platform.LocalView
|
|
|
|
|
import androidx.core.view.WindowCompat
|
2023-06-05 11:51:12 -07:00
|
|
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
2023-06-06 13:13:54 -07:00
|
|
|
import com.anthonyla.paperize.data.settings.SettingsViewModel
|
|
|
|
|
import com.anthonyla.paperize.data.navigation.BottomNavScreens
|
|
|
|
|
import com.anthonyla.paperize.data.navigation.navGraph
|
2023-06-10 11:14:24 -07:00
|
|
|
import com.google.accompanist.navigation.animation.AnimatedNavHost
|
2023-06-06 13:13:54 -07:00
|
|
|
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
2023-05-28 23:43:42 -07:00
|
|
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
2023-05-27 10:38:50 -07:00
|
|
|
|
2023-06-06 13:13:54 -07:00
|
|
|
@OptIn(ExperimentalAnimationApi::class)
|
2023-05-27 10:38:50 -07:00
|
|
|
@Composable
|
2023-06-06 13:13:54 -07:00
|
|
|
fun PaperizeApp(
|
2023-06-02 11:09:34 -07:00
|
|
|
settingsViewModel: SettingsViewModel,
|
|
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
2023-06-06 13:13:54 -07:00
|
|
|
SetTransparentSystemBars(settingsViewModel.isDarkMode())
|
2023-05-27 10:38:50 -07:00
|
|
|
|
2023-06-06 13:13:54 -07:00
|
|
|
val navController = rememberAnimatedNavController()
|
2023-06-05 11:51:12 -07:00
|
|
|
var topLevel by rememberSaveable { mutableStateOf(true) }
|
|
|
|
|
|
|
|
|
|
// Hide top level bar and bottom navigation bar when the current screen is not the top level screen
|
|
|
|
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
|
|
|
|
topLevel = when (navBackStackEntry?.destination?.route) {
|
|
|
|
|
BottomNavScreens.Wallpaper.route,
|
|
|
|
|
BottomNavScreens.Library.route,
|
|
|
|
|
BottomNavScreens.Configure.route -> true
|
|
|
|
|
else -> false
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-27 10:38:50 -07:00
|
|
|
val bottomNavOptions = listOf(
|
|
|
|
|
BottomNavScreens.Wallpaper,
|
|
|
|
|
BottomNavScreens.Library,
|
2023-05-28 23:43:42 -07:00
|
|
|
BottomNavScreens.Configure
|
2023-05-27 10:38:50 -07:00
|
|
|
)
|
2023-06-05 11:51:12 -07:00
|
|
|
|
2023-05-27 10:38:50 -07:00
|
|
|
Scaffold (
|
2023-06-01 14:03:19 -07:00
|
|
|
topBar = {
|
2023-06-10 11:14:24 -07:00
|
|
|
TopAppBar(navController = navController, topLevel)
|
2023-06-01 14:03:19 -07:00
|
|
|
},
|
2023-05-28 23:43:42 -07:00
|
|
|
bottomBar = {
|
2023-06-05 11:51:12 -07:00
|
|
|
if (topLevel) BottomNavigationBar(
|
|
|
|
|
navController = navController,
|
|
|
|
|
screens = bottomNavOptions
|
|
|
|
|
) }
|
2023-06-10 11:14:24 -07:00
|
|
|
) { innerPadding -> AnimatedNavHost (
|
2023-05-28 23:43:42 -07:00
|
|
|
navController,
|
|
|
|
|
startDestination = "bottomNavigation",
|
|
|
|
|
Modifier.padding(innerPadding)
|
|
|
|
|
) {
|
2023-06-04 11:54:36 -07:00
|
|
|
navGraph(navController)
|
2023-05-27 10:38:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-30 17:40:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2023-06-02 11:09:34 -07:00
|
|
|
fun SetTransparentSystemBars(darkMode: Boolean) {
|
2023-05-30 17:40:10 -07:00
|
|
|
val systemUiController = rememberSystemUiController()
|
|
|
|
|
val view = LocalView.current
|
|
|
|
|
SideEffect {
|
|
|
|
|
with(view.context as Activity) {
|
|
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
|
|
systemUiController.setSystemBarsColor(
|
|
|
|
|
color = Color.Transparent,
|
2023-06-02 11:09:34 -07:00
|
|
|
darkIcons = !darkMode
|
2023-05-30 17:40:10 -07:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-27 10:38:50 -07:00
|
|
|
}
|