mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-07 03:05:51 +08:00
优化部分代码
This commit is contained in:
@@ -33,7 +33,6 @@ import android.view.ViewGroup
|
|||||||
import android.widget.BaseAdapter
|
import android.widget.BaseAdapter
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.constraintlayout.utils.widget.ImageFilterView
|
import androidx.constraintlayout.utils.widget.ImageFilterView
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.fankes.miui.notify.R
|
import com.fankes.miui.notify.R
|
||||||
@@ -45,6 +44,8 @@ import com.fankes.miui.notify.params.IconPackParams
|
|||||||
import com.fankes.miui.notify.ui.base.BaseActivity
|
import com.fankes.miui.notify.ui.base.BaseActivity
|
||||||
import com.fankes.miui.notify.utils.SystemUITool
|
import com.fankes.miui.notify.utils.SystemUITool
|
||||||
import com.fankes.miui.notify.utils.showDialog
|
import com.fankes.miui.notify.utils.showDialog
|
||||||
|
import com.fankes.miui.notify.utils.snake
|
||||||
|
import com.fankes.miui.notify.utils.toast
|
||||||
import com.fankes.miui.notify.view.MaterialSwitch
|
import com.fankes.miui.notify.view.MaterialSwitch
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
|
|
||||||
@@ -67,8 +68,14 @@ class ConfigureActivity : BaseActivity() {
|
|||||||
/** 刷新适配器结果相关 */
|
/** 刷新适配器结果相关 */
|
||||||
refreshAdapterResult()
|
refreshAdapterResult()
|
||||||
/** 设置上下按钮点击事件 */
|
/** 设置上下按钮点击事件 */
|
||||||
findViewById<View>(R.id.config_title_up).setOnClickListener { onScrollEvent?.invoke(false) }
|
findViewById<View>(R.id.config_title_up).setOnClickListener {
|
||||||
findViewById<View>(R.id.config_title_down).setOnClickListener { onScrollEvent?.invoke(true) }
|
snake(msg = "滚动到顶部")
|
||||||
|
onScrollEvent?.invoke(false)
|
||||||
|
}
|
||||||
|
findViewById<View>(R.id.config_title_down).setOnClickListener {
|
||||||
|
snake(msg = "滚动到底部")
|
||||||
|
onScrollEvent?.invoke(true)
|
||||||
|
}
|
||||||
/** 设置过滤按钮点击事件 */
|
/** 设置过滤按钮点击事件 */
|
||||||
findViewById<View>(R.id.config_title_filter).setOnClickListener {
|
findViewById<View>(R.id.config_title_filter).setOnClickListener {
|
||||||
showDialog {
|
showDialog {
|
||||||
@@ -90,7 +97,7 @@ class ConfigureActivity : BaseActivity() {
|
|||||||
onChanged?.invoke()
|
onChanged?.invoke()
|
||||||
refreshAdapterResult()
|
refreshAdapterResult()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(applicationContext, "条件不能为空", Toast.LENGTH_SHORT).show()
|
toast(msg = "条件不能为空")
|
||||||
it.performClick()
|
it.performClick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +187,7 @@ class ConfigureActivity : BaseActivity() {
|
|||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
})
|
})
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Toast.makeText(this, "无法启动系统默认浏览器", Toast.LENGTH_SHORT).show()
|
toast(msg = "无法启动系统默认浏览器")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,6 @@ import android.os.Bundle
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.widget.SwitchCompat
|
import androidx.appcompat.widget.SwitchCompat
|
||||||
import androidx.constraintlayout.utils.widget.ImageFilterView
|
import androidx.constraintlayout.utils.widget.ImageFilterView
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@@ -93,7 +92,7 @@ class MainActivity : BaseActivity() {
|
|||||||
noCancelable()
|
noCancelable()
|
||||||
}
|
}
|
||||||
/** 判断是否 Hook */
|
/** 判断是否 Hook */
|
||||||
isHooked() -> {
|
YukiHookModuleStatus.isActive() -> {
|
||||||
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.bg_green_round)
|
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.bg_green_round)
|
||||||
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.ic_success)
|
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.ic_success)
|
||||||
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
||||||
@@ -174,7 +173,7 @@ class MainActivity : BaseActivity() {
|
|||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
})
|
})
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Toast.makeText(this, "你可能没有安装酷安", Toast.LENGTH_SHORT).show()
|
toast(msg = "你可能没有安装酷安")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** 项目地址点击事件 */
|
/** 项目地址点击事件 */
|
||||||
@@ -187,7 +186,7 @@ class MainActivity : BaseActivity() {
|
|||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
})
|
})
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Toast.makeText(this, "无法启动系统默认浏览器", Toast.LENGTH_SHORT).show()
|
toast(msg = "无法启动系统默认浏览器")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,7 +194,7 @@ class MainActivity : BaseActivity() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
/** MIUI 12 的版本特殊 - 所以给出提示 */
|
/** MIUI 12 的版本特殊 - 所以给出提示 */
|
||||||
if (!isWarnDialogShowing && isHooked() && miuiVersion == "12" && isMiuiNotifyStyle)
|
if (!isWarnDialogShowing && YukiHookModuleStatus.isActive() && miuiVersion == "12" && isMiuiNotifyStyle)
|
||||||
showDialog {
|
showDialog {
|
||||||
isWarnDialogShowing = true
|
isWarnDialogShowing = true
|
||||||
title = "经典通知栏样式已启用"
|
title = "经典通知栏样式已启用"
|
||||||
@@ -205,10 +204,4 @@ class MainActivity : BaseActivity() {
|
|||||||
noCancelable()
|
noCancelable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断模块是否激活
|
|
||||||
* @return [Boolean] 激活状态
|
|
||||||
*/
|
|
||||||
private fun isHooked() = YukiHookModuleStatus.isActive()
|
|
||||||
}
|
}
|
@@ -22,11 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.fankes.miui.notify.utils
|
package com.fankes.miui.notify.utils
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
|
||||||
import android.widget.Toast
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.highcapable.yukihookapi.hook.xposed.YukiHookModuleStatus
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统界面工具
|
* 系统界面工具
|
||||||
@@ -46,7 +44,7 @@ object SystemUITool {
|
|||||||
execShellSu(cmd = "pgrep systemui").also { pid ->
|
execShellSu(cmd = "pgrep systemui").also { pid ->
|
||||||
if (pid.isNotBlank())
|
if (pid.isNotBlank())
|
||||||
execShellSu(cmd = "kill -9 $pid")
|
execShellSu(cmd = "kill -9 $pid")
|
||||||
else Toast.makeText(context, "ROOT 权限获取失败", Toast.LENGTH_SHORT).show()
|
else toast(msg = "ROOT 权限获取失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancelButton()
|
cancelButton()
|
||||||
@@ -57,9 +55,7 @@ object SystemUITool {
|
|||||||
* @param context 实例
|
* @param context 实例
|
||||||
*/
|
*/
|
||||||
fun showNeedRestartSnake(context: Context) =
|
fun showNeedRestartSnake(context: Context) =
|
||||||
Snackbar.make((context as Activity).findViewById(android.R.id.content), "设置需要重启系统界面才能生效", Snackbar.LENGTH_LONG)
|
if (YukiHookModuleStatus.isActive())
|
||||||
.apply {
|
context.snake(msg = "设置需要重启系统界面才能生效", actionText = "立即重启") { restartSystemUI(context) }
|
||||||
setActionTextColor(Color.WHITE)
|
else context.snake(msg = "模块没有激活,更改不会生效")
|
||||||
setAction("立即重启") { restartSystemUI(context) }
|
|
||||||
}.show()
|
|
||||||
}
|
}
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
package com.fankes.miui.notify.utils
|
package com.fankes.miui.notify.utils
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@@ -34,7 +35,9 @@ import android.os.Build
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.service.notification.StatusBarNotification
|
import android.service.notification.StatusBarNotification
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
|
import android.widget.Toast
|
||||||
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.highcapable.yukihookapi.hook.factory.callStatic
|
import com.highcapable.yukihookapi.hook.factory.callStatic
|
||||||
import com.highcapable.yukihookapi.hook.factory.classOf
|
import com.highcapable.yukihookapi.hook.factory.classOf
|
||||||
import com.highcapable.yukihookapi.hook.factory.hasClass
|
import com.highcapable.yukihookapi.hook.factory.hasClass
|
||||||
@@ -261,6 +264,26 @@ fun execShellSu(cmd: String) = safeOfNothing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹出 [Toast]
|
||||||
|
* @param msg 提示内容
|
||||||
|
*/
|
||||||
|
fun toast(msg: String) = Toast.makeText(appContext, msg, Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹出 [Snackbar]
|
||||||
|
* @param msg 提示内容
|
||||||
|
* @param actionText 按钮文本 - 不写默认取消按钮
|
||||||
|
* @param it 按钮事件回调
|
||||||
|
*/
|
||||||
|
fun Context.snake(msg: String, actionText: String = "", it: () -> Unit = {}) =
|
||||||
|
Snackbar.make((this as Activity).findViewById(android.R.id.content), msg, Snackbar.LENGTH_LONG)
|
||||||
|
.apply {
|
||||||
|
if (actionText.isBlank()) return@apply
|
||||||
|
setActionTextColor(Color.WHITE)
|
||||||
|
setAction(actionText) { it() }
|
||||||
|
}.show()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忽略异常返回值
|
* 忽略异常返回值
|
||||||
* @param it 回调 - 如果异常为空
|
* @param it 回调 - 如果异常为空
|
||||||
|
Reference in New Issue
Block a user