Skip to content

Commit

Permalink
增加黑名单支持, 其中包括磁贴、跳转、分享、平行小窗
Browse files Browse the repository at this point in the history
增加平行小窗的判断逻辑,减少无限添加应用导致内存过多的可能,减少应用加载
去除悬浮球的平行小窗适配
  • Loading branch information
LiuYiGL committed May 13, 2023
1 parent 5604319 commit 5f0d315
Show file tree
Hide file tree
Showing 19 changed files with 560 additions and 217 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {

implementation project(path: ':blockmiui')
implementation 'androidx.annotation:annotation-jvm:1.6.0'
implementation 'androidx.collection:collection:1.2.0'

// 基础依赖
implementation 'com.highcapable.yukihookapi:api:1.1.11'
Expand Down
48 changes: 48 additions & 0 deletions app/src/main/java/org/liuyi/mifreeformx/BlackList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.liuyi.mifreeformx

import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
import org.liuyi.mifreeformx.bean.BlackListBean

/**
* @Author: Liuyi
* @Date: 2023/05/09/9:47:41
* @Description:
*/


object BlackList {

object AppJumpSourceBlacklist :
BlackListBean(PrefsData("app_jump_source_blacklist", setOf("com.android.providers.media.module")))

object AppJumpTargetBlacklist : BlackListBean(
PrefsData(
"app_jump_target_blacklist",
setOf("com.android.camera", "com.miui.tsmclient", "com.lbe.security.miui")
)
)

object AppShareSourceBlacklist :
BlackListBean(PrefsData("app_share_source_blacklist", setOf("com.android.providers.media.module")))

object AppShareTargetBlacklist : BlackListBean(
PrefsData(
"app_share_target_blacklist",
setOf("com.android.camera", "com.miui.tsmclient", "com.lbe.security.miui")
)
)

object ParallelFreeformBlacklist : BlackListBean(
PrefsData(
"parallel_small_window_blacklist",
setOf("com.android.camera", "com.miui.tsmclient", "com.lbe.security.miui")
)
)

object TileBlacklist : BlackListBean(
PrefsData(
"tile_blacklist",
setOf("com.android.camera", "com.miui.tsmclient", "com.lbe.security.miui")
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.liuyi.mifreeformx.activity
import android.os.Bundle
import cn.fkj233.ui.activity.MIUIActivity
import cn.fkj233.ui.dialog.MIUIDialog
import com.blankj.utilcode.util.AppUtils
import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.hook.factory.prefs
import org.liuyi.mifreeformx.R
import org.liuyi.mifreeformx.activity.page.*

Expand All @@ -14,6 +16,10 @@ import org.liuyi.mifreeformx.activity.page.*
*/
class MainActivity : MIUIActivity() {

companion object {
lateinit var appsInfo: Any
}

init {
registerPage(MainPage::class.java)
registerPage(NotificationAndControlCenterPage::class.java)
Expand All @@ -22,6 +28,7 @@ class MainActivity : MIUIActivity() {
registerPage(MiscellaneousPage::class.java)
registerPage(MenuPage::class.java)
registerPage(AboutPage::class.java)
registerPage(AppSelectPage::class.java)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.liuyi.mifreeformx.activity.page

import android.annotation.SuppressLint
import cn.fkj233.ui.activity.annotation.BMPage
import cn.fkj233.ui.activity.fragment.MIUIFragment
import com.blankj.utilcode.util.AppUtils
import com.highcapable.yukihookapi.hook.factory.prefs
import com.highcapable.yukihookapi.hook.log.loggerD
import org.liuyi.mifreeformx.R
import org.liuyi.mifreeformx.adapter.AppSelectAdapter
import org.liuyi.mifreeformx.bean.BlackListBean
import org.liuyi.mifreeformx.utils.PinyinUtils
import kotlin.concurrent.thread

/**
* @Author: Liuyi
* @Date: 2023/05/07/13:26:35
* @Description:
*/
@SuppressLint("NonConstantResourceId")
@BMPage(key = "AppSelectPage", titleId = R.string.select_app)
class AppSelectPage : MyBasePage() {

init {
skipLoadItem = true
}

companion object {
init {
thread { allAppInfo }
}

val allAppInfo: MutableList<AppUtils.AppInfo> by lazy { AppUtils.getAppsInfo() }
var currentBlackList: BlackListBean? = null
}

private var lastBlackList: BlackListBean? = null


private val mAppSelectAdapter by lazy {
AppSelectAdapter(activity, allAppInfo.toMutableList(), mutableSetOf(), setOf()) { _, _ ->
lastBlackList?.addAll(activity.prefs(), selectedSet)
}
}


override fun onCreate() {
List {
adapter = mAppSelectAdapter
}
}

override fun asyncInit(fragment: MIUIFragment) {
fragment.showLoading()
// 初始化
mAppSelectAdapter.apply {
val current = currentBlackList?.getAll(activity.prefs())

mAppInfoList = current?.let {
allAppInfo.toMutableList().apply {
sortWith { a1, a2 ->
if (current.contains(a1.packageName) && current.contains(a2.packageName)) {
PinyinUtils.ccs2Pinyin(a1.name).compareTo(PinyinUtils.ccs2Pinyin(a2.name))
} else if (current.contains(a1.packageName)) {
-1
} else if (current.contains(a2.packageName)) {
1
} else PinyinUtils.ccs2Pinyin(a1.name).compareTo(PinyinUtils.ccs2Pinyin(a2.name))
}
}
} ?: mutableListOf()

disEnabledSet = currentBlackList?.forceList ?: setOf()
selectedSet = current?.toMutableSet() ?: mutableSetOf()

loggerD(msg = "当前黑名单: $currentBlackList")
loggerD(msg = "上次黑名单: $lastBlackList")
loggerD(msg = "不可选项: $disEnabledSet")
loggerD(msg = "当前选择项: $selectedSet")
notifyDataSetChanged()
}
lastBlackList = currentBlackList
currentBlackList = null
fragment.initData()
fragment.closeLoading()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.liuyi.mifreeformx.activity.page
import android.annotation.SuppressLint
import cn.fkj233.ui.activity.annotation.BMPage
import cn.fkj233.ui.activity.view.TextSummaryV
import org.liuyi.mifreeformx.BlackList
import org.liuyi.mifreeformx.DataConst
import org.liuyi.mifreeformx.R

Expand All @@ -27,6 +28,14 @@ class JumpAndShareBetweenApplicationsPage : MyBasePage() {
),
createSwitchV(DataConst.APP_JUMP)
)
TextSummaryWithArrow(TextSummaryV(text = "源黑名单", tips = "不使用小窗处理打开其他应用") {
AppSelectPage.currentBlackList = BlackList.AppJumpSourceBlacklist
showFragment("AppSelectPage")
})
TextSummaryWithArrow(TextSummaryV(text = "目标黑名单", tips = "对将打开的应用不处理") {
AppSelectPage.currentBlackList = BlackList.AppJumpTargetBlacklist
showFragment("AppSelectPage")
})

Line()
TitleText(textId = R.string.share_between_applications)
Expand All @@ -44,5 +53,13 @@ class JumpAndShareBetweenApplicationsPage : MyBasePage() {
),
createSwitchV(DataConst.SHARE_TO_APP_FORCE_NEW_TASK)
)
TextSummaryWithArrow(TextSummaryV(text = "源黑名单", tips = "不处理当前应用的分享") {
AppSelectPage.currentBlackList = BlackList.AppShareSourceBlacklist
showFragment("AppSelectPage")
})
TextSummaryWithArrow(TextSummaryV(text = "目标黑名单", tips = "不处理分享的目标应用") {
AppSelectPage.currentBlackList = BlackList.AppShareTargetBlacklist
showFragment("AppSelectPage")
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.liuyi.mifreeformx.activity.page
import android.annotation.SuppressLint
import cn.fkj233.ui.activity.annotation.BMPage
import cn.fkj233.ui.activity.view.TextSummaryV
import org.liuyi.mifreeformx.BlackList
import org.liuyi.mifreeformx.DataConst
import org.liuyi.mifreeformx.R

Expand Down Expand Up @@ -47,6 +48,10 @@ class NotificationAndControlCenterPage : MyBasePage() {
),
createSwitchV(DataConst.FORCE_CONTROL_ALL_OPEN)
)
TextSummaryWithArrow(TextSummaryV(text = "黑名单") {
AppSelectPage.currentBlackList = BlackList.TileBlacklist
showFragment("AppSelectPage")
})

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.liuyi.mifreeformx.activity.page
import android.annotation.SuppressLint
import cn.fkj233.ui.activity.annotation.BMPage
import cn.fkj233.ui.activity.view.TextSummaryV
import org.liuyi.mifreeformx.BlackList
import org.liuyi.mifreeformx.DataConst
import org.liuyi.mifreeformx.R

Expand All @@ -23,5 +24,9 @@ class ParallelSmallWindowPage : MyBasePage() {
),
createSwitchV(DataConst.PARALLEL_MULTI_WINDOW_PLUS)
)
TextSummaryWithArrow(TextSummaryV(text = "黑名单") {
AppSelectPage.currentBlackList = BlackList.ParallelFreeformBlacklist
showFragment("AppSelectPage")
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.liuyi.mifreeformx.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.CompoundButton
import android.widget.LinearLayout
import cn.fkj233.ui.activity.fragment.MIUIFragment
import cn.fkj233.ui.activity.view.ImageTextSummaryWithSwitchV
import cn.fkj233.ui.activity.view.ImageV
import cn.fkj233.ui.activity.view.SwitchV
import cn.fkj233.ui.activity.view.TextSummaryV
import com.blankj.utilcode.util.AppUtils.AppInfo

/**
* @Author: Liuyi
* @Date: 2023/05/08/22:21:49
* @Description:
*/
class AppSelectAdapter(
var mContext: Context,
var mAppInfoList: MutableList<AppInfo>,
var selectedSet: MutableSet<String>,
var disEnabledSet: Set<String>,
private val block: AppSelectAdapter.(Boolean, AppInfo) -> Unit
) : BaseAdapter() {


override fun getCount() = mAppInfoList.size

override fun getItem(position: Int) = mAppInfoList[position]

override fun getItemId(position: Int) = position.toLong()

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
return LinearLayout(mContext).also { layout ->
mAppInfoList[position].run {
SwitchV("").let { switchV ->
ImageTextSummaryWithSwitchV(
ImageV(icon),
TextSummaryV(text = name, tips = packageName),
switchV
).let {
it.onDraw(MIUIFragment(""), layout, it.create(mContext) {})
switchV.switch.apply {
isChecked = selectedSet.contains(packageName)
isEnabled = !disEnabledSet.contains(packageName)
setOnCheckedChangeListener { _, isChecked ->
if (isChecked) selectedSet += this@run.packageName
else selectedSet -= this@run.packageName
block(this@AppSelectAdapter, isChecked, this@run)
}
}
}
}
}

}
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/org/liuyi/mifreeformx/bean/BlackList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.liuyi.mifreeformx.bean

import android.app.Activity
import com.highcapable.yukihookapi.hook.param.PackageParam
import com.highcapable.yukihookapi.hook.xposed.prefs.YukiHookPrefsBridge

/**
* @Author: Liuyi
* @Date: 2023/05/12/20:32:26
* @Description:
*/
interface BlackList {

fun add(prefs: YukiHookPrefsBridge? = null, item: String)

fun addAll(prefs: YukiHookPrefsBridge? = null, items: Set<String>)

fun remove(prefs: YukiHookPrefsBridge? = null, item: String)

fun contains(prefs: YukiHookPrefsBridge? = null, item: String): Boolean

fun size(prefs: YukiHookPrefsBridge? = null, item: String): Int

fun clear(prefs: YukiHookPrefsBridge? = null, item: String)

fun getAll(prefs: YukiHookPrefsBridge? = null): Set<String>
}
Loading

0 comments on commit 5f0d315

Please sign in to comment.