Skip to content

Commit

Permalink
1.修复分类视图的全选和搜索bug
Browse files Browse the repository at this point in the history
2.微调ui界面
3.优化横屏(平板用户)的界面布局
如果分类视图中压缩包整合类型的MOD无法正常显示需要刷新再重试, 如果依然存在为题可能需要卸载后重新安装
  • Loading branch information
laoxinH committed Oct 28, 2024
1 parent fcf941b commit a1207ef
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 154 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/top/laoxin/modmanager/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MainActivity : ComponentActivity() {
darkIcons = true
)
systemUiController.setNavigationBarColor(
color = colors.background,
color = colors.surfaceContainer,
darkIcons = true
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class UserPreferencesRepository(
"SCAN_DIRECTORY_MODS" to booleanPreferencesKey("SCAN_DIRECTORY_MODS"),
// 删除解压目录
"DELETE_UNZIP_DIRECTORY" to booleanPreferencesKey("DELETE_UNZIP_DIRECTORY"),
// 展示分类视图
"SHOW_CATEGORY_VIEW" to booleanPreferencesKey("SHOW_CATEGORY_VIEW"),
)
const val TAG = "UserPreferencesRepo"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ data class ConsoleUiState(
// 显示删除解压目录弹窗
val showDeleteUnzipDialog: Boolean = false,
val delUnzipDictionary: Boolean = false,
// 展示分类视图
val showCategoryView: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ data class ModUiState(
val searchContent: String = "",
// 当前的游戏mod目录
val currentGameModPath: String = "",
// 当前页面的文件
val currentFiles: List<File> = emptyList(),
val isShowBack: Boolean = true
// 当前页面的mods
val currentMods: List<ModBean> = emptyList()
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ data class UserPreferencesState(
val selectedGameIndex: Int = 0,
val scanDirectoryMods: Boolean = false,
val delUnzipDictionary: Boolean = false,
// 展示分类视图
val showCategoryView: Boolean = false,
)
43 changes: 33 additions & 10 deletions app/src/main/java/top/laoxin/modmanager/ui/view/Console.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.laoxin.modmanager.ui.view

import android.annotation.SuppressLint
import android.content.res.Configuration
import android.net.Uri
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
Expand Down Expand Up @@ -139,11 +140,11 @@ fun ConsoleContent(viewModel: ConsoleViewModel) {
viewModel.setOpenPermissionRequestDialog(false)
}
}
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(8.dp))
// 权限信息
// PermissionInformationCard()

Spacer(modifier = Modifier.height(16.dp))
// Spacer(modifier = Modifier.height(16.dp))
// 游戏信息
GameInformationCard(
viewModel,
Expand Down Expand Up @@ -418,6 +419,19 @@ fun ConfigurationCard(viewModel: ConsoleViewModel, uiState: ConsoleUiState) {
viewModel.openDelUnzipDialog(it)
})
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = stringResource(id = R.string.console_configuration_show_browswer),
style = typography.titleMedium
)
Switch(checked = uiState.showCategoryView, onCheckedChange = {
viewModel.setShowCategoryView(it)
})
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
Expand Down Expand Up @@ -467,19 +481,28 @@ fun ConsolePage(viewModel: ConsoleViewModel) {

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun ConsoleTopBar(viewModel: ConsoleViewModel) {
fun ConsoleTopBar(
viewModel: ConsoleViewModel,
modifier: Modifier = Modifier,

configuration: Int
) {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
titleContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
navigationIconContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
containerColor = if (configuration == Configuration.ORIENTATION_LANDSCAPE) MaterialTheme.colorScheme.surface else MaterialTheme.colorScheme.surfaceContainer,
//titleContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
//navigationIconContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
),
modifier = modifier,

title = {
Text(
stringResource(id = R.string.console),
style = typography.titleLarge
if ( configuration != Configuration.ORIENTATION_LANDSCAPE) {
Text(
stringResource(id = R.string.console),
style = typography.titleLarge

)
)
}
},
actions = {
Text(text = "启动游戏")
Expand Down
91 changes: 60 additions & 31 deletions app/src/main/java/top/laoxin/modmanager/ui/view/ModManagerApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import android.graphics.drawable.BitmapDrawable
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -24,6 +30,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Dashboard
import androidx.compose.material.icons.filled.ImagesearchRoller
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand All @@ -33,6 +40,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
Expand Down Expand Up @@ -69,6 +77,7 @@ enum class NavigationIndex(
}


@OptIn(ExperimentalAnimationApi::class)
@Composable
fun ModManagerApp() {
val modViewModel: ModViewModel = viewModel(factory = ModViewModel.Factory)
Expand All @@ -93,9 +102,9 @@ fun ModManagerApp() {
topBar = {
// 根据当前页面显示不同的顶部工具栏
when (pagerState.currentPage) {
NavigationIndex.CONSOLE.ordinal -> ConsoleTopBar(consoleViewModel)
NavigationIndex.MOD.ordinal -> ModTopBar(modViewModel)
NavigationIndex.SETTINGS.ordinal -> SettingTopBar()
NavigationIndex.CONSOLE.ordinal -> ConsoleTopBar(consoleViewModel,configuration = configuration.orientation)
NavigationIndex.MOD.ordinal -> ModTopBar(modViewModel,configuration = configuration.orientation)
NavigationIndex.SETTINGS.ordinal -> SettingTopBar(configuration = configuration.orientation)
}
val uiState by modViewModel.uiState.collectAsState()
Tips(
Expand All @@ -117,7 +126,7 @@ fun ModManagerApp() {
) { innerPadding ->
val context = LocalContext.current // 在这里获取 Context
val exitToast: Toast =
remember { Toast.makeText(context, "再按一次退出应用", Toast.LENGTH_SHORT) }
remember { Toast.makeText(context, context.getText(R.string.toast_quit_qpp), Toast.LENGTH_SHORT) }
val activity = context as? Activity // 获取当前 Activity

BackHandler(enabled = pagerState.currentPage == NavigationIndex.CONSOLE.ordinal) {
Expand All @@ -140,16 +149,31 @@ fun ModManagerApp() {
}
}

HorizontalPager(
state = pagerState,
count = NavigationIndex.entries.size,
modifier = Modifier.padding(innerPadding)
) { page ->
// 根据当前页显示不同的内容
when (page) {
NavigationIndex.CONSOLE.ordinal -> ConsolePage(consoleViewModel)
NavigationIndex.MOD.ordinal -> ModPage(modViewModel)
NavigationIndex.SETTINGS.ordinal -> SettingPage()
// 使用 AnimatedContent 实现页面切换动画
AnimatedContent(
targetState = pagerState.currentPage,
transitionSpec = {
if (targetState > initialState) {
(slideInHorizontally(initialOffsetX = { fullWidth -> fullWidth }) + fadeIn()).togetherWith(
slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth }) + fadeOut()
)
} else {
(slideInHorizontally(initialOffsetX = { fullWidth -> -fullWidth }) + fadeIn()).togetherWith(
slideOutHorizontally(targetOffsetX = { fullWidth -> fullWidth }) + fadeOut()
)
}.using(SizeTransform(clip = false))
}
) { _ ->
HorizontalPager(
state = pagerState,
count = NavigationIndex.entries.size,
modifier = Modifier.padding(innerPadding)
) { page ->
when (page) {
NavigationIndex.CONSOLE.ordinal -> ConsolePage(consoleViewModel)
NavigationIndex.MOD.ordinal -> ModPage(modViewModel)
NavigationIndex.SETTINGS.ordinal -> SettingPage()
}
}
}
}
Expand All @@ -173,25 +197,33 @@ fun NavigationRail(
NavigationRail(
modifier = Modifier
.fillMaxHeight()
.padding(0.dp)
.padding(0.dp),
// containerColor = MaterialTheme.colorScheme.surfaceContainer,
) {
// 顶部的按钮
// 顶部的当前页面名称
val currentPageName = stringResource(id = NavigationIndex.entries[pagerState.currentPage].title)
Text(
text = currentPageName,
modifier = Modifier.padding(16.dp)
)
Column {

NavigationIndex.entries.forEachIndexed { index, navigationItem ->
val isSelected = pagerState.currentPage == index



NavigationRailItem(
selected = isSelected,
onClick = {
val currentTime = System.currentTimeMillis()
if ((currentTime - lastClickTime) < 300 && isSelected) { // 检测双击
// 刷新当前页面的逻辑
if ((currentTime - lastClickTime) < 300 && isSelected) {
refreshCurrentPage(pagerState.currentPage, modViewModel)
} else {
modViewModel.exitSelect()
if (!isSelected) {
coroutineScope.launch {
pagerState.scrollToPage(index)
pagerState.animateScrollToPage(index)
}
}
}
Expand All @@ -209,26 +241,24 @@ fun NavigationRail(
Text(text = stringResource(id = navigationItem.title))
}
},
alwaysShowLabel = false // 确保标签只在 isSelected 为 true 时显示
alwaysShowLabel = false
)
// 两个选项间添加间隔
Spacer(modifier = Modifier.padding(10.dp))
}
}

Spacer(modifier = Modifier.weight(1f)) // 将游戏图标推到最底部
Spacer(modifier = Modifier.weight(1f))

// 底部的游戏图标
Column(
modifier = Modifier
.padding(bottom = 16.dp) // 调整底部间距
.padding(bottom = 16.dp)
) {
gameIcon?.let {
Image(
bitmap = it,
contentDescription = null,
modifier = Modifier
.size(64.dp) // 调整图标大小
.size(64.dp)
.padding(8.dp)
)
}
Expand All @@ -245,7 +275,7 @@ fun NavigationBar(
val coroutineScope = rememberCoroutineScope()
var lastClickTime by remember { mutableLongStateOf(0L) }

NavigationBar {
NavigationBar() {
NavigationIndex.entries.forEachIndexed { index, navigationItem ->
val isSelected = pagerState.currentPage == index

Expand All @@ -254,13 +284,12 @@ fun NavigationBar(
onClick = {
val currentTime = System.currentTimeMillis()
if ((currentTime - lastClickTime) < 300 && isSelected) { // 检测双击
// 刷新当前页面的逻辑
refreshCurrentPage(pagerState.currentPage, modViewModel)
} else {
modViewModel.exitSelect()
if (!isSelected) {
coroutineScope.launch {
pagerState.scrollToPage(index)
pagerState.animateScrollToPage(index)
}
}
}
Expand All @@ -278,7 +307,7 @@ fun NavigationBar(
Text(text = stringResource(id = navigationItem.title))
}
},
alwaysShowLabel = false // 确保标签只在 isSelected 为 true 时显示
alwaysShowLabel = false
)
}
}
Expand Down Expand Up @@ -340,8 +369,8 @@ fun getGameIcon(packageName: String): ImageBitmap? {
Bitmap.Config.ARGB_8888
).also { bitmap ->
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
(drawable as AdaptiveIconDrawable).setBounds(0, 0, canvas.width, canvas.height)
(drawable as AdaptiveIconDrawable).draw(canvas)
}
}

Expand Down
29 changes: 18 additions & 11 deletions app/src/main/java/top/laoxin/modmanager/ui/view/Setting.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.laoxin.modmanager.ui.view

import android.content.Context
import android.content.res.Configuration
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -442,17 +443,23 @@ fun ThinksDialogCommon(

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingTopBar() {
TopAppBar(colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
titleContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
navigationIconContentColor = MaterialTheme.colorScheme.onSecondaryContainer,
),
title = {
Text(
stringResource(id = R.string.settings), style = MaterialTheme.typography.titleLarge
)
})
fun SettingTopBar(modifier: Modifier = Modifier, configuration: Int) {
if( configuration != Configuration.ORIENTATION_LANDSCAPE) {
TopAppBar(
modifier = modifier,
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceContainer,

),
title = {

Text(
stringResource(id = R.string.settings), style = MaterialTheme.typography.titleLarge
)

})
}

}

@Preview
Expand Down
Loading

0 comments on commit a1207ef

Please sign in to comment.