From d7bad7164e2d582492984b725006c1aa0bf9110a Mon Sep 17 00:00:00 2001 From: lisonge Date: Sat, 9 Sep 2023 16:17:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/li/songe/gkd/ui/ControlPage.kt | 78 ++++++++++++++----- .../main/java/li/songe/gkd/ui/ControlVm.kt | 6 +- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/li/songe/gkd/ui/ControlPage.kt b/app/src/main/java/li/songe/gkd/ui/ControlPage.kt index cf88d34..ccd0d3d 100644 --- a/app/src/main/java/li/songe/gkd/ui/ControlPage.kt +++ b/app/src/main/java/li/songe/gkd/ui/ControlPage.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material.Divider import androidx.compose.material.Icon import androidx.compose.material.Scaffold import androidx.compose.material.Text @@ -26,7 +27,9 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.core.app.NotificationManagerCompat import androidx.hilt.navigation.compose.hiltViewModel +import com.blankj.utilcode.util.ToastUtils import com.ramcosta.composedestinations.navigation.navigate import li.songe.gkd.MainActivity import li.songe.gkd.service.GkdAbService @@ -47,7 +50,6 @@ fun ControlPage() { val navController = LocalNavController.current val vm = hiltViewModel() val latestRecordDesc by vm.latestRecordDescFlow.collectAsState() - val subsStatus by vm.subsStatusFlow.collectAsState() val store by storeFlow.collectAsState() @@ -68,31 +70,69 @@ fun ControlPage() { .padding(0.dp, 10.dp) .padding(padding) ) { - val gkdAccessRunning by usePollState { GkdAbService.isRunning() } - if (!gkdAccessRunning) { - AuthCard(title = "无障碍授权", - desc = "用于获取屏幕信息,点击屏幕上的控件", + + val notifEnabled by usePollState { + NotificationManagerCompat.from(context).areNotificationsEnabled() + } + if (!notifEnabled) { + AuthCard(title = "通知权限", + desc = "用于启动后台服务,展示服务运行状态", onAuthClick = { - val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + val intent = Intent() + intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) + intent.putExtra(Settings.EXTRA_CHANNEL_ID, context.applicationInfo.uid) context.startActivity(intent) }) + Divider() + } + + val gkdAccessRunning by usePollState { GkdAbService.isRunning() } + if (!gkdAccessRunning) { + AuthCard(title = "无障碍权限", + desc = "用于获取屏幕信息,点击屏幕上的控件", + onAuthClick = { + if (notifEnabled) { + val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(intent) + } else { + ToastUtils.showShort("必须先开启[通知权限]") + } + }) + Divider() } - Spacer(modifier = Modifier.height(5.dp)) - TextSwitch(name = "服务开启", - desc = "保持服务开启,根据订阅规则匹配屏幕目标节点", - checked = store.enableService, - onCheckedChange = { - updateStorage( - storeFlow, store.copy( - enableService = it + val canDrawOverlays by usePollState { Settings.canDrawOverlays(context) } + if (!canDrawOverlays) { + AuthCard(title = "悬浮窗权限", + desc = "用于后台提示,显示保存快照按钮等功能", + onAuthClick = { + val intent = Intent( + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, ) - ) - }) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(intent) + }) + Divider() + } + + + if (gkdAccessRunning) { + TextSwitch(name = "服务开启", + desc = "保持服务开启,根据订阅规则匹配屏幕目标节点", + checked = store.enableService, + onCheckedChange = { + updateStorage( + storeFlow, store.copy( + enableService = it + ) + ) + }) + Divider() + } - Spacer(modifier = Modifier.height(5.dp)) Row( horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, @@ -112,7 +152,7 @@ fun ControlPage() { fontSize = 14.sp ) } - Icon(imageVector = Icons.Default.KeyboardArrowRight, contentDescription = null) + Icon(imageVector = Icons.Default.KeyboardArrowRight, contentDescription = "") } } diff --git a/app/src/main/java/li/songe/gkd/ui/ControlVm.kt b/app/src/main/java/li/songe/gkd/ui/ControlVm.kt index 6a35ade..f0fae56 100644 --- a/app/src/main/java/li/songe/gkd/ui/ControlVm.kt +++ b/app/src/main/java/li/songe/gkd/ui/ControlVm.kt @@ -23,9 +23,9 @@ class ControlVm @Inject constructor() : ViewModel() { ) { latestRecord, subsIdToRaw, appInfoCache -> if (latestRecord == null) return@combine null val groupName = - subsIdToRaw[latestRecord?.subsId]?.apps?.find { a -> a.id == latestRecord?.appId }?.groups?.find { g -> g.key == latestRecord?.groupKey }?.name - val appName = appInfoCache[latestRecord?.appId]?.name - val appShowName = appName ?: latestRecord?.appId ?: "" + subsIdToRaw[latestRecord.subsId]?.apps?.find { a -> a.id == latestRecord.appId }?.groups?.find { g -> g.key == latestRecord.groupKey }?.name + val appName = appInfoCache[latestRecord.appId]?.name + val appShowName = appName ?: latestRecord.appId ?: "" if (groupName != null) { if (groupName.contains(appShowName)) { groupName