| 21 | import de.robv.android.xposed.XposedBridge; |
| 22 | |
| 23 | public class SettingEntryHook implements Initializable, ProfileActivityRowHook.Callback { |
| 24 | public static final SettingEntryHook INSTANCE = new SettingEntryHook(); |
| 25 | |
| 26 | private SettingEntryHook() { |
| 27 | } |
| 28 | |
| 29 | private static final String TMOE_SETTINGS_ROW = "TMOE_SETTINGS_ROW"; |
| 30 | private static final int TMOE_SETTINGS_ITEM_ID = 0x7F0E0001; |
| 31 | private static final int SETTINGS_ACTIVITY_LANGUAGE_ITEM_ID = 10; |
| 32 | private static final int SETTINGS_ACTIVITY_ICON_COLOR_TOP = 0xFFB07AF5; |
| 33 | private static final int SETTINGS_ACTIVITY_ICON_COLOR_BOTTOM = 0xFF8C57E8; |
| 34 | private static Method sSettingsCellFactoryMethod = null; |
| 35 | private static boolean sSettingsActivityHooked = false; |
| 36 | |
| 37 | private boolean mInitialized = false; |
| 38 | |
| 39 | @Override |
| 40 | public boolean initialize() { |
| 41 | if (mInitialized) { |
| 42 | return true; |
| 43 | } |
| 44 | ProfileActivityRowHook.addCallback(this); |
| 45 | hookSettingsActivityEntry(); |
| 46 | mInitialized = true; |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | private static void presentTMoeSettingsFragment(@NonNull Object parentFragment) { |
| 51 | ViewGroup parentLayout = ProxyFragmentRttiHandler.staticGetParentLayout(parentFragment); |
| 52 | if (parentLayout != null) { |
| 53 | ProxyFragmentRttiHandler.staticPresentFragment(parentLayout, new SettingsFragment(), false); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean onBindViewHolder(@NonNull String key, @NonNull Object holder, @NonNull Object adpater, @NonNull Object profileActivity) { |
| 59 | if (!TMOE_SETTINGS_ROW.equals(key)) { |
| 60 | return false; |
| 61 | } |
| 62 | FrameLayout textCell = (FrameLayout) Reflex.getInstanceObjectOrNull(holder, "itemView"); |
| 63 | if (textCell != null) { |
| 64 | // color and theme is already set by Telegram, we only need to set the text and icon |
| 65 | // textCell.setTextAndIcon(text, iconResId, true) |
| 66 | // inject resources |
| 67 | Parasitics.injectModuleResources(textCell.getContext().getResources()); |
| 68 | Parasitics.injectModuleResources(HostInfo.getApplication().getResources()); |
| 69 | String text = LocaleController.getString("TMoeSettings", R.string.TMoeSettings); |
| 70 | int iconResId = R.drawable.ic_setting_hex_outline_24; |
| 71 | try { |
| 72 | try { |
| 73 | Reflex.invokeVirtual(textCell, "setTextAndIcon", text, iconResId, true, |
| 74 | CharSequence.class, int.class, boolean.class, void.class); |
| 75 | } catch (NoSuchMethodException e) { |
| 76 | Reflex.invokeVirtual(textCell, "setTextAndIcon", text, iconResId, true, |
| 77 | String.class, int.class, boolean.class, void.class); |
| 78 | } |
| 79 | } catch (Throwable t) { |
| 80 | throw new RuntimeException(t); |
nothing calls this directly
no outgoing calls
no test coverage detected