Skip to content

Commit

Permalink
feat: 规则启用控制
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 23, 2023
1 parent e9d94ad commit 5cd30e4
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 129 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/li/songe/gkd/data/ClickLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ data class ClickLog(
@Delete
suspend fun delete(vararg objects: ClickLog): Int


@Query("DELETE FROM click_log WHERE subs_id=:subsItemId")
suspend fun deleteBySubsId(subsItemId: Long): Int

@Query("DELETE FROM click_log")
suspend fun deleteAll()

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/li/songe/gkd/data/SubsItem.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package li.songe.gkd.data

import android.content.ContentValues
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Dao
Expand Down Expand Up @@ -42,11 +41,12 @@ data class SubsItem(
}

suspend fun removeAssets() {
DbSet.subsItemDao.delete(this)
DbSet.subsConfigDao.delete(id)
withContext(IO) {
subsFile.exists() && subsFile.delete()
}
DbSet.subsItemDao.delete(this)
DbSet.subsConfigDao.delete(id)
DbSet.clickLogDao.deleteBySubsId(id)
}

companion object {
Expand Down
79 changes: 41 additions & 38 deletions app/src/main/java/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import li.songe.gkd.util.Singleton
import li.songe.gkd.util.appInfoCacheFlow
import li.songe.gkd.util.launchAsFn
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.storeFlow
import li.songe.gkd.util.subsIdToRawFlow

@RootNavGraph
Expand All @@ -81,6 +82,7 @@ fun AppItemPage(
val subsConfigs by vm.subsConfigsFlow.collectAsState()
val appRaw by vm.subsAppFlow.collectAsState()
val appInfoCache by appInfoCacheFlow.collectAsState()
val store by storeFlow.collectAsState()

val appRawVal = appRaw
val subsItemVal = subsItem
Expand Down Expand Up @@ -187,18 +189,19 @@ fun AppItemPage(
}

val subsConfig = subsConfigs.find { it.groupKey == group.key }
Switch(checked = (subsConfig?.enable ?: group.enable) ?: true,
modifier = Modifier,
onCheckedChange = scope.launchAsFn { enable ->
val newItem = (subsConfig?.copy(enable = enable) ?: SubsConfig(
type = SubsConfig.GroupType,
subsItemId = subsItemId,
appId = appId,
groupKey = group.key,
enable = enable
))
DbSet.subsConfigDao.insert(newItem)
})
Switch(checked = (subsConfig?.enable ?: store.enableGroup ?: group.enable
?: true),
modifier = Modifier,
onCheckedChange = scope.launchAsFn { enable ->
val newItem = (subsConfig?.copy(enable = enable) ?: SubsConfig(
type = SubsConfig.GroupType,
subsItemId = subsItemId,
appId = appId,
groupKey = group.key,
enable = enable
))
DbSet.subsConfigDao.insert(newItem)
})
}
}
}
Expand All @@ -212,32 +215,32 @@ fun AppItemPage(

showGroupItem?.let { showGroupItemVal ->
AlertDialog(modifier = Modifier.defaultMinSize(300.dp),
onDismissRequest = { setShowGroupItem(null) },
title = {
Text(text = showGroupItemVal.name)
},
text = {
Column {
if (showGroupItemVal.enable == false) {
Text(text = "该规则组默认不启用")
Spacer(modifier = Modifier.height(10.dp))
}
Text(text = showGroupItemVal.desc ?: "-")
}
},
confirmButton = {
TextButton(onClick = {
val groupAppText = Singleton.json.encodeToString(
appRaw?.copy(
groups = listOf(showGroupItemVal)
)
)
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
}) {
Text(text = "复制规则组")
}
})
onDismissRequest = { setShowGroupItem(null) },
title = {
Text(text = showGroupItemVal.name)
},
text = {
Column {
if (showGroupItemVal.enable == false) {
Text(text = "该规则组默认不启用")
Spacer(modifier = Modifier.height(10.dp))
}
Text(text = showGroupItemVal.desc ?: "-")
}
},
confirmButton = {
TextButton(onClick = {
val groupAppText = Singleton.json.encodeToString(
appRaw?.copy(
groups = listOf(showGroupItemVal)
)
)
ClipboardUtils.copyText(groupAppText)
ToastUtils.showShort("复制成功")
}) {
Text(text = "复制规则组")
}
})
}

if (menuGroupRaw != null && appRawVal != null && subsItemVal != null) {
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/li/songe/gkd/ui/ControlPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,6 @@ fun ControlPage() {
)
})
Divider()

TextSwitch(name = "无障碍前台",
desc = "某些机型需添加前台悬浮窗才能正常工作",
checked = store.enableAbFloatWindow,
onCheckedChange = {
updateStorage(
storeFlow, store.copy(
enableAbFloatWindow = it
)
)
})
Divider()
}

Row(
Expand Down
Loading

0 comments on commit 5cd30e4

Please sign in to comment.