Skip to content

Commit

Permalink
ui: Slim navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
mikooomich committed Nov 1, 2024
1 parent a6051da commit 0b7b59b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
28 changes: 22 additions & 6 deletions app/src/main/java/com/dd3boh/outertune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.add
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.only
Expand Down Expand Up @@ -81,6 +82,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastAny
Expand Down Expand Up @@ -129,6 +131,7 @@ import com.dd3boh.outertune.constants.ScannerSensitivityKey
import com.dd3boh.outertune.constants.ScannerStrictExtKey
import com.dd3boh.outertune.constants.SearchSource
import com.dd3boh.outertune.constants.SearchSourceKey
import com.dd3boh.outertune.constants.SlimNavBarKey
import com.dd3boh.outertune.constants.StopMusicOnTaskClearKey
import com.dd3boh.outertune.db.MusicDatabase
import com.dd3boh.outertune.db.entities.SearchHistory
Expand Down Expand Up @@ -428,6 +431,7 @@ class MainActivity : ComponentActivity() {
val inSelectMode = navBackStackEntry?.savedStateHandle?.getStateFlow("inSelectMode", false)?.collectAsState()
val (previousTab, setPreviousTab) = rememberSaveable { mutableStateOf("home") }

val (slimNav) = rememberPreference(SlimNavBarKey, defaultValue = false)
val (enabledTabs) = rememberPreference(EnabledTabsKey, defaultValue = DEFAULT_ENABLED_TABS)
val navigationItems =
if (!newInterfaceStyle) Screens.getScreens(enabledTabs) else Screens.MainScreensNew
Expand Down Expand Up @@ -500,6 +504,15 @@ class MainActivity : ComponentActivity() {
navBackStackEntry?.destination?.route == null ||
navigationItems.fastAny { it.route == navBackStackEntry?.destination?.route } && !active
}

fun getNavPadding(): Dp {
return if (shouldShowNavigationBar) {
if (slimNav) 48.dp else 64.dp
} else {
0.dp
}
}

val navigationBarHeight by animateDpAsState(
targetValue = if (shouldShowNavigationBar) NavigationBarHeight else 0.dp,
animationSpec = NavigationBarAnimationSpec,
Expand All @@ -508,7 +521,7 @@ class MainActivity : ComponentActivity() {

val playerBottomSheetState = rememberBottomSheetState(
dismissedBound = 0.dp,
collapsedBound = bottomInset + (if (shouldShowNavigationBar) NavigationBarHeight else 0.dp) + MiniPlayerHeight,
collapsedBound = bottomInset + getNavPadding() + MiniPlayerHeight + 4.dp,
expandedBound = maxHeight,
)

Expand Down Expand Up @@ -807,6 +820,7 @@ class MainActivity : ComponentActivity() {
NavigationBar(
modifier = Modifier
.align(Alignment.BottomCenter)
.height(bottomInset + getNavPadding())
.offset {
if (navigationBarHeight == 0.dp) {
IntOffset(
Expand Down Expand Up @@ -838,11 +852,13 @@ class MainActivity : ComponentActivity() {
)
},
label = {
Text(
text = stringResource(screen.titleId),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
if (!slimNav) {
Text(
text = stringResource(screen.titleId),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
},
onClick = {
if (navBackStackEntry?.destination?.hierarchy?.any { it.route == screen.route } == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val FlatSubfoldersKey = booleanPreferencesKey("flatSubfolders")
val EnabledTabsKey = stringPreferencesKey("enabledTabs")
val DefaultOpenTabKey = stringPreferencesKey("defaultOpenTab")
val DefaultOpenTabNewKey = stringPreferencesKey("defaultOpenTabNew")
val SlimNavBarKey = booleanPreferencesKey("slimNavBar")

/**
* Content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material.icons.rounded.Contrast
import androidx.compose.material.icons.rounded.DarkMode
import androidx.compose.material.icons.rounded.DragHandle
import androidx.compose.material.icons.rounded.FolderCopy
import androidx.compose.material.icons.rounded.MoreHoriz
import androidx.compose.material.icons.rounded.Palette
import androidx.compose.material.icons.rounded.PlaylistPlay
import androidx.compose.material.icons.rounded.Reorder
Expand Down Expand Up @@ -56,6 +57,7 @@ import com.dd3boh.outertune.constants.NewInterfaceKey
import com.dd3boh.outertune.constants.PlayerBackgroundStyleKey
import com.dd3boh.outertune.constants.PureBlackKey
import com.dd3boh.outertune.constants.ShowLikedAndDownloadedPlaylist
import com.dd3boh.outertune.constants.SlimNavBarKey
import com.dd3boh.outertune.constants.ThumbnailCornerRadius
import com.dd3boh.outertune.extensions.move
import com.dd3boh.outertune.ui.component.ActionPromptDialog
Expand Down Expand Up @@ -105,6 +107,7 @@ fun AppearanceSettings(
val (defaultOpenTabNew, onDefaultOpenTabNewChange) = rememberEnumPreference(DefaultOpenTabNewKey, defaultValue = NavigationTabNew.HOME)
val (newInterfaceStyle, onNewInterfaceStyleChange) = rememberPreference(key = NewInterfaceKey, defaultValue = true)
val (showLikedAndDownloadedPlaylist, onShowLikedAndDownloadedPlaylistChange) = rememberPreference(key = ShowLikedAndDownloadedPlaylist, defaultValue = true)
val (slimNav, onSlimNavChange) = rememberPreference(SlimNavBarKey, defaultValue = false)
val (flatSubfolders, onFlatSubfoldersChange) = rememberPreference(FlatSubfoldersKey, defaultValue = true)

val availableBackgroundStyles = PlayerBackgroundStyle.entries.filter {
Expand Down Expand Up @@ -204,6 +207,14 @@ fun AppearanceSettings(
onCheckedChange = onShowLikedAndDownloadedPlaylistChange
)

SwitchPreference(
title = { Text(stringResource(R.string.slim_navbar_title)) },
description = stringResource(R.string.slim_navbar_description),
icon = { Icon(Icons.Rounded.MoreHoriz, null) },
checked = slimNav,
onCheckedChange = onSlimNavChange
)

PreferenceEntry(
title = { Text("Tab arrangement") },
icon = { Icon(Icons.Rounded.Reorder, null) },
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@
<string name="player_background_blur">Blur</string>
<string name="new_interface">New interface layout</string>
<string name="show_liked_and_downloaded_playlist">Show liked and downloaded playlists in library</string>">
<string name="slim_navbar_title">Slim navbar</string>
<string name="slim_navbar_description">Remove text labels to reduce navbar height</string>

<!-- Content settings -->
<string name="ytm_sync">Automatically sync with your YouTube Music account</string>
Expand Down

0 comments on commit 0b7b59b

Please sign in to comment.