Added central top app bar with more vertical setting icon, added basic support for toggleable dynamic theme and dark mode in Theme.kt
This commit is contained in:
1 parent
d2530210ab
commit
0ef127a3b7
8 files changed
+141
-36
No files matched your search
Generated
+1
-14
@@ -3,20 +3,7 @@
|
|||||||
<component name="deploymentTargetDropDown">
|
<component name="deploymentTargetDropDown">
|
||||||
<value>
|
<value>
|
||||||
<entry key="app">
|
<entry key="app">
|
||||||
<State>
|
<State />
|
||||||
<runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="RUNNING_DEVICE_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="SERIAL_NUMBER" />
|
|
||||||
<value value="adb-RFCTA1MRS4H-skBDcQ._adb-tls-connect._tcp" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2023-05-31T19:20:02.273701400Z" />
|
|
||||||
</State>
|
|
||||||
</entry>
|
</entry>
|
||||||
</value>
|
</value>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ 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.activity.viewModels
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
|
import androidx.compose.material.Surface
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import com.anthonyla.livewallpaper.data.settings.SettingsViewModel
|
import com.anthonyla.livewallpaper.data.settings.SettingsViewModel
|
||||||
import com.anthonyla.livewallpaper.themes.LiveWallpaperTheme
|
import com.anthonyla.livewallpaper.themes.LiveWallpaperTheme
|
||||||
import com.anthonyla.livewallpaper.ui.LiveWallpaperApp
|
import com.anthonyla.livewallpaper.ui.LiveWallpaperApp
|
||||||
@@ -16,9 +20,27 @@ class MainActivity : ComponentActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContent {
|
setContent {
|
||||||
LiveWallpaperTheme {
|
LiveWallpaperTheme (isDarkMode(), isDynamicTheming()) {
|
||||||
LiveWallpaperApp(settingsViewModel)
|
Surface(elevation = 5.dp) {
|
||||||
|
LiveWallpaperApp(settingsViewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Composable
|
||||||
|
private fun isDarkMode(): Boolean {
|
||||||
|
return when (settingsViewModel.getDarkMode()) {
|
||||||
|
true -> true
|
||||||
|
false -> false
|
||||||
|
null -> isSystemInDarkTheme()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isDynamicTheming(): Boolean {
|
||||||
|
return when (settingsViewModel.getDynamicTheme()) {
|
||||||
|
true, null -> true
|
||||||
|
false -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,4 +17,5 @@ sealed class BottomNavScreens(val route: String, @StringRes val resourceId: Int,
|
|||||||
object Wallpaper : BottomNavScreens("wallpaper", R.string.wallpaper, Icons.Filled.Home)
|
object Wallpaper : BottomNavScreens("wallpaper", R.string.wallpaper, Icons.Filled.Home)
|
||||||
object Library : BottomNavScreens("library", R.string.library, Icons.Filled.List)
|
object Library : BottomNavScreens("library", R.string.library, Icons.Filled.List)
|
||||||
object Configure : BottomNavScreens("configure", R.string.configure, Icons.Filled.Settings)
|
object Configure : BottomNavScreens("configure", R.string.configure, Icons.Filled.Settings)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,8 @@ import androidx.compose.material3.NavigationBar
|
|||||||
import androidx.compose.material3.NavigationBarDefaults
|
import androidx.compose.material3.NavigationBarDefaults
|
||||||
import androidx.compose.material3.NavigationBarDefaults.containerColor
|
import androidx.compose.material3.NavigationBarDefaults.containerColor
|
||||||
import androidx.compose.material3.NavigationBarItem
|
import androidx.compose.material3.NavigationBarItem
|
||||||
|
import androidx.compose.material3.NavigationBarItemDefaults
|
||||||
|
import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.contentColorFor
|
import androidx.compose.material3.contentColorFor
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -27,7 +29,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState
|
|||||||
@Composable
|
@Composable
|
||||||
fun BottomNavigationBar(
|
fun BottomNavigationBar(
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
screens: List<BottomNavScreens>
|
screens: List<BottomNavScreens>,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
containerColor = containerColor,
|
containerColor = containerColor,
|
||||||
@@ -40,11 +43,12 @@ fun BottomNavigationBar(
|
|||||||
val currentDestination = navBackStackEntry?.destination
|
val currentDestination = navBackStackEntry?.destination
|
||||||
screens.forEach { screen ->
|
screens.forEach { screen ->
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
|
colors = NavigationBarItemDefaults.colors(),
|
||||||
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = screen.resourceId),
|
text = stringResource(id = screen.resourceId),
|
||||||
fontWeight = FontWeight.SemiBold
|
fontWeight = FontWeight.SemiBold,
|
||||||
) },
|
) },
|
||||||
icon = {
|
icon = {
|
||||||
Icon(screen.icon,
|
Icon(screen.icon,
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.anthonyla.livewallpaper.navigation
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Favorite
|
||||||
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
|
import androidx.compose.material3.TopAppBarDefaults.windowInsets
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import com.anthonyla.livewallpaper.R
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun TopBar (
|
||||||
|
navController: NavController,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
CenterAlignedTopAppBar(
|
||||||
|
title = {},
|
||||||
|
navigationIcon = {},
|
||||||
|
windowInsets = windowInsets,
|
||||||
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(),
|
||||||
|
scrollBehavior = null,
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { /* doSomething() */ }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.MoreVert,
|
||||||
|
contentDescription = stringResource(R.string.MoreVertIcon)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
package com.anthonyla.livewallpaper.themes
|
package com.anthonyla.livewallpaper.themes
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import android.os.Build
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.material3.lightColorScheme
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
|
import androidx.compose.material3.dynamicDarkColorScheme
|
||||||
|
import androidx.compose.material3.dynamicLightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
|
||||||
private val LightColors = lightColorScheme(
|
private val LightColors = lightColorScheme(
|
||||||
@@ -72,19 +79,57 @@ private val DarkColors = darkColorScheme(
|
|||||||
scrim = md_theme_dark_scrim,
|
scrim = md_theme_dark_scrim,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val typography = Typography(
|
||||||
|
headlineSmall = TextStyle(
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
fontSize = 24.sp,
|
||||||
|
lineHeight = 32.sp,
|
||||||
|
letterSpacing = 0.sp
|
||||||
|
),
|
||||||
|
titleLarge = TextStyle(
|
||||||
|
fontWeight = FontWeight.Normal,
|
||||||
|
fontSize = 18.sp,
|
||||||
|
lineHeight = 28.sp,
|
||||||
|
letterSpacing = 0.sp
|
||||||
|
),
|
||||||
|
bodyLarge = TextStyle(
|
||||||
|
fontWeight = FontWeight.Normal,
|
||||||
|
fontSize = 16.sp,
|
||||||
|
lineHeight = 24.sp,
|
||||||
|
letterSpacing = 0.15.sp
|
||||||
|
),
|
||||||
|
bodyMedium = TextStyle(
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
fontSize = 14.sp,
|
||||||
|
lineHeight = 20.sp,
|
||||||
|
letterSpacing = 0.25.sp
|
||||||
|
),
|
||||||
|
labelMedium = TextStyle(
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
lineHeight = 16.sp,
|
||||||
|
letterSpacing = 0.5.sp
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LiveWallpaperTheme(
|
fun LiveWallpaperTheme(
|
||||||
useDarkTheme: Boolean = isSystemInDarkTheme(),
|
useDarkTheme: Boolean,
|
||||||
content: @Composable() () -> Unit
|
useDynamicTheme: Boolean,
|
||||||
) {
|
content: @Composable () -> Unit
|
||||||
val colors = if (!useDarkTheme) {
|
) { // Check if dynamic theming is enabled in settings
|
||||||
LightColors
|
val context = LocalContext.current
|
||||||
} else {
|
val colors = when {((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)) && useDynamicTheme -> {
|
||||||
DarkColors
|
if (useDarkTheme) dynamicDarkColorScheme(context)
|
||||||
}
|
else dynamicLightColorScheme(context)
|
||||||
|
}
|
||||||
MaterialTheme(
|
useDarkTheme -> DarkColors
|
||||||
colorScheme = colors,
|
else -> LightColors
|
||||||
content = content
|
}
|
||||||
)
|
MaterialTheme(
|
||||||
|
colorScheme = colors,
|
||||||
|
typography = typography,
|
||||||
|
content = content
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -18,27 +18,31 @@ import androidx.navigation.compose.rememberNavController
|
|||||||
import com.anthonyla.livewallpaper.data.settings.SettingsViewModel
|
import com.anthonyla.livewallpaper.data.settings.SettingsViewModel
|
||||||
import com.anthonyla.livewallpaper.navigation.BottomNavScreens
|
import com.anthonyla.livewallpaper.navigation.BottomNavScreens
|
||||||
import com.anthonyla.livewallpaper.navigation.BottomNavigationBar
|
import com.anthonyla.livewallpaper.navigation.BottomNavigationBar
|
||||||
|
import com.anthonyla.livewallpaper.navigation.TopBar
|
||||||
import com.anthonyla.livewallpaper.navigation.bottomNav
|
import com.anthonyla.livewallpaper.navigation.bottomNav
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun LiveWallpaperApp(settingsViewModel: SettingsViewModel, modifier: Modifier = Modifier) {
|
fun LiveWallpaperApp(settingsViewModel: SettingsViewModel, modifier: Modifier = Modifier) {
|
||||||
|
val navController = rememberNavController()
|
||||||
|
|
||||||
SetTransparentSystemBars()
|
SetTransparentSystemBars()
|
||||||
|
|
||||||
// Bottom navigation
|
// Bottom navigation
|
||||||
val navController = rememberNavController()
|
|
||||||
val bottomNavOptions = listOf(
|
val bottomNavOptions = listOf(
|
||||||
BottomNavScreens.Wallpaper,
|
BottomNavScreens.Wallpaper,
|
||||||
BottomNavScreens.Library,
|
BottomNavScreens.Library,
|
||||||
BottomNavScreens.Configure
|
BottomNavScreens.Configure
|
||||||
)
|
)
|
||||||
Scaffold (
|
Scaffold (
|
||||||
|
topBar = {
|
||||||
|
TopBar(navController = navController)
|
||||||
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
BottomNavigationBar(navController = navController, screens = bottomNavOptions)
|
BottomNavigationBar(navController = navController, screens = bottomNavOptions)
|
||||||
},
|
},
|
||||||
) {
|
) { innerPadding -> NavHost (
|
||||||
innerPadding -> NavHost (
|
|
||||||
navController,
|
navController,
|
||||||
startDestination = "bottomNavigation",
|
startDestination = "bottomNavigation",
|
||||||
Modifier.padding(innerPadding)
|
Modifier.padding(innerPadding)
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
<string name="library">Library</string>
|
<string name="library">Library</string>
|
||||||
<string name="configure">Configure</string>
|
<string name="configure">Configure</string>
|
||||||
<string name="wallpaper">Wallpaper</string>
|
<string name="wallpaper">Wallpaper</string>
|
||||||
|
<string name="MoreVertIcon">Options</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in new issue
Block a user