Skip to content

Commit

Permalink
feat: 应用-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Feb 5, 2024
1 parent 6c552c1 commit 0c1c617
Show file tree
Hide file tree
Showing 31 changed files with 1,640 additions and 926 deletions.
27 changes: 25 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/data/AppInfo.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
package li.songe.gkd.data

import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.graphics.drawable.Drawable
import android.os.Build
import li.songe.gkd.app

data class AppInfo(
val id: String,
val name: String,
val icon: Drawable?,
val versionCode: Int,
val versionCode: Long,
val versionName: String?,
val isSystem: Boolean,
)
val mtime: Long,
)

fun PackageInfo.toAppInfo(): AppInfo? {
applicationInfo ?: return null
return AppInfo(
id = packageName,
name = applicationInfo.loadLabel(app.packageManager).toString(),
icon = applicationInfo.loadIcon(app.packageManager),
versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
longVersionCode
} else {
@Suppress("DEPRECATION")
versionCode.toLong()
},
versionName = versionName,
isSystem = (ApplicationInfo.FLAG_SYSTEM and applicationInfo.flags) != 0,
mtime = lastUpdateTime
)
}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/data/AppRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AppRule(
subsItem: SubsItem,
group: RawSubscription.RawAppGroup,
rawSubs: RawSubscription,
exclude: String,
exclude: String?,
val app: RawSubscription.RawApp,
) : ResolvedRule(
rule = rule,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GlobalRule(
rule: RawSubscription.RawGlobalRule,
group: RawSubscription.RawGlobalGroup,
rawSubs: RawSubscription,
exclude: String,
exclude: String?,
) : ResolvedRule(
rule = rule,
group = group,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/data/ResolvedRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sealed class ResolvedRule(
val group: RawSubscription.RawGroupProps,
val rawSubs: RawSubscription,
val subsItem: SubsItem,
val exclude: String,
val exclude: String?,
) {
val key = rule.key
val index = group.rules.indexOf(rule)
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/kotlin/li/songe/gkd/service/AbState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import li.songe.gkd.data.GlobalRule
import li.songe.gkd.data.ResolvedRule
import li.songe.gkd.data.SubsConfig
import li.songe.gkd.db.DbSet
import li.songe.gkd.util.AllRules
import li.songe.gkd.util.Ext.getDefaultLauncherAppId
import li.songe.gkd.util.allRulesFlow
import li.songe.gkd.util.RuleSummary
import li.songe.gkd.util.increaseClickCount
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.recordStoreFlow
import li.songe.gkd.util.ruleSummaryFlow

data class TopActivity(
val appId: String = "",
Expand All @@ -31,7 +31,7 @@ data class ActivityRule(
private val appRules: List<AppRule> = emptyList(),
private val globalRules: List<GlobalRule> = emptyList(),
val topActivity: TopActivity = TopActivity(),
val allRules: AllRules = AllRules(),
val ruleSummary: RuleSummary = RuleSummary(),
) {
val currentRules = (appRules + globalRules).sortedBy { r -> r.order }
}
Expand All @@ -57,17 +57,17 @@ private fun getFixTopActivity(): TopActivity {
fun getAndUpdateCurrentRules(): ActivityRule {
val topActivity = getFixTopActivity()
val oldActivityRule = activityRuleFlow.value
val allRules = allRulesFlow.value
val allRules = ruleSummaryFlow.value
val idChanged = topActivity.appId != oldActivityRule.topActivity.appId
val topChanged = idChanged || oldActivityRule.topActivity != topActivity
if (topChanged || oldActivityRule.allRules !== allRules) {
if (topChanged || oldActivityRule.ruleSummary !== allRules) {
val newActivityRule = ActivityRule(
allRules = allRules,
ruleSummary = allRules,
topActivity = topActivity,
appRules = (allRules.appIdToRules[topActivity.appId] ?: emptyList()).filter { rule ->
rule.matchActivity(topActivity.appId, topActivity.activityId)
},
globalRules = allRulesFlow.value.globalRules.filter { r ->
globalRules = ruleSummaryFlow.value.globalRules.filter { r ->
r.matchActivity(topActivity.appId, topActivity.activityId)
},
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ class GkdAbService : CompositionAbService({
}
}
val t = System.currentTimeMillis()
if (t - lastTriggerTime < 10_000 || t - appChangeTime < 5_000) {
scope.launch(actionThread) {// 在任意规则触发10s内或APP切换5s内使用主动探测查询
if (t - lastTriggerTime < 5_000 || t - appChangeTime < 5_000) {
scope.launch(actionThread) {// 在任意规则触发5s内或APP切换5s内使用主动探测查询
delay(300)
if (queryTaskJob?.isActive != true) {
newQueryTask()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/service/ManageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import li.songe.gkd.composition.CompositionService
import li.songe.gkd.notif.abNotif
import li.songe.gkd.notif.createNotif
import li.songe.gkd.notif.defaultChannel
import li.songe.gkd.util.allRulesFlow
import li.songe.gkd.util.clickCountFlow
import li.songe.gkd.util.map
import li.songe.gkd.util.ruleSummaryFlow
import li.songe.gkd.util.storeFlow

class ManageService : CompositionService({
Expand All @@ -27,7 +27,7 @@ class ManageService : CompositionService({
val scope = useScope()
scope.launch {
combine(
allRulesFlow,
ruleSummaryFlow,
clickCountFlow,
storeFlow.map(scope) { it.enableService },
GkdAbService.isRunning
Expand Down
129 changes: 129 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package li.songe.gkd.ui

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.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
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
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.appInfoCacheFlow
import li.songe.gkd.util.ruleSummaryFlow

@RootNavGraph
@Destination(style = ProfileTransitions::class)
@Composable
fun AppConfigPage(appId: String) {
val navController = LocalNavController.current
val vm = hiltViewModel<AppConfigVm>()
val appInfoCache by appInfoCacheFlow.collectAsState()
val appInfo = appInfoCache[appId]
val ruleSummary by ruleSummaryFlow.collectAsState()

val globalGroups = ruleSummary.globalGroups

val appGroups = ruleSummary.appIdToAllGroups[appId] ?: emptyList()

Scaffold(topBar = {
TopAppBar(navigationIcon = {
IconButton(onClick = {
navController.popBackStack()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
)
}
}, title = {
Text(
text = appInfo?.name ?: appId,
maxLines = 1,
softWrap = false,
overflow = TextOverflow.Ellipsis,
)
}, actions = {})
}, content = { contentPadding ->
LazyColumn(
modifier = Modifier.padding(contentPadding)
) {
items(appGroups) { (group, enable) ->
Row(
modifier = Modifier
.padding(10.dp, 6.dp)
.fillMaxWidth()
.height(45.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column(
modifier = Modifier
.weight(1f)
.fillMaxHeight(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
text = group.name,
maxLines = 1,
softWrap = false,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth()
)
if (group.valid) {
Text(
text = group.desc ?: "",
maxLines = 1,
softWrap = false,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth(),
fontSize = 14.sp
)
} else {
Text(
text = "非法选择器",
modifier = Modifier.fillMaxWidth(),
fontSize = 14.sp,
color = MaterialTheme.colorScheme.error
)
}
}
Spacer(modifier = Modifier.width(10.dp))
IconButton(onClick = {}) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = "more",
)
}
Spacer(modifier = Modifier.width(10.dp))
Switch(checked = enable, modifier = Modifier, onCheckedChange = {})
}
}
}
})
}
11 changes: 11 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package li.songe.gkd.ui

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class AppConfigVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() {

}
1 change: 1 addition & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import kotlinx.coroutines.Dispatchers
import li.songe.gkd.data.CategoryConfig
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.db.DbSet
import li.songe.gkd.ui.home.enableGroupRadioOptions
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.launchTry
Expand Down
Loading

0 comments on commit 0c1c617

Please sign in to comment.