mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-04 09:45:34 +08:00
Modify merge seek bar changed event to SeekBarFactory
This commit is contained in:
@@ -109,30 +109,6 @@ object ConfigData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取 [Int] 数据
|
|
||||||
* @param data 键值数据模板
|
|
||||||
* @return [Int]
|
|
||||||
*/
|
|
||||||
private fun getInt(data: PrefsData<Int>) = 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<Int>, 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] 数据
|
* 读取 [String] 数据
|
||||||
* @param data 键值数据模板
|
* @param data 键值数据模板
|
||||||
@@ -157,6 +133,30 @@ object ConfigData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取 [Int] 数据
|
||||||
|
* @param data 键值数据模板
|
||||||
|
* @return [Int]
|
||||||
|
*/
|
||||||
|
internal fun getInt(data: PrefsData<Int>) = 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<Int>, 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] 数据
|
* 读取 [Boolean] 数据
|
||||||
* @param data 键值数据模板
|
* @param data 键值数据模板
|
||||||
|
@@ -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.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* <https://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
* 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<Int>, 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?) {}
|
||||||
|
})
|
||||||
|
}
|
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
package com.fankes.coloros.notify.ui.activity
|
package com.fankes.coloros.notify.ui.activity
|
||||||
|
|
||||||
import android.widget.SeekBar
|
|
||||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.fankes.coloros.notify.BuildConfig
|
import com.fankes.coloros.notify.BuildConfig
|
||||||
import com.fankes.coloros.notify.R
|
import com.fankes.coloros.notify.R
|
||||||
@@ -126,10 +124,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
binding.notifyMediaPanelAutoExpSwitch.isVisible = false
|
binding.notifyMediaPanelAutoExpSwitch.isVisible = false
|
||||||
binding.notifyMediaPanelAutoExpText.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.notifyIconAutoSyncText.text = ConfigData.notifyIconFixAutoTime
|
||||||
binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) {
|
binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) {
|
||||||
onInitialize {
|
onInitialize {
|
||||||
@@ -237,30 +231,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true)
|
SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
|
binding.notifyPanelConfigSeekbar.bind(ConfigData.NOTIFY_PANEL_ALPHA_LEVEL, binding.notifyPanelConfigText, suffix = "%") {
|
||||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
SystemUITool.refreshSystemUI(context = this)
|
||||||
binding.notifyPanelConfigText.text = "$progress%"
|
}
|
||||||
}
|
binding.notifyIconCustomCornerSeekbar.bind(ConfigData.NOTIFY_ICON_CORNER_SIZE, binding.notifyIconCustomCornerText, suffix = " dp") {
|
||||||
|
SystemUITool.refreshSystemUI(context = this)
|
||||||
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.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() }
|
binding.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() }
|
||||||
/** 自动更新在线规则修改时间按钮点击事件 */
|
/** 自动更新在线规则修改时间按钮点击事件 */
|
||||||
|
Reference in New Issue
Block a user