Skip to content

Commit

Permalink
perf: a11yAuth/emptyText/appListAuth tip
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Sep 12, 2024
1 parent 2ce08c8 commit 757193d
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 234 deletions.
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
Expand All @@ -37,6 +36,7 @@ import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import li.songe.gkd.MainActivity
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.StartEllipsisText
import li.songe.gkd.ui.component.waitResult
import li.songe.gkd.ui.style.EmptyHeight
Expand Down Expand Up @@ -138,11 +138,7 @@ fun ActivityLogPage() {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (logCount == 0) {
Text(
text = "暂无记录",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
)
EmptyText(text = "暂无记录")
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
Expand All @@ -59,6 +58,7 @@ import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.updateDialogOptions
import li.songe.gkd.ui.destinations.AppItemPageDestination
import li.songe.gkd.ui.destinations.GlobalRulePageDestination
Expand Down Expand Up @@ -255,11 +255,7 @@ fun AppConfigPage(appId: String) {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (globalGroups.size + appGroups.size == 0) {
Text(
text = "暂无规则",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center
)
EmptyText(text = "暂无规则")
} else {
// 避免被 floatingActionButton 遮挡
Spacer(modifier = Modifier.height(EmptyHeight))
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
Expand All @@ -68,6 +67,7 @@ import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.waitResult
import li.songe.gkd.ui.destinations.GroupImagePageDestination
Expand Down Expand Up @@ -344,11 +344,7 @@ fun AppItemPage(
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (appRaw.groups.isEmpty()) {
Text(
text = "暂无规则",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center
)
EmptyText(text = "暂无规则")
} else if (editable) {
Spacer(modifier = Modifier.height(EmptyHeight))
}
Expand Down
62 changes: 24 additions & 38 deletions app/src/main/kotlin/li/songe/gkd/ui/AuthA11yPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.AlertDialog
Expand All @@ -25,9 +26,6 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -50,6 +48,7 @@ import li.songe.gkd.permission.shizukuOkState
import li.songe.gkd.permission.writeSecureSettingsState
import li.songe.gkd.service.fixRestartService
import li.songe.gkd.shizuku.newPackageManager
import li.songe.gkd.util.AuthModeOption
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.launchAsFn
Expand All @@ -69,7 +68,7 @@ fun AuthA11yPage() {
val vm = viewModel<AuthA11yVm>()
val showCopyDlg by vm.showCopyDlgFlow.collectAsState()
val writeSecureSettings by writeSecureSettingsState.stateFlow.collectAsState()
var mode by remember { mutableIntStateOf(-1) }
val authModeOption by vm.authModeOptionFlow.collectAsState()

val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = {
Expand Down Expand Up @@ -108,35 +107,30 @@ fun AuthA11yPage() {
.padding(16.dp, 0.dp)
.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = if (mode == 0) {
containerColor = if (authModeOption == AuthModeOption.Basic) {
MaterialTheme.colorScheme.primaryContainer
} else {
Color.Unspecified
}
),
onClick = { mode = 0 }
onClick = { vm.authModeOptionFlow.value = AuthModeOption.Basic }
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = mode == 0,
onClick = { mode = 0 }
selected = authModeOption == AuthModeOption.Basic,
onClick = { vm.authModeOptionFlow.value = AuthModeOption.Basic }
)
Text(
text = "普通授权(简单)",
text = "${AuthModeOption.Basic.label}(简单)",
style = MaterialTheme.typography.bodyLarge,
)
}
Text(
modifier = Modifier.padding(16.dp, 0.dp),
style = MaterialTheme.typography.bodyMedium,
text = "1. 授予[无障碍权限]"
)
Text(
modifier = Modifier.padding(16.dp, 0.dp),
style = MaterialTheme.typography.bodyMedium,
text = "2. 无障碍服务关闭后需重新授权"
text = "1. 授予[无障碍权限]\n2. 无障碍服务关闭后需重新授权"
)
Row(
modifier = Modifier
Expand All @@ -158,37 +152,27 @@ fun AuthA11yPage() {
.padding(16.dp, 0.dp)
.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = if (mode == 1) {
containerColor = if (authModeOption == AuthModeOption.Advanced) {
MaterialTheme.colorScheme.primaryContainer
} else {
Color.Unspecified
}
),
onClick = { mode = 1 }
onClick = { vm.authModeOptionFlow.value = AuthModeOption.Advanced }
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = mode == 1,
onClick = { mode = 1 }
selected = authModeOption == AuthModeOption.Advanced,
onClick = { vm.authModeOptionFlow.value = AuthModeOption.Advanced }
)
Text(text = "高级授权(推荐)")
Text(text = "${AuthModeOption.Advanced.label}(推荐)")
}
Text(
modifier = Modifier.padding(16.dp, 0.dp),
style = MaterialTheme.typography.bodyMedium,
text = "1. 授予[写入安全设置权限]"
)
Text(
modifier = Modifier.padding(16.dp, 0.dp),
style = MaterialTheme.typography.bodyMedium,
text = "2. 授权永久有效, 可自动重启无障碍服务"
)
Text(
modifier = Modifier.padding(16.dp, 0.dp),
style = MaterialTheme.typography.bodyMedium,
text = "3. 搭配通知栏快捷图标可实现无感重启, 无限保活"
text = "1. 授予[写入安全设置权限]\n2. 授权永久有效, 可自动重启无障碍服务\n3. 搭配通知栏快捷图标可实现无感重启, 无限保活"
)
Row(
modifier = Modifier
Expand Down Expand Up @@ -234,13 +218,15 @@ fun AuthA11yPage() {
Column(modifier = Modifier.fillMaxWidth()) {
Text(text = "1. 有一台安装了 adb 的电脑\n\n2.手机开启调试模式后连接电脑授权调试\n\n3. 在电脑 cmd/pwsh 中运行如下命令")
Spacer(modifier = Modifier.height(4.dp))
Text(
text = commandText,
modifier = Modifier
.clip(MaterialTheme.shapes.extraSmall)
.background(MaterialTheme.colorScheme.secondaryContainer)
.padding(4.dp)
)
SelectionContainer {
Text(
text = commandText,
modifier = Modifier
.clip(MaterialTheme.shapes.extraSmall)
.background(MaterialTheme.colorScheme.secondaryContainer)
.padding(4.dp)
)
}
}
},
confirmButton = {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/AuthA11yVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import li.songe.gkd.permission.writeSecureSettingsState
import li.songe.gkd.util.AuthModeOption

class AuthA11yVm : ViewModel() {
init {
Expand All @@ -21,4 +22,5 @@ class AuthA11yVm : ViewModel() {
}

val showCopyDlgFlow = MutableStateFlow(false)
}
val authModeOptionFlow = MutableStateFlow<AuthModeOption?>(null)
}
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
Expand All @@ -52,6 +51,7 @@ import li.songe.gkd.MainActivity
import li.songe.gkd.data.CategoryConfig
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.updateDialogOptions
import li.songe.gkd.ui.component.waitResult
Expand Down Expand Up @@ -267,11 +267,7 @@ fun CategoryPage(subsItemId: Long) {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (categories.isEmpty()) {
Text(
text = "暂无类别",
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
EmptyText(text = "暂无类别")
} else if (editable) {
Spacer(modifier = Modifier.height(EmptyHeight))
}
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
Expand All @@ -58,6 +57,7 @@ import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.stringify
import li.songe.gkd.data.switch
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.StartEllipsisText
import li.songe.gkd.ui.component.waitResult
import li.songe.gkd.ui.destinations.AppItemPageDestination
Expand Down Expand Up @@ -196,11 +196,7 @@ fun ClickLogPage() {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (clickLogCount == 0) {
Text(
text = "暂无记录",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center
)
EmptyText(text = "暂无记录")
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import li.songe.gkd.data.stringify
import li.songe.gkd.db.DbSet
import li.songe.gkd.service.launcherAppId
import li.songe.gkd.ui.component.AppBarTextField
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.QueryPkgAuthCard
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.style.EmptyHeight
import li.songe.gkd.ui.style.appItemPadding
Expand Down Expand Up @@ -349,10 +351,11 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(text = "暂无搜索结果")
EmptyText(text = "暂无搜索结果")
Spacer(modifier = Modifier.height(EmptyHeight))
}
}
QueryPkgAuthCard()
}
}
})
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
Expand All @@ -65,6 +64,7 @@ import li.songe.gkd.MainActivity
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.TowLineText
import li.songe.gkd.ui.component.waitResult
import li.songe.gkd.ui.destinations.GlobalRuleExcludePageDestination
Expand Down Expand Up @@ -299,11 +299,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (globalGroups.isEmpty()) {
Text(
text = "暂无规则",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center
)
EmptyText(text = "暂无规则")
} else if (editable) {
Spacer(modifier = Modifier.height(EmptyHeight))
}
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -28,12 +27,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import com.ramcosta.composedestinations.navigation.navigate
import li.songe.gkd.MainActivity
import li.songe.gkd.ui.component.EmptyText
import li.songe.gkd.ui.component.updateDialogOptions
import li.songe.gkd.ui.destinations.AppItemPageDestination
import li.songe.gkd.ui.destinations.GlobalRulePageDestination
Expand Down Expand Up @@ -127,11 +126,7 @@ fun SlowGroupPage() {
item {
Spacer(modifier = Modifier.height(EmptyHeight))
if (ruleSummary.slowGroupCount == 0) {
Text(
text = "暂无规则",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center
)
EmptyText(text = "暂无规则")
}
}
}
Expand Down
Loading

0 comments on commit 757193d

Please sign in to comment.