Added some documentation for navigation and changed the status bar to transparent
This commit is contained in:
1 parent
910af0a86e
commit
127805bc70
16 files changed
+185
-33
No files matched your search
@@ -3,27 +3,16 @@ package com.anthonyla.livewallpaper
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.anthonyla.livewallpaper.theming.LiveWallpaperTheme
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import com.anthonyla.livewallpaper.themes.LiveWallpaperTheme
|
||||
import com.anthonyla.livewallpaper.ui.LiveWallpaperApp
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Enable full screen app mode
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
setContent {
|
||||
|
||||
// Update the status bar to transparent
|
||||
val systemUiController = rememberSystemUiController()
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
DisposableEffect(systemUiController) {
|
||||
systemUiController.setSystemBarsColor(color = Color.Transparent)
|
||||
onDispose {}
|
||||
}
|
||||
systemUiController.setSystemBarsColor(color = Color.Transparent)
|
||||
|
||||
LiveWallpaperTheme {
|
||||
LiveWallpaperApp()
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.livewallpaper.R
|
||||
|
||||
/**
|
||||
* BottomNavScreens groups the different screens of the bottom navigation bar together.
|
||||
* Each object represents a screen and has a route for the NavController, the name of the route,
|
||||
* and a icon that is shown on the bottom navigation bar.
|
||||
*/
|
||||
sealed class BottomNavScreens(val route: String, @StringRes val resourceId: Int, val icon: ImageVector) {
|
||||
object Wallpaper : BottomNavScreens("wallpaper", R.string.wallpaper, Icons.Filled.Home)
|
||||
object Library : BottomNavScreens("library", R.string.library, Icons.Filled.List)
|
||||
object Setting : BottomNavScreens("setting", R.string.setting, Icons.Filled.Settings)
|
||||
object Configure : BottomNavScreens("configure", R.string.configure, Icons.Filled.Settings)
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.livewallpaper.navigation
|
||||
|
||||
import androidx.compose.material.BottomNavigationItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.NavigationBar
|
||||
@@ -15,6 +14,11 @@ import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the bottom navigation bar composable
|
||||
* Three screens = Wallpaper, Collection, Configure
|
||||
*/
|
||||
@Composable
|
||||
fun BottomNavigationBar(
|
||||
navController: NavController,
|
||||
|
||||
@@ -6,13 +6,17 @@ import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.navigation
|
||||
import com.anthonyla.livewallpaper.ui.Library
|
||||
import com.anthonyla.livewallpaper.ui.Setting
|
||||
import com.anthonyla.livewallpaper.ui.Configure
|
||||
import com.anthonyla.livewallpaper.ui.Wallpaper
|
||||
|
||||
/**
|
||||
* The bottomNav graph builder links the routes for the different screens of the bottom navigation
|
||||
* bar together.
|
||||
*/
|
||||
fun NavGraphBuilder.bottomNav(navController: NavController, modifier: Modifier = Modifier) {
|
||||
navigation(startDestination = BottomNavScreens.Wallpaper.route, route = "bottomNavigation") {
|
||||
composable(BottomNavScreens.Wallpaper.route) { Wallpaper() }
|
||||
composable(BottomNavScreens.Library.route) { Library() }
|
||||
composable(BottomNavScreens.Setting.route) { Setting() }
|
||||
composable(BottomNavScreens.Configure.route) { Configure() }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.anthonyla.livewallpaper.theming
|
||||
package com.anthonyla.livewallpaper.themes
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.anthonyla.livewallpaper.theming
|
||||
package com.anthonyla.livewallpaper.themes
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.anthonyla.livewallpaper.theming
|
||||
package com.anthonyla.livewallpaper.themes
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
+2
-2
@@ -5,6 +5,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun Setting(modifier: Modifier = Modifier) {
|
||||
Text(text = "setting")
|
||||
fun Configure(modifier: Modifier = Modifier) {
|
||||
Text(text = "configure")
|
||||
}
|
||||
@@ -4,28 +4,46 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.anthonyla.livewallpaper.navigation.BottomNavScreens
|
||||
import com.anthonyla.livewallpaper.navigation.BottomNavigationBar
|
||||
import com.anthonyla.livewallpaper.navigation.bottomNav
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LiveWallpaperApp(modifier: Modifier = Modifier) {
|
||||
val navController = rememberNavController()
|
||||
// Transparent status bar
|
||||
val systemUiController = rememberSystemUiController()
|
||||
SideEffect {
|
||||
systemUiController.setStatusBarColor(
|
||||
color = Color.Transparent,
|
||||
// check if app is in dark mode or not
|
||||
darkIcons = false
|
||||
)
|
||||
}
|
||||
|
||||
// Bottom navigation
|
||||
val navController = rememberNavController()
|
||||
val bottomNavOptions = listOf(
|
||||
BottomNavScreens.Wallpaper,
|
||||
BottomNavScreens.Library,
|
||||
BottomNavScreens.Setting
|
||||
BottomNavScreens.Configure
|
||||
)
|
||||
Scaffold (
|
||||
bottomBar = { BottomNavigationBar(navController = navController, screens = bottomNavOptions) },
|
||||
) { innerPadding ->
|
||||
NavHost(navController, startDestination = "bottomNavigation", Modifier.padding(innerPadding)) {
|
||||
bottomBar = {
|
||||
BottomNavigationBar(navController = navController, screens = bottomNavOptions)
|
||||
},
|
||||
) {
|
||||
innerPadding -> NavHost (
|
||||
navController,
|
||||
startDestination = "bottomNavigation",
|
||||
Modifier.padding(innerPadding)
|
||||
) {
|
||||
bottomNav(navController)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
<string name="app_name">LiveWallpaper</string>
|
||||
<string name="library">Library</string>
|
||||
<string name="setting">Setting</string>
|
||||
<string name="configure">Configure</string>
|
||||
<string name="wallpaper">Wallpaper</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user