dm-135
This commit is contained in:
parent
c6aad75658
commit
f7a5db99a0
2 changed files with 94 additions and 35 deletions
|
|
@ -22,62 +22,62 @@ import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
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.Tg_MarketPlace
|
||||||
import com.example.login_v3.home.Message.UI.Tg_Message
|
import com.example.login_v3.home.Message.UI.Tg_Message
|
||||||
import com.example.login_v3.home.Tg_Server
|
import com.example.login_v3.home.Tg_Server
|
||||||
import com.example.login_v3.home.setting.Tg_Setting
|
import com.example.login_v3.home.setting.Tg_Setting
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
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
|
@Composable
|
||||||
fun MainScreen_tab() {
|
fun MainScreen_tab(
|
||||||
|
// 注入 Theme_ViewModel 來讀取壁紙狀態
|
||||||
|
themeViewModel: Theme_ViewModel = hiltViewModel()
|
||||||
|
) {
|
||||||
val screensViewModel: ScreensViewModel = viewModel()
|
val screensViewModel: ScreensViewModel = viewModel()
|
||||||
val bottomBarViewModel: BottomBarViewModel = viewModel()
|
val bottomBarViewModel: BottomBarViewModel = viewModel()
|
||||||
|
|
||||||
//show bottom bar or not
|
// show bottom bar or not
|
||||||
val showBottomBar by bottomBarViewModel.showBottomBar.collectAsState()
|
val showBottomBar by bottomBarViewModel.showBottomBar.collectAsState()
|
||||||
val navHeight = 64.dp
|
val navHeight = 64.dp
|
||||||
val gap = 40.dp
|
val gap = 40.dp
|
||||||
val bottomBarHeight = navHeight + gap
|
val bottomBarHeight = navHeight + gap
|
||||||
|
|
||||||
Scaffold(
|
// 使用剛剛做好的壁紙元件包在最外層
|
||||||
containerColor = Color.Transparent,
|
AppWallpaperBackground(viewModel = themeViewModel) {
|
||||||
modifier = Modifier
|
Scaffold(
|
||||||
.fillMaxSize()
|
containerColor = Color.Transparent, // 必須保持透明,底層的壁紙才看得到
|
||||||
.background(brush = Brush.verticalGradient(
|
modifier = Modifier.fillMaxSize(),
|
||||||
colors = listOf(
|
bottomBar = {
|
||||||
Color(0xFFDA7029),
|
BottomBarAnimated(
|
||||||
Color(0xFF777777),
|
visible = showBottomBar,
|
||||||
Color(0xFFB34800)
|
height = bottomBarHeight,
|
||||||
)
|
content = {
|
||||||
)),
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Box(
|
||||||
bottomBar = {
|
modifier = Modifier
|
||||||
BottomBarAnimated(
|
.fillMaxWidth()
|
||||||
visible = showBottomBar,
|
.height(navHeight)
|
||||||
height = bottomBarHeight,
|
) {
|
||||||
content = {
|
nav_Wheel_display_block(screensViewModel = screensViewModel)
|
||||||
Column(modifier = Modifier.fillMaxWidth()) {
|
}
|
||||||
Box(
|
Spacer(modifier = Modifier.height(gap))
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(navHeight)
|
|
||||||
) {
|
|
||||||
nav_Wheel_display_block(screensViewModel = screensViewModel)
|
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(gap)) // 真正的底下空白
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
) { innerPadding ->
|
||||||
|
Screens_NavGraph(
|
||||||
|
paddingValues = innerPadding,
|
||||||
|
screensViewModel = screensViewModel,
|
||||||
|
bottomBarViewModel = bottomBarViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { innerPadding ->
|
|
||||||
Screens_NavGraph(
|
|
||||||
paddingValues = innerPadding,
|
|
||||||
screensViewModel = screensViewModel,
|
|
||||||
bottomBarViewModel = bottomBarViewModel
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue