Skip to content

Commit

Permalink
feat: separately purify Live and UP in dyn all page (yujincheng08#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyHai authored Jan 3, 2025
1 parent e065e7c commit af10950
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/me/iacn/biliroaming/DynamicFilterDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class DynamicFilterDialog(activity: Activity, prefs: SharedPreferences) :
).let { root.addView(it.first); it.second }
rmUpOfAllSwitch.isChecked = prefs.getBoolean("customize_dynamic_all_rm_up", false)

val rmLiveOfAllSwitch = switchPrefsItem(
string(R.string.customize_dynamic_all_rm_live_title)
).let { root.addView(it.first); it.second }
rmLiveOfAllSwitch.isChecked = prefs.getBoolean("customize_dynamic_all_rm_live", false)

val rmUpOfVideoSwitch = switchPrefsItem(
string(R.string.customize_dynamic_video_rm_up_title)
).let { root.addView(it.first); it.second }
Expand Down Expand Up @@ -143,6 +148,7 @@ class DynamicFilterDialog(activity: Activity, prefs: SharedPreferences) :
putBoolean("purify_campus", rmCampusTabSwitch.isChecked)
putBoolean("customize_dynamic_all_rm_topic", rmTopicOfAllSwitch.isChecked)
putBoolean("customize_dynamic_all_rm_up", rmUpOfAllSwitch.isChecked)
putBoolean("customize_dynamic_all_rm_live", rmLiveOfAllSwitch.isChecked)
putBoolean("customize_dynamic_video_rm_up", rmUpOfVideoSwitch.isChecked)
putBoolean("filter_apply_to_video", filterApplyToVideoSwitch.isChecked)
putBoolean("customize_dynamic_rm_blocked", rmBlockedSwitch.isChecked)
Expand Down
43 changes: 33 additions & 10 deletions app/src/main/java/me/iacn/biliroaming/hook/DynamicHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DynamicHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
private val removeTopicOfAll = sPrefs.getBoolean("customize_dynamic_all_rm_topic", false)
private val removeUpOfAll = sPrefs.getBoolean("customize_dynamic_all_rm_up", false)
private val removeLiveOfAll = sPrefs.getBoolean("customize_dynamic_all_rm_live", false)
private val removeUpOfVideo = sPrefs.getBoolean("customize_dynamic_video_rm_up", false)
private val preferVideoTab = sPrefs.getBoolean("prefer_video_tab", false)
private val filterApplyToVideo = sPrefs.getBoolean("filter_apply_to_video", false)
Expand All @@ -37,21 +38,43 @@ class DynamicHook(classLoader: ClassLoader) : BaseHook(classLoader) {

override fun startHook() {
val hidden = sPrefs.getBoolean("hidden", false)
if (hidden && (needFilterDynamic || removeTopicOfAll || removeUpOfAll)) {
if (hidden && (needFilterDynamic || removeTopicOfAll || removeUpOfAll || removeLiveOfAll)) {
dynamicMossV2?.hookBeforeMethod(
"dynAll",
"com.bapis.bilibili.app.dynamic.v2.DynAllReq",
instance.mossResponseHandlerClass
) {
it.args[1] = it.args[1].mossResponseHandlerProxy { result ->
result?.let {
if (removeTopicOfAll)
it.callMethod("clearTopicList")
if (removeUpOfAll)
it.callMethod("clearUpList")
if (needFilterDynamic)
filterDynamic(it)
) { param ->
param.args[1] = param.args[1].mossResponseHandlerProxy { reply ->
reply ?: return@mossResponseHandlerProxy
Log.d("upList: ${reply.callMethod("getUpList")}")
if (removeTopicOfAll)
reply.callMethod("clearTopicList")
if (removeUpOfAll || removeLiveOfAll) {
reply.callMethod("getUpList")?.runCatching UpList@{
val upList = this@UpList
val firstList =
upList.callMethodAs("getListList") ?: emptyList<Any>()
val secondList =
upList.callMethodAs("getListSecondList") ?: emptyList<Any>()
val allUpItems = firstList + secondList
val newItems = allUpItems.filter { item ->
val liveState = item.callMethodAs<Int>("getLiveStateValue")
val isLive = liveState > 0
when {
removeUpOfAll && removeLiveOfAll -> false
removeUpOfAll -> isLive
else -> !isLive
}
}.onEachIndexed { index, item ->
item.callMethod("setPos", index + 1L)
}
upList.callMethod("clearList")
upList.callMethod("clearListSecond")
upList.callMethod("addAllList", newItems)
}?.onFailure { Log.e(it) }
}
if (needFilterDynamic)
filterDynamic(reply)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@
<string name="customize_dynamic_summary">支持移除同城及校园标签,支持移除话题及最常访问,支持按类型和关键词过滤动态</string>
<string name="customize_dynamic_prefer_video_tab">首选视频标签</string>
<string name="customize_dynamic_all_rm_topic_title">移除热门话题(综合)</string>
<string name="customize_dynamic_all_rm_up_title">移除最常访问(综合)</string>
<string name="customize_dynamic_all_rm_up_title">移除最常访问UP(综合)</string>
<string name="customize_dynamic_all_rm_live_title">移除最常访问直播(综合)</string>
<string name="customize_dynamic_video_rm_up_title">移除最常访问(视频)</string>
<string name="customize_dynamic_filter_apply_to_video">过滤设置同时作用于视频分区</string>
<string name="customize_dynamic_rm_blocked_title">屏蔽无权查看动态(例如充电专属)</string>
Expand Down

0 comments on commit af10950

Please sign in to comment.