Modify merge seek bar changed event to SeekBarFactory

This commit is contained in:
2023-02-04 02:42:45 +08:00
parent 69f3637d22
commit 7e4c20ca05
3 changed files with 84 additions and 39 deletions

View File

@@ -96,30 +96,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] 数据
* @param data 键值数据模板
@@ -144,6 +120,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] 数据
* @param data 键值数据模板

View File

@@ -0,0 +1,57 @@
/*
* MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
* https://github.com/fankes/MIUINativeNotifyIcon
*
* 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.miui.notify.data.factory
import android.widget.SeekBar
import android.widget.TextView
import com.fankes.miui.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?) {}
})
}

View File

@@ -24,7 +24,6 @@
package com.fankes.miui.notify.ui.activity
import android.widget.SeekBar
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.fankes.miui.notify.BuildConfig
@@ -160,8 +159,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.mainTextMiuiVersion.text = "系统版本:[$androidVersionCodeName] $miuiFullVersion"
binding.warnSCountDisTip.isGone = miuiVersionCode > 12.5
binding.warnMiuiNotifyStyleTip.isGone = miuiVersionCode > 12
binding.notifyIconCustomCornerSeekbar.progress = ConfigData.notifyIconCornerSize
binding.notifyIconCustomCornerText.text = "${ConfigData.notifyIconCornerSize} dp"
binding.statusIconCountText.text = ConfigData.liftedStatusIconCount.toString()
binding.notifyIconAutoSyncText.text = ConfigData.notifyIconFixAutoTime
binding.moduleEnableSwitch.bind(ConfigData.ENABLE_MODULE) {
@@ -248,18 +245,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
SystemUITool.refreshSystemUI(context = this@MainActivity, isRefreshCacheOnly = true)
}
}
binding.notifyIconCustomCornerSeekbar.setOnSeekBarChangeListener(object : SeekBar.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.notifyIconCustomCornerSeekbar.bind(ConfigData.NOTIFY_ICON_CORNER_SIZE, binding.notifyIconCustomCornerText, suffix = " dp") {
SystemUITool.refreshSystemUI(context = this)
}
/** MIUI 通知显示设置按钮点击事件 */
binding.miuiNotifyStyleButton.setOnClickListener { SystemUITool.openMiuiNotificationDisplaySettings(context = this) }
/** 通知图标优化名单按钮点击事件 */