1+ package cc.ioctl.tmoe.hook.func
2+
3+ import android.content.Context
4+ import android.graphics.PorterDuff
5+ import android.graphics.PorterDuffColorFilter
6+ import android.graphics.drawable.Drawable
7+ import android.view.Gravity
8+ import android.view.View
9+ import android.view.ViewGroup
10+ import android.widget.ImageView
11+ import cc.ioctl.tmoe.R
12+ import cc.ioctl.tmoe.base.annotation.FunctionHookEntry
13+ import cc.ioctl.tmoe.hook.base.CommonDynamicHook
14+ import cc.ioctl.tmoe.ui.LocaleController
15+ import com.github.kyuubiran.ezxhelper.utils.*
16+
17+
18+ @FunctionHookEntry
19+ object MutualContactsBtnOption : CommonDynamicHook() {
20+ object MutualViewTag
21+ var needAddMutual: Boolean = false ;
22+ override fun initOnce (): Boolean = tryOrLogFalse {
23+ val themeClzName = " org.telegram.ui.ActionBar.Theme"
24+ val themeGetColor = findMethod(themeClzName) { name == " getColor" && parameterCount == 2 }
25+ val themePlayerActionBarSelector =
26+ findField(themeClzName) { name == " key_player_actionBarSelector" }.get(null ) as Int
27+ val themeWindowBackgroundWhiteGrayIcon =
28+ findField(themeClzName) { name == " key_windowBackgroundWhiteGrayIcon" }.get(null ) as Int
29+ val themeCreateSelectorDrawable =
30+ findMethod(themeClzName) { name == " createSelectorDrawable" }
31+
32+ Log .dx(" ${MutualContactsBtnOption .javaClass.name} : before onCreateViewHolder" )
33+ findMethod(" org.telegram.ui.Adapters.ContactsAdapter" ) { name == " onCreateViewHolder" }.hookBefore {
34+ needAddMutual = it.args[1 ] as Int == 0
35+ }
36+
37+ Log .dx(" ${MutualContactsBtnOption .javaClass.name} : before findUserCell" )
38+ findConstructor(" org.telegram.ui.Cells.UserCell" ) { parameterTypes.size == 6 }.hookAfter {
39+ if (! isEnabled || ! needAddMutual) return @hookAfter
40+ if (it.args[5 ] != null && it.args[5 ].javaClass.canonicalName != " $themeClzName .ResourcesProvider" ) return @hookAfter // neko workaround
41+ val context = it.args[0 ] as Context
42+ val resourcesProvider = it.args[5 ]
43+ Log .dx(" ${MutualContactsBtnOption .javaClass.name} : findUserCell: init mutual view" )
44+ val mutualView = ImageView (context)
45+ mutualView.tag = MutualViewTag
46+ mutualView.setImageResource(R .drawable.ic_round_swap_horiz_24)
47+ mutualView.scaleType = ImageView .ScaleType .CENTER
48+ mutualView.visibility = View .GONE
49+ mutualView.contentDescription =
50+ LocaleController .getString(" MutualContact" , R .string.MutualContact )
51+ mutualView.background = themeCreateSelectorDrawable.invoke(
52+ null ,
53+ themeGetColor.invoke(
54+ null ,
55+ themePlayerActionBarSelector, resourcesProvider
56+ )
57+ ) as Drawable
58+ mutualView.colorFilter = PorterDuffColorFilter (
59+ themeGetColor.invoke(
60+ null ,
61+ themeWindowBackgroundWhiteGrayIcon, resourcesProvider
62+ ) as Int , PorterDuff .Mode .MULTIPLY
63+ )
64+ mutualView.importantForAccessibility = View .IMPORTANT_FOR_ACCESSIBILITY_NO
65+
66+ val layoutHelperCreateFrame =
67+ findMethod(" org.telegram.ui.Components.LayoutHelper" ) {
68+ name == " createFrame" && parameterCount == 7
69+ }
70+ val tgIsRtl =
71+ findField(" org.telegram.messenger.LocaleController" ) { name == " isRTL" }
72+ .get(null ) as Boolean
73+ (it.thisObject as ViewGroup ).addView(
74+ mutualView,
75+ layoutHelperCreateFrame.invoke(
76+ null ,
77+ 40 , 40 ,
78+ (if (tgIsRtl) Gravity .START else Gravity .END ) or Gravity .CENTER_VERTICAL ,
79+ if (tgIsRtl) 8 else 0 , 0 ,
80+ if (tgIsRtl) 0 else 8 , 0
81+ ) as ViewGroup .LayoutParams
82+ )
83+ }
84+
85+ Log .dx(" ${MutualContactsBtnOption .javaClass.name} : before findUpdate" )
86+ findMethod(" org.telegram.ui.Cells.UserCell" ) { name == " update" }.hookAfter {
87+ val mutualView = (it.thisObject as ViewGroup ).findViewWithTag<ImageView >(MutualViewTag )
88+ ? : return @hookAfter
89+ val currObj = it.thisObject.findFieldObject { name == " currentObject" }
90+ try {
91+ if (currObj.getObject(" mutual_contact" ) as Boolean ) {
92+ mutualView.visibility = View .VISIBLE
93+ }
94+ } catch (e: Exception ) {
95+ Log .d(" ${MutualContactsBtnOption .javaClass.name} : findUpdate: seems that not a user object" )
96+ }
97+ }
98+ }
99+ }
0 commit comments