diff --git a/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt b/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt index e970b97..98372f0 100644 --- a/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt +++ b/app/src/main/java/com/fankes/coloros/notify/data/ConfigData.kt @@ -109,30 +109,6 @@ object ConfigData { } } - /** - * 读取 [Int] 数据 - * @param data 键值数据模板 - * @return [Int] - */ - private fun getInt(data: PrefsData) = when (instance) { - is Context -> (instance as Context).modulePrefs.get(data) - is PackageParam -> (instance as PackageParam).prefs.get(data) - else -> error("Unknown type for get prefs data") - } - - /** - * 存入 [Int] 数据 - * @param data 键值数据模板 - * @param value 键值内容 - */ - private fun putInt(data: PrefsData, value: Int) { - when (instance) { - is Context -> (instance as Context).modulePrefs.put(data, value) - is PackageParam -> loggerW(msg = "Not support for this method") - else -> error("Unknown type for put prefs data") - } - } - /** * 读取 [String] 数据 * @param data 键值数据模板 @@ -157,6 +133,30 @@ object ConfigData { } } + /** + * 读取 [Int] 数据 + * @param data 键值数据模板 + * @return [Int] + */ + internal fun getInt(data: PrefsData) = when (instance) { + is Context -> (instance as Context).modulePrefs.get(data) + is PackageParam -> (instance as PackageParam).prefs.get(data) + else -> error("Unknown type for get prefs data") + } + + /** + * 存入 [Int] 数据 + * @param data 键值数据模板 + * @param value 键值内容 + */ + internal fun putInt(data: PrefsData, value: Int) { + when (instance) { + is Context -> (instance as Context).modulePrefs.put(data, value) + is PackageParam -> loggerW(msg = "Not support for this method") + else -> error("Unknown type for put prefs data") + } + } + /** * 读取 [Boolean] 数据 * @param data 键值数据模板 diff --git a/app/src/main/java/com/fankes/coloros/notify/data/factory/SeekBarFactory.kt b/app/src/main/java/com/fankes/coloros/notify/data/factory/SeekBarFactory.kt new file mode 100644 index 0000000..c3e3bce --- /dev/null +++ b/app/src/main/java/com/fankes/coloros/notify/data/factory/SeekBarFactory.kt @@ -0,0 +1,57 @@ +/* + * ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications. + * Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com) + * https://github.com/fankes/ColorOSNotifyIcon + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + *

+ * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * + * This file is Created by fankes on 2023/2/4. + */ +@file:Suppress("SetTextI18n") + +package com.fankes.coloros.notify.data.factory + +import android.widget.SeekBar +import android.widget.TextView +import com.fankes.coloros.notify.data.ConfigData +import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData + +/** + * 绑定到 [SeekBar] 自动设置进度与 [TextView] + * @param data 键值数据模板 + * @param textView 文本框 + * @param suffix 文本显示的后缀 - 默认空 + * @param onChange 当改变停止时回调 + */ +fun SeekBar.bind(data: PrefsData, textView: TextView, suffix: String = "", onChange: (Int) -> Unit = {}) { + ConfigData.getInt(data).also { value -> + textView.text = "$value$suffix" + progress = value + } + setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + textView.text = "$progress$suffix" + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + ConfigData.putInt(data, seekBar.progress) + onChange(seekBar.progress) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) {} + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt index e01e6b7..3427acb 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt @@ -24,8 +24,6 @@ package com.fankes.coloros.notify.ui.activity -import android.widget.SeekBar -import android.widget.SeekBar.OnSeekBarChangeListener import androidx.core.view.isVisible import com.fankes.coloros.notify.BuildConfig import com.fankes.coloros.notify.R @@ -126,10 +124,6 @@ class MainActivity : BaseActivity() { binding.notifyMediaPanelAutoExpSwitch.isVisible = false binding.notifyMediaPanelAutoExpText.isVisible = false } - binding.notifyPanelConfigSeekbar.progress = ConfigData.notifyPanelAlphaLevel - binding.notifyIconCustomCornerSeekbar.progress = ConfigData.notifyIconCornerSize - binding.notifyPanelConfigText.text = "${ConfigData.notifyPanelAlphaLevel}%" - binding.notifyIconCustomCornerText.text = "${ConfigData.notifyIconCornerSize} dp" binding.notifyIconAutoSyncText.text = ConfigData.notifyIconFixAutoTime binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) { onInitialize { @@ -237,30 +231,12 @@ class MainActivity : BaseActivity() { SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true) } } - binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - binding.notifyPanelConfigText.text = "$progress%" - } - - override fun onStopTrackingTouch(seekBar: SeekBar) { - ConfigData.notifyPanelAlphaLevel = seekBar.progress - SystemUITool.refreshSystemUI(context = this@MainActivity) - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) {} - }) - binding.notifyIconCustomCornerSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - binding.notifyIconCustomCornerText.text = "$progress dp" - } - - override fun onStopTrackingTouch(seekBar: SeekBar) { - ConfigData.notifyIconCornerSize = seekBar.progress - SystemUITool.refreshSystemUI(context = this@MainActivity) - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) {} - }) + binding.notifyPanelConfigSeekbar.bind(ConfigData.NOTIFY_PANEL_ALPHA_LEVEL, binding.notifyPanelConfigText, suffix = "%") { + SystemUITool.refreshSystemUI(context = this) + } + binding.notifyIconCustomCornerSeekbar.bind(ConfigData.NOTIFY_ICON_CORNER_SIZE, binding.notifyIconCustomCornerText, suffix = " dp") { + SystemUITool.refreshSystemUI(context = this) + } /** 通知图标优化名单按钮点击事件 */ binding.notifyIconFixButton.setOnClickListener { navigate() } /** 自动更新在线规则修改时间按钮点击事件 */