Skip to content

Commit

Permalink
perf: some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Feb 22, 2024
1 parent d683296 commit 3d10cfe
Show file tree
Hide file tree
Showing 14 changed files with 692 additions and 667 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ dependencies {

implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room.ktx)
implementation(libs.androidx.room.paging)
ksp(libs.androidx.room.compiler)

implementation(libs.androidx.paging.runtime)
implementation(libs.androidx.paging.compose)

implementation(libs.ktor.server.core)
implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.content.negotiation)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/data/ClickLog.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package li.songe.gkd.data

import android.os.Parcelable
import androidx.paging.PagingSource
import androidx.room.ColumnInfo
import androidx.room.Dao
import androidx.room.Delete
Expand Down Expand Up @@ -49,6 +50,9 @@ data class ClickLog(
@Query("SELECT * FROM click_log ORDER BY id DESC LIMIT 1000")
fun query(): Flow<List<ClickLog>>

@Query("SELECT * FROM click_log ORDER BY id DESC ")
fun pagingSource(): PagingSource<Int, ClickLog>

@Query("SELECT COUNT(*) FROM click_log")
fun count(): Flow<Int>

Expand Down
78 changes: 38 additions & 40 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,53 +295,51 @@ fun AppItemPage(
.padding(16.dp),
shape = RoundedCornerShape(16.dp),
) {
Column {
Text(text = "编辑禁用", modifier = Modifier
Text(text = "编辑禁用", modifier = Modifier
.clickable {
setExcludeGroupRaw(menuGroupRaw)
setMenuGroupRaw(null)
}
.padding(16.dp)
.fillMaxWidth())
if (editable) {
Text(text = "编辑规则组", modifier = Modifier
.clickable {
setExcludeGroupRaw(menuGroupRaw)
setEditGroupRaw(menuGroupRaw)
setMenuGroupRaw(null)
}
.padding(16.dp)
.fillMaxWidth())
if (editable) {
Text(text = "编辑规则组", modifier = Modifier
.clickable {
setEditGroupRaw(menuGroupRaw)
setMenuGroupRaw(null)
}
.padding(16.dp)
.fillMaxWidth())
Text(text = "删除规则组", modifier = Modifier
.clickable {
vm.viewModelScope.launchTry(Dispatchers.IO) {
subsRaw ?: return@launchTry
val newSubsRaw = subsRaw.copy(
apps = subsRaw.apps
.toMutableList()
.apply {
set(
indexOfFirst { a -> a.id == appRawVal.id },
appRawVal.copy(
groups = appRawVal.groups
.filter { g -> g.key != menuGroupRaw.key }
)
Text(text = "删除规则组", modifier = Modifier
.clickable {
vm.viewModelScope.launchTry(Dispatchers.IO) {
subsRaw ?: return@launchTry
val newSubsRaw = subsRaw.copy(
apps = subsRaw.apps
.toMutableList()
.apply {
set(
indexOfFirst { a -> a.id == appRawVal.id },
appRawVal.copy(
groups = appRawVal.groups
.filter { g -> g.key != menuGroupRaw.key }
)
}
)
updateSubscription(newSubsRaw)
DbSet.subsItemDao.update(subsItemVal.copy(mtime = System.currentTimeMillis()))
DbSet.subsConfigDao.delete(
subsItemVal.id, appRawVal.id, menuGroupRaw.key
)
toast("删除成功")
setMenuGroupRaw(null)
}
)
}
)
updateSubscription(newSubsRaw)
DbSet.subsItemDao.update(subsItemVal.copy(mtime = System.currentTimeMillis()))
DbSet.subsConfigDao.delete(
subsItemVal.id, appRawVal.id, menuGroupRaw.key
)
toast("删除成功")
setMenuGroupRaw(null)
}
.padding(16.dp)
.fillMaxWidth(),
color = MaterialTheme.colorScheme.error
)
}
}
.padding(16.dp)
.fillMaxWidth(),
color = MaterialTheme.colorScheme.error
)
}
}
}
Expand Down
106 changes: 51 additions & 55 deletions app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,37 +181,35 @@ fun CategoryPage(subsItemId: Long) {
.padding(16.dp),
shape = RoundedCornerShape(16.dp),
) {
Column {
enableGroupRadioOptions.forEach { option ->
val onClick: () -> Unit = {
vm.viewModelScope.launchTry(Dispatchers.IO) {
DbSet.categoryConfigDao.insert(
(categoryConfig ?: CategoryConfig(
enable = option.second,
subsItemId = subsItemId,
categoryKey = category.key
)).copy(enable = option.second)
)
}
enableGroupRadioOptions.forEach { option ->
val onClick: () -> Unit = {
vm.viewModelScope.launchTry(Dispatchers.IO) {
DbSet.categoryConfigDao.insert(
(categoryConfig ?: CategoryConfig(
enable = option.second,
subsItemId = subsItemId,
categoryKey = category.key
)).copy(enable = option.second)
)
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.selectable(
selected = (option.second == enable),
onClick = onClick
)
.padding(horizontal = 16.dp)
) {
RadioButton(
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.selectable(
selected = (option.second == enable),
onClick = onClick
)
Text(
text = option.first, modifier = Modifier.padding(start = 16.dp)
)
}
.padding(horizontal = 16.dp)
) {
RadioButton(
selected = (option.second == enable),
onClick = onClick
)
Text(
text = option.first, modifier = Modifier.padding(start = 16.dp)
)
}
}
}
Expand Down Expand Up @@ -328,36 +326,34 @@ fun CategoryPage(subsItemId: Long) {
.padding(16.dp),
shape = RoundedCornerShape(16.dp),
) {
Column {
Text(text = "编辑", modifier = Modifier
.clickable {
setEditNameCategory(menuCategory)
setMenuCategory(null)
}
.padding(16.dp)
.fillMaxWidth())
Text(text = "删除", modifier = Modifier
.clickable {
vm.viewModelScope.launchTry(Dispatchers.IO) {
subsItem?.apply {
updateSubscription(subsRawVal.copy(
categories = subsRawVal.categories.filter { c -> c.key != menuCategory.key }
))
DbSet.subsItemDao.update(copy(mtime = System.currentTimeMillis()))
}
DbSet.categoryConfigDao.deleteByCategoryKey(
subsItemId,
menuCategory.key
)
toast("删除成功")
setMenuCategory(null)
Text(text = "编辑", modifier = Modifier
.clickable {
setEditNameCategory(menuCategory)
setMenuCategory(null)
}
.padding(16.dp)
.fillMaxWidth())
Text(text = "删除", modifier = Modifier
.clickable {
vm.viewModelScope.launchTry(Dispatchers.IO) {
subsItem?.apply {
updateSubscription(subsRawVal.copy(
categories = subsRawVal.categories.filter { c -> c.key != menuCategory.key }
))
DbSet.subsItemDao.update(copy(mtime = System.currentTimeMillis()))
}
DbSet.categoryConfigDao.deleteByCategoryKey(
subsItemId,
menuCategory.key
)
toast("删除成功")
setMenuCategory(null)
}
.padding(16.dp)
.fillMaxWidth(),
color = MaterialTheme.colorScheme.error
)
}
}
.padding(16.dp)
.fillMaxWidth(),
color = MaterialTheme.colorScheme.error
)
}
}
}
Expand Down
Loading

0 comments on commit 3d10cfe

Please sign in to comment.