Skip to content

Commit d2cc8fc

Browse files
authored
Merge pull request #92 from nexplorer-3e/patch/mutual-contact
feat & chore: add MutualContact, update action/cache to make github happy
2 parents 8f90918 + 9bb70ca commit d2cc8fc

10 files changed

Lines changed: 121 additions & 5 deletions

File tree

.github/workflows/pr_ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
cache: gradle
2929

3030
- name: Cache Gradle Dependencies
31-
uses: actions/cache@v3.2.4
31+
uses: actions/cache@v4
3232
with:
3333
path: |
3434
~/.gradle/caches
@@ -39,7 +39,7 @@ jobs:
3939
gradle-deps
4040
4141
- name: Cache Gradle Build
42-
uses: actions/cache@v3.2.4
42+
uses: actions/cache@v4
4343
with:
4444
path: |
4545
~/.gradle/caches/build-cache-*

.github/workflows/push_ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
cache: gradle
3131

3232
- name: Cache Gradle Dependencies
33-
uses: actions/cache@v3.2.4
33+
uses: actions/cache@v4
3434
with:
3535
path: |
3636
~/.gradle/caches
@@ -41,7 +41,7 @@ jobs:
4141
gradle-deps
4242
4343
- name: Cache Gradle Build
44-
uses: actions/cache@v3.2.4
44+
uses: actions/cache@v4
4545
with:
4646
path: |
4747
~/.gradle/caches/build-cache-*
@@ -131,7 +131,7 @@ jobs:
131131
git status telegram-bot-api >> telegram-bot-api-status
132132
- name: Cache Bot API Binary
133133
id: cache-bot-api
134-
uses: actions/cache@v3.2.4
134+
uses: actions/cache@v4
135135
with:
136136
path: telegram-bot-api-binary
137137
key: CI-telegram-bot-api-${{ hashFiles('telegram-bot-api-status') }}

app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ class SettingsFragment : BaseHierarchyFragment() {
138138
ShowIdInProfile, "ShowIdInProfile", R.string.ShowIdInProfile,
139139
"ShowIdInProfileDesc", R.string.ShowIdInProfileDesc
140140
)
141+
functionSwitch(
142+
MutualContactsBtnOption, "MutualContact", R.string.MutualContact
143+
)
141144
}
142145
category("LostMsgMitigation", R.string.LostMsgMitigation) {
143146
functionSwitch(
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="@android:color/white"
8+
android:pathData="M6.14,11.86l-2.78,2.79c-0.19,0.2 -0.19,0.51 0,0.71l2.78,2.79c0.31,0.32 0.85,0.09 0.85,-0.35L6.99,16L13,16c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L6.99,14v-1.79c0,-0.45 -0.54,-0.67 -0.85,-0.35zM20.65,8.65l-2.78,-2.79c-0.31,-0.32 -0.85,-0.09 -0.85,0.35L17.02,8L11,8c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h6.01v1.79c0,0.45 0.54,0.67 0.85,0.35l2.78,-2.79c0.2,-0.19 0.2,-0.51 0.01,-0.7z" />
9+
</vector>

app/src/main/res/values-es/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@
4141
<string name="AddReloadMsgBtnDesc">Añadir el botón de recarga de mensajes en el menú del chat</string>
4242
<string name="ForceBlurChatAvailable">Forzar la opción de desenfoque de la barra superior</string>
4343
<string name="DisablePremiumStickerAnimation">Desactivar la animación de pegatinas premium</string>
44+
<string name="MutualContact">Contacto mutuo</string>
4445
</resources>

app/src/main/res/values-ru/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<string name="MenuItem_HistoryMessage">История</string>
6161
<string name="MenuItem_RepeatMessage">Повторить</string>
6262
<string name="Misc">Дополнительные возможности</string>
63+
<string name="MutualContact">Общий контакт</string>
6364
<string name="NotEnabled">Не включен</string>
6465
<string name="NotImplemented">Еще не реализовано</string>
6566
<string name="ProhibitChannelSwitching">Запретить переключение каналов</string>

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@
9393
<string name="BuildVarsLogsEnabledDesc">参考 BuildVars.java 中的 LOGS_ENABLED(立即生效,重启失效)</string>
9494
<string name="DialogMsg_ConfirmDumpChannelMembers">拉取群成员列表?</string>
9595
<string name="FuckTrackingHookDesc">如果您点击Telegram提供的广告,他们会收集数据作为个性化广告的基础。此功能用于屏蔽个性化广告。</string>
96+
<string name="MutualContact">双向联系人</string>
9697
</resources>

app/src/main/res/values-zh-rTW/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@
9494
<string name="GroupOrChannelId">群組 / 频道 ID</string>
9595
<string name="UserId">使用者 ID</string>
9696
<string name="IdCopied">已複製</string>
97+
<string name="MutualContact">相互聯繫人</string>
9798
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@
9999
<string name="GroupOrChannelId">Group / Channel ID</string>
100100
<string name="UserId">User ID</string>
101101
<string name="IdCopied">Copied</string>
102+
<string name="MutualContact">Mutual Contact</string>
102103
</resources>

0 commit comments

Comments
 (0)