Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
cache: gradle

- name: Cache Gradle Dependencies
uses: actions/cache@v3.2.4
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -39,7 +39,7 @@ jobs:
gradle-deps

- name: Cache Gradle Build
uses: actions/cache@v3.2.4
uses: actions/cache@v4
with:
path: |
~/.gradle/caches/build-cache-*
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cache: gradle

- name: Cache Gradle Dependencies
uses: actions/cache@v3.2.4
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -41,7 +41,7 @@ jobs:
gradle-deps

- name: Cache Gradle Build
uses: actions/cache@v3.2.4
uses: actions/cache@v4
with:
path: |
~/.gradle/caches/build-cache-*
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
git status telegram-bot-api >> telegram-bot-api-status
- name: Cache Bot API Binary
id: cache-bot-api
uses: actions/cache@v3.2.4
uses: actions/cache@v4
with:
path: telegram-bot-api-binary
key: CI-telegram-bot-api-${{ hashFiles('telegram-bot-api-status') }}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class SettingsFragment : BaseHierarchyFragment() {
ShowIdInProfile, "ShowIdInProfile", R.string.ShowIdInProfile,
"ShowIdInProfileDesc", R.string.ShowIdInProfileDesc
)
functionSwitch(
MutualContactsBtnOption, "MutualContact", R.string.MutualContact
)
}
category("LostMsgMitigation", R.string.LostMsgMitigation) {
functionSwitch(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package cc.ioctl.tmoe.hook.func

import android.content.Context
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import cc.ioctl.tmoe.R
import cc.ioctl.tmoe.base.annotation.FunctionHookEntry
import cc.ioctl.tmoe.hook.base.CommonDynamicHook
import cc.ioctl.tmoe.ui.LocaleController
import com.github.kyuubiran.ezxhelper.utils.*


@FunctionHookEntry
object MutualContactsBtnOption : CommonDynamicHook() {
object MutualViewTag
var needAddMutual: Boolean = false;
override fun initOnce(): Boolean = tryOrLogFalse {
val themeClzName = "org.telegram.ui.ActionBar.Theme"
val themeGetColor = findMethod(themeClzName) { name == "getColor" && parameterCount == 2 }
val themePlayerActionBarSelector =
findField(themeClzName) { name == "key_player_actionBarSelector" }.get(null) as Int
val themeWindowBackgroundWhiteGrayIcon =
findField(themeClzName) { name == "key_windowBackgroundWhiteGrayIcon" }.get(null) as Int
val themeCreateSelectorDrawable =
findMethod(themeClzName) { name == "createSelectorDrawable" }

Log.dx("${MutualContactsBtnOption.javaClass.name}: before onCreateViewHolder")
findMethod("org.telegram.ui.Adapters.ContactsAdapter") { name == "onCreateViewHolder" }.hookBefore {
needAddMutual = it.args[1] as Int == 0
}

Log.dx("${MutualContactsBtnOption.javaClass.name}: before findUserCell")
findConstructor("org.telegram.ui.Cells.UserCell") { parameterTypes.size == 6 }.hookAfter {
if (!isEnabled || !needAddMutual) return@hookAfter
if (it.args[5] != null && it.args[5].javaClass.canonicalName != "$themeClzName.ResourcesProvider") return@hookAfter // neko workaround
val context = it.args[0] as Context
val resourcesProvider = it.args[5]
Log.dx("${MutualContactsBtnOption.javaClass.name}: findUserCell: init mutual view")
val mutualView = ImageView(context)
mutualView.tag = MutualViewTag
mutualView.setImageResource(R.drawable.ic_round_swap_horiz_24)
mutualView.scaleType = ImageView.ScaleType.CENTER
mutualView.visibility = View.GONE
mutualView.contentDescription =
LocaleController.getString("MutualContact", R.string.MutualContact)
mutualView.background = themeCreateSelectorDrawable.invoke(
null,
themeGetColor.invoke(
null,
themePlayerActionBarSelector, resourcesProvider
)
) as Drawable
mutualView.colorFilter = PorterDuffColorFilter(
themeGetColor.invoke(
null,
themeWindowBackgroundWhiteGrayIcon, resourcesProvider
) as Int, PorterDuff.Mode.MULTIPLY
)
mutualView.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO

val layoutHelperCreateFrame =
findMethod("org.telegram.ui.Components.LayoutHelper") {
name == "createFrame" && parameterCount == 7
}
val tgIsRtl =
findField("org.telegram.messenger.LocaleController") { name == "isRTL" }
.get(null) as Boolean
(it.thisObject as ViewGroup).addView(
mutualView,
layoutHelperCreateFrame.invoke(
null,
40, 40,
(if (tgIsRtl) Gravity.START else Gravity.END) or Gravity.CENTER_VERTICAL,
if (tgIsRtl) 8 else 0, 0,
if (tgIsRtl) 0 else 8, 0
) as ViewGroup.LayoutParams
)
}

Log.dx("${MutualContactsBtnOption.javaClass.name}: before findUpdate")
findMethod("org.telegram.ui.Cells.UserCell") { name == "update" }.hookAfter {
val mutualView = (it.thisObject as ViewGroup).findViewWithTag<ImageView>(MutualViewTag)
?: return@hookAfter
val currObj = it.thisObject.findFieldObject { name == "currentObject" }
try {
if (currObj.getObject("mutual_contact") as Boolean) {
mutualView.visibility = View.VISIBLE
}
} catch (e: Exception) {
Log.d("${MutualContactsBtnOption.javaClass.name}: findUpdate: seems that not a user object")
}
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_round_swap_horiz_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
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" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
<string name="AddReloadMsgBtnDesc">Añadir el botón de recarga de mensajes en el menú del chat</string>
<string name="ForceBlurChatAvailable">Forzar la opción de desenfoque de la barra superior</string>
<string name="DisablePremiumStickerAnimation">Desactivar la animación de pegatinas premium</string>
<string name="MutualContact">Contacto mutuo</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<string name="MenuItem_HistoryMessage">История</string>
<string name="MenuItem_RepeatMessage">Повторить</string>
<string name="Misc">Дополнительные возможности</string>
<string name="MutualContact">Общий контакт</string>
<string name="NotEnabled">Не включен</string>
<string name="NotImplemented">Еще не реализовано</string>
<string name="ProhibitChannelSwitching">Запретить переключение каналов</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@
<string name="BuildVarsLogsEnabledDesc">参考 BuildVars.java 中的 LOGS_ENABLED(立即生效,重启失效)</string>
<string name="DialogMsg_ConfirmDumpChannelMembers">拉取群成员列表?</string>
<string name="FuckTrackingHookDesc">如果您点击Telegram提供的广告,他们会收集数据作为个性化广告的基础。此功能用于屏蔽个性化广告。</string>
<string name="MutualContact">双向联系人</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@
<string name="GroupOrChannelId">群組 / 频道 ID</string>
<string name="UserId">使用者 ID</string>
<string name="IdCopied">已複製</string>
<string name="MutualContact">相互聯繫人</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@
<string name="GroupOrChannelId">Group / Channel ID</string>
<string name="UserId">User ID</string>
<string name="IdCopied">Copied</string>
<string name="MutualContact">Mutual Contact</string>
</resources>