diff --git a/app/src/main/java/com/fankes/miui/notify/data/DataConst.kt b/app/src/main/java/com/fankes/miui/notify/data/DataConst.kt index c826dfb..98b9c86 100644 --- a/app/src/main/java/com/fankes/miui/notify/data/DataConst.kt +++ b/app/src/main/java/com/fankes/miui/notify/data/DataConst.kt @@ -29,7 +29,6 @@ object DataConst { val ENABLE_MODULE = PrefsData("_enable_module", true) val ENABLE_MODULE_LOG = PrefsData("_enable_module_log", false) - val ENABLE_HIDE_ICON = PrefsData("_hide_icon", false) val ENABLE_COLOR_ICON_COMPAT = PrefsData("_color_icon_compat", false) val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true) val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false) diff --git a/app/src/main/java/com/fankes/miui/notify/ui/activity/MainActivity.kt b/app/src/main/java/com/fankes/miui/notify/ui/activity/MainActivity.kt index a6ffcba..29aacf2 100644 --- a/app/src/main/java/com/fankes/miui/notify/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/fankes/miui/notify/ui/activity/MainActivity.kt @@ -24,8 +24,6 @@ package com.fankes.miui.notify.ui.activity -import android.content.ComponentName -import android.content.pm.PackageManager import android.widget.SeekBar import androidx.core.view.isGone import androidx.core.view.isVisible @@ -162,7 +160,6 @@ class MainActivity : BaseActivity() { binding.notifyIconAutoSyncChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO) binding.moduleEnableSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE) binding.moduleEnableLogSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE_LOG) - binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON) binding.colorIconCompatSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_COLOR_ICON_COMPAT) binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) binding.notifyIconForceAppIconSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) @@ -186,15 +183,6 @@ class MainActivity : BaseActivity() { modulePrefs.put(DataConst.ENABLE_MODULE_LOG, b) SystemUITool.showNeedRestartSnake(context = this) } - binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> - if (btn.isPressed.not()) return@setOnCheckedChangeListener - modulePrefs.put(DataConst.ENABLE_HIDE_ICON, b) - packageManager.setComponentEnabledSetting( - ComponentName(this@MainActivity, "com.fankes.miui.notify.Home"), - if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP - ) - } binding.statusIconCountSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener modulePrefs.put(DataConst.ENABLE_HOOK_STATUS_ICON_COUNT, b) @@ -257,6 +245,12 @@ class MainActivity : BaseActivity() { override fun onStartTrackingTouch(seekBar: SeekBar?) {} }) + /** 设置桌面图标显示隐藏 */ + binding.hideIconInLauncherSwitch.isChecked = isLauncherIconShowing.not() + binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> + if (btn.isPressed.not()) return@setOnCheckedChangeListener + hideOrShowLauncherIcon(b) + } /** 通知图标优化名单按钮点击事件 */ binding.notifyIconFixButton.setOnClickListener { navigate() } /** 设置警告 */ diff --git a/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt index a0cbb40..3950d04 100644 --- a/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt @@ -28,12 +28,10 @@ import android.app.Activity import android.app.Notification import android.app.Service import android.app.WallpaperManager -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context -import android.content.Intent +import android.content.* import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo +import android.content.pm.PackageManager import android.content.pm.PackageManager.PackageInfoFlags import android.content.res.Configuration import android.content.res.Resources @@ -52,6 +50,7 @@ import androidx.core.app.NotificationManagerCompat import androidx.core.content.getSystemService import androidx.core.content.pm.PackageInfoCompat import androidx.core.content.res.ResourcesCompat +import com.fankes.miui.notify.BuildConfig import com.google.android.material.snackbar.Snackbar import com.highcapable.yukihookapi.hook.factory.hasClass import com.highcapable.yukihookapi.hook.factory.method @@ -573,4 +572,27 @@ fun Long.stampToDate(format: String = "yyyy-MM-dd HH:mm:ss") = fun Any?.delayedRun(ms: Long = 150, it: () -> Unit) = runInSafe { @Suppress("DEPRECATION") Handler().postDelayed({ it() }, ms) -} \ No newline at end of file +} + +/** + * 隐藏或显示启动器图标 + * + * - 你可能需要 LSPosed 的最新版本以开启高版本系统中隐藏 APP 桌面图标功能 + * @param isShow 是否显示 + */ +fun Context.hideOrShowLauncherIcon(isShow: Boolean) { + packageManager?.setComponentEnabledSetting( + ComponentName(packageName, "${BuildConfig.APPLICATION_ID}.Home"), + if (isShow) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP + ) +} + +/** + * 获取启动器图标状态 + * @return [Boolean] 是否显示 + */ +val Context.isLauncherIconShowing + get() = packageManager?.getComponentEnabledSetting( + ComponentName(packageName, "${BuildConfig.APPLICATION_ID}.Home") + ) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED \ No newline at end of file