Skip to content

Commit 3ccde65

Browse files
committed
Added enable or disable prefs cache function
1 parent 7503a64 commit 3ccde65

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package com.fankes.coloros.notify.data
2727
import android.content.Context
2828
import com.fankes.coloros.notify.const.IconRuleSourceSyncType
2929
import com.fankes.coloros.notify.utils.factory.isUpperOfAndroidS
30+
import com.highcapable.yukihookapi.YukiHookAPI
3031
import com.highcapable.yukihookapi.hook.factory.prefs
3132
import com.highcapable.yukihookapi.hook.log.loggerW
3233
import com.highcapable.yukihookapi.hook.param.PackageParam
@@ -40,6 +41,9 @@ object ConfigData {
4041
/** 启用模块 */
4142
val ENABLE_MODULE = PrefsData("_enable_module", true)
4243

44+
/** 启用数据缓存 */
45+
val ENABLE_PREFS_CACHE = PrefsData("_enable_prefs_cache", true)
46+
4347
/** 启用模块日志 */
4448
val ENABLE_MODULE_LOG = PrefsData("_enable_module_log", false)
4549

@@ -113,6 +117,8 @@ object ConfigData {
113117
is Context, is PackageParam -> this.instance = instance
114118
else -> error("Unknown type for init ConfigData")
115119
}
120+
/** 设置是否启用数据缓存 */
121+
YukiHookAPI.Configs.isEnablePrefsBridgeCache = isEnablePrefsCache
116122
}
117123

118124
/**
@@ -197,6 +203,16 @@ object ConfigData {
197203
putBoolean(ENABLE_MODULE, value)
198204
}
199205

206+
/**
207+
* 是否启用数据缓存
208+
* @return [Boolean]
209+
*/
210+
var isEnablePrefsCache
211+
get() = getBoolean(ENABLE_PREFS_CACHE)
212+
set(value) {
213+
putBoolean(ENABLE_PREFS_CACHE, value)
214+
}
215+
200216
/**
201217
* 是否启用模块日志
202218
* @return [Boolean]

app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
130130
binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) {
131131
onInitialize {
132132
binding.moduleEnableLogSwitch.isVisible = it
133+
binding.moduleEnableLogText.isVisible = it
134+
binding.modulePrefsCacheEnableSwitch.isVisible = it
135+
binding.modulePrefsCacheEnableText.isVisible = it
133136
binding.expAllDebugLogButton.isVisible = it && ConfigData.isEnableModuleLog
134137
binding.notifyIconConfigItem.isVisible = it
135138
binding.devNotifyConfigItem.isVisible = it
@@ -141,6 +144,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
141144
SystemUITool.showNeedRestartSnake(context = this@MainActivity)
142145
}
143146
}
147+
binding.modulePrefsCacheEnableSwitch.bind(ConfigData.ENABLE_PREFS_CACHE) {
148+
onChanged { SystemUITool.showNeedRestartSnake(context = this@MainActivity) }
149+
}
144150
binding.moduleEnableLogSwitch.bind(ConfigData.ENABLE_MODULE_LOG) {
145151
onInitialize { binding.expAllDebugLogButton.isVisible = it && ConfigData.isEnableModule }
146152
onChanged {

app/src/main/res/layout/activity_main.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,47 @@
253253
android:layout_marginLeft="15dp"
254254
android:layout_marginTop="5dp"
255255
android:layout_marginRight="15dp"
256+
android:layout_marginBottom="5dp"
256257
android:text="启用模块"
257258
android:textColor="@color/colorTextGray"
258259
android:textSize="15sp" />
259260

261+
<TextView
262+
android:layout_width="match_parent"
263+
android:layout_height="wrap_content"
264+
android:layout_marginLeft="15dp"
265+
android:layout_marginRight="15dp"
266+
android:layout_marginBottom="10dp"
267+
android:alpha="0.6"
268+
android:lineSpacingExtra="6dp"
269+
android:text="模块关闭后一切功能都将彻底停止工作。"
270+
android:textColor="@color/colorTextDark"
271+
android:textSize="12sp" />
272+
273+
<com.fankes.coloros.notify.ui.widget.MaterialSwitch
274+
android:id="@+id/module_prefs_cache_enable_switch"
275+
android:layout_width="match_parent"
276+
android:layout_height="30dp"
277+
android:layout_marginLeft="15dp"
278+
android:layout_marginRight="15dp"
279+
android:layout_marginBottom="10dp"
280+
android:text="启用数据缓存"
281+
android:textColor="@color/colorTextGray"
282+
android:textSize="15sp" />
283+
284+
<TextView
285+
android:id="@+id/module_prefs_cache_enable_text"
286+
android:layout_width="match_parent"
287+
android:layout_height="wrap_content"
288+
android:layout_marginLeft="15dp"
289+
android:layout_marginRight="15dp"
290+
android:layout_marginBottom="5dp"
291+
android:alpha="0.6"
292+
android:lineSpacingExtra="6dp"
293+
android:text="此选项默认开启,默认情况下模块会将数据缓存在内存中,防止每次重复读取数据造成卡顿,如果开启此选项后一段时间导致系统界面 (系统 UI) 崩溃 (内存溢出),你可以尝试关闭此选项,但是这有可能会造成在通知较多时下拉通知栏出现卡顿。"
294+
android:textColor="@color/colorTextDark"
295+
android:textSize="12sp" />
296+
260297
<com.fankes.coloros.notify.ui.widget.MaterialSwitch
261298
android:id="@+id/module_enable_log_switch"
262299
android:layout_width="match_parent"
@@ -284,14 +321,15 @@
284321
android:textSize="15sp" />
285322

286323
<TextView
324+
android:id="@+id/module_enable_log_text"
287325
android:layout_width="match_parent"
288326
android:layout_height="wrap_content"
289327
android:layout_marginLeft="15dp"
290328
android:layout_marginRight="15dp"
291329
android:layout_marginBottom="10dp"
292330
android:alpha="0.6"
293331
android:lineSpacingExtra="6dp"
294-
android:text="模块关闭后一切功能都将彻底停止工作"
332+
android:text="默认情况下不建议开启此选项,仅在模块故障时开启,此时你可以发送调试日志给开发者帮助我们快速定位问题"
295333
android:textColor="@color/colorTextDark"
296334
android:textSize="12sp" />
297335
</LinearLayout>

0 commit comments

Comments
 (0)