manager: Improve loading and empty state handling in SuperUserScreen

This commit is contained in:
ShirkNeko
2025-07-03 00:03:59 +08:00
parent fc828ff3aa
commit eccc70c0c9

View File

@@ -1,5 +1,6 @@
package com.sukisu.ultra.ui.screen package com.sukisu.ultra.ui.screen
import android.annotation.SuppressLint
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.* import androidx.compose.animation.core.*
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -26,7 +27,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
@@ -462,13 +462,14 @@ fun SuperUserScreen(navigator: DestinationsNavigator) {
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
// 根据加载状态显示不同内容 // 根据加载状态显示不同内容
if (viewModel.isRefreshing || viewModel.appList.isEmpty()) { if ((viewModel.isRefreshing || viewModel.appList.isEmpty()) && viewModel.search.isEmpty()) {
LoadingAnimation( LoadingAnimation(
isLoading = true isLoading = true
) )
} else { } else {
EmptyState( EmptyState(
selectedCategory = selectedCategory selectedCategory = selectedCategory,
isSearchEmpty = viewModel.search.isNotEmpty()
) )
} }
} }
@@ -900,17 +901,6 @@ private fun LoadingAnimation(
) { ) {
val infiniteTransition = rememberInfiniteTransition(label = "loading") val infiniteTransition = rememberInfiniteTransition(label = "loading")
// 旋转动画
val rotation by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
),
label = "rotation"
)
// 透明度动画 // 透明度动画
val alpha by infiniteTransition.animateFloat( val alpha by infiniteTransition.animateFloat(
initialValue = 0.3f, initialValue = 0.3f,
@@ -932,18 +922,6 @@ private fun LoadingAnimation(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
// 主加载图标
Icon(
imageVector = Icons.Filled.Refresh,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary.copy(alpha = alpha),
modifier = Modifier
.size(64.dp)
.rotate(rotation)
)
Spacer(modifier = Modifier.height(16.dp))
// 进度指示器 // 进度指示器
LinearProgressIndicator( LinearProgressIndicator(
modifier = Modifier modifier = Modifier
@@ -960,9 +938,11 @@ private fun LoadingAnimation(
* 空状态组件 * 空状态组件
*/ */
@Composable @Composable
@SuppressLint("ModifierParameter")
private fun EmptyState( private fun EmptyState(
selectedCategory: AppCategory, selectedCategory: AppCategory,
modifier: Modifier = Modifier modifier: Modifier = Modifier,
isSearchEmpty: Boolean = false
) { ) {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
@@ -970,7 +950,7 @@ private fun EmptyState(
modifier = modifier modifier = modifier
) { ) {
Icon( Icon(
imageVector = Icons.Filled.Archive, imageVector = if (isSearchEmpty) Icons.Filled.SearchOff else Icons.Filled.Archive,
contentDescription = null, contentDescription = null,
tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.6f), tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.6f),
modifier = Modifier modifier = Modifier
@@ -978,7 +958,7 @@ private fun EmptyState(
.padding(bottom = 16.dp) .padding(bottom = 16.dp)
) )
Text( Text(
text = if (selectedCategory == AppCategory.ALL) { text = if (isSearchEmpty || selectedCategory == AppCategory.ALL) {
stringResource(R.string.no_apps_found) stringResource(R.string.no_apps_found)
} else { } else {
stringResource(R.string.no_apps_in_category) stringResource(R.string.no_apps_in_category)