mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 03:32:38 +08:00
perf: update time interval
This commit is contained in:
parent
262559fe53
commit
526a67bf78
|
@ -47,6 +47,7 @@ import li.songe.gkd.shizuku.shizukuIsSafeOK
|
|||
import li.songe.gkd.shizuku.useSafeGetTasksFc
|
||||
import li.songe.gkd.shizuku.useSafeInputTapFc
|
||||
import li.songe.gkd.shizuku.useShizukuAliveState
|
||||
import li.songe.gkd.ui.home.UpdateTimeOption
|
||||
import li.songe.gkd.util.VOLUME_CHANGED_ACTION
|
||||
import li.songe.gkd.util.checkSubsUpdate
|
||||
import li.songe.gkd.util.launchTry
|
||||
|
@ -387,7 +388,7 @@ class GkdAbService : CompositionAbService({
|
|||
val i = storeFlow.value.updateSubsInterval
|
||||
if (i <= 0) return@onAccessibilityEvent
|
||||
val t = System.currentTimeMillis()
|
||||
if (t - lastUpdateSubsTime > i.coerceAtLeast(60 * 60_000)) {
|
||||
if (t - lastUpdateSubsTime > i.coerceAtLeast(UpdateTimeOption.Everyday.value)) {
|
||||
lastUpdateSubsTime = t
|
||||
checkSubsUpdate()
|
||||
}
|
||||
|
|
|
@ -58,13 +58,18 @@ import li.songe.gkd.data.CategoryConfig
|
|||
import li.songe.gkd.data.RawSubscription
|
||||
import li.songe.gkd.db.DbSet
|
||||
import li.songe.gkd.ui.component.getDialogResult
|
||||
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
|
||||
import li.songe.gkd.util.toast
|
||||
import li.songe.gkd.util.updateSubscription
|
||||
|
||||
val enableGroupRadioOptions = arrayOf(
|
||||
"跟随订阅" to null,
|
||||
"全部启用" to true,
|
||||
"全部关闭" to false,
|
||||
)
|
||||
|
||||
@RootNavGraph
|
||||
@Destination(style = ProfileTransitions::class)
|
||||
@Composable
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.blankj.utilcode.util.ClipboardUtils
|
|||
import com.blankj.utilcode.util.LogUtils
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.update
|
||||
import li.songe.gkd.MainActivity
|
||||
import li.songe.gkd.appScope
|
||||
import li.songe.gkd.ui.component.SettingItem
|
||||
|
@ -102,26 +103,25 @@ fun useSettingsPage(): ScaffoldExt {
|
|||
.padding(16.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
updateTimeRadioOptions.forEach { option ->
|
||||
UpdateTimeOption.allSubObject.forEach { option ->
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(selected = (option.second == store.updateSubsInterval),
|
||||
.selectable(
|
||||
selected = (option.value == store.updateSubsInterval),
|
||||
onClick = {
|
||||
storeFlow.value =
|
||||
store.copy(updateSubsInterval = option.second)
|
||||
|
||||
storeFlow.update { it.copy(updateSubsInterval = option.value) }
|
||||
})
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
RadioButton(
|
||||
selected = (option.second == store.updateSubsInterval),
|
||||
selected = (option.value == store.updateSubsInterval),
|
||||
onClick = {
|
||||
storeFlow.value = store.copy(updateSubsInterval = option.second)
|
||||
storeFlow.update { it.copy(updateSubsInterval = option.value) }
|
||||
})
|
||||
Text(
|
||||
text = option.first, modifier = Modifier.padding(start = 16.dp)
|
||||
text = option.label, modifier = Modifier.padding(start = 16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ fun useSettingsPage(): ScaffoldExt {
|
|||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = updateTimeRadioOptions.find { it.second == store.updateSubsInterval }?.first
|
||||
text = UpdateTimeOption.allSubObject.find { it.value == store.updateSubsInterval }?.label
|
||||
?: store.updateSubsInterval.toString(), fontSize = 14.sp
|
||||
)
|
||||
Icon(
|
||||
|
@ -478,21 +478,19 @@ fun useSettingsPage(): ScaffoldExt {
|
|||
}
|
||||
}
|
||||
|
||||
private val updateTimeRadioOptions = listOf(
|
||||
"暂停" to -1L,
|
||||
"每小时" to 60 * 60_000L,
|
||||
"每6小时" to 6 * 60 * 60_000L,
|
||||
"每12小时" to 12 * 60 * 60_000L,
|
||||
"每天" to 24 * 60 * 60_000L
|
||||
)
|
||||
sealed class UpdateTimeOption(val value: Long, val label: String) {
|
||||
data object Pause : UpdateTimeOption(-1, "暂停")
|
||||
data object Everyday : UpdateTimeOption(24 * 60 * 60_000, "每天")
|
||||
data object Every3Days : UpdateTimeOption(24 * 60 * 60_000 * 3, "每3天")
|
||||
data object Every7Days : UpdateTimeOption(24 * 60 * 60_000 * 7, "每7天")
|
||||
|
||||
private val darkThemeRadioOptions = listOf(
|
||||
companion object {
|
||||
val allSubObject by lazy { arrayOf(Pause, Everyday, Every3Days, Every7Days) }
|
||||
}
|
||||
}
|
||||
|
||||
private val darkThemeRadioOptions = arrayOf(
|
||||
"跟随系统" to null,
|
||||
"启用" to true,
|
||||
"关闭" to false,
|
||||
)
|
||||
val enableGroupRadioOptions = listOf(
|
||||
"跟随订阅" to null,
|
||||
"全部启用" to true,
|
||||
"全部关闭" to false,
|
||||
)
|
|
@ -1,5 +1,6 @@
|
|||
package li.songe.gkd.util
|
||||
|
||||
|
||||
sealed class SortTypeOption(val value: Int, val label: String) {
|
||||
data object SortByName : SortTypeOption(0, "按名称")
|
||||
data object SortByAppMtime : SortTypeOption(1, "按更新时间")
|
||||
|
|
|
@ -10,6 +10,7 @@ import kotlinx.coroutines.withContext
|
|||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import li.songe.gkd.appScope
|
||||
import li.songe.gkd.ui.home.UpdateTimeOption
|
||||
|
||||
private inline fun <reified T> createStorageFlow(
|
||||
key: String,
|
||||
|
@ -45,7 +46,7 @@ data class Store(
|
|||
val excludeFromRecents: Boolean = false,
|
||||
val captureScreenshot: Boolean = false,
|
||||
val httpServerPort: Int = 8888,
|
||||
val updateSubsInterval: Long = 6 * 60 * 60_000L,
|
||||
val updateSubsInterval: Long = UpdateTimeOption.Everyday.value,
|
||||
val captureVolumeChange: Boolean = false,
|
||||
val autoCheckAppUpdate: Boolean = true,
|
||||
val toastWhenClick: Boolean = true,
|
||||
|
@ -63,7 +64,15 @@ data class Store(
|
|||
)
|
||||
|
||||
val storeFlow by lazy {
|
||||
createStorageFlow("store-v2") { Store() }
|
||||
createStorageFlow("store-v2") { Store() }.apply {
|
||||
if (UpdateTimeOption.allSubObject.all { it.value != value.updateSubsInterval }) {
|
||||
update {
|
||||
it.copy(
|
||||
updateSubsInterval = UpdateTimeOption.Everyday.value
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
|
|
Loading…
Reference in New Issue
Block a user