forked from shatyuka/Zhiliao
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
e676864
commit 630c6a2
Showing
5 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
app/src/main/java/com/shatyuka/zhiliao/hooks/ActivityInfoAd.kt
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
app/src/main/java/com/shatyuka/zhiliao/hooks/TopTabs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.shatyuka.zhiliao.hooks | ||
|
||
import com.shatyuka.zhiliao.Helper | ||
import de.robv.android.xposed.XC_MethodHook | ||
import de.robv.android.xposed.XposedBridge.hookMethod | ||
import de.robv.android.xposed.XposedHelpers.getObjectField | ||
import de.robv.android.xposed.XposedHelpers.setObjectField | ||
import java.util.stream.Collectors | ||
|
||
/** | ||
* api: /root/tab | ||
*/ | ||
class TopTabs : BaseHook() { | ||
|
||
private val PREFS_KEY_NAME = "edit_tabs" | ||
|
||
private var activityInfo: Class<*>? = null | ||
private var topTabs: Class<*>? = null | ||
|
||
override fun getName(): String { | ||
return "自定义首页顶部Tab(TopTabs)" | ||
} | ||
|
||
override fun init(classLoader: ClassLoader) { | ||
try { | ||
activityInfo = classLoader.loadClass("com.zhihu.android.api.model.ActivityInfo") | ||
} catch (e: Exception) { | ||
logE(e.message) | ||
} | ||
|
||
try { | ||
topTabs = classLoader.loadClass("com.zhihu.android.api.model.TopTabs") | ||
} catch (e: Exception) { | ||
logE(e.message) | ||
} | ||
} | ||
|
||
override fun hook() { | ||
if (!Helper.prefs.getBoolean("switch_mainswitch", false)) { | ||
return | ||
} | ||
|
||
hookMethod(Helper.JacksonHelper.ObjectReader_readValue, object : XC_MethodHook() { | ||
override fun afterHookedMethod(param: MethodHookParam) { | ||
if (param.result == null) { | ||
return | ||
} | ||
when (param.result.javaClass) { | ||
activityInfo -> { | ||
setObjectField(param.result, "topActivity", null) | ||
} | ||
|
||
topTabs -> { | ||
postProcessTopTabs(param.result) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
private fun postProcessTopTabs(topTabs: Any) { | ||
setObjectField(topTabs, "topActivity", null) | ||
filterTabs(topTabs) | ||
} | ||
|
||
private fun filterTabs(topTabs: Any) { | ||
val tabList = getObjectField(topTabs, "tabs") as List<*> | ||
|
||
val resultTabList = ArrayList<Any>() | ||
val tabTypeMap = HashMap<String, Any>() | ||
val originTabTypeList = ArrayList<String>() | ||
|
||
tabList.forEach { | ||
val tabType = getObjectField(it, "tabType") as String | ||
tabTypeMap[tabType] = it!! | ||
originTabTypeList.add(tabType) | ||
} | ||
|
||
getAllowedTabTypeList().forEach { | ||
val tab = tabTypeMap[it] | ||
if (tab != null) { | ||
resultTabList.add(tab) | ||
} | ||
} | ||
|
||
if (resultTabList.isNotEmpty()) { | ||
setObjectField(topTabs, "tabs", resultTabList) | ||
} else { | ||
resetAllowedTabTypeList(originTabTypeList) | ||
} | ||
} | ||
|
||
private fun getAllowedTabTypeList(): List<String> { | ||
return Helper.prefs.getString(PREFS_KEY_NAME, "")?.split("|")?.stream() | ||
?.map { it.trim() }?.collect(Collectors.toList()) ?: ArrayList() | ||
} | ||
|
||
private fun resetAllowedTabTypeList(tabTypeList: List<String>) { | ||
Helper.prefs.edit().putString( | ||
PREFS_KEY_NAME, tabTypeList.stream().collect(Collectors.joining("|")) | ||
).apply() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters