Skip to content

Commit

Permalink
feat: add ShowIdInProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed May 19, 2024
1 parent d4e0064 commit bce750d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 21 deletions.
40 changes: 39 additions & 1 deletion app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,41 @@ package cc.ioctl.tmoe.fragment

import android.widget.Toast
import cc.ioctl.tmoe.R
import cc.ioctl.tmoe.hook.func.*
import cc.ioctl.tmoe.hook.func.AddInfoContainer
import cc.ioctl.tmoe.hook.func.AddReloadMsgBtn
import cc.ioctl.tmoe.hook.func.AddSubItemChannel
import cc.ioctl.tmoe.hook.func.AntiAntiCopy
import cc.ioctl.tmoe.hook.func.AntiAntiForward
import cc.ioctl.tmoe.hook.func.ChannelDetailNumbers
import cc.ioctl.tmoe.hook.func.DatabaseCorruptionWarning
import cc.ioctl.tmoe.hook.func.DisableInstantCamera
import cc.ioctl.tmoe.hook.func.DisablePremiumStickerAnimation
import cc.ioctl.tmoe.hook.func.DumpGroupMember
import cc.ioctl.tmoe.hook.func.EnableDebugMode
import cc.ioctl.tmoe.hook.func.ExtendedOfflineSearch
import cc.ioctl.tmoe.hook.func.ForceBlurChatAvailable
import cc.ioctl.tmoe.hook.func.FuckTrackingHook
import cc.ioctl.tmoe.hook.func.HidePhoneNumber
import cc.ioctl.tmoe.hook.func.HidePremiumStickerSetTab
import cc.ioctl.tmoe.hook.func.HideServiceStories
import cc.ioctl.tmoe.hook.func.HideSponsoredMsg
import cc.ioctl.tmoe.hook.func.HideUserAvatar
import cc.ioctl.tmoe.hook.func.HistoricGroupMemberRecord
import cc.ioctl.tmoe.hook.func.HistoricalNewsOption
import cc.ioctl.tmoe.hook.func.KeepVideoMuted
import cc.ioctl.tmoe.hook.func.LocalGroupMemberList
import cc.ioctl.tmoe.hook.func.ProhibitChannelSwitching
import cc.ioctl.tmoe.hook.func.ProhibitChatGreetings
import cc.ioctl.tmoe.hook.func.ProhibitEnableReactions
import cc.ioctl.tmoe.hook.func.ProhibitSpoilers
import cc.ioctl.tmoe.hook.func.SendCommand
import cc.ioctl.tmoe.hook.func.ShowExactLastSeenTime
import cc.ioctl.tmoe.hook.func.ShowIdInProfile
import cc.ioctl.tmoe.hook.func.ShowMsgId
import cc.ioctl.tmoe.hook.func.TgnetLogControlStartupApplyHelper
import cc.ioctl.tmoe.hook.func.TgnetLogController
import cc.ioctl.tmoe.hook.func.UseSystemEmoji
import cc.ioctl.tmoe.hook.func.ViewTopicAsMsgByDefault
import cc.ioctl.tmoe.ui.LocaleController
import cc.ioctl.tmoe.ui.dsl.BaseHierarchyFragment
import cc.ioctl.tmoe.ui.dsl.HierarchyDescription
Expand Down Expand Up @@ -128,6 +162,10 @@ class SettingsFragment : BaseHierarchyFragment() {
functionSwitch(
HideServiceStories, "HideServiceStories", R.string.HideServiceStories
)
functionSwitch(
ShowIdInProfile, "ShowIdInProfile", R.string.ShowIdInProfile,
"ShowIdInProfileDesc", R.string.ShowIdInProfileDesc
)
}
category("LostMsgMitigation", R.string.LostMsgMitigation) {
functionSwitch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -83,7 +84,7 @@ public interface Callback {
* @param profileActivity
* @return true if handled, otherwise false
*/
boolean onBindViewHolder(String key, Object holder, Object adpater, Object profileActivity);
boolean onBindViewHolder(@NonNull String key, @NonNull Object holder, @NonNull Object adpater, @NonNull Object profileActivity);

/**
* getItemViewType
Expand All @@ -92,17 +93,17 @@ public interface Callback {
* @param profileActivity
* @return type, -1 to skip
*/
int getItemViewType(String key, Object adapter, Object profileActivity);
int getItemViewType(@NonNull String key, @NonNull Object adapter, @NonNull Object profileActivity);

/**
*
* @param key
* @param adapter
* @return true if handled, otherwise false
*/
boolean onItemClicked(String key, Object adapter, Object profileActivity);
boolean onItemClicked(@NonNull String key, @NonNull Object adapter, @NonNull Object profileActivity);

void onInsertRow(RowManipulator manipulator, Object profileActivity);
void onInsertRow(@NonNull RowManipulator manipulator, @NonNull Object profileActivity);
}

private static final List<Callback> sCallbacks = new ArrayList<>();
Expand Down
20 changes: 4 additions & 16 deletions app/src/main/java/cc/ioctl/tmoe/hook/core/SettingEntryHook.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package cc.ioctl.tmoe.hook.core;

import android.content.Context;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

import cc.ioctl.tmoe.R;
import cc.ioctl.tmoe.fragment.SettingsFragment;
import cc.ioctl.tmoe.lifecycle.Parasitics;
import cc.ioctl.tmoe.rtti.ProxyFragmentRttiHandler;
import cc.ioctl.tmoe.ui.LocaleController;
import cc.ioctl.tmoe.util.HostInfo;
import cc.ioctl.tmoe.util.Initiator;
import cc.ioctl.tmoe.util.Reflex;
import cc.ioctl.tmoe.util.Utils;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;

public class SettingEntryHook implements Initializable, ProfileActivityRowHook.Callback {
public static final SettingEntryHook INSTANCE = new SettingEntryHook();
Expand Down Expand Up @@ -54,7 +42,7 @@ private static void presentTMoeSettingsFragment(@NonNull Object parentFragment)
}

@Override
public boolean onBindViewHolder(String key, Object holder, Object adpater, Object profileActivity) {
public boolean onBindViewHolder(@NonNull String key, @NonNull Object holder, @NonNull Object adpater, @NonNull Object profileActivity) {
if (!TMOE_SETTINGS_ROW.equals(key)) return false;
FrameLayout textCell = (FrameLayout) Reflex.getInstanceObjectOrNull(holder, "itemView");
if (textCell != null) {
Expand Down Expand Up @@ -83,13 +71,13 @@ public boolean onBindViewHolder(String key, Object holder, Object adpater, Objec
}

@Override
public int getItemViewType(String key, Object adapter, Object profileActivity) {
public int getItemViewType(@NonNull String key, @NonNull Object adapter, @NonNull Object profileActivity) {
if (TMOE_SETTINGS_ROW.equals(key)) return 4;
return -1;
}

@Override
public boolean onItemClicked(String key, Object adapter, Object profileActivity) {
public boolean onItemClicked(@NonNull String key, @NonNull Object adapter, @NonNull Object profileActivity) {
if (TMOE_SETTINGS_ROW.equals(key)) {
presentTMoeSettingsFragment(profileActivity);
return false;
Expand All @@ -98,7 +86,7 @@ public boolean onItemClicked(String key, Object adapter, Object profileActivity)
}

@Override
public void onInsertRow(ProfileActivityRowHook.RowManipulator manipulator, Object profileActivity) {
public void onInsertRow(@NonNull ProfileActivityRowHook.RowManipulator manipulator, @NonNull Object profileActivity) {
// put our fields into the list just before the language row
int targetRow = manipulator.getRowIdForField("languageRow");
if (targetRow <= 0) {
Expand Down
81 changes: 81 additions & 0 deletions app/src/main/java/cc/ioctl/tmoe/hook/func/ShowIdInProfile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cc.ioctl.tmoe.hook.func

import android.content.ClipData
import android.content.ClipboardManager
import android.widget.FrameLayout
import android.widget.Toast
import cc.ioctl.tmoe.R
import cc.ioctl.tmoe.base.annotation.FunctionHookEntry
import cc.ioctl.tmoe.hook.base.CommonDynamicHook
import cc.ioctl.tmoe.hook.core.ProfileActivityRowHook
import cc.ioctl.tmoe.lifecycle.Parasitics
import cc.ioctl.tmoe.ui.LocaleController
import cc.ioctl.tmoe.util.HostInfo
import cc.ioctl.tmoe.util.Reflex
import de.robv.android.xposed.XposedHelpers

@FunctionHookEntry
object ShowIdInProfile : CommonDynamicHook(), ProfileActivityRowHook.Callback {
private val rowName = "SHOW_ID_IN_PROFILE"

override fun initOnce(): Boolean {
ProfileActivityRowHook.addCallback(this)
return true
}

override fun onBindViewHolder(
key: String,
holder: Any,
adpater: Any,
profileActivity: Any
): Boolean {
if (rowName != key) return false
(Reflex.getInstanceObjectOrNull(holder, "itemView") as? FrameLayout)?.let { textCell ->
Parasitics.injectModuleResources(HostInfo.getApplication().resources)
val userId = getUserId(profileActivity)
val realId = if (userId == 0L) getChatId(profileActivity) else userId
val isUser = userId != 0L
val title = if (isUser) LocaleController.getString("UserId", R.string.UserId)
else LocaleController.getString("GroupOrChannelId", R.string.GroupOrChannelId)
XposedHelpers.callMethod(textCell, "setTextAndValue", realId.toString(), title, false)
}
return true
}

override fun getItemViewType(key: String, adapter: Any, profileActivity: Any): Int {
if (rowName == key) return 2 // VIEW_TYPE_TEXT_DETAIL
return -1
}

override fun onItemClicked(key: String, adapter: Any, profileActivity: Any): Boolean {
if (rowName != key) return false
val userId = getUserId(profileActivity)
val realId = if (userId == 0L) getChatId(profileActivity) else userId
val context = HostInfo.getApplication()
context.getSystemService(ClipboardManager::class.java)
.setPrimaryClip(ClipData.newPlainText("", realId.toString()))
Toast.makeText(context, LocaleController.getString("IdCopied", R.string.IdCopied), Toast.LENGTH_SHORT).show()
return true
}

override fun onInsertRow(
manipulator: ProfileActivityRowHook.RowManipulator,
profileActivity: Any
) {
var row = manipulator.getRowIdForField("infoHeaderRow")
row = if (row == -1) 1 else row + 1
manipulator.insertRowAtPosition(rowName, row)
}

private fun getUserId(profileActivity: Any): Long {
return XposedHelpers.getObjectField(profileActivity, "userId") as Long
}

private fun getChatId(profileActivity: Any): Long {
val chat = XposedHelpers.getObjectField(profileActivity, "currentChat")
if (chat != null) {
return XposedHelpers.getObjectField(chat, "id") as Long
}
return 0L
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@
<string name="ShowExactLastSeenTimeDesc">仅对有权限查看用户最后上线时间的用户有效</string>
<string name="DisableInstantCamera">禁用即时相机</string>
<string name="HideServiceStories">隐藏“服务通知”的动态</string>
<string name="ShowIdInProfile">资料页显示 ID</string>
<string name="GroupOrChannelId">群聊 / 频道 ID</string>
<string name="UserId">用户 ID</string>
<string name="IdCopied">已复制</string>
<string name="ShowIdInProfileDesc">在用户、频道和群聊资料页面显示 ID</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@
<string name="FuckTrackingHookDesc">If you click on an ad provided by Telegram, they will track it and might use it as the basis for personalizing the ad.This function is to disable it</string>
<string name="DisableInstantCamera">Disable Instant Camera</string>
<string name="HideServiceStories">Hide stories from service notifications</string>
<string name="ShowIdInProfile">Show id in profile</string>
<string name="ShowIdInProfileDesc">Show id in profile page of user, chat or channel</string>
<string name="GroupOrChannelId">Group / Channel ID</string>
<string name="UserId">User ID</string>
<string name="IdCopied">Copied</string>
</resources>

0 comments on commit bce750d

Please sign in to comment.