Просмотр исходного кода

[优化] 添加未开启模糊时的顶栏与底栏透明度选项

HapeLee 7 месяцев назад
Родитель
Сommit
f31138338b

+ 2 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -186,6 +186,8 @@ object PreferKey {
     const val materialVersion = "materialVersion"
     const val materialVersion = "materialVersion"
     const val composeEngine = "composeEngine"
     const val composeEngine = "composeEngine"
     const val containerOpacity = "containerOpacity"
     const val containerOpacity = "containerOpacity"
+    const val topBarOpacity = "topBarOpacity"
+    const val bottomBarOpacity = "bottomBarOpacity"
     const val enableBlur = "enableBlur"
     const val enableBlur = "enableBlur"
     const val enableProgressiveBlur = "enableProgressiveBlur"
     const val enableProgressiveBlur = "enableProgressiveBlur"
     const val useFlexibleTopAppBar = "useFlexibleTopAppBar"
     const val useFlexibleTopAppBar = "useFlexibleTopAppBar"

+ 4 - 0
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfig.kt

@@ -9,6 +9,10 @@ object ThemeConfig {
 
 
     var containerOpacity by prefDelegate(PreferKey.containerOpacity, 100)
     var containerOpacity by prefDelegate(PreferKey.containerOpacity, 100)
 
 
+    var topBarOpacity by prefDelegate(PreferKey.topBarOpacity, 100)
+
+    var bottomBarOpacity by prefDelegate(PreferKey.bottomBarOpacity, 100)
+
     var enableBlur by prefDelegate(PreferKey.enableBlur, false)
     var enableBlur by prefDelegate(PreferKey.enableBlur, false)
 
 
     var enableProgressiveBlur by prefDelegate(PreferKey.enableProgressiveBlur, true)
     var enableProgressiveBlur by prefDelegate(PreferKey.enableProgressiveBlur, true)

+ 46 - 12
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfigScreen.kt

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
 import android.content.Context
 import android.content.Context
 import android.os.Handler
 import android.os.Handler
 import android.os.Looper
 import android.os.Looper
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.animation.core.animateDpAsState
 import androidx.compose.animation.core.animateDpAsState
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.Canvas
 import androidx.compose.foundation.Canvas
@@ -365,6 +366,51 @@ fun ThemeConfigScreen(
                     checked = ThemeConfig.useFlexibleTopAppBar,
                     checked = ThemeConfig.useFlexibleTopAppBar,
                     onCheckedChange = { ThemeConfig.useFlexibleTopAppBar = it }
                     onCheckedChange = { ThemeConfig.useFlexibleTopAppBar = it }
                 )
                 )
+                SwitchSettingItem(
+                    title = stringResource(R.string.is_blur_enable),
+                    checked = ThemeConfig.enableBlur,
+                    onCheckedChange = {
+                        ThemeConfig.enableBlur = it
+                        if (!it) ThemeConfig.enableProgressiveBlur = false
+                    }
+                )
+                AnimatedVisibility(visible = ThemeConfig.enableBlur) {
+                    SwitchSettingItem(
+                        title = stringResource(R.string.is_blur_progressive_enable),
+                        checked = ThemeConfig.enableProgressiveBlur,
+                        onCheckedChange = { ThemeConfig.enableProgressiveBlur = it }
+                    )
+                }
+                AnimatedVisibility(visible = !ThemeConfig.enableBlur) {
+                    Column(
+                        verticalArrangement = Arrangement.spacedBy(2.dp)
+                    ) {
+                        SliderSettingItem(
+                            title = stringResource(R.string.top_bar_opacity),
+                            description = stringResource(
+                                R.string.top_bar_opacity_summary,
+                                ThemeConfig.topBarOpacity
+                            ),
+                            value = ThemeConfig.topBarOpacity.toFloat(),
+                            defaultValue = 100f,
+                            valueRange = 0f..100f,
+                            steps = 99,
+                            onValueChange = { ThemeConfig.topBarOpacity = it.toInt() }
+                        )
+                        SliderSettingItem(
+                            title = stringResource(R.string.bottom_bar_opacity),
+                            description = stringResource(
+                                R.string.bottom_bar_opacity_summary,
+                                ThemeConfig.bottomBarOpacity
+                            ),
+                            value = ThemeConfig.bottomBarOpacity.toFloat(),
+                            defaultValue = 100f,
+                            valueRange = 0f..100f,
+                            steps = 99,
+                            onValueChange = { ThemeConfig.bottomBarOpacity = it.toInt() }
+                        )
+                    }
+                }
                 SliderSettingItem(
                 SliderSettingItem(
                     title = stringResource(R.string.container_opacity),
                     title = stringResource(R.string.container_opacity),
                     description = stringResource(
                     description = stringResource(
@@ -377,18 +423,6 @@ fun ThemeConfigScreen(
                     steps = 99,
                     steps = 99,
                     onValueChange = { ThemeConfig.containerOpacity = it.toInt() }
                     onValueChange = { ThemeConfig.containerOpacity = it.toInt() }
                 )
                 )
-                SwitchSettingItem(
-                    title = stringResource(R.string.is_blur_enable),
-                    checked = ThemeConfig.enableBlur,
-                    onCheckedChange = { ThemeConfig.enableBlur = it }
-                )
-                if (ThemeConfig.enableBlur) {
-                    SwitchSettingItem(
-                        title = stringResource(R.string.is_blur_progressive_enable),
-                        checked = ThemeConfig.enableProgressiveBlur,
-                        onCheckedChange = { ThemeConfig.enableProgressiveBlur = it }
-                    )
-                }
             }
             }
 
 
             SplicedColumnGroup(title = stringResource(R.string.day)) {
             SplicedColumnGroup(title = stringResource(R.string.day)) {

+ 5 - 1
app/src/main/java/io/legado/app/ui/main/MainScreen.kt

@@ -56,6 +56,7 @@ import io.legado.app.R
 import io.legado.app.ui.book.info.BookInfoActivity
 import io.legado.app.ui.book.info.BookInfoActivity
 import io.legado.app.ui.book.search.SearchActivity
 import io.legado.app.ui.book.search.SearchActivity
 import io.legado.app.ui.config.mainConfig.MainConfig
 import io.legado.app.ui.config.mainConfig.MainConfig
+import io.legado.app.ui.config.themeConfig.ThemeConfig
 import io.legado.app.ui.main.bookshelf.BookshelfScreen
 import io.legado.app.ui.main.bookshelf.BookshelfScreen
 import io.legado.app.ui.main.bookshelf.BookshelfViewModel
 import io.legado.app.ui.main.bookshelf.BookshelfViewModel
 import io.legado.app.ui.main.explore.ExploreScreen
 import io.legado.app.ui.main.explore.ExploreScreen
@@ -243,7 +244,10 @@ fun MainScreen(
                         containerColor = GlassDefaults.glassColor(
                         containerColor = GlassDefaults.glassColor(
                             noBlurColor = BottomAppBarDefaults.containerColor,
                             noBlurColor = BottomAppBarDefaults.containerColor,
                             blurAlpha = GlassDefaults.DefaultBlurAlpha
                             blurAlpha = GlassDefaults.DefaultBlurAlpha
-                        )
+                        ).let { baseColor ->
+                            val opacity = (ThemeConfig.bottomBarOpacity.coerceIn(0, 100)) / 100f
+                            baseColor.copy(alpha = (baseColor.alpha * opacity).coerceIn(0f, 1f))
+                        }
                     ) {
                     ) {
                         val alwaysShowLabel = when (labelVisibilityMode) {
                         val alwaysShowLabel = when (labelVisibilityMode) {
                             "labeled" -> true
                             "labeled" -> true

+ 56 - 51
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfConfigSheet.kt

@@ -1,6 +1,7 @@
 package io.legado.app.ui.main.bookshelf
 package io.legado.app.ui.main.bookshelf
 
 
 import android.content.res.Configuration
 import android.content.res.Configuration
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.animation.animateContentSize
 import androidx.compose.animation.animateContentSize
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Column
@@ -95,7 +96,9 @@ fun BookshelfConfigSheet(
 
 
             // Layout Mode
             // Layout Mode
             val layoutMode =
             val layoutMode =
-                if (isLandscape) BookshelfConfig.bookshelfLayoutModeLandscape else BookshelfConfig.bookshelfLayoutModePortrait
+                if (isLandscape) BookshelfConfig.bookshelfLayoutModeLandscape
+                else BookshelfConfig.bookshelfLayoutModePortrait
+
             CompactDropdownSettingItem(
             CompactDropdownSettingItem(
                 title = "布局模式",
                 title = "布局模式",
                 description = stringResource(if (isLandscape) R.string.screen_landscape else R.string.screen_portrait),
                 description = stringResource(if (isLandscape) R.string.screen_landscape else R.string.screen_portrait),
@@ -109,59 +112,61 @@ fun BookshelfConfigSheet(
                 }
                 }
             )
             )
 
 
-            if (layoutMode == 1) {
-                CompactDropdownSettingItem(
-                    title = "网格样式",
-                    selectedValue = BookshelfConfig.bookshelfGridLayout.toString(),
-                    displayEntries = stringArrayResource(R.array.bookshelf_grid_layout),
-                    entryValues = Array(stringArrayResource(R.array.bookshelf_grid_layout).size) { it.toString() },
-                    imageVector = Icons.Default.ViewCompact,
-                    onValueChange = { BookshelfConfig.bookshelfGridLayout = it.toInt() }
-                )
-                CompactSwitchSettingItem(
-                    title = "标题小字体",
-                    checked = BookshelfConfig.bookshelfTitleSmallFont,
-                    imageVector = Icons.Default.TextFormat,
-                    color = MaterialTheme.colorScheme.surface,
-                    onCheckedChange = { BookshelfConfig.bookshelfTitleSmallFont = it }
-                )
-
-                CompactSwitchSettingItem(
-                    title = "标题居中",
-                    checked = BookshelfConfig.bookshelfTitleCenter,
-                    color = MaterialTheme.colorScheme.surface,
-                    onCheckedChange = { BookshelfConfig.bookshelfTitleCenter = it }
-                )
-            } else {
-                CompactSwitchSettingItem(
-                    title = "紧凑模式",
-                    checked = BookshelfConfig.bookshelfLayoutCompact,
-                    imageVector = Icons.Default.ViewCompact,
-                    color = MaterialTheme.colorScheme.surface,
-                    onCheckedChange = { BookshelfConfig.bookshelfLayoutCompact = it }
-                )
-                CompactSwitchSettingItem(
-                    title = "显示分隔线",
-                    checked = BookshelfConfig.bookshelfShowDivider,
-                    imageVector = Icons.Default.ViewCompact,
-                    color = MaterialTheme.colorScheme.surface,
-                    onCheckedChange = { BookshelfConfig.bookshelfShowDivider = it }
-                )
+            AnimatedVisibility(
+                visible = layoutMode == 1
+            ) {
+                Column(
+                    verticalArrangement = Arrangement.spacedBy(8.dp)
+                ) {
+                    CompactDropdownSettingItem(
+                        title = "网格样式",
+                        selectedValue = BookshelfConfig.bookshelfGridLayout.toString(),
+                        displayEntries = stringArrayResource(R.array.bookshelf_grid_layout),
+                        entryValues = Array(stringArrayResource(R.array.bookshelf_grid_layout).size) { it.toString() },
+                        imageVector = Icons.Default.ViewCompact,
+                        onValueChange = { BookshelfConfig.bookshelfGridLayout = it.toInt() }
+                    )
+
+                    CompactSwitchSettingItem(
+                        title = "标题小字体",
+                        checked = BookshelfConfig.bookshelfTitleSmallFont,
+                        imageVector = Icons.Default.TextFormat,
+                        color = MaterialTheme.colorScheme.surface,
+                        onCheckedChange = { BookshelfConfig.bookshelfTitleSmallFont = it }
+                    )
+
+                    CompactSwitchSettingItem(
+                        title = "标题居中",
+                        checked = BookshelfConfig.bookshelfTitleCenter,
+                        color = MaterialTheme.colorScheme.surface,
+                        onCheckedChange = { BookshelfConfig.bookshelfTitleCenter = it }
+                    )
+                }
             }
             }
 
 
-            // Grid Count
-            val gridCount =
-                if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape else BookshelfConfig.bookshelfLayoutGridPortrait
-            CompactSliderSettingItem(
-                title = stringResource(R.string.number_rows_columns),
-                value = gridCount.toFloat(),
-                valueRange = 1f..15f,
-                steps = 14,
-                onValueChange = {
-                    if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape = it.toInt()
-                    else BookshelfConfig.bookshelfLayoutGridPortrait = it.toInt()
+            AnimatedVisibility(
+                visible = layoutMode != 1
+            ) {
+                Column(
+                    verticalArrangement = Arrangement.spacedBy(8.dp)
+                ) {
+                    CompactSwitchSettingItem(
+                        title = "紧凑模式",
+                        checked = BookshelfConfig.bookshelfLayoutCompact,
+                        imageVector = Icons.Default.ViewCompact,
+                        color = MaterialTheme.colorScheme.surface,
+                        onCheckedChange = { BookshelfConfig.bookshelfLayoutCompact = it }
+                    )
+
+                    CompactSwitchSettingItem(
+                        title = "显示分隔线",
+                        checked = BookshelfConfig.bookshelfShowDivider,
+                        imageVector = Icons.Default.ViewCompact,
+                        color = MaterialTheme.colorScheme.surface,
+                        onCheckedChange = { BookshelfConfig.bookshelfShowDivider = it }
+                    )
                 }
                 }
-            )
+            }
 
 
             CompactSliderSettingItem(
             CompactSliderSettingItem(
                 title = "标题最大行数",
                 title = "标题最大行数",

+ 13 - 5
app/src/main/java/io/legado/app/ui/widget/components/GlassMediumFlexibleTopAppBar.kt

@@ -74,32 +74,40 @@ object GlassTopAppBarDefaults {
         }
         }
 
 
         return TopAppBarDefaults.topAppBarColors(
         return TopAppBarDefaults.topAppBarColors(
-            containerColor = containerColor,
-            scrolledContainerColor = scrolledContainerColor
+            containerColor = applyTopBarOpacity(containerColor),
+            scrolledContainerColor = applyTopBarOpacity(scrolledContainerColor)
         )
         )
     }
     }
 
 
     @Composable
     @Composable
     fun containerColor(): Color {
     fun containerColor(): Color {
-        return GlassDefaults.glassColor(
+        val baseColor = GlassDefaults.glassColor(
             noBlurColor = MaterialTheme.colorScheme.surface,
             noBlurColor = MaterialTheme.colorScheme.surface,
             blurAlpha = GlassDefaults.TransparentAlpha
             blurAlpha = GlassDefaults.TransparentAlpha
         )
         )
+        return applyTopBarOpacity(baseColor)
     }
     }
 
 
     @Composable
     @Composable
     fun scrolledContainerColor(): Color {
     fun scrolledContainerColor(): Color {
-        return GlassDefaults.glassColor(
+        val baseColor = GlassDefaults.glassColor(
             noBlurColor = MaterialTheme.colorScheme.surfaceContainer,
             noBlurColor = MaterialTheme.colorScheme.surfaceContainer,
             blurAlpha = GlassDefaults.TransparentAlpha
             blurAlpha = GlassDefaults.TransparentAlpha
         )
         )
+        return applyTopBarOpacity(baseColor)
     }
     }
 
 
     @Composable
     @Composable
     fun controlContainerColor(): Color {
     fun controlContainerColor(): Color {
-        return GlassDefaults.glassColor(
+        val baseColor = GlassDefaults.glassColor(
             noBlurColor = MaterialTheme.colorScheme.surfaceContainerHighest,
             noBlurColor = MaterialTheme.colorScheme.surfaceContainerHighest,
             blurAlpha = GlassDefaults.DefaultBlurAlpha
             blurAlpha = GlassDefaults.DefaultBlurAlpha
         )
         )
+        return applyTopBarOpacity(baseColor)
+    }
+
+    private fun applyTopBarOpacity(color: Color): Color {
+        val opacity = (ThemeConfig.topBarOpacity.coerceIn(0, 100)) / 100f
+        return color.copy(alpha = (color.alpha * opacity).coerceIn(0f, 1f))
     }
     }
 }
 }

+ 3 - 3
app/src/main/java/io/legado/app/ui/widget/components/SplicedColumnGroup.kt

@@ -42,11 +42,11 @@ fun SplicedColumnGroup(
         Card(
         Card(
             shape = RoundedCornerShape(16.dp),
             shape = RoundedCornerShape(16.dp),
             colors = CardDefaults.cardColors(containerColor = Color.Transparent),
             colors = CardDefaults.cardColors(containerColor = Color.Transparent),
-            modifier = Modifier.fillMaxWidth()
+            modifier = Modifier
+                .fillMaxWidth()
+                .animateContentSize()
         ) {
         ) {
             Column(
             Column(
-                modifier = Modifier
-                    .animateContentSize(),
                 verticalArrangement = Arrangement.spacedBy(2.dp)
                 verticalArrangement = Arrangement.spacedBy(2.dp)
             ) {
             ) {
                 content()
                 content()

+ 4 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -1397,6 +1397,10 @@
     <string name="compose_engine">主题风格</string>
     <string name="compose_engine">主题风格</string>
     <string name="container_opacity">容器背景不透明度</string>
     <string name="container_opacity">容器背景不透明度</string>
     <string name="container_opacity_summary">%d</string>
     <string name="container_opacity_summary">%d</string>
+    <string name="top_bar_opacity">顶栏不透明度</string>
+    <string name="top_bar_opacity_summary">%d</string>
+    <string name="bottom_bar_opacity">底栏不透明度</string>
+    <string name="bottom_bar_opacity_summary">%d</string>
     <string name="web_service_auto_start">启动应用时打开Web服务</string>
     <string name="web_service_auto_start">启动应用时打开Web服务</string>
     <string name="read_aloud_preload">听书预加载数量</string>
     <string name="read_aloud_preload">听书预加载数量</string>
     <string name="read_aloud_preload_summary">%d</string>
     <string name="read_aloud_preload_summary">%d</string>

+ 4 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1216,4 +1216,8 @@
     <string name="auto_check_new_backup_s">打开软件时检查是否有新备份,有新备份时提示是否更新</string>
     <string name="auto_check_new_backup_s">打开软件时检查是否有新备份,有新备份时提示是否更新</string>
     <string name="welcome_book_folder_tip">设置本地书籍保存目录,后续也可在设置中修改。</string>
     <string name="welcome_book_folder_tip">设置本地书籍保存目录,后续也可在设置中修改。</string>
     <string name="welcome_book_folder_not_selected">未选择文件夹</string>
     <string name="welcome_book_folder_not_selected">未选择文件夹</string>
+    <string name="top_bar_opacity">頂欄不透明度</string>
+    <string name="top_bar_opacity_summary">%d</string>
+    <string name="bottom_bar_opacity">底欄不透明度</string>
+    <string name="bottom_bar_opacity_summary">%d</string>
 </resources>
 </resources>

+ 4 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -1218,4 +1218,8 @@
     <string name="auto_check_new_backup_s">打开软件时检查是否有新备份,有新备份时提示是否更新</string>
     <string name="auto_check_new_backup_s">打开软件时检查是否有新备份,有新备份时提示是否更新</string>
     <string name="welcome_book_folder_tip">设置本地书籍保存目录,后续也可在设置中修改。</string>
     <string name="welcome_book_folder_tip">设置本地书籍保存目录,后续也可在设置中修改。</string>
     <string name="welcome_book_folder_not_selected">未选择文件夹</string>
     <string name="welcome_book_folder_not_selected">未选择文件夹</string>
+    <string name="top_bar_opacity">頂欄不透明度</string>
+    <string name="top_bar_opacity_summary">%d</string>
+    <string name="bottom_bar_opacity">底欄不透明度</string>
+    <string name="bottom_bar_opacity_summary">%d</string>
 </resources>
 </resources>

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -1401,6 +1401,10 @@
     <string name="compose_engine">主题风格</string>
     <string name="compose_engine">主题风格</string>
     <string name="container_opacity">容器背景不透明度</string>
     <string name="container_opacity">容器背景不透明度</string>
     <string name="container_opacity_summary">%d</string>
     <string name="container_opacity_summary">%d</string>
+    <string name="top_bar_opacity">顶栏不透明度</string>
+    <string name="top_bar_opacity_summary">%d</string>
+    <string name="bottom_bar_opacity">底栏不透明度</string>
+    <string name="bottom_bar_opacity_summary">%d</string>
     <string name="web_service_auto_start">启动应用时打开Web服务</string>
     <string name="web_service_auto_start">启动应用时打开Web服务</string>
     <string name="read_aloud_preload">听书预加载数量</string>
     <string name="read_aloud_preload">听书预加载数量</string>
     <string name="read_aloud_preload_summary">%d</string>
     <string name="read_aloud_preload_summary">%d</string>