diff --git a/app/src/main/java/com/example/login_v3/navigation/Main_Screen_tab.kt b/app/src/main/java/com/example/login_v3/navigation/Main_Screen_tab.kt index 46c6cc7..717eae8 100644 --- a/app/src/main/java/com/example/login_v3/navigation/Main_Screen_tab.kt +++ b/app/src/main/java/com/example/login_v3/navigation/Main_Screen_tab.kt @@ -22,62 +22,62 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel import com.example.login_v3.home.Tg_MarketPlace import com.example.login_v3.home.Message.UI.Tg_Message import com.example.login_v3.home.Tg_Server import com.example.login_v3.home.setting.Tg_Setting import androidx.lifecycle.viewmodel.compose.viewModel +import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel +import androidx.hilt.navigation.compose.hiltViewModel // 確保有引入 hiltViewModel +import com.example.login_v3.navigation.components.AppWallpaperBackground @Composable -fun MainScreen_tab() { - +fun MainScreen_tab( + // 注入 Theme_ViewModel 來讀取壁紙狀態 + themeViewModel: Theme_ViewModel = hiltViewModel() +) { val screensViewModel: ScreensViewModel = viewModel() val bottomBarViewModel: BottomBarViewModel = viewModel() - //show bottom bar or not + // show bottom bar or not val showBottomBar by bottomBarViewModel.showBottomBar.collectAsState() val navHeight = 64.dp val gap = 40.dp val bottomBarHeight = navHeight + gap - Scaffold( - containerColor = Color.Transparent, - modifier = Modifier - .fillMaxSize() - .background(brush = Brush.verticalGradient( - colors = listOf( - Color(0xFFDA7029), - Color(0xFF777777), - Color(0xFFB34800) - ) - )), - - bottomBar = { - BottomBarAnimated( - visible = showBottomBar, - height = bottomBarHeight, - content = { - Column(modifier = Modifier.fillMaxWidth()) { - Box( - modifier = Modifier - .fillMaxWidth() - .height(navHeight) - ) { - nav_Wheel_display_block(screensViewModel = screensViewModel) + // 使用剛剛做好的壁紙元件包在最外層 + AppWallpaperBackground(viewModel = themeViewModel) { + Scaffold( + containerColor = Color.Transparent, // 必須保持透明,底層的壁紙才看得到 + modifier = Modifier.fillMaxSize(), + bottomBar = { + BottomBarAnimated( + visible = showBottomBar, + height = bottomBarHeight, + content = { + Column(modifier = Modifier.fillMaxWidth()) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(navHeight) + ) { + nav_Wheel_display_block(screensViewModel = screensViewModel) + } + Spacer(modifier = Modifier.height(gap)) } - Spacer(modifier = Modifier.height(gap)) // 真正的底下空白 } - } + ) + } + ) { innerPadding -> + Screens_NavGraph( + paddingValues = innerPadding, + screensViewModel = screensViewModel, + bottomBarViewModel = bottomBarViewModel ) } - ) { innerPadding -> - Screens_NavGraph( - paddingValues = innerPadding, - screensViewModel = screensViewModel, - bottomBarViewModel = bottomBarViewModel - ) } } diff --git a/app/src/main/java/com/example/login_v3/navigation/components/App_Wallpaper_Background.kt b/app/src/main/java/com/example/login_v3/navigation/components/App_Wallpaper_Background.kt new file mode 100644 index 0000000..1e18bbc --- /dev/null +++ b/app/src/main/java/com/example/login_v3/navigation/components/App_Wallpaper_Background.kt @@ -0,0 +1,59 @@ +package com.example.login_v3.navigation.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale +import coil.compose.AsyncImage +import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel +import java.io.File + +@Composable +fun AppWallpaperBackground( + viewModel: Theme_ViewModel, + modifier: Modifier = Modifier, + content: @Composable () -> Unit +) { + // 監聽來自 DataStore 的壁紙路徑 + val wallpaperPath by viewModel.customWallpaperPath.collectAsState() + + // 檢查檔案是否真的存在 + val wallpaperFile = wallpaperPath?.let { File(it) } + val hasCustomWallpaper = wallpaperFile != null && wallpaperFile.exists() + + Box(modifier = modifier.fillMaxSize()) { + if (hasCustomWallpaper) { + // 1. 如果有自訂壁紙,使用 Coil 填滿背景 + AsyncImage( + model = wallpaperFile, + contentDescription = "App Custom Wallpaper", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Crop // 裁切填滿 + ) + } else { + // 2. 如果沒有,使用你原本的三色漸層 + Box( + modifier = Modifier + .fillMaxSize() + .background( + brush = Brush.verticalGradient( + colors = listOf( + Color(0xFFDA7029), + Color(0xFF777777), + Color(0xFFB34800) + ) + ) + ) + ) + } + + // 3. 將原本的 Scaffold 或內容蓋在背景上方 + content() + } +} \ No newline at end of file