Skip to content

Commit

Permalink
feat: 支持显示 exampleUrls + 状态栏优化
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 8, 2023
1 parent 05ddbb2 commit 7357897
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 361 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,7 @@ dependencies {
implementation(libs.others.reorderable)

implementation(libs.androidx.splashscreen)

implementation(libs.coil.compose)
implementation(libs.coil.gif)
}
5 changes: 2 additions & 3 deletions app/src/main/java/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import androidx.activity.compose.setContent
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import com.dylanc.activityresult.launcher.PickContentLauncher
Expand All @@ -29,7 +28,6 @@ import li.songe.gkd.util.storeFlow

@AndroidEntryPoint
class MainActivity : CompositionActivity({
installSplashScreen()
useLifeCycleLog()

val launcher = StartActivityLauncher(this)
Expand All @@ -47,7 +45,8 @@ class MainActivity : CompositionActivity({
}

setContent {
val navController = rememberNavController()

val navController = rememberNavController()
AppTheme {
UpgradeDialog()
CompositionLocalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package li.songe.gkd.composition
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen

open class CompositionActivity(
private val block: CompositionActivity.(Bundle?) -> Unit,
Expand All @@ -26,6 +28,8 @@ open class CompositionActivity(
}

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
super.onCreate(savedInstanceState)
block(savedInstanceState)
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/li/songe/gkd/data/SubscriptionRaw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ data class SubscriptionRaw(
}
}
}

@IgnoredOnParcel
val allExampleUrls by lazy {
mutableListOf<String>().apply {
if (exampleUrls != null) {
addAll(exampleUrls)
}
rules.forEach { r ->
if (r.exampleUrls != null) {
addAll(r.exampleUrls)
}
}
}
}
}

@Serializable
Expand Down
36 changes: 27 additions & 9 deletions app/src/main/java/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import kotlinx.serialization.encodeToString
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.data.SubscriptionRaw
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.destinations.GroupItemPageDestination
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.Singleton
Expand All @@ -66,6 +67,7 @@ import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.subsIdToRawFlow
import li.songe.gkd.util.navigate

@RootNavGraph
@Destination(style = ProfileTransitions::class)
Expand Down Expand Up @@ -238,16 +240,32 @@ fun AppItemPage(
}
},
confirmButton = {
TextButton(onClick = {
val groupAppText = Singleton.json.encodeToString(
appRaw?.copy(
groups = listOf(showGroupItemVal)
Row {
if (showGroupItemVal.allExampleUrls.isNotEmpty()) {
TextButton(onClick = {
setShowGroupItem(null)
navController.navigate(
GroupItemPageDestination(
subsInt = subsItemId,
appId = appId,
groupKey = showGroupItemVal.key
)
)
}) {
Text(text = "查看图片")
}
}
TextButton(onClick = {
val groupAppText = Singleton.json.encodeToString(
appRaw?.copy(
groups = listOf(showGroupItemVal)
)
)
)
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
}) {
Text(text = "复制规则组")
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
}) {
Text(text = "复制规则组")
}
}
})
}
Expand Down
187 changes: 85 additions & 102 deletions app/src/main/java/li/songe/gkd/ui/ControlPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -48,7 +45,6 @@ import li.songe.gkd.util.usePollState

val controlNav = BottomNavItem(label = "主页", icon = SafeR.ic_home, route = "settings")

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ControlPage() {
val context = LocalContext.current as MainActivity
Expand All @@ -64,116 +60,103 @@ fun ControlPage() {
}
val canDrawOverlays by usePollState { Settings.canDrawOverlays(context) }

Scaffold(
topBar = {
TopAppBar(title = {
Text(
text = "GKD"
)

Column(
modifier = Modifier.verticalScroll(
state = rememberScrollState()
)
) {
if (!notifEnabled) {
AuthCard(title = "通知权限", desc = "用于启动后台服务,展示服务运行状态", onAuthClick = {
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)
})
},
) { padding ->
Column(
modifier = Modifier
.verticalScroll(
state = rememberScrollState()
)
.padding(padding)
) {
if (!notifEnabled) {
AuthCard(title = "通知权限",
desc = "用于启动后台服务,展示服务运行状态",
onAuthClick = {
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()
}
Divider()
}

if (!gkdAccessRunning) {
AuthCard(title = "无障碍权限",
desc = "用于获取屏幕信息,点击屏幕上的控件",
onAuthClick = {
if (notifEnabled) {
appScope.launchTry(Dispatchers.IO) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
// android.content.ActivityNotFoundException
// https://bugly.qq.com/v2/crash-reporting/crashes/d0ce46b353/113010?pid=1
context.startActivity(intent)
}
} else {
ToastUtils.showShort("必须先开启[通知权限]")
if (!gkdAccessRunning) {
AuthCard(title = "无障碍权限",
desc = "用于获取屏幕信息,点击屏幕上的控件",
onAuthClick = {
if (notifEnabled) {
appScope.launchTry(Dispatchers.IO) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
// android.content.ActivityNotFoundException
// https://bugly.qq.com/v2/crash-reporting/crashes/d0ce46b353/113010?pid=1
context.startActivity(intent)
}
})
Divider()
}
} else {
ToastUtils.showShort("必须先开启[通知权限]")
}
})
Divider()
}

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 (!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
)
if (gkdAccessRunning) {
TextSwitch(name = "服务开启",
desc = "保持服务开启,根据订阅规则匹配屏幕目标节点",
checked = store.enableService,
onCheckedChange = {
updateStorage(
storeFlow, store.copy(
enableService = it
)
})
Divider()
}

Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.clickable {
navController.navigate(ClickLogPageDestination)
}
.padding(10.dp, 5.dp),
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = "点击记录", fontSize = 18.sp
)
Spacer(modifier = Modifier.height(2.dp))
Text(
text = "如误触可在此快速定位关闭规则", fontSize = 14.sp
)
}
Icon(imageVector = Icons.Default.KeyboardArrowRight, contentDescription = null)
}
})
Divider()
}

Column(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp, 5.dp)
) {
Text(text = subsStatus, fontSize = 18.sp)
if (latestRecordDesc != null) {
Text(
text = "最近点击: $latestRecordDesc", fontSize = 14.sp
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.clickable {
navController.navigate(ClickLogPageDestination)
}
.padding(10.dp, 5.dp),
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = "点击记录", fontSize = 18.sp
)
Spacer(modifier = Modifier.height(2.dp))
Text(
text = "如误触可在此快速定位关闭规则", fontSize = 14.sp
)
}
Icon(imageVector = Icons.Default.KeyboardArrowRight, contentDescription = null)
}
Divider()

Column(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp, 5.dp)
) {
Text(text = subsStatus, fontSize = 18.sp)
if (latestRecordDesc != null) {
Text(
text = "最近点击: $latestRecordDesc", fontSize = 14.sp
)
}
}

}
}
Loading

0 comments on commit 7357897

Please sign in to comment.