Implemented drop down menu for settings icon moreVert
This commit is contained in:
1 parent
09a6e2f031
commit
d4872cdf29
8 files changed
+77
-24
No files matched your search
@@ -2,20 +2,18 @@ package com.anthonyla.livewallpaper.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.List
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.Menu
|
||||
import androidx.compose.material.icons.rounded.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.
|
||||
* List of screens for 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 Configure : BottomNavScreens("configure", R.string.configure, Icons.Filled.Settings)
|
||||
object Wallpaper : BottomNavScreens("wallpaper", R.string.wallpaper, Icons.Rounded.Home)
|
||||
object Library : BottomNavScreens("library", R.string.library, Icons.Rounded.Menu)
|
||||
object Configure : BottomNavScreens("configure", R.string.configure, Icons.Rounded.Settings)
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.livewallpaper.navigation
|
||||
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.NavigationBar
|
||||
@@ -8,7 +7,6 @@ import androidx.compose.material3.NavigationBarDefaults
|
||||
import androidx.compose.material3.NavigationBarDefaults.containerColor
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@@ -7,16 +7,17 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.navigation
|
||||
import com.anthonyla.livewallpaper.ui.Library
|
||||
import com.anthonyla.livewallpaper.ui.Configure
|
||||
import com.anthonyla.livewallpaper.ui.Settings
|
||||
import com.anthonyla.livewallpaper.ui.Wallpaper
|
||||
|
||||
/**
|
||||
* The bottomNav graph builder links the routes for the different screens of the bottom navigation
|
||||
* bar together.
|
||||
* The Nav graph builder links the routes for the different screens in the app
|
||||
*/
|
||||
fun NavGraphBuilder.bottomNav(navController: NavController, modifier: Modifier = Modifier) {
|
||||
fun NavGraphBuilder.navGraph(navController: NavController, modifier: Modifier = Modifier) {
|
||||
navigation(startDestination = BottomNavScreens.Wallpaper.route, route = "bottomNavigation") {
|
||||
composable(BottomNavScreens.Wallpaper.route) { Wallpaper(navController) }
|
||||
composable(BottomNavScreens.Library.route) { Library(navController) }
|
||||
composable(BottomNavScreens.Configure.route) { Configure(navController) }
|
||||
composable(SettingsNavScreens.Settings.route) { Settings(navController) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.anthonyla.livewallpaper.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.livewallpaper.R
|
||||
|
||||
/**
|
||||
* List of screens for app settings
|
||||
*/
|
||||
sealed class SettingsNavScreens(val route: String, @StringRes val resourceId: Int, val icon: ImageVector) {
|
||||
object Settings : SettingsNavScreens("settings", R.string.settings, Icons.Rounded.Settings)
|
||||
}
|
||||
@@ -1,19 +1,28 @@
|
||||
package com.anthonyla.livewallpaper.navigation
|
||||
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.rounded.MoreVert
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.windowInsets
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import com.anthonyla.livewallpaper.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -22,6 +31,7 @@ fun TopBar (
|
||||
navController: NavController,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var expanded by rememberSaveable { mutableStateOf(false) }
|
||||
CenterAlignedTopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {},
|
||||
@@ -29,13 +39,33 @@ fun TopBar (
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(),
|
||||
scrollBehavior = null,
|
||||
actions = {
|
||||
IconButton(onClick = { /* doSomething() */ }) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
expanded = !expanded
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
imageVector = Icons.Rounded.MoreVert,
|
||||
contentDescription = stringResource(R.string.MoreVertIcon)
|
||||
)
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = {expanded = false},
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.dropdownmenu_settings)) },
|
||||
onClick = {
|
||||
navController.navigate(SettingsNavScreens.Settings.route) {
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package com.anthonyla.livewallpaper.ui
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
@@ -19,7 +16,7 @@ import com.anthonyla.livewallpaper.data.settings.SettingsViewModel
|
||||
import com.anthonyla.livewallpaper.navigation.BottomNavScreens
|
||||
import com.anthonyla.livewallpaper.navigation.BottomNavigationBar
|
||||
import com.anthonyla.livewallpaper.navigation.TopBar
|
||||
import com.anthonyla.livewallpaper.navigation.bottomNav
|
||||
import com.anthonyla.livewallpaper.navigation.navGraph
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -52,7 +49,7 @@ fun LiveWallpaperApp(
|
||||
startDestination = "bottomNavigation",
|
||||
Modifier.padding(innerPadding)
|
||||
) {
|
||||
bottomNav(navController)
|
||||
navGraph(navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.anthonyla.livewallpaper.ui
|
||||
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavController
|
||||
|
||||
@Composable
|
||||
fun Settings(navController: NavController, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
text = "settings"
|
||||
)
|
||||
}
|
||||
@@ -4,4 +4,6 @@
|
||||
<string name="configure">Configure</string>
|
||||
<string name="wallpaper">Wallpaper</string>
|
||||
<string name="MoreVertIcon">Options</string>
|
||||
<string name="dropdownmenu_settings">Settings</string>
|
||||
<string name="settings">settings</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user